bacKED OUT cow
[linux-2.6.git] / patch-2.6.22.18-vs2.3.0.32.diff
1 diff -Nurp linux-2.6.22.18/arch/alpha/Kconfig linux-2.6.22.18-vs2.3.0.32/arch/alpha/Kconfig
2 --- linux-2.6.22.18/arch/alpha/Kconfig  2007-07-21 23:59:44.000000000 +0200
3 +++ linux-2.6.22.18-vs2.3.0.32/arch/alpha/Kconfig       2008-02-11 12:35:31.000000000 +0100
4 @@ -662,6 +662,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 -Nurp linux-2.6.22.18/arch/alpha/kernel/asm-offsets.c linux-2.6.22.18-vs2.3.0.32/arch/alpha/kernel/asm-offsets.c
14 --- linux-2.6.22.18/arch/alpha/kernel/asm-offsets.c     2006-06-18 03:49:35.000000000 +0200
15 +++ linux-2.6.22.18-vs2.3.0.32/arch/alpha/kernel/asm-offsets.c  2008-02-11 12:35:31.000000000 +0100
16 @@ -36,6 +36,7 @@ void foo(void)
17         DEFINE(PT_PTRACED, PT_PTRACED);
18         DEFINE(CLONE_VM, CLONE_VM);
19         DEFINE(CLONE_UNTRACED, CLONE_UNTRACED);
20 +       DEFINE(CLONE_KTHREAD, CLONE_KTHREAD);
21         DEFINE(SIGCHLD, SIGCHLD);
22         BLANK();
23  
24 diff -Nurp linux-2.6.22.18/arch/alpha/kernel/entry.S linux-2.6.22.18-vs2.3.0.32/arch/alpha/kernel/entry.S
25 --- linux-2.6.22.18/arch/alpha/kernel/entry.S   2007-07-21 23:59:44.000000000 +0200
26 +++ linux-2.6.22.18-vs2.3.0.32/arch/alpha/kernel/entry.S        2008-02-11 12:35:31.000000000 +0100
27 @@ -643,7 +643,7 @@ kernel_thread:
28         stq     $2, 152($sp)            /* HAE */
29  
30         /* Shuffle FLAGS to the front; add CLONE_VM.  */
31 -       ldi     $1, CLONE_VM|CLONE_UNTRACED
32 +       ldi     $1, CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD;
33         or      $18, $1, $16
34         bsr     $26, sys_clone
35  
36 @@ -872,24 +872,15 @@ sys_getxgid:
37         .globl  sys_getxpid
38         .ent    sys_getxpid
39  sys_getxpid:
40 +       lda     $sp, -16($sp)
41 +       stq     $26, 0($sp)
42         .prologue 0
43 -       ldq     $2, TI_TASK($8)
44  
45 -       /* See linux/kernel/timer.c sys_getppid for discussion
46 -          about this loop.  */
47 -       ldq     $3, TASK_GROUP_LEADER($2)
48 -       ldq     $4, TASK_REAL_PARENT($3)
49 -       ldl     $0, TASK_TGID($2)
50 -1:     ldl     $1, TASK_TGID($4)
51 -#ifdef CONFIG_SMP
52 -       mov     $4, $5
53 -       mb
54 -       ldq     $3, TASK_GROUP_LEADER($2)
55 -       ldq     $4, TASK_REAL_PARENT($3)
56 -       cmpeq   $4, $5, $5
57 -       beq     $5, 1b
58 -#endif
59 -       stq     $1, 80($sp)
60 +       lda     $16, 96($sp)
61 +       jsr     $26, do_getxpid
62 +       ldq     $26, 0($sp)
63 +
64 +       lda     $sp, 16($sp)
65         ret
66  .end sys_getxpid
67  
68 diff -Nurp linux-2.6.22.18/arch/alpha/kernel/osf_sys.c linux-2.6.22.18-vs2.3.0.32/arch/alpha/kernel/osf_sys.c
69 --- linux-2.6.22.18/arch/alpha/kernel/osf_sys.c 2007-07-21 23:59:44.000000000 +0200
70 +++ linux-2.6.22.18-vs2.3.0.32/arch/alpha/kernel/osf_sys.c      2008-02-11 12:35:31.000000000 +0100
71 @@ -883,7 +883,7 @@ osf_gettimeofday(struct timeval32 __user
72  {
73         if (tv) {
74                 struct timeval ktv;
75 -               do_gettimeofday(&ktv);
76 +               vx_gettimeofday(&ktv);
77                 if (put_tv32(tv, &ktv))
78                         return -EFAULT;
79         }
80 diff -Nurp linux-2.6.22.18/arch/alpha/kernel/ptrace.c linux-2.6.22.18-vs2.3.0.32/arch/alpha/kernel/ptrace.c
81 --- linux-2.6.22.18/arch/alpha/kernel/ptrace.c  2006-06-18 03:49:35.000000000 +0200
82 +++ linux-2.6.22.18-vs2.3.0.32/arch/alpha/kernel/ptrace.c       2008-02-11 12:35:31.000000000 +0100
83 @@ -15,6 +15,7 @@
84  #include <linux/slab.h>
85  #include <linux/security.h>
86  #include <linux/signal.h>
87 +#include <linux/vs_base.h>
88  
89  #include <asm/uaccess.h>
90  #include <asm/pgtable.h>
91 @@ -283,6 +284,11 @@ do_sys_ptrace(long request, long pid, lo
92                 goto out_notsk;
93         }
94  
95 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT)) {
96 +               ret = -EPERM;
97 +               goto out;
98 +       }
99 +
100         if (request == PTRACE_ATTACH) {
101                 ret = ptrace_attach(child);
102                 goto out;
103 diff -Nurp linux-2.6.22.18/arch/alpha/kernel/semaphore.c linux-2.6.22.18-vs2.3.0.32/arch/alpha/kernel/semaphore.c
104 --- linux-2.6.22.18/arch/alpha/kernel/semaphore.c       2006-06-18 03:49:35.000000000 +0200
105 +++ linux-2.6.22.18-vs2.3.0.32/arch/alpha/kernel/semaphore.c    2008-02-11 12:35:31.000000000 +0100
106 @@ -68,8 +68,8 @@ __down_failed(struct semaphore *sem)
107         DECLARE_WAITQUEUE(wait, tsk);
108  
109  #ifdef CONFIG_DEBUG_SEMAPHORE
110 -       printk("%s(%d): down failed(%p)\n",
111 -              tsk->comm, tsk->pid, sem);
112 +       printk("%s(%d:#%u): down failed(%p)\n",
113 +              tsk->comm, tsk->pid, tsk->xid, sem);
114  #endif
115  
116         tsk->state = TASK_UNINTERRUPTIBLE;
117 @@ -97,8 +97,8 @@ __down_failed(struct semaphore *sem)
118         wake_up(&sem->wait);
119  
120  #ifdef CONFIG_DEBUG_SEMAPHORE
121 -       printk("%s(%d): down acquired(%p)\n",
122 -              tsk->comm, tsk->pid, sem);
123 +       printk("%s(%d:#%u): down acquired(%p)\n",
124 +              tsk->comm, tsk->pid, tsk->xid, sem);
125  #endif
126  }
127  
128 @@ -110,8 +110,8 @@ __down_failed_interruptible(struct semap
129         long ret = 0;
130  
131  #ifdef CONFIG_DEBUG_SEMAPHORE
132 -       printk("%s(%d): down failed(%p)\n",
133 -              tsk->comm, tsk->pid, sem);
134 +       printk("%s(%d:#%u): down failed(%p)\n",
135 +              tsk->comm, tsk->pid, tsk->xid, sem);
136  #endif
137  
138         tsk->state = TASK_INTERRUPTIBLE;
139 diff -Nurp linux-2.6.22.18/arch/alpha/kernel/systbls.S linux-2.6.22.18-vs2.3.0.32/arch/alpha/kernel/systbls.S
140 --- linux-2.6.22.18/arch/alpha/kernel/systbls.S 2007-07-21 23:59:44.000000000 +0200
141 +++ linux-2.6.22.18-vs2.3.0.32/arch/alpha/kernel/systbls.S      2008-02-11 12:35:31.000000000 +0100
142 @@ -446,7 +446,7 @@ sys_call_table:
143         .quad sys_stat64                        /* 425 */
144         .quad sys_lstat64
145         .quad sys_fstat64
146 -       .quad sys_ni_syscall                    /* sys_vserver */
147 +       .quad sys_vserver                       /* sys_vserver */
148         .quad sys_ni_syscall                    /* sys_mbind */
149         .quad sys_ni_syscall                    /* sys_get_mempolicy */
150         .quad sys_ni_syscall                    /* sys_set_mempolicy */
151 diff -Nurp linux-2.6.22.18/arch/alpha/kernel/traps.c linux-2.6.22.18-vs2.3.0.32/arch/alpha/kernel/traps.c
152 --- linux-2.6.22.18/arch/alpha/kernel/traps.c   2007-05-04 15:55:03.000000000 +0200
153 +++ linux-2.6.22.18-vs2.3.0.32/arch/alpha/kernel/traps.c        2008-02-11 12:35:31.000000000 +0100
154 @@ -182,7 +182,8 @@ die_if_kernel(char * str, struct pt_regs
155  #ifdef CONFIG_SMP
156         printk("CPU %d ", hard_smp_processor_id());
157  #endif
158 -       printk("%s(%d): %s %ld\n", current->comm, current->pid, str, err);
159 +       printk("%s(%d[#%u]): %s %ld\n", current->comm,
160 +               current->pid, current->xid, str, err);
161         dik_show_regs(regs, r9_15);
162         dik_show_trace((unsigned long *)(regs+1));
163         dik_show_code((unsigned int *)regs->pc);
164 diff -Nurp linux-2.6.22.18/arch/alpha/mm/fault.c linux-2.6.22.18-vs2.3.0.32/arch/alpha/mm/fault.c
165 --- linux-2.6.22.18/arch/alpha/mm/fault.c       2007-07-21 23:59:44.000000000 +0200
166 +++ linux-2.6.22.18-vs2.3.0.32/arch/alpha/mm/fault.c    2008-02-11 12:35:31.000000000 +0100
167 @@ -197,8 +197,8 @@ do_page_fault(unsigned long address, uns
168                 down_read(&mm->mmap_sem);
169                 goto survive;
170         }
171 -       printk(KERN_ALERT "VM: killing process %s(%d)\n",
172 -              current->comm, current->pid);
173 +       printk(KERN_ALERT "VM: killing process %s(%d:#%u)\n",
174 +              current->comm, current->pid, current->xid);
175         if (!user_mode(regs))
176                 goto no_context;
177         do_exit(SIGKILL);
178 diff -Nurp linux-2.6.22.18/arch/arm/Kconfig linux-2.6.22.18-vs2.3.0.32/arch/arm/Kconfig
179 --- linux-2.6.22.18/arch/arm/Kconfig    2007-07-21 23:59:44.000000000 +0200
180 +++ linux-2.6.22.18-vs2.3.0.32/arch/arm/Kconfig 2008-02-11 12:35:31.000000000 +0100
181 @@ -1042,6 +1042,8 @@ source "arch/arm/oprofile/Kconfig"
182  
183  source "arch/arm/Kconfig.debug"
184  
185 +source "kernel/vserver/Kconfig"
186 +
187  source "security/Kconfig"
188  
189  source "crypto/Kconfig"
190 diff -Nurp linux-2.6.22.18/arch/arm/kernel/calls.S linux-2.6.22.18-vs2.3.0.32/arch/arm/kernel/calls.S
191 --- linux-2.6.22.18/arch/arm/kernel/calls.S     2007-07-21 23:59:44.000000000 +0200
192 +++ linux-2.6.22.18-vs2.3.0.32/arch/arm/kernel/calls.S  2008-02-11 12:35:31.000000000 +0100
193 @@ -322,7 +322,7 @@
194  /* 310 */      CALL(sys_request_key)
195                 CALL(sys_keyctl)
196                 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
197 -/* vserver */  CALL(sys_ni_syscall)
198 +               CALL(sys_vserver)
199                 CALL(sys_ioprio_set)
200  /* 315 */      CALL(sys_ioprio_get)
201                 CALL(sys_inotify_init)
202 diff -Nurp linux-2.6.22.18/arch/arm/kernel/process.c linux-2.6.22.18-vs2.3.0.32/arch/arm/kernel/process.c
203 --- linux-2.6.22.18/arch/arm/kernel/process.c   2007-07-21 23:59:44.000000000 +0200
204 +++ linux-2.6.22.18-vs2.3.0.32/arch/arm/kernel/process.c        2008-02-11 12:35:31.000000000 +0100
205 @@ -261,7 +261,8 @@ void __show_regs(struct pt_regs *regs)
206  void show_regs(struct pt_regs * regs)
207  {
208         printk("\n");
209 -       printk("Pid: %d, comm: %20s\n", current->pid, current->comm);
210 +       printk("Pid: %d[#%u], comm: %20s\n",
211 +               current->pid, current->xid, current->comm);
212         __show_regs(regs);
213         __backtrace();
214  }
215 @@ -423,7 +424,8 @@ pid_t kernel_thread(int (*fn)(void *), v
216         regs.ARM_pc = (unsigned long)kernel_thread_helper;
217         regs.ARM_cpsr = SVC_MODE;
218  
219 -       return do_fork(flags|CLONE_VM|CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
220 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
221 +               0, &regs, 0, NULL, NULL);
222  }
223  EXPORT_SYMBOL(kernel_thread);
224  
225 diff -Nurp linux-2.6.22.18/arch/arm/kernel/traps.c linux-2.6.22.18-vs2.3.0.32/arch/arm/kernel/traps.c
226 --- linux-2.6.22.18/arch/arm/kernel/traps.c     2007-07-21 23:59:44.000000000 +0200
227 +++ linux-2.6.22.18-vs2.3.0.32/arch/arm/kernel/traps.c  2008-02-11 12:35:31.000000000 +0100
228 @@ -222,8 +222,8 @@ static void __die(const char *str, int e
229                str, err, ++die_counter);
230         print_modules();
231         __show_regs(regs);
232 -       printk("Process %s (pid: %d, stack limit = 0x%p)\n",
233 -               tsk->comm, tsk->pid, thread + 1);
234 +       printk("Process %s (pid: %d:#%u, stack limit = 0x%p)\n",
235 +               tsk->comm, tsk->pid, tsk->xid, thread + 1);
236  
237         if (!user_mode(regs) || in_interrupt()) {
238                 dump_mem("Stack: ", regs->ARM_sp,
239 diff -Nurp linux-2.6.22.18/arch/arm/mm/fault.c linux-2.6.22.18-vs2.3.0.32/arch/arm/mm/fault.c
240 --- linux-2.6.22.18/arch/arm/mm/fault.c 2007-07-21 23:59:44.000000000 +0200
241 +++ linux-2.6.22.18-vs2.3.0.32/arch/arm/mm/fault.c      2008-02-11 12:35:31.000000000 +0100
242 @@ -266,7 +266,8 @@ do_page_fault(unsigned long addr, unsign
243                  * happened to us that made us unable to handle
244                  * the page fault gracefully.
245                  */
246 -               printk("VM: killing process %s\n", tsk->comm);
247 +               printk("VM: killing process %s(%d:#%u)\n",
248 +                       tsk->comm, tsk->pid, tsk->xid);
249                 do_exit(SIGKILL);
250                 return 0;
251  
252 diff -Nurp linux-2.6.22.18/arch/arm26/Kconfig linux-2.6.22.18-vs2.3.0.32/arch/arm26/Kconfig
253 --- linux-2.6.22.18/arch/arm26/Kconfig  2007-07-21 23:59:44.000000000 +0200
254 +++ linux-2.6.22.18-vs2.3.0.32/arch/arm26/Kconfig       2008-02-11 12:35:31.000000000 +0100
255 @@ -243,6 +243,8 @@ source "drivers/usb/Kconfig"
256  
257  source "arch/arm26/Kconfig.debug"
258  
259 +source "kernel/vserver/Kconfig"
260 +
261  source "security/Kconfig"
262  
263  source "crypto/Kconfig"
264 diff -Nurp linux-2.6.22.18/arch/arm26/kernel/calls.S linux-2.6.22.18-vs2.3.0.32/arch/arm26/kernel/calls.S
265 --- linux-2.6.22.18/arch/arm26/kernel/calls.S   2006-06-18 03:49:35.000000000 +0200
266 +++ linux-2.6.22.18-vs2.3.0.32/arch/arm26/kernel/calls.S        2008-02-11 12:35:31.000000000 +0100
267 @@ -257,6 +257,11 @@ __syscall_start:
268                 .long   sys_lremovexattr
269                 .long   sys_fremovexattr
270                 .long   sys_tkill
271 +
272 +               .rept   313 - (. - __syscall_start) / 4
273 +                       .long   sys_ni_syscall
274 +               .endr
275 +               .long   sys_vserver     /* 313 */
276  __syscall_end:
277  
278                 .rept   NR_syscalls - (__syscall_end - __syscall_start) / 4
279 diff -Nurp linux-2.6.22.18/arch/arm26/kernel/process.c linux-2.6.22.18-vs2.3.0.32/arch/arm26/kernel/process.c
280 --- linux-2.6.22.18/arch/arm26/kernel/process.c 2007-05-04 15:55:07.000000000 +0200
281 +++ linux-2.6.22.18-vs2.3.0.32/arch/arm26/kernel/process.c      2008-02-11 12:35:31.000000000 +0100
282 @@ -365,7 +365,8 @@ pid_t kernel_thread(int (*fn)(void *), v
283          regs.ARM_r3 = (unsigned long)do_exit;
284          regs.ARM_pc = (unsigned long)kernel_thread_helper | MODE_SVC26;
285  
286 -        return do_fork(flags|CLONE_VM|CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
287 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
288 +               0, &regs, 0, NULL, NULL);
289  }
290  EXPORT_SYMBOL(kernel_thread);
291  
292 diff -Nurp linux-2.6.22.18/arch/arm26/kernel/traps.c linux-2.6.22.18-vs2.3.0.32/arch/arm26/kernel/traps.c
293 --- linux-2.6.22.18/arch/arm26/kernel/traps.c   2007-05-04 15:55:07.000000000 +0200
294 +++ linux-2.6.22.18-vs2.3.0.32/arch/arm26/kernel/traps.c        2008-02-11 12:35:31.000000000 +0100
295 @@ -185,8 +185,9 @@ NORET_TYPE void die(const char *str, str
296         printk("Internal error: %s: %x\n", str, err);
297         printk("CPU: %d\n", smp_processor_id());
298         show_regs(regs);
299 -       printk("Process %s (pid: %d, stack limit = 0x%p)\n",
300 -               current->comm, current->pid, end_of_stack(tsk));
301 +       printk("Process %s (pid: %d[#%u], stack limit = 0x%p)\n",
302 +               current->comm, current->pid,
303 +               current->xid, end_of_stack(tsk));
304  
305         if (!user_mode(regs) || in_interrupt()) {
306                 __dump_stack(tsk, (unsigned long)(regs + 1));
307 diff -Nurp linux-2.6.22.18/arch/cris/arch-v10/kernel/process.c linux-2.6.22.18-vs2.3.0.32/arch/cris/arch-v10/kernel/process.c
308 --- linux-2.6.22.18/arch/cris/arch-v10/kernel/process.c 2007-05-04 15:55:07.000000000 +0200
309 +++ linux-2.6.22.18-vs2.3.0.32/arch/cris/arch-v10/kernel/process.c      2008-02-11 12:35:31.000000000 +0100
310 @@ -103,7 +103,8 @@ int kernel_thread(int (*fn)(void *), voi
311         regs.dccr = 1 << I_DCCR_BITNR;
312  
313         /* Ok, create the new process.. */
314 -        return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
315 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
316 +               0, &regs, 0, NULL, NULL);
317  }
318  
319  /* setup the child's kernel stack with a pt_regs and switch_stack on it.
320 diff -Nurp linux-2.6.22.18/arch/cris/arch-v32/kernel/process.c linux-2.6.22.18-vs2.3.0.32/arch/cris/arch-v32/kernel/process.c
321 --- linux-2.6.22.18/arch/cris/arch-v32/kernel/process.c 2007-05-04 15:55:07.000000000 +0200
322 +++ linux-2.6.22.18-vs2.3.0.32/arch/cris/arch-v32/kernel/process.c      2008-02-11 12:35:31.000000000 +0100
323 @@ -120,7 +120,8 @@ kernel_thread(int (*fn)(void *), void * 
324         regs.ccs = 1 << (I_CCS_BITNR + CCS_SHIFT);
325  
326         /* Create the new process. */
327 -        return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
328 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
329 +               0, &regs, 0, NULL, NULL);
330  }
331  
332  /*
333 diff -Nurp linux-2.6.22.18/arch/cris/Kconfig linux-2.6.22.18-vs2.3.0.32/arch/cris/Kconfig
334 --- linux-2.6.22.18/arch/cris/Kconfig   2007-07-21 23:58:14.000000000 +0200
335 +++ linux-2.6.22.18-vs2.3.0.32/arch/cris/Kconfig        2008-02-11 12:35:31.000000000 +0100
336 @@ -200,6 +200,8 @@ source "drivers/usb/Kconfig"
337  
338  source "arch/cris/Kconfig.debug"
339  
340 +source "kernel/vserver/Kconfig"
341 +
342  source "security/Kconfig"
343  
344  source "crypto/Kconfig"
345 diff -Nurp linux-2.6.22.18/arch/frv/kernel/kernel_thread.S linux-2.6.22.18-vs2.3.0.32/arch/frv/kernel/kernel_thread.S
346 --- linux-2.6.22.18/arch/frv/kernel/kernel_thread.S     2006-06-18 03:49:35.000000000 +0200
347 +++ linux-2.6.22.18-vs2.3.0.32/arch/frv/kernel/kernel_thread.S  2008-02-11 12:35:31.000000000 +0100
348 @@ -13,6 +13,8 @@
349  #include <asm/unistd.h>
350  
351  #define CLONE_VM       0x00000100      /* set if VM shared between processes */
352 +#define CLONE_KTHREAD  0x10000000      /* kernel thread */
353 +#define CLONE_KT       (CLONE_VM | CLONE_KTHREAD)      /* kernel thread flags */
354  #define        KERN_ERR        "<3>"
355  
356         .section .rodata
357 @@ -37,7 +39,7 @@ kernel_thread:
358  
359         # start by forking the current process, but with shared VM
360         setlos.p        #__NR_clone,gr7         ; syscall number
361 -       ori             gr10,#CLONE_VM,gr8      ; first syscall arg     [clone_flags]
362 +       ori             gr10,#CLONE_KT,gr8      ; first syscall arg     [clone_flags]
363         sethi.p         #0xe4e4,gr9             ; second syscall arg    [newsp]
364         setlo           #0xe4e4,gr9
365         setlos.p        #0,gr10                 ; third syscall arg     [parent_tidptr]
366 diff -Nurp linux-2.6.22.18/arch/h8300/Kconfig linux-2.6.22.18-vs2.3.0.32/arch/h8300/Kconfig
367 --- linux-2.6.22.18/arch/h8300/Kconfig  2007-07-21 23:59:44.000000000 +0200
368 +++ linux-2.6.22.18-vs2.3.0.32/arch/h8300/Kconfig       2008-02-11 12:35:32.000000000 +0100
369 @@ -222,6 +222,8 @@ source "fs/Kconfig"
370  
371  source "arch/h8300/Kconfig.debug"
372  
373 +source "kernel/vserver/Kconfig"
374 +
375  source "security/Kconfig"
376  
377  source "crypto/Kconfig"
378 diff -Nurp linux-2.6.22.18/arch/h8300/kernel/process.c linux-2.6.22.18-vs2.3.0.32/arch/h8300/kernel/process.c
379 --- linux-2.6.22.18/arch/h8300/kernel/process.c 2007-05-04 15:55:07.000000000 +0200
380 +++ linux-2.6.22.18-vs2.3.0.32/arch/h8300/kernel/process.c      2008-02-11 12:35:32.000000000 +0100
381 @@ -134,7 +134,7 @@ int kernel_thread(int (*fn)(void *), voi
382  
383         fs = get_fs();
384         set_fs (KERNEL_DS);
385 -       clone_arg = flags | CLONE_VM;
386 +       clone_arg = flags | CLONE_VM | CLONE_KTHREAD;
387         __asm__("mov.l sp,er3\n\t"
388                 "sub.l er2,er2\n\t"
389                 "mov.l %2,er1\n\t"
390 diff -Nurp linux-2.6.22.18/arch/i386/Kconfig linux-2.6.22.18-vs2.3.0.32/arch/i386/Kconfig
391 --- linux-2.6.22.18/arch/i386/Kconfig   2007-07-21 23:59:44.000000000 +0200
392 +++ linux-2.6.22.18-vs2.3.0.32/arch/i386/Kconfig        2008-02-11 12:35:32.000000000 +0100
393 @@ -1230,6 +1230,8 @@ endmenu
394  
395  source "arch/i386/Kconfig.debug"
396  
397 +source "kernel/vserver/Kconfig"
398 +
399  source "security/Kconfig"
400  
401  source "crypto/Kconfig"
402 diff -Nurp linux-2.6.22.18/arch/i386/kernel/process.c linux-2.6.22.18-vs2.3.0.32/arch/i386/kernel/process.c
403 --- linux-2.6.22.18/arch/i386/kernel/process.c  2007-07-21 23:59:45.000000000 +0200
404 +++ linux-2.6.22.18-vs2.3.0.32/arch/i386/kernel/process.c       2008-02-11 12:35:32.000000000 +0100
405 @@ -302,8 +302,10 @@ void show_regs(struct pt_regs * regs)
406         unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L;
407  
408         printk("\n");
409 -       printk("Pid: %d, comm: %20s\n", current->pid, current->comm);
410 -       printk("EIP: %04x:[<%08lx>] CPU: %d\n",0xffff & regs->xcs,regs->eip, smp_processor_id());
411 +       printk("Pid: %d[#%u], comm: %20s\n",
412 +               current->pid, current->xid, current->comm);
413 +       printk("EIP: %04x:[<%08lx>] CPU: %d\n",
414 +               0xffff & regs->xcs,regs->eip, smp_processor_id());
415         print_symbol("EIP is at %s\n", regs->eip);
416  
417         if (user_mode_vm(regs))
418 @@ -355,7 +357,8 @@ int kernel_thread(int (*fn)(void *), voi
419         regs.eflags = X86_EFLAGS_IF | X86_EFLAGS_SF | X86_EFLAGS_PF | 0x2;
420  
421         /* Ok, create the new process.. */
422 -       return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
423 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
424 +               0, &regs, 0, NULL, NULL);
425  }
426  EXPORT_SYMBOL(kernel_thread);
427  
428 diff -Nurp linux-2.6.22.18/arch/i386/kernel/syscall_table.S linux-2.6.22.18-vs2.3.0.32/arch/i386/kernel/syscall_table.S
429 --- linux-2.6.22.18/arch/i386/kernel/syscall_table.S    2007-07-21 23:59:45.000000000 +0200
430 +++ linux-2.6.22.18-vs2.3.0.32/arch/i386/kernel/syscall_table.S 2008-02-11 12:35:32.000000000 +0100
431 @@ -272,7 +272,7 @@ ENTRY(sys_call_table)
432         .long sys_tgkill        /* 270 */
433         .long sys_utimes
434         .long sys_fadvise64_64
435 -       .long sys_ni_syscall    /* sys_vserver */
436 +       .long sys_vserver
437         .long sys_mbind
438         .long sys_get_mempolicy
439         .long sys_set_mempolicy
440 diff -Nurp linux-2.6.22.18/arch/i386/kernel/sysenter.c linux-2.6.22.18-vs2.3.0.32/arch/i386/kernel/sysenter.c
441 --- linux-2.6.22.18/arch/i386/kernel/sysenter.c 2007-08-26 03:38:36.000000000 +0200
442 +++ linux-2.6.22.18-vs2.3.0.32/arch/i386/kernel/sysenter.c      2008-02-11 12:35:32.000000000 +0100
443 @@ -17,6 +17,7 @@
444  #include <linux/elf.h>
445  #include <linux/mm.h>
446  #include <linux/module.h>
447 +#include <linux/vs_memory.h>
448  
449  #include <asm/cpufeature.h>
450  #include <asm/msr.h>
451 diff -Nurp linux-2.6.22.18/arch/i386/kernel/traps.c linux-2.6.22.18-vs2.3.0.32/arch/i386/kernel/traps.c
452 --- linux-2.6.22.18/arch/i386/kernel/traps.c    2007-07-21 23:59:45.000000000 +0200
453 +++ linux-2.6.22.18-vs2.3.0.32/arch/i386/kernel/traps.c 2008-02-11 12:35:32.000000000 +0100
454 @@ -56,6 +56,8 @@
455  #include <asm/stacktrace.h>
456  
457  #include <linux/module.h>
458 +#include <linux/vs_context.h>
459 +#include <linux/vserver/history.h>
460  
461  #include "mach_traps.h"
462  
463 @@ -303,8 +305,8 @@ void show_registers(struct pt_regs *regs
464                 regs->esi, regs->edi, regs->ebp, esp);
465         printk(KERN_EMERG "ds: %04x   es: %04x   fs: %04x  gs: %04x  ss: %04x\n",
466                regs->xds & 0xffff, regs->xes & 0xffff, regs->xfs & 0xffff, gs, ss);
467 -       printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)",
468 -               TASK_COMM_LEN, current->comm, current->pid,
469 +       printk(KERN_EMERG "Process %.*s (pid: %d[#%u], ti=%p task=%p task.ti=%p)",
470 +               TASK_COMM_LEN, current->comm, current->pid, current->xid,
471                 current_thread_info(), current, task_thread_info(current));
472         /*
473          * When in-kernel, we also print out the stack and code at the
474 @@ -375,6 +377,8 @@ void die(const char * str, struct pt_reg
475  
476         oops_enter();
477  
478 +       vxh_throw_oops();
479 +
480         if (die.lock_owner != raw_smp_processor_id()) {
481                 console_verbose();
482                 spin_lock_irqsave(&die.lock, flags);
483 @@ -412,9 +416,9 @@ void die(const char * str, struct pt_reg
484                 if (nl)
485                         printk("\n");
486                 if (notify_die(DIE_OOPS, str, regs, err,
487 -                                       current->thread.trap_no, SIGSEGV) !=
488 -                               NOTIFY_STOP) {
489 +                       current->thread.trap_no, SIGSEGV) != NOTIFY_STOP) {
490                         show_registers(regs);
491 +                       vxh_dump_history();
492                         /* Executive summary in case the oops scrolled away */
493                         esp = (unsigned long) (&regs->esp);
494                         savesegment(ss, ss);
495 diff -Nurp linux-2.6.22.18/arch/i386/mm/fault.c linux-2.6.22.18-vs2.3.0.32/arch/i386/mm/fault.c
496 --- linux-2.6.22.18/arch/i386/mm/fault.c        2007-09-05 07:07:59.000000000 +0200
497 +++ linux-2.6.22.18-vs2.3.0.32/arch/i386/mm/fault.c     2008-02-11 12:35:32.000000000 +0100
498 @@ -587,7 +587,8 @@ out_of_memory:
499                 down_read(&mm->mmap_sem);
500                 goto survive;
501         }
502 -       printk("VM: killing process %s\n", tsk->comm);
503 +       printk("VM: killing process %s(%d:#%u)\n",
504 +               tsk->comm, tsk->pid, tsk->xid);
505         if (error_code & 4)
506                 do_exit(SIGKILL);
507         goto no_context;
508 diff -Nurp linux-2.6.22.18/arch/ia64/ia32/binfmt_elf32.c linux-2.6.22.18-vs2.3.0.32/arch/ia64/ia32/binfmt_elf32.c
509 --- linux-2.6.22.18/arch/ia64/ia32/binfmt_elf32.c       2007-07-21 23:58:15.000000000 +0200
510 +++ linux-2.6.22.18-vs2.3.0.32/arch/ia64/ia32/binfmt_elf32.c    2008-02-11 12:35:32.000000000 +0100
511 @@ -233,7 +233,8 @@ ia32_setup_arg_pages (struct linux_binpr
512                         kmem_cache_free(vm_area_cachep, mpnt);
513                         return ret;
514                 }
515 -               current->mm->stack_vm = current->mm->total_vm = vma_pages(mpnt);
516 +               vx_vmpages_sub(current->mm, current->mm->total_vm - vma_pages(mpnt));
517 +               current->mm->stack_vm = current->mm->total_vm;
518         }
519  
520         for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
521 diff -Nurp linux-2.6.22.18/arch/ia64/ia32/ia32_entry.S linux-2.6.22.18-vs2.3.0.32/arch/ia64/ia32/ia32_entry.S
522 --- linux-2.6.22.18/arch/ia64/ia32/ia32_entry.S 2007-07-21 23:59:45.000000000 +0200
523 +++ linux-2.6.22.18-vs2.3.0.32/arch/ia64/ia32/ia32_entry.S      2008-02-11 12:35:32.000000000 +0100
524 @@ -446,7 +446,7 @@ ia32_syscall_table:
525         data8 sys_tgkill        /* 270 */
526         data8 compat_sys_utimes
527         data8 sys32_fadvise64_64
528 -       data8 sys_ni_syscall
529 +       data8 sys32_vserver
530         data8 sys_ni_syscall
531         data8 sys_ni_syscall    /* 275 */
532         data8 sys_ni_syscall
533 diff -Nurp linux-2.6.22.18/arch/ia64/ia32/sys_ia32.c linux-2.6.22.18-vs2.3.0.32/arch/ia64/ia32/sys_ia32.c
534 --- linux-2.6.22.18/arch/ia64/ia32/sys_ia32.c   2007-07-21 23:58:15.000000000 +0200
535 +++ linux-2.6.22.18-vs2.3.0.32/arch/ia64/ia32/sys_ia32.c        2008-02-11 12:35:32.000000000 +0100
536 @@ -1182,7 +1182,7 @@ sys32_gettimeofday (struct compat_timeva
537  {
538         if (tv) {
539                 struct timeval ktv;
540 -               do_gettimeofday(&ktv);
541 +               vx_gettimeofday(&ktv);
542                 if (put_tv32(tv, &ktv))
543                         return -EFAULT;
544         }
545 diff -Nurp linux-2.6.22.18/arch/ia64/Kconfig linux-2.6.22.18-vs2.3.0.32/arch/ia64/Kconfig
546 --- linux-2.6.22.18/arch/ia64/Kconfig   2007-07-21 23:59:45.000000000 +0200
547 +++ linux-2.6.22.18-vs2.3.0.32/arch/ia64/Kconfig        2008-02-11 12:35:32.000000000 +0100
548 @@ -592,6 +592,8 @@ endmenu
549  
550  source "arch/ia64/Kconfig.debug"
551  
552 +source "kernel/vserver/Kconfig"
553 +
554  source "security/Kconfig"
555  
556  source "crypto/Kconfig"
557 diff -Nurp linux-2.6.22.18/arch/ia64/kernel/asm-offsets.c linux-2.6.22.18-vs2.3.0.32/arch/ia64/kernel/asm-offsets.c
558 --- linux-2.6.22.18/arch/ia64/kernel/asm-offsets.c      2007-07-21 23:58:15.000000000 +0200
559 +++ linux-2.6.22.18-vs2.3.0.32/arch/ia64/kernel/asm-offsets.c   2008-02-11 12:35:32.000000000 +0100
560 @@ -192,6 +192,7 @@ void foo(void)
561      /* for assembly files which can't include sched.h: */
562         DEFINE(IA64_CLONE_VFORK, CLONE_VFORK);
563         DEFINE(IA64_CLONE_VM, CLONE_VM);
564 +       DEFINE(IA64_CLONE_KTHREAD, CLONE_KTHREAD);
565  
566         BLANK();
567         DEFINE(IA64_CPUINFO_NSEC_PER_CYC_OFFSET,
568 diff -Nurp linux-2.6.22.18/arch/ia64/kernel/entry.S linux-2.6.22.18-vs2.3.0.32/arch/ia64/kernel/entry.S
569 --- linux-2.6.22.18/arch/ia64/kernel/entry.S    2007-07-21 23:59:45.000000000 +0200
570 +++ linux-2.6.22.18-vs2.3.0.32/arch/ia64/kernel/entry.S 2008-02-11 12:35:32.000000000 +0100
571 @@ -1547,7 +1547,7 @@ sys_call_table:
572         data8 sys_mq_notify
573         data8 sys_mq_getsetattr
574         data8 sys_kexec_load
575 -       data8 sys_ni_syscall                    // reserved for vserver
576 +       data8 sys_vserver
577         data8 sys_waitid                        // 1270
578         data8 sys_add_key
579         data8 sys_request_key
580 diff -Nurp linux-2.6.22.18/arch/ia64/kernel/perfmon.c linux-2.6.22.18-vs2.3.0.32/arch/ia64/kernel/perfmon.c
581 --- linux-2.6.22.18/arch/ia64/kernel/perfmon.c  2007-07-21 23:59:45.000000000 +0200
582 +++ linux-2.6.22.18-vs2.3.0.32/arch/ia64/kernel/perfmon.c       2008-02-11 12:35:32.000000000 +0100
583 @@ -40,6 +40,7 @@
584  #include <linux/capability.h>
585  #include <linux/rcupdate.h>
586  #include <linux/completion.h>
587 +#include <linux/vs_memory.h>
588  
589  #include <asm/errno.h>
590  #include <asm/intrinsics.h>
591 @@ -2395,7 +2396,7 @@ pfm_smpl_buffer_alloc(struct task_struct
592          */
593         insert_vm_struct(mm, vma);
594  
595 -       mm->total_vm  += size >> PAGE_SHIFT;
596 +       vx_vmpages_add(mm, size >> PAGE_SHIFT);
597         vm_stat_account(vma->vm_mm, vma->vm_flags, vma->vm_file,
598                                                         vma_pages(vma));
599         up_write(&task->mm->mmap_sem);
600 diff -Nurp linux-2.6.22.18/arch/ia64/kernel/process.c linux-2.6.22.18-vs2.3.0.32/arch/ia64/kernel/process.c
601 --- linux-2.6.22.18/arch/ia64/kernel/process.c  2007-07-21 23:59:45.000000000 +0200
602 +++ linux-2.6.22.18-vs2.3.0.32/arch/ia64/kernel/process.c       2008-02-11 12:35:32.000000000 +0100
603 @@ -105,7 +105,8 @@ show_regs (struct pt_regs *regs)
604         unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
605  
606         print_modules();
607 -       printk("\nPid: %d, CPU %d, comm: %20s\n", current->pid, smp_processor_id(), current->comm);
608 +       printk("\nPid: %d[#%u], CPU %d, comm: %20s\n",
609 +               current->pid, current->xid, smp_processor_id(), current->comm);
610         printk("psr : %016lx ifs : %016lx ip  : [<%016lx>]    %s\n",
611                regs->cr_ipsr, regs->cr_ifs, ip, print_tainted());
612         print_symbol("ip is at %s\n", ip);
613 @@ -696,7 +697,8 @@ kernel_thread (int (*fn)(void *), void *
614         regs.sw.ar_fpsr = regs.pt.ar_fpsr = ia64_getreg(_IA64_REG_AR_FPSR);
615         regs.sw.ar_bspstore = (unsigned long) current + IA64_RBS_OFFSET;
616         regs.sw.pr = (1 << PRED_KERNEL_STACK);
617 -       return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs.pt, 0, NULL, NULL);
618 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
619 +               0, &regs.pt, 0, NULL, NULL);
620  }
621  EXPORT_SYMBOL(kernel_thread);
622  
623 diff -Nurp linux-2.6.22.18/arch/ia64/kernel/ptrace.c linux-2.6.22.18-vs2.3.0.32/arch/ia64/kernel/ptrace.c
624 --- linux-2.6.22.18/arch/ia64/kernel/ptrace.c   2007-07-21 23:58:15.000000000 +0200
625 +++ linux-2.6.22.18-vs2.3.0.32/arch/ia64/kernel/ptrace.c        2008-02-11 12:35:32.000000000 +0100
626 @@ -17,6 +17,7 @@
627  #include <linux/security.h>
628  #include <linux/audit.h>
629  #include <linux/signal.h>
630 +#include <linux/vs_base.h>
631  
632  #include <asm/pgtable.h>
633  #include <asm/processor.h>
634 @@ -1443,6 +1444,9 @@ sys_ptrace (long request, pid_t pid, uns
635         read_unlock(&tasklist_lock);
636         if (!child)
637                 goto out;
638 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
639 +               goto out_tsk;
640 +
641         ret = -EPERM;
642         if (pid == 1)           /* no messing around with init! */
643                 goto out_tsk;
644 diff -Nurp linux-2.6.22.18/arch/ia64/kernel/traps.c linux-2.6.22.18-vs2.3.0.32/arch/ia64/kernel/traps.c
645 --- linux-2.6.22.18/arch/ia64/kernel/traps.c    2007-07-21 23:59:45.000000000 +0200
646 +++ linux-2.6.22.18-vs2.3.0.32/arch/ia64/kernel/traps.c 2008-02-11 12:35:32.000000000 +0100
647 @@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
648         put_cpu();
649  
650         if (++die.lock_owner_depth < 3) {
651 -               printk("%s[%d]: %s %ld [%d]\n",
652 -                       current->comm, current->pid, str, err, ++die_counter);
653 +               printk("%s[%d[#%u]]: %s %ld [%d]\n",
654 +                       current->comm, current->pid, current->xid,
655 +                       str, err, ++die_counter);
656                 (void) notify_die(DIE_OOPS, (char *)str, regs, err, 255, SIGSEGV);
657                 show_regs(regs);
658         } else
659 @@ -313,8 +314,9 @@ handle_fpu_swa (int fp_fault, struct pt_
660                         if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
661                                 last.time = current_jiffies + 5 * HZ;
662                                 printk(KERN_WARNING
663 -                                       "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
664 -                                       current->comm, current->pid, regs->cr_iip + ia64_psr(regs)->ri, isr);
665 +                                       "%s(%d[#%u]): floating-point assist fault at ip %016lx, isr %016lx\n",
666 +                                       current->comm, current->pid, current->xid,
667 +                                       regs->cr_iip + ia64_psr(regs)->ri, isr);
668                         }
669                 }
670         }
671 diff -Nurp linux-2.6.22.18/arch/ia64/mm/fault.c linux-2.6.22.18-vs2.3.0.32/arch/ia64/mm/fault.c
672 --- linux-2.6.22.18/arch/ia64/mm/fault.c        2007-07-21 23:59:45.000000000 +0200
673 +++ linux-2.6.22.18-vs2.3.0.32/arch/ia64/mm/fault.c     2008-02-11 12:35:32.000000000 +0100
674 @@ -10,6 +10,7 @@
675  #include <linux/interrupt.h>
676  #include <linux/kprobes.h>
677  #include <linux/kdebug.h>
678 +#include <linux/vs_memory.h>
679  
680  #include <asm/pgtable.h>
681  #include <asm/processor.h>
682 diff -Nurp linux-2.6.22.18/arch/m32r/kernel/process.c linux-2.6.22.18-vs2.3.0.32/arch/m32r/kernel/process.c
683 --- linux-2.6.22.18/arch/m32r/kernel/process.c  2007-07-21 23:58:15.000000000 +0200
684 +++ linux-2.6.22.18-vs2.3.0.32/arch/m32r/kernel/process.c       2008-02-11 12:35:32.000000000 +0100
685 @@ -211,8 +211,8 @@ int kernel_thread(int (*fn)(void *), voi
686         regs.psw = M32R_PSW_BIE;
687  
688         /* Ok, create the new process. */
689 -       return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL,
690 -               NULL);
691 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
692 +               0, &regs, 0, NULL, NULL);
693  }
694  
695  /*
696 diff -Nurp linux-2.6.22.18/arch/m32r/kernel/traps.c linux-2.6.22.18-vs2.3.0.32/arch/m32r/kernel/traps.c
697 --- linux-2.6.22.18/arch/m32r/kernel/traps.c    2007-05-04 15:57:13.000000000 +0200
698 +++ linux-2.6.22.18-vs2.3.0.32/arch/m32r/kernel/traps.c 2008-02-11 12:35:32.000000000 +0100
699 @@ -195,8 +195,9 @@ static void show_registers(struct pt_reg
700         } else {
701                 printk("SPI: %08lx\n", sp);
702         }
703 -       printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
704 -               current->comm, current->pid, 0xffff & i, 4096+(unsigned long)current);
705 +       printk("Process %s (pid: %d[#%u], process nr: %d, stackpage=%08lx)",
706 +               current->comm, current->pid, current->xid,
707 +               0xffff & i, 4096+(unsigned long)current);
708  
709         /*
710          * When in-kernel, we also print out the stack and code at the
711 diff -Nurp linux-2.6.22.18/arch/m68k/Kconfig linux-2.6.22.18-vs2.3.0.32/arch/m68k/Kconfig
712 --- linux-2.6.22.18/arch/m68k/Kconfig   2007-07-21 23:59:45.000000000 +0200
713 +++ linux-2.6.22.18-vs2.3.0.32/arch/m68k/Kconfig        2008-02-11 12:35:32.000000000 +0100
714 @@ -678,6 +678,8 @@ source "fs/Kconfig"
715  
716  source "arch/m68k/Kconfig.debug"
717  
718 +source "kernel/vserver/Kconfig"
719 +
720  source "security/Kconfig"
721  
722  source "crypto/Kconfig"
723 diff -Nurp linux-2.6.22.18/arch/m68k/kernel/process.c linux-2.6.22.18-vs2.3.0.32/arch/m68k/kernel/process.c
724 --- linux-2.6.22.18/arch/m68k/kernel/process.c  2007-05-04 15:57:14.000000000 +0200
725 +++ linux-2.6.22.18-vs2.3.0.32/arch/m68k/kernel/process.c       2008-02-11 12:35:32.000000000 +0100
726 @@ -159,7 +159,8 @@ int kernel_thread(int (*fn)(void *), voi
727  
728         {
729         register long retval __asm__ ("d0");
730 -       register long clone_arg __asm__ ("d1") = flags | CLONE_VM | CLONE_UNTRACED;
731 +       register long clone_arg __asm__ ("d1") =
732 +               flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD;
733  
734         retval = __NR_clone;
735         __asm__ __volatile__
736 diff -Nurp linux-2.6.22.18/arch/m68k/kernel/ptrace.c linux-2.6.22.18-vs2.3.0.32/arch/m68k/kernel/ptrace.c
737 --- linux-2.6.22.18/arch/m68k/kernel/ptrace.c   2007-07-21 23:59:45.000000000 +0200
738 +++ linux-2.6.22.18-vs2.3.0.32/arch/m68k/kernel/ptrace.c        2008-02-11 12:35:32.000000000 +0100
739 @@ -18,6 +18,7 @@
740  #include <linux/ptrace.h>
741  #include <linux/user.h>
742  #include <linux/signal.h>
743 +#include <linux/vs_base.h>
744  
745  #include <asm/uaccess.h>
746  #include <asm/page.h>
747 @@ -278,6 +279,8 @@ long arch_ptrace(struct task_struct *chi
748                 ret = ptrace_request(child, request, addr, data);
749                 break;
750         }
751 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
752 +               goto out_tsk;
753  
754         return ret;
755  out_eio:
756 diff -Nurp linux-2.6.22.18/arch/m68k/kernel/traps.c linux-2.6.22.18-vs2.3.0.32/arch/m68k/kernel/traps.c
757 --- linux-2.6.22.18/arch/m68k/kernel/traps.c    2007-07-21 23:58:15.000000000 +0200
758 +++ linux-2.6.22.18-vs2.3.0.32/arch/m68k/kernel/traps.c 2008-02-11 12:35:32.000000000 +0100
759 @@ -899,8 +899,8 @@ void show_registers(struct pt_regs *regs
760         printk("d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
761                regs->d4, regs->d5, regs->a0, regs->a1);
762  
763 -       printk("Process %s (pid: %d, task=%p)\n",
764 -               current->comm, current->pid, current);
765 +       printk("Process %s (pid: %d[#%u], task=%p)\n",
766 +               current->comm, current->pid, current->xid, current);
767         addr = (unsigned long)&fp->un;
768         printk("Frame format=%X ", regs->format);
769         switch (regs->format) {
770 diff -Nurp linux-2.6.22.18/arch/m68knommu/Kconfig linux-2.6.22.18-vs2.3.0.32/arch/m68knommu/Kconfig
771 --- linux-2.6.22.18/arch/m68knommu/Kconfig      2007-07-21 23:59:45.000000000 +0200
772 +++ linux-2.6.22.18-vs2.3.0.32/arch/m68knommu/Kconfig   2008-02-11 12:35:32.000000000 +0100
773 @@ -670,6 +670,8 @@ source "fs/Kconfig"
774  
775  source "arch/m68knommu/Kconfig.debug"
776  
777 +source "kernel/vserver/Kconfig"
778 +
779  source "security/Kconfig"
780  
781  source "crypto/Kconfig"
782 diff -Nurp linux-2.6.22.18/arch/m68knommu/kernel/process.c linux-2.6.22.18-vs2.3.0.32/arch/m68knommu/kernel/process.c
783 --- linux-2.6.22.18/arch/m68knommu/kernel/process.c     2007-05-04 15:58:04.000000000 +0200
784 +++ linux-2.6.22.18-vs2.3.0.32/arch/m68knommu/kernel/process.c  2008-02-11 12:35:32.000000000 +0100
785 @@ -122,7 +122,7 @@ void show_regs(struct pt_regs * regs)
786  int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
787  {
788         int retval;
789 -       long clone_arg = flags | CLONE_VM;
790 +       long clone_arg = flags | CLONE_VM | CLONE_KTHREAD;
791         mm_segment_t fs;
792  
793         fs = get_fs();
794 diff -Nurp linux-2.6.22.18/arch/m68knommu/kernel/traps.c linux-2.6.22.18-vs2.3.0.32/arch/m68knommu/kernel/traps.c
795 --- linux-2.6.22.18/arch/m68knommu/kernel/traps.c       2007-07-21 23:58:15.000000000 +0200
796 +++ linux-2.6.22.18-vs2.3.0.32/arch/m68knommu/kernel/traps.c    2008-02-11 12:35:32.000000000 +0100
797 @@ -80,8 +80,9 @@ void die_if_kernel(char *str, struct pt_
798         printk(KERN_EMERG "d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
799                fp->d4, fp->d5, fp->a0, fp->a1);
800  
801 -       printk(KERN_EMERG "Process %s (pid: %d, stackpage=%08lx)\n",
802 -               current->comm, current->pid, PAGE_SIZE+(unsigned long)current);
803 +       printk(KERN_EMERG "Process %s (pid: %d[#%u], stackpage=%08lx)\n",
804 +               current->comm, current->pid, current->xid,
805 +               PAGE_SIZE+(unsigned long)current);
806         show_stack(NULL, (unsigned long *)fp);
807         do_exit(SIGSEGV);
808  }
809 diff -Nurp linux-2.6.22.18/arch/mips/Kconfig linux-2.6.22.18-vs2.3.0.32/arch/mips/Kconfig
810 --- linux-2.6.22.18/arch/mips/Kconfig   2007-07-21 23:59:45.000000000 +0200
811 +++ linux-2.6.22.18-vs2.3.0.32/arch/mips/Kconfig        2008-02-11 12:35:32.000000000 +0100
812 @@ -1959,6 +1959,8 @@ source "arch/mips/oprofile/Kconfig"
813  
814  source "arch/mips/Kconfig.debug"
815  
816 +source "kernel/vserver/Kconfig"
817 +
818  source "security/Kconfig"
819  
820  source "crypto/Kconfig"
821 diff -Nurp linux-2.6.22.18/arch/mips/kernel/linux32.c linux-2.6.22.18-vs2.3.0.32/arch/mips/kernel/linux32.c
822 --- linux-2.6.22.18/arch/mips/kernel/linux32.c  2007-07-21 23:59:45.000000000 +0200
823 +++ linux-2.6.22.18-vs2.3.0.32/arch/mips/kernel/linux32.c       2008-02-11 12:35:32.000000000 +0100
824 @@ -229,7 +229,7 @@ sys32_gettimeofday(struct compat_timeval
825  {
826         if (tv) {
827                 struct timeval ktv;
828 -               do_gettimeofday(&ktv);
829 +               vx_gettimeofday(&ktv);
830                 if (put_tv32(tv, &ktv))
831                         return -EFAULT;
832         }
833 diff -Nurp linux-2.6.22.18/arch/mips/kernel/process.c linux-2.6.22.18-vs2.3.0.32/arch/mips/kernel/process.c
834 --- linux-2.6.22.18/arch/mips/kernel/process.c  2007-07-21 23:58:16.000000000 +0200
835 +++ linux-2.6.22.18-vs2.3.0.32/arch/mips/kernel/process.c       2008-02-11 12:35:32.000000000 +0100
836 @@ -236,7 +236,8 @@ long kernel_thread(int (*fn)(void *), vo
837  #endif
838  
839         /* Ok, create the new process.. */
840 -       return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
841 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
842 +               0, &regs, 0, NULL, NULL);
843  }
844  
845  /*
846 diff -Nurp linux-2.6.22.18/arch/mips/kernel/ptrace.c linux-2.6.22.18-vs2.3.0.32/arch/mips/kernel/ptrace.c
847 --- linux-2.6.22.18/arch/mips/kernel/ptrace.c   2007-07-21 23:59:45.000000000 +0200
848 +++ linux-2.6.22.18-vs2.3.0.32/arch/mips/kernel/ptrace.c        2008-02-11 12:35:32.000000000 +0100
849 @@ -25,6 +25,7 @@
850  #include <linux/user.h>
851  #include <linux/security.h>
852  #include <linux/signal.h>
853 +#include <linux/vs_base.h>
854  
855  #include <asm/byteorder.h>
856  #include <asm/cpu.h>
857 @@ -171,6 +172,9 @@ long arch_ptrace(struct task_struct *chi
858  {
859         int ret;
860  
861 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
862 +               goto out;
863 +
864         switch (request) {
865         /* when I and D space are separate, these will need to be fixed. */
866         case PTRACE_PEEKTEXT: /* read word at location addr. */
867 diff -Nurp linux-2.6.22.18/arch/mips/kernel/scall32-o32.S linux-2.6.22.18-vs2.3.0.32/arch/mips/kernel/scall32-o32.S
868 --- linux-2.6.22.18/arch/mips/kernel/scall32-o32.S      2007-07-21 23:59:45.000000000 +0200
869 +++ linux-2.6.22.18-vs2.3.0.32/arch/mips/kernel/scall32-o32.S   2008-02-11 12:35:32.000000000 +0100
870 @@ -619,7 +619,7 @@ einval:     li      v0, -EINVAL
871         sys     sys_mq_timedreceive     5
872         sys     sys_mq_notify           2       /* 4275 */
873         sys     sys_mq_getsetattr       3
874 -       sys     sys_ni_syscall          0       /* sys_vserver */
875 +       sys     sys_vserver             3
876         sys     sys_waitid              5
877         sys     sys_ni_syscall          0       /* available, was setaltroot */
878         sys     sys_add_key             5       /* 4280 */
879 diff -Nurp linux-2.6.22.18/arch/mips/kernel/scall64-64.S linux-2.6.22.18-vs2.3.0.32/arch/mips/kernel/scall64-64.S
880 --- linux-2.6.22.18/arch/mips/kernel/scall64-64.S       2007-07-21 23:59:45.000000000 +0200
881 +++ linux-2.6.22.18-vs2.3.0.32/arch/mips/kernel/scall64-64.S    2008-02-11 12:35:32.000000000 +0100
882 @@ -434,7 +434,7 @@ sys_call_table:
883         PTR     sys_mq_timedreceive
884         PTR     sys_mq_notify
885         PTR     sys_mq_getsetattr               /* 5235 */
886 -       PTR     sys_ni_syscall                  /* sys_vserver */
887 +       PTR     sys_vserver
888         PTR     sys_waitid
889         PTR     sys_ni_syscall                  /* available, was setaltroot */
890         PTR     sys_add_key
891 diff -Nurp linux-2.6.22.18/arch/mips/kernel/scall64-n32.S linux-2.6.22.18-vs2.3.0.32/arch/mips/kernel/scall64-n32.S
892 --- linux-2.6.22.18/arch/mips/kernel/scall64-n32.S      2007-07-21 23:59:45.000000000 +0200
893 +++ linux-2.6.22.18-vs2.3.0.32/arch/mips/kernel/scall64-n32.S   2008-02-11 12:35:32.000000000 +0100
894 @@ -360,7 +360,7 @@ EXPORT(sysn32_call_table)
895         PTR     compat_sys_mq_timedreceive
896         PTR     compat_sys_mq_notify
897         PTR     compat_sys_mq_getsetattr
898 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
899 +       PTR     sys32_vserver                   /* 6240 */
900         PTR     compat_sys_waitid
901         PTR     sys_ni_syscall                  /* available, was setaltroot */
902         PTR     sys_add_key
903 diff -Nurp linux-2.6.22.18/arch/mips/kernel/scall64-o32.S linux-2.6.22.18-vs2.3.0.32/arch/mips/kernel/scall64-o32.S
904 --- linux-2.6.22.18/arch/mips/kernel/scall64-o32.S      2007-07-21 23:59:45.000000000 +0200
905 +++ linux-2.6.22.18-vs2.3.0.32/arch/mips/kernel/scall64-o32.S   2008-02-11 12:35:32.000000000 +0100
906 @@ -482,7 +482,7 @@ sys_call_table:
907         PTR     compat_sys_mq_timedreceive
908         PTR     compat_sys_mq_notify            /* 4275 */
909         PTR     compat_sys_mq_getsetattr
910 -       PTR     sys_ni_syscall                  /* sys_vserver */
911 +       PTR     sys32_vserver
912         PTR     sys32_waitid
913         PTR     sys_ni_syscall                  /* available, was setaltroot */
914         PTR     sys_add_key                     /* 4280 */
915 diff -Nurp linux-2.6.22.18/arch/mips/kernel/traps.c linux-2.6.22.18-vs2.3.0.32/arch/mips/kernel/traps.c
916 --- linux-2.6.22.18/arch/mips/kernel/traps.c    2007-07-21 23:59:48.000000000 +0200
917 +++ linux-2.6.22.18-vs2.3.0.32/arch/mips/kernel/traps.c 2008-02-11 12:35:32.000000000 +0100
918 @@ -302,8 +302,9 @@ void show_registers(struct pt_regs *regs
919  {
920         show_regs(regs);
921         print_modules();
922 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p)\n",
923 -               current->comm, current->pid, current_thread_info(), current);
924 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p)\n",
925 +               current->comm, current->pid, current->xid,
926 +               current_thread_info(), current);
927         show_stacktrace(current, regs);
928         show_code((unsigned int *) regs->cp0_epc);
929         printk("\n");
930 diff -Nurp linux-2.6.22.18/arch/mips/mm/fault.c linux-2.6.22.18-vs2.3.0.32/arch/mips/mm/fault.c
931 --- linux-2.6.22.18/arch/mips/mm/fault.c        2007-07-21 23:59:48.000000000 +0200
932 +++ linux-2.6.22.18-vs2.3.0.32/arch/mips/mm/fault.c     2008-02-11 12:35:32.000000000 +0100
933 @@ -179,7 +179,8 @@ out_of_memory:
934                 down_read(&mm->mmap_sem);
935                 goto survive;
936         }
937 -       printk("VM: killing process %s\n", tsk->comm);
938 +       printk("VM: killing process %s(%d:#%u)\n",
939 +               tsk->comm, tsk->pid, tsk->xid);
940         if (user_mode(regs))
941                 do_exit(SIGKILL);
942         goto no_context;
943 diff -Nurp linux-2.6.22.18/arch/parisc/Kconfig linux-2.6.22.18-vs2.3.0.32/arch/parisc/Kconfig
944 --- linux-2.6.22.18/arch/parisc/Kconfig 2007-07-21 23:58:18.000000000 +0200
945 +++ linux-2.6.22.18-vs2.3.0.32/arch/parisc/Kconfig      2008-02-11 12:35:32.000000000 +0100
946 @@ -271,6 +271,8 @@ source "arch/parisc/oprofile/Kconfig"
947  
948  source "arch/parisc/Kconfig.debug"
949  
950 +source "kernel/vserver/Kconfig"
951 +
952  source "security/Kconfig"
953  
954  source "crypto/Kconfig"
955 diff -Nurp linux-2.6.22.18/arch/parisc/kernel/entry.S linux-2.6.22.18-vs2.3.0.32/arch/parisc/kernel/entry.S
956 --- linux-2.6.22.18/arch/parisc/kernel/entry.S  2007-07-21 23:59:48.000000000 +0200
957 +++ linux-2.6.22.18-vs2.3.0.32/arch/parisc/kernel/entry.S       2008-02-11 12:35:32.000000000 +0100
958 @@ -761,6 +761,7 @@ END(fault_vector_11)
959  
960  #define CLONE_VM 0x100 /* Must agree with <linux/sched.h> */
961  #define CLONE_UNTRACED 0x00800000
962 +#define CLONE_KTHREAD 0x10000000
963  
964         .import do_fork
965  ENTRY(__kernel_thread)
966 diff -Nurp linux-2.6.22.18/arch/parisc/kernel/process.c linux-2.6.22.18-vs2.3.0.32/arch/parisc/kernel/process.c
967 --- linux-2.6.22.18/arch/parisc/kernel/process.c        2007-07-21 23:59:48.000000000 +0200
968 +++ linux-2.6.22.18-vs2.3.0.32/arch/parisc/kernel/process.c     2008-02-11 12:35:32.000000000 +0100
969 @@ -173,7 +173,7 @@ pid_t kernel_thread(int (*fn)(void *), v
970          *        kernel_thread can become a #define.
971          */
972  
973 -       return __kernel_thread(fn, arg, flags);
974 +       return __kernel_thread(fn, arg, flags | CLONE_KTHREAD);
975  }
976  EXPORT_SYMBOL(kernel_thread);
977  
978 diff -Nurp linux-2.6.22.18/arch/parisc/kernel/syscall_table.S linux-2.6.22.18-vs2.3.0.32/arch/parisc/kernel/syscall_table.S
979 --- linux-2.6.22.18/arch/parisc/kernel/syscall_table.S  2007-07-21 23:59:48.000000000 +0200
980 +++ linux-2.6.22.18-vs2.3.0.32/arch/parisc/kernel/syscall_table.S       2008-02-11 12:35:32.000000000 +0100
981 @@ -363,7 +363,7 @@
982         ENTRY_COMP(mbind)               /* 260 */
983         ENTRY_COMP(get_mempolicy)
984         ENTRY_COMP(set_mempolicy)
985 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
986 +       ENTRY_DIFF(vserver)
987         ENTRY_SAME(add_key)
988         ENTRY_SAME(request_key)         /* 265 */
989         ENTRY_SAME(keyctl)
990 diff -Nurp linux-2.6.22.18/arch/parisc/kernel/sys_parisc32.c linux-2.6.22.18-vs2.3.0.32/arch/parisc/kernel/sys_parisc32.c
991 --- linux-2.6.22.18/arch/parisc/kernel/sys_parisc32.c   2007-07-21 23:59:48.000000000 +0200
992 +++ linux-2.6.22.18-vs2.3.0.32/arch/parisc/kernel/sys_parisc32.c        2008-02-11 12:35:32.000000000 +0100
993 @@ -204,11 +204,11 @@ static inline long get_ts32(struct times
994  asmlinkage int
995  sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
996  {
997 -    extern void do_gettimeofday(struct timeval *tv);
998 +    extern void vx_gettimeofday(struct timeval *tv);
999  
1000      if (tv) {
1001             struct timeval ktv;
1002 -           do_gettimeofday(&ktv);
1003 +           vx_gettimeofday(&ktv);
1004             if (put_compat_timeval(tv, &ktv))
1005                     return -EFAULT;
1006      }
1007 diff -Nurp linux-2.6.22.18/arch/parisc/kernel/traps.c linux-2.6.22.18-vs2.3.0.32/arch/parisc/kernel/traps.c
1008 --- linux-2.6.22.18/arch/parisc/kernel/traps.c  2007-07-21 23:59:48.000000000 +0200
1009 +++ linux-2.6.22.18-vs2.3.0.32/arch/parisc/kernel/traps.c       2008-02-11 12:35:32.000000000 +0100
1010 @@ -218,8 +218,9 @@ void die_if_kernel(char *str, struct pt_
1011                 if (err == 0)
1012                         return; /* STFU */
1013  
1014 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
1015 -                       current->comm, current->pid, str, err, regs->iaoq[0]);
1016 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
1017 +                       current->comm, current->pid, current->xid,
1018 +                       str, err, regs->iaoq[0]);
1019  #ifdef PRINT_USER_FAULTS
1020                 /* XXX for debugging only */
1021                 show_regs(regs);
1022 @@ -251,8 +252,8 @@ KERN_CRIT "                     ||     |
1023                 pdc_console_restart();
1024         
1025         if (err)
1026 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
1027 -                       current->comm, current->pid, str, err);
1028 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
1029 +                       current->comm, current->pid, current->xid, str, err);
1030  
1031         /* Wot's wrong wif bein' racy? */
1032         if (current->thread.flags & PARISC_KERNEL_DEATH) {
1033 diff -Nurp linux-2.6.22.18/arch/parisc/mm/fault.c linux-2.6.22.18-vs2.3.0.32/arch/parisc/mm/fault.c
1034 --- linux-2.6.22.18/arch/parisc/mm/fault.c      2007-07-21 23:58:18.000000000 +0200
1035 +++ linux-2.6.22.18-vs2.3.0.32/arch/parisc/mm/fault.c   2008-02-11 12:35:32.000000000 +0100
1036 @@ -209,8 +209,9 @@ bad_area:
1037  
1038  #ifdef PRINT_USER_FAULTS
1039                 printk(KERN_DEBUG "\n");
1040 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
1041 -                   tsk->pid, tsk->comm, code, address);
1042 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
1043 +                   "command='%s' type=%lu address=0x%08lx\n",
1044 +                   tsk->pid, tsk->xid, tsk->comm, code, address);
1045                 if (vma) {
1046                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
1047                                         vma->vm_start, vma->vm_end);
1048 @@ -260,7 +261,8 @@ no_context:
1049  
1050    out_of_memory:
1051         up_read(&mm->mmap_sem);
1052 -       printk(KERN_CRIT "VM: killing process %s\n", current->comm);
1053 +       printk(KERN_CRIT "VM: killing process %s(%d:#%u)\n",
1054 +               current->comm, current->pid, current->xid);
1055         if (user_mode(regs))
1056                 do_exit(SIGKILL);
1057         goto no_context;
1058 diff -Nurp linux-2.6.22.18/arch/powerpc/Kconfig linux-2.6.22.18-vs2.3.0.32/arch/powerpc/Kconfig
1059 --- linux-2.6.22.18/arch/powerpc/Kconfig        2007-07-21 23:59:48.000000000 +0200
1060 +++ linux-2.6.22.18-vs2.3.0.32/arch/powerpc/Kconfig     2008-02-11 12:35:32.000000000 +0100
1061 @@ -906,6 +906,8 @@ endmenu
1062  
1063  source "arch/powerpc/Kconfig.debug"
1064  
1065 +source "kernel/vserver/Kconfig"
1066 +
1067  source "security/Kconfig"
1068  
1069  config KEYS_COMPAT
1070 diff -Nurp linux-2.6.22.18/arch/powerpc/kernel/asm-offsets.c linux-2.6.22.18-vs2.3.0.32/arch/powerpc/kernel/asm-offsets.c
1071 --- linux-2.6.22.18/arch/powerpc/kernel/asm-offsets.c   2007-07-21 23:59:48.000000000 +0200
1072 +++ linux-2.6.22.18-vs2.3.0.32/arch/powerpc/kernel/asm-offsets.c        2008-02-11 12:35:32.000000000 +0100
1073 @@ -250,6 +250,7 @@ int main(void)
1074  
1075         DEFINE(CLONE_VM, CLONE_VM);
1076         DEFINE(CLONE_UNTRACED, CLONE_UNTRACED);
1077 +       DEFINE(CLONE_KTHREAD, CLONE_KTHREAD);
1078  
1079  #ifndef CONFIG_PPC64
1080         DEFINE(MM_PGD, offsetof(struct mm_struct, pgd));
1081 diff -Nurp linux-2.6.22.18/arch/powerpc/kernel/irq.c linux-2.6.22.18-vs2.3.0.32/arch/powerpc/kernel/irq.c
1082 --- linux-2.6.22.18/arch/powerpc/kernel/irq.c   2007-07-21 23:59:48.000000000 +0200
1083 +++ linux-2.6.22.18-vs2.3.0.32/arch/powerpc/kernel/irq.c        2008-02-11 12:35:32.000000000 +0100
1084 @@ -53,6 +53,7 @@
1085  #include <linux/mutex.h>
1086  #include <linux/bootmem.h>
1087  #include <linux/pci.h>
1088 +#include <linux/vs_context.h>
1089  
1090  #include <asm/uaccess.h>
1091  #include <asm/system.h>
1092 diff -Nurp linux-2.6.22.18/arch/powerpc/kernel/misc_32.S linux-2.6.22.18-vs2.3.0.32/arch/powerpc/kernel/misc_32.S
1093 --- linux-2.6.22.18/arch/powerpc/kernel/misc_32.S       2007-07-21 23:59:48.000000000 +0200
1094 +++ linux-2.6.22.18-vs2.3.0.32/arch/powerpc/kernel/misc_32.S    2008-02-11 12:35:32.000000000 +0100
1095 @@ -745,7 +745,7 @@ _GLOBAL(kernel_thread)
1096         mr      r30,r3          /* function */
1097         mr      r31,r4          /* argument */
1098         ori     r3,r5,CLONE_VM  /* flags */
1099 -       oris    r3,r3,CLONE_UNTRACED>>16
1100 +       oris    r3,r3,(CLONE_UNTRACED|CLONE_KTHREAD)>>16
1101         li      r4,0            /* new sp (unused) */
1102         li      r0,__NR_clone
1103         sc
1104 diff -Nurp linux-2.6.22.18/arch/powerpc/kernel/misc_64.S linux-2.6.22.18-vs2.3.0.32/arch/powerpc/kernel/misc_64.S
1105 --- linux-2.6.22.18/arch/powerpc/kernel/misc_64.S       2007-07-21 23:58:18.000000000 +0200
1106 +++ linux-2.6.22.18-vs2.3.0.32/arch/powerpc/kernel/misc_64.S    2008-02-11 12:35:32.000000000 +0100
1107 @@ -434,7 +434,7 @@ _GLOBAL(kernel_thread)
1108         mr      r29,r3
1109         mr      r30,r4
1110         ori     r3,r5,CLONE_VM  /* flags */
1111 -       oris    r3,r3,(CLONE_UNTRACED>>16)
1112 +       oris    r3,r3,(CLONE_UNTRACED|CLONE_KTHREAD)>>16
1113         li      r4,0            /* new sp (unused) */
1114         li      r0,__NR_clone
1115         sc
1116 diff -Nurp linux-2.6.22.18/arch/powerpc/kernel/process.c linux-2.6.22.18-vs2.3.0.32/arch/powerpc/kernel/process.c
1117 --- linux-2.6.22.18/arch/powerpc/kernel/process.c       2007-09-29 14:11:48.000000000 +0200
1118 +++ linux-2.6.22.18-vs2.3.0.32/arch/powerpc/kernel/process.c    2008-02-11 12:35:32.000000000 +0100
1119 @@ -422,8 +422,9 @@ void show_regs(struct pt_regs * regs)
1120         trap = TRAP(regs);
1121         if (trap == 0x300 || trap == 0x600)
1122                 printk("DAR: "REG", DSISR: "REG"\n", regs->dar, regs->dsisr);
1123 -       printk("TASK = %p[%d] '%s' THREAD: %p",
1124 -              current, current->pid, current->comm, task_thread_info(current));
1125 +       printk("TASK = %p[%d,#%u] '%s' THREAD: %p",
1126 +              current, current->pid, current->xid,
1127 +              current->comm, task_thread_info(current));
1128  
1129  #ifdef CONFIG_SMP
1130         printk(" CPU: %d", smp_processor_id());
1131 diff -Nurp linux-2.6.22.18/arch/powerpc/kernel/sys_ppc32.c linux-2.6.22.18-vs2.3.0.32/arch/powerpc/kernel/sys_ppc32.c
1132 --- linux-2.6.22.18/arch/powerpc/kernel/sys_ppc32.c     2007-07-21 23:59:48.000000000 +0200
1133 +++ linux-2.6.22.18-vs2.3.0.32/arch/powerpc/kernel/sys_ppc32.c  2008-02-11 12:35:32.000000000 +0100
1134 @@ -205,7 +205,7 @@ asmlinkage long compat_sys_gettimeofday(
1135  {
1136         if (tv) {
1137                 struct timeval ktv;
1138 -               do_gettimeofday(&ktv);
1139 +               vx_gettimeofday(&ktv);
1140                 if (put_tv32(tv, &ktv))
1141                         return -EFAULT;
1142         }
1143 diff -Nurp linux-2.6.22.18/arch/powerpc/kernel/traps.c linux-2.6.22.18-vs2.3.0.32/arch/powerpc/kernel/traps.c
1144 --- linux-2.6.22.18/arch/powerpc/kernel/traps.c 2007-07-21 23:59:48.000000000 +0200
1145 +++ linux-2.6.22.18-vs2.3.0.32/arch/powerpc/kernel/traps.c      2008-02-11 12:35:32.000000000 +0100
1146 @@ -878,8 +878,9 @@ void nonrecoverable_exception(struct pt_
1147  
1148  void trace_syscall(struct pt_regs *regs)
1149  {
1150 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
1151 -              current, current->pid, regs->nip, regs->link, regs->gpr[0],
1152 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
1153 +              current, current->pid, current->xid,
1154 +              regs->nip, regs->link, regs->gpr[0],
1155                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
1156  }
1157  
1158 diff -Nurp linux-2.6.22.18/arch/powerpc/kernel/vdso.c linux-2.6.22.18-vs2.3.0.32/arch/powerpc/kernel/vdso.c
1159 --- linux-2.6.22.18/arch/powerpc/kernel/vdso.c  2007-07-21 23:59:48.000000000 +0200
1160 +++ linux-2.6.22.18-vs2.3.0.32/arch/powerpc/kernel/vdso.c       2008-02-11 12:35:32.000000000 +0100
1161 @@ -21,6 +21,7 @@
1162  #include <linux/elf.h>
1163  #include <linux/security.h>
1164  #include <linux/bootmem.h>
1165 +#include <linux/vs_memory.h>
1166  
1167  #include <asm/pgtable.h>
1168  #include <asm/system.h>
1169 diff -Nurp linux-2.6.22.18/arch/powerpc/mm/fault.c linux-2.6.22.18-vs2.3.0.32/arch/powerpc/mm/fault.c
1170 --- linux-2.6.22.18/arch/powerpc/mm/fault.c     2007-07-21 23:59:48.000000000 +0200
1171 +++ linux-2.6.22.18-vs2.3.0.32/arch/powerpc/mm/fault.c  2008-02-11 12:35:32.000000000 +0100
1172 @@ -378,7 +378,8 @@ out_of_memory:
1173                 down_read(&mm->mmap_sem);
1174                 goto survive;
1175         }
1176 -       printk("VM: killing process %s\n", current->comm);
1177 +       printk("VM: killing process %s(%d:#%u)\n",
1178 +               current->comm, current->pid, current->xid);
1179         if (user_mode(regs))
1180                 do_exit(SIGKILL);
1181         return SIGKILL;
1182 diff -Nurp linux-2.6.22.18/arch/ppc/Kconfig linux-2.6.22.18-vs2.3.0.32/arch/ppc/Kconfig
1183 --- linux-2.6.22.18/arch/ppc/Kconfig    2007-07-21 23:58:19.000000000 +0200
1184 +++ linux-2.6.22.18-vs2.3.0.32/arch/ppc/Kconfig 2008-02-11 12:35:32.000000000 +0100
1185 @@ -1455,6 +1455,8 @@ source "arch/powerpc/oprofile/Kconfig"
1186  
1187  source "arch/ppc/Kconfig.debug"
1188  
1189 +source "kernel/vserver/Kconfig"
1190 +
1191  source "security/Kconfig"
1192  
1193  source "crypto/Kconfig"
1194 diff -Nurp linux-2.6.22.18/arch/ppc/kernel/asm-offsets.c linux-2.6.22.18-vs2.3.0.32/arch/ppc/kernel/asm-offsets.c
1195 --- linux-2.6.22.18/arch/ppc/kernel/asm-offsets.c       2007-07-21 23:59:49.000000000 +0200
1196 +++ linux-2.6.22.18-vs2.3.0.32/arch/ppc/kernel/asm-offsets.c    2008-02-11 12:35:32.000000000 +0100
1197 @@ -120,6 +120,7 @@ main(void)
1198         DEFINE(TRAP, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, trap));
1199         DEFINE(CLONE_VM, CLONE_VM);
1200         DEFINE(CLONE_UNTRACED, CLONE_UNTRACED);
1201 +       DEFINE(CLONE_KTHREAD, CLONE_KTHREAD);
1202         DEFINE(MM_PGD, offsetof(struct mm_struct, pgd));
1203  
1204         /* About the CPU features table */
1205 diff -Nurp linux-2.6.22.18/arch/ppc/kernel/misc.S linux-2.6.22.18-vs2.3.0.32/arch/ppc/kernel/misc.S
1206 --- linux-2.6.22.18/arch/ppc/kernel/misc.S      2007-05-04 15:57:15.000000000 +0200
1207 +++ linux-2.6.22.18-vs2.3.0.32/arch/ppc/kernel/misc.S   2008-02-11 12:35:32.000000000 +0100
1208 @@ -848,7 +848,7 @@ _GLOBAL(kernel_thread)
1209         mr      r30,r3          /* function */
1210         mr      r31,r4          /* argument */
1211         ori     r3,r5,CLONE_VM  /* flags */
1212 -       oris    r3,r3,CLONE_UNTRACED>>16
1213 +       oris    r3,r3,(CLONE_UNTRACED|CLONE_KTHREAD)>>16
1214         li      r4,0            /* new sp (unused) */
1215         li      r0,__NR_clone
1216         sc
1217 diff -Nurp linux-2.6.22.18/arch/ppc/kernel/traps.c linux-2.6.22.18-vs2.3.0.32/arch/ppc/kernel/traps.c
1218 --- linux-2.6.22.18/arch/ppc/kernel/traps.c     2007-07-21 23:59:49.000000000 +0200
1219 +++ linux-2.6.22.18-vs2.3.0.32/arch/ppc/kernel/traps.c  2008-02-11 12:35:32.000000000 +0100
1220 @@ -696,8 +696,9 @@ void nonrecoverable_exception(struct pt_
1221  
1222  void trace_syscall(struct pt_regs *regs)
1223  {
1224 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
1225 -              current, current->pid, regs->nip, regs->link, regs->gpr[0],
1226 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
1227 +              current, current->pid, current->xid,
1228 +              regs->nip, regs->link, regs->gpr[0],
1229                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
1230  }
1231  
1232 diff -Nurp linux-2.6.22.18/arch/ppc/mm/fault.c linux-2.6.22.18-vs2.3.0.32/arch/ppc/mm/fault.c
1233 --- linux-2.6.22.18/arch/ppc/mm/fault.c 2007-05-04 15:57:15.000000000 +0200
1234 +++ linux-2.6.22.18-vs2.3.0.32/arch/ppc/mm/fault.c      2008-02-11 12:35:32.000000000 +0100
1235 @@ -296,7 +296,8 @@ out_of_memory:
1236                 down_read(&mm->mmap_sem);
1237                 goto survive;
1238         }
1239 -       printk("VM: killing process %s\n", current->comm);
1240 +       printk("VM: killing process %s(%d:#%u)\n",
1241 +               current->comm, current->pid, current->xid);
1242         if (user_mode(regs))
1243                 do_exit(SIGKILL);
1244         return SIGKILL;
1245 diff -Nurp linux-2.6.22.18/arch/s390/Kconfig linux-2.6.22.18-vs2.3.0.32/arch/s390/Kconfig
1246 --- linux-2.6.22.18/arch/s390/Kconfig   2007-07-21 23:59:49.000000000 +0200
1247 +++ linux-2.6.22.18-vs2.3.0.32/arch/s390/Kconfig        2008-02-11 12:35:32.000000000 +0100
1248 @@ -551,6 +551,8 @@ endmenu
1249  
1250  source "arch/s390/Kconfig.debug"
1251  
1252 +source "kernel/vserver/Kconfig"
1253 +
1254  source "security/Kconfig"
1255  
1256  source "crypto/Kconfig"
1257 diff -Nurp linux-2.6.22.18/arch/s390/kernel/compat_linux.c linux-2.6.22.18-vs2.3.0.32/arch/s390/kernel/compat_linux.c
1258 --- linux-2.6.22.18/arch/s390/kernel/compat_linux.c     2007-07-21 23:59:49.000000000 +0200
1259 +++ linux-2.6.22.18-vs2.3.0.32/arch/s390/kernel/compat_linux.c  2008-02-11 12:35:32.000000000 +0100
1260 @@ -567,7 +567,7 @@ asmlinkage long sys32_gettimeofday(struc
1261  {
1262         if (tv) {
1263                 struct timeval ktv;
1264 -               do_gettimeofday(&ktv);
1265 +               vx_gettimeofday(&ktv);
1266                 if (put_tv32(tv, &ktv))
1267                         return -EFAULT;
1268         }
1269 diff -Nurp linux-2.6.22.18/arch/s390/kernel/process.c linux-2.6.22.18-vs2.3.0.32/arch/s390/kernel/process.c
1270 --- linux-2.6.22.18/arch/s390/kernel/process.c  2007-07-21 23:59:49.000000000 +0200
1271 +++ linux-2.6.22.18-vs2.3.0.32/arch/s390/kernel/process.c       2008-02-11 12:35:32.000000000 +0100
1272 @@ -164,9 +164,9 @@ void show_regs(struct pt_regs *regs)
1273         struct task_struct *tsk = current;
1274  
1275          printk("CPU:    %d    %s\n", task_thread_info(tsk)->cpu, print_tainted());
1276 -        printk("Process %s (pid: %d, task: %p, ksp: %p)\n",
1277 -              current->comm, current->pid, (void *) tsk,
1278 -              (void *) tsk->thread.ksp);
1279 +       printk("Process %s (pid: %d[#%u], task: %p, ksp: %p)\n",
1280 +              current->comm, current->pid, current->xid,
1281 +              (void *) tsk, (void *) tsk->thread.ksp);
1282  
1283         show_registers(regs);
1284         /* Show stack backtrace if pt_regs is from kernel mode */
1285 @@ -197,7 +197,7 @@ int kernel_thread(int (*fn)(void *), voi
1286         regs.orig_gpr2 = -1;
1287  
1288         /* Ok, create the new process.. */
1289 -       return do_fork(flags | CLONE_VM | CLONE_UNTRACED,
1290 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
1291                        0, &regs, 0, NULL, NULL);
1292  }
1293  
1294 diff -Nurp linux-2.6.22.18/arch/s390/kernel/ptrace.c linux-2.6.22.18-vs2.3.0.32/arch/s390/kernel/ptrace.c
1295 --- linux-2.6.22.18/arch/s390/kernel/ptrace.c   2007-07-21 23:58:19.000000000 +0200
1296 +++ linux-2.6.22.18-vs2.3.0.32/arch/s390/kernel/ptrace.c        2008-02-11 12:35:32.000000000 +0100
1297 @@ -33,6 +33,7 @@
1298  #include <linux/security.h>
1299  #include <linux/audit.h>
1300  #include <linux/signal.h>
1301 +#include <linux/vs_base.h>
1302  
1303  #include <asm/segment.h>
1304  #include <asm/page.h>
1305 @@ -725,7 +726,13 @@ sys_ptrace(long request, long pid, long 
1306                 goto out;
1307         }
1308  
1309 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT)) {
1310 +               ret = -EPERM;
1311 +               goto out_tsk;
1312 +       }
1313 +
1314         ret = do_ptrace(child, request, addr, data);
1315 +out_tsk:
1316         put_task_struct(child);
1317  out:
1318         unlock_kernel();
1319 diff -Nurp linux-2.6.22.18/arch/s390/kernel/syscalls.S linux-2.6.22.18-vs2.3.0.32/arch/s390/kernel/syscalls.S
1320 --- linux-2.6.22.18/arch/s390/kernel/syscalls.S 2007-07-21 23:59:49.000000000 +0200
1321 +++ linux-2.6.22.18-vs2.3.0.32/arch/s390/kernel/syscalls.S      2008-02-11 12:35:32.000000000 +0100
1322 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
1323  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
1324  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
1325  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
1326 -NI_SYSCALL                                                     /* reserved for vserver */
1327 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
1328  SYSCALL(s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
1329  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
1330  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
1331 diff -Nurp linux-2.6.22.18/arch/s390/mm/fault.c linux-2.6.22.18-vs2.3.0.32/arch/s390/mm/fault.c
1332 --- linux-2.6.22.18/arch/s390/mm/fault.c        2007-07-21 23:59:49.000000000 +0200
1333 +++ linux-2.6.22.18-vs2.3.0.32/arch/s390/mm/fault.c     2008-02-11 12:35:32.000000000 +0100
1334 @@ -216,7 +216,8 @@ static int do_out_of_memory(struct pt_re
1335                 down_read(&mm->mmap_sem);
1336                 return 1;
1337         }
1338 -       printk("VM: killing process %s\n", tsk->comm);
1339 +       printk("VM: killing process %s(%d:#%u)\n",
1340 +               tsk->comm, tsk->pid, tsk->xid);
1341         if (regs->psw.mask & PSW_MASK_PSTATE)
1342                 do_exit(SIGKILL);
1343         do_no_context(regs, error_code, address);
1344 diff -Nurp linux-2.6.22.18/arch/sh/Kconfig linux-2.6.22.18-vs2.3.0.32/arch/sh/Kconfig
1345 --- linux-2.6.22.18/arch/sh/Kconfig     2007-07-21 23:59:49.000000000 +0200
1346 +++ linux-2.6.22.18-vs2.3.0.32/arch/sh/Kconfig  2008-02-11 12:35:32.000000000 +0100
1347 @@ -723,6 +723,8 @@ source "arch/sh/oprofile/Kconfig"
1348  
1349  source "arch/sh/Kconfig.debug"
1350  
1351 +source "kernel/vserver/Kconfig"
1352 +
1353  source "security/Kconfig"
1354  
1355  source "crypto/Kconfig"
1356 diff -Nurp linux-2.6.22.18/arch/sh/kernel/irq.c linux-2.6.22.18-vs2.3.0.32/arch/sh/kernel/irq.c
1357 --- linux-2.6.22.18/arch/sh/kernel/irq.c        2007-07-21 23:59:49.000000000 +0200
1358 +++ linux-2.6.22.18-vs2.3.0.32/arch/sh/kernel/irq.c     2008-02-11 12:35:33.000000000 +0100
1359 @@ -12,6 +12,7 @@
1360  #include <linux/kernel_stat.h>
1361  #include <linux/seq_file.h>
1362  #include <linux/irq.h>
1363 +#include <linux/vs_context.h>
1364  #include <asm/processor.h>
1365  #include <asm/machvec.h>
1366  #include <asm/uaccess.h>
1367 diff -Nurp linux-2.6.22.18/arch/sh/kernel/process.c linux-2.6.22.18-vs2.3.0.32/arch/sh/kernel/process.c
1368 --- linux-2.6.22.18/arch/sh/kernel/process.c    2007-07-21 23:59:49.000000000 +0200
1369 +++ linux-2.6.22.18-vs2.3.0.32/arch/sh/kernel/process.c 2008-02-11 12:35:33.000000000 +0100
1370 @@ -118,7 +118,8 @@ void machine_power_off(void)
1371  void show_regs(struct pt_regs * regs)
1372  {
1373         printk("\n");
1374 -       printk("Pid : %d, Comm: %20s\n", current->pid, current->comm);
1375 +       printk("Pid : %d:#%u, Comm: %20s\n",
1376 +               current->pid, current->xid, current->comm);
1377         print_symbol("PC is at %s\n", instruction_pointer(regs));
1378         printk("PC  : %08lx SP  : %08lx SR  : %08lx ",
1379                regs->pc, regs->regs[15], regs->sr);
1380 @@ -179,7 +180,7 @@ int kernel_thread(int (*fn)(void *), voi
1381         regs.sr = (1 << 30);
1382  
1383         /* Ok, create the new process.. */
1384 -       return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0,
1385 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD, 0,
1386                        &regs, 0, NULL, NULL);
1387  }
1388  
1389 diff -Nurp linux-2.6.22.18/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.22.18-vs2.3.0.32/arch/sh/kernel/vsyscall/vsyscall.c
1390 --- linux-2.6.22.18/arch/sh/kernel/vsyscall/vsyscall.c  2007-07-21 23:59:49.000000000 +0200
1391 +++ linux-2.6.22.18-vs2.3.0.32/arch/sh/kernel/vsyscall/vsyscall.c       2008-02-11 12:35:33.000000000 +0100
1392 @@ -18,6 +18,7 @@
1393  #include <linux/module.h>
1394  #include <linux/elf.h>
1395  #include <linux/sched.h>
1396 +#include <linux/vs_memory.h>
1397  
1398  /*
1399   * Should the kernel map a VDSO page into processes and pass its
1400 diff -Nurp linux-2.6.22.18/arch/sh/mm/fault.c linux-2.6.22.18-vs2.3.0.32/arch/sh/mm/fault.c
1401 --- linux-2.6.22.18/arch/sh/mm/fault.c  2007-07-21 23:59:49.000000000 +0200
1402 +++ linux-2.6.22.18-vs2.3.0.32/arch/sh/mm/fault.c       2008-02-11 12:35:33.000000000 +0100
1403 @@ -201,7 +201,8 @@ out_of_memory:
1404                 down_read(&mm->mmap_sem);
1405                 goto survive;
1406         }
1407 -       printk("VM: killing process %s\n", tsk->comm);
1408 +       printk("VM: killing process %s(%d:#%u)\n",
1409 +               tsk->comm, tsk->pid, tsk->xid);
1410         if (user_mode(regs))
1411                 do_exit(SIGKILL);
1412         goto no_context;
1413 diff -Nurp linux-2.6.22.18/arch/sh64/kernel/process.c linux-2.6.22.18-vs2.3.0.32/arch/sh64/kernel/process.c
1414 --- linux-2.6.22.18/arch/sh64/kernel/process.c  2007-07-21 23:59:49.000000000 +0200
1415 +++ linux-2.6.22.18-vs2.3.0.32/arch/sh64/kernel/process.c       2008-02-11 12:35:33.000000000 +0100
1416 @@ -400,8 +400,8 @@ int kernel_thread(int (*fn)(void *), voi
1417         regs.pc = (unsigned long)kernel_thread_helper;
1418         regs.sr = (1 << 30);
1419  
1420 -       return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0,
1421 -                      &regs, 0, NULL, NULL);
1422 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
1423 +               0, &regs, 0, NULL, NULL);
1424  }
1425  
1426  /*
1427 diff -Nurp linux-2.6.22.18/arch/sh64/mm/fault.c linux-2.6.22.18-vs2.3.0.32/arch/sh64/mm/fault.c
1428 --- linux-2.6.22.18/arch/sh64/mm/fault.c        2007-07-21 23:59:49.000000000 +0200
1429 +++ linux-2.6.22.18-vs2.3.0.32/arch/sh64/mm/fault.c     2008-02-11 12:35:33.000000000 +0100
1430 @@ -81,7 +81,7 @@ static inline void print_vma(struct vm_a
1431  
1432  static inline void print_task(struct task_struct *tsk)
1433  {
1434 -       printk("Task pid %d\n", tsk->pid);
1435 +       printk("Task pid %d:#%u\n", tsk->pid, tsk->xid);
1436  }
1437  
1438  static pte_t *lookup_pte(struct mm_struct *mm, unsigned long address)
1439 @@ -330,7 +330,8 @@ out_of_memory:
1440                 down_read(&mm->mmap_sem);
1441                 goto survive;
1442         }
1443 -       printk("VM: killing process %s\n", tsk->comm);
1444 +       printk("VM: killing process %s(%d:#%u)\n",
1445 +               tsk->comm, tsk->pid, tsk->xid);
1446         if (user_mode(regs))
1447                 do_exit(SIGKILL);
1448         goto no_context;
1449 diff -Nurp linux-2.6.22.18/arch/sparc/Kconfig linux-2.6.22.18-vs2.3.0.32/arch/sparc/Kconfig
1450 --- linux-2.6.22.18/arch/sparc/Kconfig  2007-07-21 23:59:49.000000000 +0200
1451 +++ linux-2.6.22.18-vs2.3.0.32/arch/sparc/Kconfig       2008-02-11 12:35:33.000000000 +0100
1452 @@ -317,6 +317,8 @@ endmenu
1453  
1454  source "arch/sparc/Kconfig.debug"
1455  
1456 +source "kernel/vserver/Kconfig"
1457 +
1458  source "security/Kconfig"
1459  
1460  source "crypto/Kconfig"
1461 diff -Nurp linux-2.6.22.18/arch/sparc/kernel/process.c linux-2.6.22.18-vs2.3.0.32/arch/sparc/kernel/process.c
1462 --- linux-2.6.22.18/arch/sparc/kernel/process.c 2007-07-21 23:59:49.000000000 +0200
1463 +++ linux-2.6.22.18-vs2.3.0.32/arch/sparc/kernel/process.c      2008-02-11 12:35:33.000000000 +0100
1464 @@ -705,7 +705,8 @@ pid_t kernel_thread(int (*fn)(void *), v
1465                              /* Notreached by child. */
1466                              "1: mov %%o0, %0\n\t" :
1467                              "=r" (retval) :
1468 -                            "i" (__NR_clone), "r" (flags | CLONE_VM | CLONE_UNTRACED),
1469 +                            "i" (__NR_clone), "r" (flags |
1470 +                                       CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD),
1471                              "i" (__NR_exit),  "r" (fn), "r" (arg) :
1472                              "g1", "g2", "g3", "o0", "o1", "memory", "cc");
1473         return retval;
1474 diff -Nurp linux-2.6.22.18/arch/sparc/kernel/ptrace.c linux-2.6.22.18-vs2.3.0.32/arch/sparc/kernel/ptrace.c
1475 --- linux-2.6.22.18/arch/sparc/kernel/ptrace.c  2007-05-04 15:58:05.000000000 +0200
1476 +++ linux-2.6.22.18-vs2.3.0.32/arch/sparc/kernel/ptrace.c       2008-02-11 12:35:33.000000000 +0100
1477 @@ -19,6 +19,7 @@
1478  #include <linux/smp_lock.h>
1479  #include <linux/security.h>
1480  #include <linux/signal.h>
1481 +#include <linux/vs_base.h>
1482  
1483  #include <asm/pgtable.h>
1484  #include <asm/system.h>
1485 @@ -302,6 +303,10 @@ asmlinkage void do_ptrace(struct pt_regs
1486                 pt_error_return(regs, -ret);
1487                 goto out;
1488         }
1489 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT)) {
1490 +               pt_error_return(regs, ESRCH);
1491 +               goto out_tsk;
1492 +       }
1493  
1494         if ((current->personality == PER_SUNOS && request == PTRACE_SUNATTACH)
1495             || (current->personality != PER_SUNOS && request == PTRACE_ATTACH)) {
1496 diff -Nurp linux-2.6.22.18/arch/sparc/kernel/systbls.S linux-2.6.22.18-vs2.3.0.32/arch/sparc/kernel/systbls.S
1497 --- linux-2.6.22.18/arch/sparc/kernel/systbls.S 2007-07-21 23:59:49.000000000 +0200
1498 +++ linux-2.6.22.18-vs2.3.0.32/arch/sparc/kernel/systbls.S      2008-02-11 12:35:33.000000000 +0100
1499 @@ -71,7 +71,7 @@ sys_call_table:
1500  /*250*/        .long sparc_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
1501  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
1502  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
1503 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
1504 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
1505  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
1506  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
1507  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
1508 diff -Nurp linux-2.6.22.18/arch/sparc/kernel/traps.c linux-2.6.22.18-vs2.3.0.32/arch/sparc/kernel/traps.c
1509 --- linux-2.6.22.18/arch/sparc/kernel/traps.c   2007-07-21 23:59:49.000000000 +0200
1510 +++ linux-2.6.22.18-vs2.3.0.32/arch/sparc/kernel/traps.c        2008-02-11 12:35:33.000000000 +0100
1511 @@ -99,7 +99,8 @@ void die_if_kernel(char *str, struct pt_
1512  "              /_| \\__/ |_\\\n"
1513  "                 \\__U_/\n");
1514  
1515 -       printk("%s(%d): %s [#%d]\n", current->comm, current->pid, str, ++die_counter);
1516 +       printk("%s(%d[#%u]): %s [#%d]\n", current->comm,
1517 +               current->pid, current->xid, str, ++die_counter);
1518         show_regs(regs);
1519  
1520         __SAVE; __SAVE; __SAVE; __SAVE;
1521 diff -Nurp linux-2.6.22.18/arch/sparc/mm/fault.c linux-2.6.22.18-vs2.3.0.32/arch/sparc/mm/fault.c
1522 --- linux-2.6.22.18/arch/sparc/mm/fault.c       2007-07-21 23:59:49.000000000 +0200
1523 +++ linux-2.6.22.18-vs2.3.0.32/arch/sparc/mm/fault.c    2008-02-11 12:35:33.000000000 +0100
1524 @@ -367,7 +367,8 @@ no_context:
1525   */
1526  out_of_memory:
1527         up_read(&mm->mmap_sem);
1528 -       printk("VM: killing process %s\n", tsk->comm);
1529 +       printk("VM: killing process %s(%d:#%u)\n",
1530 +               tsk->comm, tsk->pid, tsk->xid);
1531         if (from_user)
1532                 do_exit(SIGKILL);
1533         goto no_context;
1534 diff -Nurp linux-2.6.22.18/arch/sparc64/Kconfig linux-2.6.22.18-vs2.3.0.32/arch/sparc64/Kconfig
1535 --- linux-2.6.22.18/arch/sparc64/Kconfig        2007-07-21 23:59:49.000000000 +0200
1536 +++ linux-2.6.22.18-vs2.3.0.32/arch/sparc64/Kconfig     2008-02-11 12:35:33.000000000 +0100
1537 @@ -451,6 +451,8 @@ endmenu
1538  
1539  source "arch/sparc64/Kconfig.debug"
1540  
1541 +source "kernel/vserver/Kconfig"
1542 +
1543  source "security/Kconfig"
1544  
1545  source "crypto/Kconfig"
1546 diff -Nurp linux-2.6.22.18/arch/sparc64/kernel/binfmt_aout32.c linux-2.6.22.18-vs2.3.0.32/arch/sparc64/kernel/binfmt_aout32.c
1547 --- linux-2.6.22.18/arch/sparc64/kernel/binfmt_aout32.c 2007-05-04 15:58:05.000000000 +0200
1548 +++ linux-2.6.22.18-vs2.3.0.32/arch/sparc64/kernel/binfmt_aout32.c      2008-02-11 12:35:33.000000000 +0100
1549 @@ -27,6 +27,7 @@
1550  #include <linux/binfmts.h>
1551  #include <linux/personality.h>
1552  #include <linux/init.h>
1553 +#include <linux/vs_memory.h>
1554  
1555  #include <asm/system.h>
1556  #include <asm/uaccess.h>
1557 diff -Nurp linux-2.6.22.18/arch/sparc64/kernel/process.c linux-2.6.22.18-vs2.3.0.32/arch/sparc64/kernel/process.c
1558 --- linux-2.6.22.18/arch/sparc64/kernel/process.c       2007-07-21 23:59:49.000000000 +0200
1559 +++ linux-2.6.22.18-vs2.3.0.32/arch/sparc64/kernel/process.c    2008-02-11 12:35:33.000000000 +0100
1560 @@ -707,7 +707,8 @@ pid_t kernel_thread(int (*fn)(void *), v
1561                              /* Notreached by child. */
1562                              "1:" :
1563                              "=r" (retval) :
1564 -                            "i" (__NR_clone), "r" (flags | CLONE_VM | CLONE_UNTRACED),
1565 +                            "i" (__NR_clone), "r" (flags |
1566 +                               CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD),
1567                              "i" (__NR_exit),  "r" (fn), "r" (arg) :
1568                              "g1", "g2", "g3", "o0", "o1", "memory", "cc");
1569         return retval;
1570 diff -Nurp linux-2.6.22.18/arch/sparc64/kernel/ptrace.c linux-2.6.22.18-vs2.3.0.32/arch/sparc64/kernel/ptrace.c
1571 --- linux-2.6.22.18/arch/sparc64/kernel/ptrace.c        2007-05-04 15:58:05.000000000 +0200
1572 +++ linux-2.6.22.18-vs2.3.0.32/arch/sparc64/kernel/ptrace.c     2008-02-11 12:35:33.000000000 +0100
1573 @@ -22,6 +22,7 @@
1574  #include <linux/seccomp.h>
1575  #include <linux/audit.h>
1576  #include <linux/signal.h>
1577 +#include <linux/vs_base.h>
1578  
1579  #include <asm/asi.h>
1580  #include <asm/pgtable.h>
1581 @@ -215,6 +216,10 @@ asmlinkage void do_ptrace(struct pt_regs
1582                 pt_error_return(regs, -ret);
1583                 goto out;
1584         }
1585 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT)) {
1586 +               pt_error_return(regs, ESRCH);
1587 +               goto out_tsk;
1588 +       }
1589  
1590         if ((current->personality == PER_SUNOS && request == PTRACE_SUNATTACH)
1591             || (current->personality != PER_SUNOS && request == PTRACE_ATTACH)) {
1592 diff -Nurp linux-2.6.22.18/arch/sparc64/kernel/sys_sparc32.c linux-2.6.22.18-vs2.3.0.32/arch/sparc64/kernel/sys_sparc32.c
1593 --- linux-2.6.22.18/arch/sparc64/kernel/sys_sparc32.c   2007-07-21 23:59:49.000000000 +0200
1594 +++ linux-2.6.22.18-vs2.3.0.32/arch/sparc64/kernel/sys_sparc32.c        2008-02-11 12:35:33.000000000 +0100
1595 @@ -729,7 +729,7 @@ asmlinkage long sys32_gettimeofday(struc
1596  {
1597         if (tv) {
1598                 struct timeval ktv;
1599 -               do_gettimeofday(&ktv);
1600 +               vx_gettimeofday(&ktv);
1601                 if (put_tv32(tv, &ktv))
1602                         return -EFAULT;
1603         }
1604 diff -Nurp linux-2.6.22.18/arch/sparc64/kernel/systbls.S linux-2.6.22.18-vs2.3.0.32/arch/sparc64/kernel/systbls.S
1605 --- linux-2.6.22.18/arch/sparc64/kernel/systbls.S       2007-07-21 23:59:49.000000000 +0200
1606 +++ linux-2.6.22.18-vs2.3.0.32/arch/sparc64/kernel/systbls.S    2008-02-11 12:35:33.000000000 +0100
1607 @@ -72,7 +72,7 @@ sys_call_table32:
1608  /*250*/        .word sys32_mremap, sys32_sysctl, sys32_getsid, sys_fdatasync, sys32_nfsservctl
1609         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
1610  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
1611 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
1612 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
1613  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
1614         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
1615  /*280*/        .word sys32_tee, sys_add_key, sys_request_key, sys_keyctl, compat_sys_openat
1616 @@ -144,7 +144,7 @@ sys_call_table:
1617  /*250*/        .word sys64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
1618         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
1619  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
1620 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
1621 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
1622  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
1623         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
1624  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
1625 diff -Nurp linux-2.6.22.18/arch/sparc64/kernel/traps.c linux-2.6.22.18-vs2.3.0.32/arch/sparc64/kernel/traps.c
1626 --- linux-2.6.22.18/arch/sparc64/kernel/traps.c 2007-09-05 07:07:59.000000000 +0200
1627 +++ linux-2.6.22.18-vs2.3.0.32/arch/sparc64/kernel/traps.c      2008-02-11 12:35:33.000000000 +0100
1628 @@ -2225,7 +2225,8 @@ void die_if_kernel(char *str, struct pt_
1629  "              /_| \\__/ |_\\\n"
1630  "                 \\__U_/\n");
1631  
1632 -       printk("%s(%d): %s [#%d]\n", current->comm, current->pid, str, ++die_counter);
1633 +       printk("%s(%d[#%u]): %s [#%d]\n", current->comm,
1634 +               current->pid, current->xid, str, ++die_counter);
1635         notify_die(DIE_OOPS, str, regs, 0, 255, SIGSEGV);
1636         __asm__ __volatile__("flushw");
1637         __show_regs(regs);
1638 diff -Nurp linux-2.6.22.18/arch/sparc64/mm/fault.c linux-2.6.22.18-vs2.3.0.32/arch/sparc64/mm/fault.c
1639 --- linux-2.6.22.18/arch/sparc64/mm/fault.c     2007-09-05 07:07:59.000000000 +0200
1640 +++ linux-2.6.22.18-vs2.3.0.32/arch/sparc64/mm/fault.c  2008-02-11 12:35:33.000000000 +0100
1641 @@ -463,7 +463,8 @@ handle_kernel_fault:
1642  out_of_memory:
1643         insn = get_fault_insn(regs, insn);
1644         up_read(&mm->mmap_sem);
1645 -       printk("VM: killing process %s\n", current->comm);
1646 +       printk("VM: killing process %s(%d:#%u)\n",
1647 +               current->comm, current->pid, current->xid);
1648         if (!(regs->tstate & TSTATE_PRIV))
1649                 do_exit(SIGKILL);
1650         goto handle_kernel_fault;
1651 diff -Nurp linux-2.6.22.18/arch/sparc64/solaris/fs.c linux-2.6.22.18-vs2.3.0.32/arch/sparc64/solaris/fs.c
1652 --- linux-2.6.22.18/arch/sparc64/solaris/fs.c   2007-05-04 15:58:05.000000000 +0200
1653 +++ linux-2.6.22.18-vs2.3.0.32/arch/sparc64/solaris/fs.c        2008-02-11 12:35:33.000000000 +0100
1654 @@ -368,7 +368,7 @@ static int report_statvfs(struct vfsmoun
1655                 int j = strlen (p);
1656                 
1657                 if (j > 15) j = 15;
1658 -               if (IS_RDONLY(inode)) i = 1;
1659 +               if (IS_RDONLY(inode) || MNT_IS_RDONLY(mnt)) i = 1;
1660                 if (mnt->mnt_flags & MNT_NOSUID) i |= 2;
1661                 if (!sysv_valid_dev(inode->i_sb->s_dev))
1662                         return -EOVERFLOW;
1663 @@ -404,7 +404,7 @@ static int report_statvfs64(struct vfsmo
1664                 int j = strlen (p);
1665                 
1666                 if (j > 15) j = 15;
1667 -               if (IS_RDONLY(inode)) i = 1;
1668 +               if (IS_RDONLY(inode) || MNT_IS_RDONLY(mnt)) i = 1;
1669                 if (mnt->mnt_flags & MNT_NOSUID) i |= 2;
1670                 if (!sysv_valid_dev(inode->i_sb->s_dev))
1671                         return -EOVERFLOW;
1672 diff -Nurp linux-2.6.22.18/arch/um/Kconfig linux-2.6.22.18-vs2.3.0.32/arch/um/Kconfig
1673 --- linux-2.6.22.18/arch/um/Kconfig     2007-07-21 23:59:49.000000000 +0200
1674 +++ linux-2.6.22.18-vs2.3.0.32/arch/um/Kconfig  2008-02-11 12:35:33.000000000 +0100
1675 @@ -316,6 +316,8 @@ source "drivers/connector/Kconfig"
1676  
1677  source "fs/Kconfig"
1678  
1679 +source "kernel/vserver/Kconfig"
1680 +
1681  source "security/Kconfig"
1682  
1683  source "crypto/Kconfig"
1684 diff -Nurp linux-2.6.22.18/arch/um/kernel/trap.c linux-2.6.22.18-vs2.3.0.32/arch/um/kernel/trap.c
1685 --- linux-2.6.22.18/arch/um/kernel/trap.c       2007-07-21 23:59:50.000000000 +0200
1686 +++ linux-2.6.22.18-vs2.3.0.32/arch/um/kernel/trap.c    2008-02-11 12:35:33.000000000 +0100
1687 @@ -210,7 +210,8 @@ unsigned long segv(struct faultinfo fi, 
1688                 current->thread.arch.faultinfo = fi;
1689                 force_sig_info(SIGBUS, &si, current);
1690         } else if (err == -ENOMEM) {
1691 -               printk("VM: killing process %s\n", current->comm);
1692 +               printk("VM: killing process %s(%d:#%u)\n",
1693 +                       current->comm, current->pid, current->xid);
1694                 do_exit(SIGKILL);
1695         } else {
1696                 BUG_ON(err != -EFAULT);
1697 diff -Nurp linux-2.6.22.18/arch/v850/Kconfig linux-2.6.22.18-vs2.3.0.32/arch/v850/Kconfig
1698 --- linux-2.6.22.18/arch/v850/Kconfig   2007-07-21 23:59:50.000000000 +0200
1699 +++ linux-2.6.22.18-vs2.3.0.32/arch/v850/Kconfig        2008-02-11 12:35:33.000000000 +0100
1700 @@ -333,6 +333,8 @@ source "drivers/usb/Kconfig"
1701  
1702  source "arch/v850/Kconfig.debug"
1703  
1704 +source "kernel/vserver/Kconfig"
1705 +
1706  source "security/Kconfig"
1707  
1708  source "crypto/Kconfig"
1709 diff -Nurp linux-2.6.22.18/arch/v850/kernel/process.c linux-2.6.22.18-vs2.3.0.32/arch/v850/kernel/process.c
1710 --- linux-2.6.22.18/arch/v850/kernel/process.c  2007-07-21 23:59:50.000000000 +0200
1711 +++ linux-2.6.22.18-vs2.3.0.32/arch/v850/kernel/process.c       2008-02-11 12:35:33.000000000 +0100
1712 @@ -82,7 +82,7 @@ int kernel_thread (int (*fn)(void *), vo
1713         /* Clone this thread.  Note that we don't pass the clone syscall's
1714            second argument -- it's ignored for calls from kernel mode (the
1715            child's SP is always set to the top of the kernel stack).  */
1716 -       arg0 = flags | CLONE_VM;
1717 +       arg0 = flags | CLONE_VM | CLONE_KTHREAD;
1718         syscall = __NR_clone;
1719         asm volatile ("trap " SYSCALL_SHORT_TRAP
1720                       : "=r" (ret), "=r" (syscall)
1721 diff -Nurp linux-2.6.22.18/arch/v850/kernel/ptrace.c linux-2.6.22.18-vs2.3.0.32/arch/v850/kernel/ptrace.c
1722 --- linux-2.6.22.18/arch/v850/kernel/ptrace.c   2007-07-21 23:59:50.000000000 +0200
1723 +++ linux-2.6.22.18-vs2.3.0.32/arch/v850/kernel/ptrace.c        2008-02-11 12:35:33.000000000 +0100
1724 @@ -23,6 +23,7 @@
1725  #include <linux/sched.h>
1726  #include <linux/ptrace.h>
1727  #include <linux/signal.h>
1728 +#include <linux/vs_base.h>
1729  
1730  #include <asm/errno.h>
1731  #include <asm/ptrace.h>
1732 @@ -116,6 +117,9 @@ long arch_ptrace(struct task_struct *chi
1733  {
1734         int rval;
1735  
1736 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
1737 +               goto out;
1738 +
1739         switch (request) {
1740                 unsigned long val, copied;
1741  
1742 diff -Nurp linux-2.6.22.18/arch/x86_64/ia32/ia32_aout.c linux-2.6.22.18-vs2.3.0.32/arch/x86_64/ia32/ia32_aout.c
1743 --- linux-2.6.22.18/arch/x86_64/ia32/ia32_aout.c        2007-05-04 15:58:05.000000000 +0200
1744 +++ linux-2.6.22.18-vs2.3.0.32/arch/x86_64/ia32/ia32_aout.c     2008-02-11 12:35:33.000000000 +0100
1745 @@ -25,6 +25,7 @@
1746  #include <linux/binfmts.h>
1747  #include <linux/personality.h>
1748  #include <linux/init.h>
1749 +#include <linux/vs_memory.h>
1750  
1751  #include <asm/system.h>
1752  #include <asm/uaccess.h>
1753 diff -Nurp linux-2.6.22.18/arch/x86_64/ia32/ia32_binfmt.c linux-2.6.22.18-vs2.3.0.32/arch/x86_64/ia32/ia32_binfmt.c
1754 --- linux-2.6.22.18/arch/x86_64/ia32/ia32_binfmt.c      2007-07-21 23:59:50.000000000 +0200
1755 +++ linux-2.6.22.18-vs2.3.0.32/arch/x86_64/ia32/ia32_binfmt.c   2008-02-11 12:35:33.000000000 +0100
1756 @@ -324,7 +324,8 @@ int ia32_setup_arg_pages(struct linux_bi
1757                         kmem_cache_free(vm_area_cachep, mpnt);
1758                         return ret;
1759                 }
1760 -               mm->stack_vm = mm->total_vm = vma_pages(mpnt);
1761 +               vx_vmpages_sub(mm, mm->total_vm - vma_pages(mpnt));
1762 +               mm->stack_vm = mm->total_vm;
1763         } 
1764  
1765         for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
1766 diff -Nurp linux-2.6.22.18/arch/x86_64/ia32/ia32entry.S linux-2.6.22.18-vs2.3.0.32/arch/x86_64/ia32/ia32entry.S
1767 --- linux-2.6.22.18/arch/x86_64/ia32/ia32entry.S        2007-09-29 14:11:36.000000000 +0200
1768 +++ linux-2.6.22.18-vs2.3.0.32/arch/x86_64/ia32/ia32entry.S     2008-02-11 12:35:33.000000000 +0100
1769 @@ -680,7 +680,7 @@ ia32_sys_call_table:
1770         .quad sys_tgkill                /* 270 */
1771         .quad compat_sys_utimes
1772         .quad sys32_fadvise64_64
1773 -       .quad quiet_ni_syscall  /* sys_vserver */
1774 +       .quad sys32_vserver
1775         .quad sys_mbind
1776         .quad compat_sys_get_mempolicy  /* 275 */
1777         .quad sys_set_mempolicy
1778 diff -Nurp linux-2.6.22.18/arch/x86_64/ia32/syscall32.c linux-2.6.22.18-vs2.3.0.32/arch/x86_64/ia32/syscall32.c
1779 --- linux-2.6.22.18/arch/x86_64/ia32/syscall32.c        2007-07-21 23:59:50.000000000 +0200
1780 +++ linux-2.6.22.18-vs2.3.0.32/arch/x86_64/ia32/syscall32.c     2008-02-11 12:35:33.000000000 +0100
1781 @@ -10,6 +10,7 @@
1782  #include <linux/init.h>
1783  #include <linux/stringify.h>
1784  #include <linux/security.h>
1785 +#include <linux/vs_memory.h>
1786  #include <asm/proto.h>
1787  #include <asm/tlbflush.h>
1788  #include <asm/ia32_unistd.h>
1789 diff -Nurp linux-2.6.22.18/arch/x86_64/ia32/sys_ia32.c linux-2.6.22.18-vs2.3.0.32/arch/x86_64/ia32/sys_ia32.c
1790 --- linux-2.6.22.18/arch/x86_64/ia32/sys_ia32.c 2007-07-21 23:59:50.000000000 +0200
1791 +++ linux-2.6.22.18-vs2.3.0.32/arch/x86_64/ia32/sys_ia32.c      2008-02-11 12:35:33.000000000 +0100
1792 @@ -454,7 +454,7 @@ sys32_gettimeofday(struct compat_timeval
1793  {
1794         if (tv) {
1795                 struct timeval ktv;
1796 -               do_gettimeofday(&ktv);
1797 +               vx_gettimeofday(&ktv);
1798                 if (put_tv32(tv, &ktv))
1799                         return -EFAULT;
1800         }
1801 diff -Nurp linux-2.6.22.18/arch/x86_64/Kconfig linux-2.6.22.18-vs2.3.0.32/arch/x86_64/Kconfig
1802 --- linux-2.6.22.18/arch/x86_64/Kconfig 2007-07-21 23:59:50.000000000 +0200
1803 +++ linux-2.6.22.18-vs2.3.0.32/arch/x86_64/Kconfig      2008-02-11 12:35:33.000000000 +0100
1804 @@ -782,6 +782,8 @@ endmenu
1805  
1806  source "arch/x86_64/Kconfig.debug"
1807  
1808 +source "kernel/vserver/Kconfig"
1809 +
1810  source "security/Kconfig"
1811  
1812  source "crypto/Kconfig"
1813 diff -Nurp linux-2.6.22.18/arch/x86_64/kernel/process.c linux-2.6.22.18-vs2.3.0.32/arch/x86_64/kernel/process.c
1814 --- linux-2.6.22.18/arch/x86_64/kernel/process.c        2007-07-21 23:59:50.000000000 +0200
1815 +++ linux-2.6.22.18-vs2.3.0.32/arch/x86_64/kernel/process.c     2008-02-11 12:35:33.000000000 +0100
1816 @@ -54,7 +54,8 @@
1817  
1818  asmlinkage extern void ret_from_fork(void);
1819  
1820 -unsigned long kernel_thread_flags = CLONE_VM | CLONE_UNTRACED;
1821 +unsigned long kernel_thread_flags =
1822 +       CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD;
1823  
1824  unsigned long boot_option_idle_override = 0;
1825  EXPORT_SYMBOL(boot_option_idle_override);
1826 @@ -310,8 +311,8 @@ void __show_regs(struct pt_regs * regs)
1827  
1828         printk("\n");
1829         print_modules();
1830 -       printk("Pid: %d, comm: %.20s %s %s %.*s\n",
1831 -               current->pid, current->comm, print_tainted(),
1832 +       printk("Pid: %d:#%u, comm: %.20s %s %s %.*s\n",
1833 +               current->pid, current->xid, current->comm, print_tainted(),
1834                 init_utsname()->release,
1835                 (int)strcspn(init_utsname()->version, " "),
1836                 init_utsname()->version);
1837 diff -Nurp linux-2.6.22.18/arch/x86_64/kernel/traps.c linux-2.6.22.18-vs2.3.0.32/arch/x86_64/kernel/traps.c
1838 --- linux-2.6.22.18/arch/x86_64/kernel/traps.c  2007-07-21 23:59:50.000000000 +0200
1839 +++ linux-2.6.22.18-vs2.3.0.32/arch/x86_64/kernel/traps.c       2008-02-11 12:35:33.000000000 +0100
1840 @@ -33,6 +33,8 @@
1841  #include <linux/uaccess.h>
1842  #include <linux/bug.h>
1843  #include <linux/kdebug.h>
1844 +#include <linux/vs_context.h>
1845 +#include <linux/vserver/history.h>
1846  
1847  #include <asm/system.h>
1848  #include <asm/io.h>
1849 @@ -413,8 +415,9 @@ void show_registers(struct pt_regs *regs
1850         rsp = regs->rsp;
1851         printk("CPU %d ", cpu);
1852         __show_regs(regs);
1853 -       printk("Process %s (pid: %d, threadinfo %p, task %p)\n",
1854 -               cur->comm, cur->pid, task_thread_info(cur), cur);
1855 +       printk("Process %s (pid: %d[#%u], threadinfo %p, task %p)\n",
1856 +               cur->comm, cur->pid, cur->xid,
1857 +               task_thread_info(cur), cur);
1858  
1859         /*
1860          * When in-kernel, we also print out the stack and code at the
1861 @@ -518,6 +521,7 @@ void __kprobes __die(const char * str, s
1862         printk("\n");
1863         notify_die(DIE_OOPS, str, regs, err, current->thread.trap_no, SIGSEGV);
1864         show_registers(regs);
1865 +       vxh_dump_history();
1866         /* Executive summary in case the oops scrolled away */
1867         printk(KERN_ALERT "RIP ");
1868         printk_address(regs->rip); 
1869 @@ -530,6 +534,7 @@ void die(const char * str, struct pt_reg
1870  {
1871         unsigned long flags = oops_begin();
1872  
1873 +       vxh_throw_oops();
1874         if (!user_mode(regs))
1875                 report_bug(regs->rip);
1876  
1877 @@ -542,12 +547,14 @@ void __kprobes die_nmi(char *str, struct
1878  {
1879         unsigned long flags = oops_begin();
1880  
1881 +       vxh_throw_oops();
1882         /*
1883          * We are in trouble anyway, lets at least try
1884          * to get a message out.
1885          */
1886         printk(str, smp_processor_id());
1887         show_registers(regs);
1888 +       vxh_dump_history();
1889         if (kexec_should_crash(current))
1890                 crash_kexec(regs);
1891         if (do_panic || panic_on_oops)
1892 @@ -580,8 +587,8 @@ static void __kprobes do_trap(int trapnr
1893  
1894                 if (exception_trace && unhandled_signal(tsk, signr))
1895                         printk(KERN_INFO
1896 -                              "%s[%d] trap %s rip:%lx rsp:%lx error:%lx\n",
1897 -                              tsk->comm, tsk->pid, str,
1898 +                              "%s[%d:#%u] trap %s rip:%lx rsp:%lx error:%lx\n",
1899 +                              tsk->comm, tsk->pid, tsk->xid, str,
1900                                regs->rip, regs->rsp, error_code); 
1901  
1902                 if (info)
1903 @@ -684,8 +691,8 @@ asmlinkage void __kprobes do_general_pro
1904  
1905                 if (exception_trace && unhandled_signal(tsk, SIGSEGV))
1906                         printk(KERN_INFO
1907 -                      "%s[%d] general protection rip:%lx rsp:%lx error:%lx\n",
1908 -                              tsk->comm, tsk->pid,
1909 +                      "%s[%d:#%u] general protection rip:%lx rsp:%lx error:%lx\n",
1910 +                              tsk->comm, tsk->pid, tsk->xid,
1911                                regs->rip, regs->rsp, error_code); 
1912  
1913                 force_sig(SIGSEGV, tsk);
1914 diff -Nurp linux-2.6.22.18/arch/x86_64/mm/fault.c linux-2.6.22.18-vs2.3.0.32/arch/x86_64/mm/fault.c
1915 --- linux-2.6.22.18/arch/x86_64/mm/fault.c      2007-07-21 23:59:50.000000000 +0200
1916 +++ linux-2.6.22.18-vs2.3.0.32/arch/x86_64/mm/fault.c   2008-02-11 12:35:33.000000000 +0100
1917 @@ -497,10 +497,10 @@ bad_area_nosemaphore:
1918  
1919                 if (exception_trace && unhandled_signal(tsk, SIGSEGV)) {
1920                         printk(
1921 -                      "%s%s[%d]: segfault at %016lx rip %016lx rsp %016lx error %lx\n",
1922 +                      "%s%s[%d:#%u]: segfault at %016lx rip %016lx rsp %016lx error %lx\n",
1923                                         tsk->pid > 1 ? KERN_INFO : KERN_EMERG,
1924 -                                       tsk->comm, tsk->pid, address, regs->rip,
1925 -                                       regs->rsp, error_code);
1926 +                                       tsk->comm, tsk->pid, tsk->xid, address,
1927 +                                       regs->rip, regs->rsp, error_code);
1928                 }
1929         
1930                 tsk->thread.cr2 = address;
1931 @@ -567,7 +567,8 @@ out_of_memory:
1932                 yield();
1933                 goto again;
1934         }
1935 -       printk("VM: killing process %s\n", tsk->comm);
1936 +       printk("VM: killing process %s(%d:#%u)\n",
1937 +               tsk->comm, tsk->pid, tsk->xid);
1938         if (error_code & 4)
1939                 do_exit(SIGKILL);
1940         goto no_context;
1941 diff -Nurp linux-2.6.22.18/Documentation/vserver/debug.txt linux-2.6.22.18-vs2.3.0.32/Documentation/vserver/debug.txt
1942 --- linux-2.6.22.18/Documentation/vserver/debug.txt     1970-01-01 01:00:00.000000000 +0100
1943 +++ linux-2.6.22.18-vs2.3.0.32/Documentation/vserver/debug.txt  2008-02-11 12:35:31.000000000 +0100
1944 @@ -0,0 +1,154 @@
1945 +
1946 +debug_cvirt:
1947 +
1948 + 2   4 "vx_map_tgid: %p/%llx: %d -> %d"
1949 +       "vx_rmap_tgid: %p/%llx: %d -> %d"
1950 +
1951 +debug_dlim:
1952 +
1953 + 0   1 "ALLOC (%p,#%d)%c inode (%d)"
1954 +       "FREE  (%p,#%d)%c inode"
1955 + 1   2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
1956 +       "FREE  (%p,#%d)%c %lld bytes"
1957 + 2   4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
1958 + 3   8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
1959 +       "ext3_has_free_blocks(%p): free=%lu, root=%lu"
1960 +       "rcu_free_dl_info(%p)"
1961 + 4  10 "alloc_dl_info(%p,%d) = %p"
1962 +       "dealloc_dl_info(%p)"
1963 +       "get_dl_info(%p[#%d.%d])"
1964 +       "put_dl_info(%p[#%d.%d])"
1965 + 5  20 "alloc_dl_info(%p,%d)*"
1966 + 6  40 "__hash_dl_info: %p[#%d]"
1967 +       "__unhash_dl_info: %p[#%d]"
1968 + 7  80 "locate_dl_info(%p,#%d) = %p"
1969 +
1970 +debug_misc:
1971 +
1972 + 0   1 "destroy_dqhash: %p [#0x%08x] c=%d"
1973 +       "new_dqhash: %p [#0x%08x]"
1974 +       "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
1975 +       "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
1976 +       "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
1977 +       "vroot_get_real_bdev not set"
1978 + 1   2 "cow_break_link(»%s«)"
1979 +       "temp copy Â»%s«"
1980 + 2   4 "dentry_open(new): %p"
1981 +       "dentry_open(old): %p"
1982 +       "lookup_create(new): %p"
1983 +       "old path Â»%s«"
1984 +       "path_lookup(old): %d"
1985 +       "vfs_create(new): %d"
1986 +       "vfs_rename: %d"
1987 +       "vfs_sendfile: %d"
1988 + 3   8 "fput(new_file=%p[#%d])"
1989 +       "fput(old_file=%p[#%d])"
1990 + 4  10 "vx_info_kill(%p[#%d],%d,%d) = %d"
1991 +       "vx_info_kill(%p[#%d],%d,%d)*"
1992 + 5  20 "vs_reboot(%p[#%d],%d)"
1993 + 6  40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
1994 +
1995 +debug_net:
1996 +
1997 + 2   4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
1998 + 3   8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
1999 +       "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
2000 + 4  10 "ip_route_connect(%p) %p,%p;%lx"
2001 + 5  20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
2002 + 6  40 "sk,egf: %p [#%d] (from %d)"
2003 +       "sk,egn: %p [#%d] (from %d)"
2004 +       "sk,req: %p [#%d] (from %d)"
2005 +       "sk: %p [#%d] (from %d)"
2006 +       "tw: %p [#%d] (from %d)"
2007 + 7  80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
2008 +       "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
2009 +
2010 +debug_nid:
2011 +
2012 + 0   1 "__lookup_nx_info(#%u): %p[#%u]"
2013 +       "alloc_nx_info(%d) = %p"
2014 +       "create_nx_info(%d) (dynamic rejected)"
2015 +       "create_nx_info(%d) = %p (already there)"
2016 +       "create_nx_info(%d) = %p (new)"
2017 +       "dealloc_nx_info(%p)"
2018 + 1   2 "alloc_nx_info(%d)*"
2019 +       "create_nx_info(%d)*"
2020 + 2   4 "get_nx_info(%p[#%d.%d])"
2021 +       "put_nx_info(%p[#%d.%d])"
2022 + 3   8 "claim_nx_info(%p[#%d.%d.%d]) %p"
2023 +       "clr_nx_info(%p[#%d.%d])"
2024 +       "init_nx_info(%p[#%d.%d])"
2025 +       "release_nx_info(%p[#%d.%d.%d]) %p"
2026 +       "set_nx_info(%p[#%d.%d])"
2027 + 4  10 "__hash_nx_info: %p[#%d]"
2028 +       "__nx_dynamic_id: [#%d]"
2029 +       "__unhash_nx_info: %p[#%d.%d.%d]"
2030 + 5  20 "moved task %p into nxi:%p[#%d]"
2031 +       "nx_migrate_task(%p,%p[#%d.%d.%d])"
2032 +       "task_get_nx_info(%p)"
2033 + 6  40 "nx_clear_persistent(%p[#%d])"
2034 +
2035 +debug_quota:
2036 +
2037 + 0   1 "quota_sync_dqh(%p,%d) discard inode %p"
2038 + 1   2 "quota_sync_dqh(%p,%d)"
2039 +       "sync_dquots(%p,%d)"
2040 +       "sync_dquots_dqh(%p,%d)"
2041 + 3   8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
2042 +
2043 +debug_switch:
2044 +
2045 + 0   1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
2046 + 1   2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
2047 + 4  10 "%s: (%s %s) returned %s with %d"
2048 +
2049 +debug_tag:
2050 +
2051 + 7  80 "dx_parse_tag(»%s«): %d:#%d"
2052 +       "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
2053 +
2054 +debug_xid:
2055 +
2056 + 0   1 "__lookup_vx_info(#%u): %p[#%u]"
2057 +       "alloc_vx_info(%d) = %p"
2058 +       "alloc_vx_info(%d)*"
2059 +       "create_vx_info(%d) (dynamic rejected)"
2060 +       "create_vx_info(%d) = %p (already there)"
2061 +       "create_vx_info(%d) = %p (new)"
2062 +       "dealloc_vx_info(%p)"
2063 +       "loc_vx_info(%d) = %p (found)"
2064 +       "loc_vx_info(%d) = %p (new)"
2065 +       "loc_vx_info(%d) = %p (not available)"
2066 + 1   2 "create_vx_info(%d)*"
2067 +       "loc_vx_info(%d)*"
2068 + 2   4 "get_vx_info(%p[#%d.%d])"
2069 +       "put_vx_info(%p[#%d.%d])"
2070 + 3   8 "claim_vx_info(%p[#%d.%d.%d]) %p"
2071 +       "clr_vx_info(%p[#%d.%d])"
2072 +       "init_vx_info(%p[#%d.%d])"
2073 +       "release_vx_info(%p[#%d.%d.%d]) %p"
2074 +       "set_vx_info(%p[#%d.%d])"
2075 + 4  10 "__hash_vx_info: %p[#%d]"
2076 +       "__unhash_vx_info: %p[#%d.%d.%d]"
2077 +       "__vx_dynamic_id: [#%d]"
2078 + 5  20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
2079 +       "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
2080 +       "moved task %p into vxi:%p[#%d]"
2081 +       "task_get_vx_info(%p)"
2082 +       "vx_migrate_task(%p,%p[#%d.%d])"
2083 + 6  40 "vx_clear_persistent(%p[#%d])"
2084 +       "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
2085 +       "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
2086 +       "vx_set_persistent(%p[#%d])"
2087 +       "vx_set_reaper(%p[#%d],%p[#%d,%d])"
2088 + 7  80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
2089 +
2090 +
2091 +debug_limit:
2092 +
2093 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
2094 +       "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
2095 +
2096 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
2097 +       "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
2098 +       "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
2099 diff -Nurp linux-2.6.22.18/drivers/block/Kconfig linux-2.6.22.18-vs2.3.0.32/drivers/block/Kconfig
2100 --- linux-2.6.22.18/drivers/block/Kconfig       2007-07-21 23:59:50.000000000 +0200
2101 +++ linux-2.6.22.18-vs2.3.0.32/drivers/block/Kconfig    2008-02-11 12:35:33.000000000 +0100
2102 @@ -311,6 +311,13 @@ config BLK_DEV_CRYPTOLOOP
2103           instead, which can be configured to be on-disk compatible with the
2104           cryptoloop device.
2105  
2106 +config BLK_DEV_VROOT
2107 +       tristate "Virtual Root device support"
2108 +       depends on QUOTACTL
2109 +       ---help---
2110 +         Saying Y here will allow you to use quota/fs ioctls on a shared
2111 +         partition within a virtual server without compromising security.
2112 +
2113  config BLK_DEV_NBD
2114         tristate "Network block device support"
2115         depends on NET
2116 diff -Nurp linux-2.6.22.18/drivers/block/loop.c linux-2.6.22.18-vs2.3.0.32/drivers/block/loop.c
2117 --- linux-2.6.22.18/drivers/block/loop.c        2007-07-21 23:59:50.000000000 +0200
2118 +++ linux-2.6.22.18-vs2.3.0.32/drivers/block/loop.c     2008-02-11 12:35:33.000000000 +0100
2119 @@ -74,6 +74,7 @@
2120  #include <linux/highmem.h>
2121  #include <linux/gfp.h>
2122  #include <linux/kthread.h>
2123 +#include <linux/vs_context.h>
2124  
2125  #include <asm/uaccess.h>
2126  
2127 @@ -790,6 +791,7 @@ static int loop_set_fd(struct loop_devic
2128         lo->lo_blocksize = lo_blocksize;
2129         lo->lo_device = bdev;
2130         lo->lo_flags = lo_flags;
2131 +       lo->lo_xid = vx_current_xid();
2132         lo->lo_backing_file = file;
2133         lo->transfer = transfer_none;
2134         lo->ioctl = NULL;
2135 @@ -909,6 +911,7 @@ static int loop_clr_fd(struct loop_devic
2136         lo->lo_encrypt_key_size = 0;
2137         lo->lo_flags = 0;
2138         lo->lo_thread = NULL;
2139 +       lo->lo_xid = 0;
2140         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
2141         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
2142         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
2143 @@ -930,7 +933,7 @@ loop_set_status(struct loop_device *lo, 
2144         struct loop_func_table *xfer;
2145  
2146         if (lo->lo_encrypt_key_size && lo->lo_key_owner != current->uid &&
2147 -           !capable(CAP_SYS_ADMIN))
2148 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
2149                 return -EPERM;
2150         if (lo->lo_state != Lo_bound)
2151                 return -ENXIO;
2152 @@ -1010,7 +1013,8 @@ loop_get_status(struct loop_device *lo, 
2153         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
2154         info->lo_encrypt_type =
2155                 lo->lo_encryption ? lo->lo_encryption->number : 0;
2156 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
2157 +       if (lo->lo_encrypt_key_size &&
2158 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
2159                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
2160                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
2161                        lo->lo_encrypt_key_size);
2162 @@ -1321,6 +1325,9 @@ static int lo_open(struct inode *inode, 
2163  {
2164         struct loop_device *lo = inode->i_bdev->bd_disk->private_data;
2165  
2166 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID))
2167 +               return -EACCES;
2168 +
2169         mutex_lock(&lo->lo_ctl_mutex);
2170         lo->lo_refcnt++;
2171         mutex_unlock(&lo->lo_ctl_mutex);
2172 diff -Nurp linux-2.6.22.18/drivers/block/Makefile linux-2.6.22.18-vs2.3.0.32/drivers/block/Makefile
2173 --- linux-2.6.22.18/drivers/block/Makefile      2007-05-04 15:58:05.000000000 +0200
2174 +++ linux-2.6.22.18-vs2.3.0.32/drivers/block/Makefile   2008-02-11 12:35:33.000000000 +0100
2175 @@ -28,4 +28,5 @@ obj-$(CONFIG_BLK_DEV_CRYPTOLOOP) += cryp
2176  obj-$(CONFIG_VIODASD)          += viodasd.o
2177  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
2178  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
2179 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
2180  
2181 diff -Nurp linux-2.6.22.18/drivers/block/vroot.c linux-2.6.22.18-vs2.3.0.32/drivers/block/vroot.c
2182 --- linux-2.6.22.18/drivers/block/vroot.c       1970-01-01 01:00:00.000000000 +0100
2183 +++ linux-2.6.22.18-vs2.3.0.32/drivers/block/vroot.c    2008-02-11 12:35:33.000000000 +0100
2184 @@ -0,0 +1,281 @@
2185 +/*
2186 + *  linux/drivers/block/vroot.c
2187 + *
2188 + *  written by Herbert Pötzl, 9/11/2002
2189 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
2190 + *
2191 + *  based on the loop.c code by Theodore Ts'o.
2192 + *
2193 + * Copyright (C) 2002-2007 by Herbert Pötzl.
2194 + * Redistribution of this file is permitted under the
2195 + * GNU General Public License.
2196 + *
2197 + */
2198 +
2199 +#include <linux/module.h>
2200 +#include <linux/moduleparam.h>
2201 +#include <linux/file.h>
2202 +#include <linux/major.h>
2203 +#include <linux/blkdev.h>
2204 +
2205 +#include <linux/vroot.h>
2206 +#include <linux/vs_context.h>
2207 +
2208 +
2209 +static int max_vroot = 8;
2210 +
2211 +static struct vroot_device *vroot_dev;
2212 +static struct gendisk **disks;
2213 +
2214 +
2215 +static int vroot_set_dev(
2216 +       struct vroot_device *vr,
2217 +       struct file *vr_file,
2218 +       struct block_device *bdev,
2219 +       unsigned int arg)
2220 +{
2221 +       struct block_device *real_bdev;
2222 +       struct file *file;
2223 +       struct inode *inode;
2224 +       int error;
2225 +
2226 +       error = -EBUSY;
2227 +       if (vr->vr_state != Vr_unbound)
2228 +               goto out;
2229 +
2230 +       error = -EBADF;
2231 +       file = fget(arg);
2232 +       if (!file)
2233 +               goto out;
2234 +
2235 +       error = -EINVAL;
2236 +       inode = file->f_dentry->d_inode;
2237 +
2238 +
2239 +       if (S_ISBLK(inode->i_mode)) {
2240 +               real_bdev = inode->i_bdev;
2241 +               vr->vr_device = real_bdev;
2242 +               __iget(real_bdev->bd_inode);
2243 +       } else
2244 +               goto out_fput;
2245 +
2246 +       vxdprintk(VXD_CBIT(misc, 0),
2247 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
2248 +               vr->vr_number, VXD_DEV(real_bdev));
2249 +
2250 +       vr->vr_state = Vr_bound;
2251 +       error = 0;
2252 +
2253 + out_fput:
2254 +       fput(file);
2255 + out:
2256 +       return error;
2257 +}
2258 +
2259 +static int vroot_clr_dev(
2260 +       struct vroot_device *vr,
2261 +       struct file *vr_file,
2262 +       struct block_device *bdev)
2263 +{
2264 +       struct block_device *real_bdev;
2265 +
2266 +       if (vr->vr_state != Vr_bound)
2267 +               return -ENXIO;
2268 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
2269 +               return -EBUSY;
2270 +
2271 +       real_bdev = vr->vr_device;
2272 +
2273 +       vxdprintk(VXD_CBIT(misc, 0),
2274 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
2275 +               vr->vr_number, VXD_DEV(real_bdev));
2276 +
2277 +       bdput(real_bdev);
2278 +       vr->vr_state = Vr_unbound;
2279 +       vr->vr_device = NULL;
2280 +       return 0;
2281 +}
2282 +
2283 +
2284 +static int vr_ioctl(struct inode *inode, struct file *file,
2285 +       unsigned int cmd, unsigned long arg)
2286 +{
2287 +       struct vroot_device *vr = inode->i_bdev->bd_disk->private_data;
2288 +       int err;
2289 +
2290 +       down(&vr->vr_ctl_mutex);
2291 +       switch (cmd) {
2292 +       case VROOT_SET_DEV:
2293 +               err = vroot_set_dev(vr, file, inode->i_bdev, arg);
2294 +               break;
2295 +       case VROOT_CLR_DEV:
2296 +               err = vroot_clr_dev(vr, file, inode->i_bdev);
2297 +               break;
2298 +       default:
2299 +               err = -EINVAL;
2300 +               break;
2301 +       }
2302 +       up(&vr->vr_ctl_mutex);
2303 +       return err;
2304 +}
2305 +
2306 +static int vr_open(struct inode *inode, struct file *file)
2307 +{
2308 +       struct vroot_device *vr = inode->i_bdev->bd_disk->private_data;
2309 +
2310 +       down(&vr->vr_ctl_mutex);
2311 +       vr->vr_refcnt++;
2312 +       up(&vr->vr_ctl_mutex);
2313 +       return 0;
2314 +}
2315 +
2316 +static int vr_release(struct inode *inode, struct file *file)
2317 +{
2318 +       struct vroot_device *vr = inode->i_bdev->bd_disk->private_data;
2319 +
2320 +       down(&vr->vr_ctl_mutex);
2321 +       --vr->vr_refcnt;
2322 +       up(&vr->vr_ctl_mutex);
2323 +       return 0;
2324 +}
2325 +
2326 +static struct block_device_operations vr_fops = {
2327 +       .owner =        THIS_MODULE,
2328 +       .open =         vr_open,
2329 +       .release =      vr_release,
2330 +       .ioctl =        vr_ioctl,
2331 +};
2332 +
2333 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
2334 +{
2335 +       struct inode *inode = bdev->bd_inode;
2336 +       struct vroot_device *vr;
2337 +       struct block_device *real_bdev;
2338 +       int minor = iminor(inode);
2339 +
2340 +       vr = &vroot_dev[minor];
2341 +       real_bdev = vr->vr_device;
2342 +
2343 +       vxdprintk(VXD_CBIT(misc, 0),
2344 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
2345 +               vr->vr_number, VXD_DEV(real_bdev));
2346 +
2347 +       if (vr->vr_state != Vr_bound)
2348 +               return ERR_PTR(-ENXIO);
2349 +
2350 +       __iget(real_bdev->bd_inode);
2351 +       return real_bdev;
2352 +}
2353 +
2354 +/*
2355 + * And now the modules code and kernel interface.
2356 + */
2357 +
2358 +module_param(max_vroot, int, 0);
2359 +
2360 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
2361 +MODULE_LICENSE("GPL");
2362 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
2363 +
2364 +MODULE_AUTHOR ("Herbert Pötzl");
2365 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
2366 +
2367 +
2368 +int __init vroot_init(void)
2369 +{
2370 +       int err, i;
2371 +
2372 +       if (max_vroot < 1 || max_vroot > 256) {
2373 +               max_vroot = MAX_VROOT_DEFAULT;
2374 +               printk(KERN_WARNING "vroot: invalid max_vroot "
2375 +                       "(must be between 1 and 256), "
2376 +                       "using default (%d)\n", max_vroot);
2377 +       }
2378 +
2379 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
2380 +               return -EIO;
2381 +
2382 +       err = -ENOMEM;
2383 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
2384 +       if (!vroot_dev)
2385 +               goto out_mem1;
2386 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
2387 +
2388 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
2389 +       if (!disks)
2390 +               goto out_mem2;
2391 +
2392 +       for (i = 0; i < max_vroot; i++) {
2393 +               disks[i] = alloc_disk(1);
2394 +               if (!disks[i])
2395 +                       goto out_mem3;
2396 +       }
2397 +
2398 +       for (i = 0; i < max_vroot; i++) {
2399 +               struct vroot_device *vr = &vroot_dev[i];
2400 +               struct gendisk *disk = disks[i];
2401 +
2402 +               memset(vr, 0, sizeof(*vr));
2403 +               init_MUTEX(&vr->vr_ctl_mutex);
2404 +               vr->vr_number = i;
2405 +               disk->major = VROOT_MAJOR;
2406 +               disk->first_minor = i;
2407 +               disk->fops = &vr_fops;
2408 +               sprintf(disk->disk_name, "vroot%d", i);
2409 +               disk->private_data = vr;
2410 +       }
2411 +
2412 +       err = register_vroot_grb(&__vroot_get_real_bdev);
2413 +       if (err)
2414 +               goto out_mem3;
2415 +
2416 +       for (i = 0; i < max_vroot; i++)
2417 +               add_disk(disks[i]);
2418 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
2419 +       return 0;
2420 +
2421 +out_mem3:
2422 +       while (i--)
2423 +               put_disk(disks[i]);
2424 +       kfree(disks);
2425 +out_mem2:
2426 +       kfree(vroot_dev);
2427 +out_mem1:
2428 +       unregister_blkdev(VROOT_MAJOR, "vroot");
2429 +       printk(KERN_ERR "vroot: ran out of memory\n");
2430 +       return err;
2431 +}
2432 +
2433 +void vroot_exit(void)
2434 +{
2435 +       int i;
2436 +
2437 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
2438 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
2439 +
2440 +       for (i = 0; i < max_vroot; i++) {
2441 +               del_gendisk(disks[i]);
2442 +               put_disk(disks[i]);
2443 +       }
2444 +       if (unregister_blkdev(VROOT_MAJOR, "vroot"))
2445 +               printk(KERN_WARNING "vroot: cannot unregister blkdev\n");
2446 +
2447 +       kfree(disks);
2448 +       kfree(vroot_dev);
2449 +}
2450 +
2451 +module_init(vroot_init);
2452 +module_exit(vroot_exit);
2453 +
2454 +#ifndef MODULE
2455 +
2456 +static int __init max_vroot_setup(char *str)
2457 +{
2458 +       max_vroot = simple_strtol(str, NULL, 0);
2459 +       return 1;
2460 +}
2461 +
2462 +__setup("max_vroot=", max_vroot_setup);
2463 +
2464 +#endif
2465 +
2466 diff -Nurp linux-2.6.22.18/drivers/char/sysrq.c linux-2.6.22.18-vs2.3.0.32/drivers/char/sysrq.c
2467 --- linux-2.6.22.18/drivers/char/sysrq.c        2007-07-21 23:59:53.000000000 +0200
2468 +++ linux-2.6.22.18-vs2.3.0.32/drivers/char/sysrq.c     2008-02-11 12:35:33.000000000 +0100
2469 @@ -36,6 +36,7 @@
2470  #include <linux/kexec.h>
2471  #include <linux/irq.h>
2472  #include <linux/hrtimer.h>
2473 +#include <linux/vserver/debug.h>
2474  
2475  #include <asm/ptrace.h>
2476  #include <asm/irq_regs.h>
2477 @@ -309,6 +310,21 @@ static struct sysrq_key_op sysrq_unrt_op
2478         .enable_mask    = SYSRQ_ENABLE_RTNICE,
2479  };
2480  
2481 +
2482 +#ifdef CONFIG_VSERVER_DEBUG
2483 +static void sysrq_handle_vxinfo(int key, struct tty_struct *tty)
2484 +{
2485 +       dump_vx_info_inactive((key == 'x')?0:1);
2486 +}
2487 +
2488 +static struct sysrq_key_op sysrq_showvxinfo_op = {
2489 +       .handler        = sysrq_handle_vxinfo,
2490 +       .help_msg       = "conteXt",
2491 +       .action_msg     = "Show Context Info",
2492 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
2493 +};
2494 +#endif
2495 +
2496  /* Key Operations table and lock */
2497  static DEFINE_SPINLOCK(sysrq_key_table_lock);
2498  
2499 @@ -357,7 +373,11 @@ static struct sysrq_key_op *sysrq_key_ta
2500         /* x: May be registered on ppc/powerpc for xmon */
2501         NULL,                           /* x */
2502         NULL,                           /* y */
2503 -       NULL                            /* z */
2504 +#ifdef CONFIG_VSERVER_DEBUG
2505 +       &sysrq_showvxinfo_op,           /* z */
2506 +#else
2507 +       NULL,                           /* z */
2508 +#endif
2509  };
2510  
2511  /* key2index calculation, -1 on invalid index */
2512 @@ -369,6 +389,8 @@ static int sysrq_key_table_key2index(int
2513                 retval = key - '0';
2514         else if ((key >= 'a') && (key <= 'z'))
2515                 retval = key + 10 - 'a';
2516 +       else if ((key >= 'A') && (key <= 'Z'))
2517 +               retval = key + 10 - 'A';
2518         else
2519                 retval = -1;
2520         return retval;
2521 diff -Nurp linux-2.6.22.18/drivers/char/tty_io.c linux-2.6.22.18-vs2.3.0.32/drivers/char/tty_io.c
2522 --- linux-2.6.22.18/drivers/char/tty_io.c       2007-07-21 23:59:53.000000000 +0200
2523 +++ linux-2.6.22.18-vs2.3.0.32/drivers/char/tty_io.c    2008-02-11 12:35:33.000000000 +0100
2524 @@ -103,6 +103,7 @@
2525  #include <linux/selection.h>
2526  
2527  #include <linux/kmod.h>
2528 +#include <linux/vs_pid.h>
2529  
2530  #undef TTY_DEBUG_HANGUP
2531  
2532 @@ -3049,13 +3050,15 @@ unlock:
2533  
2534  static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p)
2535  {
2536 +       pid_t pgrp;
2537         /*
2538          * (tty == real_tty) is a cheap way of
2539          * testing if the tty is NOT a master pty.
2540          */
2541         if (tty == real_tty && current->signal->tty != real_tty)
2542                 return -ENOTTY;
2543 -       return put_user(pid_nr(real_tty->pgrp), p);
2544 +       pgrp = vx_map_pid(pid_nr(real_tty->pgrp));
2545 +       return put_user(pgrp, p);
2546  }
2547  
2548  /**
2549 @@ -3086,6 +3089,7 @@ static int tiocspgrp(struct tty_struct *
2550                 return -ENOTTY;
2551         if (get_user(pgrp_nr, p))
2552                 return -EFAULT;
2553 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
2554         if (pgrp_nr < 0)
2555                 return -EINVAL;
2556         rcu_read_lock();
2557 diff -Nurp linux-2.6.22.18/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.22.18-vs2.3.0.32/drivers/infiniband/hw/ipath/ipath_user_pages.c
2558 --- linux-2.6.22.18/drivers/infiniband/hw/ipath/ipath_user_pages.c      2007-05-04 15:58:07.000000000 +0200
2559 +++ linux-2.6.22.18-vs2.3.0.32/drivers/infiniband/hw/ipath/ipath_user_pages.c   2008-02-11 12:35:33.000000000 +0100
2560 @@ -33,6 +33,7 @@
2561  
2562  #include <linux/mm.h>
2563  #include <linux/device.h>
2564 +#include <linux/vs_memory.h>
2565  
2566  #include "ipath_kernel.h"
2567  
2568 @@ -61,7 +62,8 @@ static int __get_user_pages(unsigned lon
2569         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur >>
2570                 PAGE_SHIFT;
2571  
2572 -       if (num_pages > lock_limit) {
2573 +       if (num_pages > lock_limit ||
2574 +               !vx_vmlocked_avail(current->mm, num_pages)) {
2575                 ret = -ENOMEM;
2576                 goto bail;
2577         }
2578 @@ -78,7 +80,7 @@ static int __get_user_pages(unsigned lon
2579                         goto bail_release;
2580         }
2581  
2582 -       current->mm->locked_vm += num_pages;
2583 +       vx_vmlocked_add(current->mm, num_pages);
2584  
2585         ret = 0;
2586         goto bail;
2587 @@ -203,7 +205,7 @@ void ipath_release_user_pages(struct pag
2588  
2589         __ipath_release_user_pages(p, num_pages, 1);
2590  
2591 -       current->mm->locked_vm -= num_pages;
2592 +       vx_vmlocked_sub(current->mm, num_pages);
2593  
2594         up_write(&current->mm->mmap_sem);
2595  }
2596 @@ -220,7 +222,7 @@ static void user_pages_account(struct wo
2597                 container_of(_work, struct ipath_user_pages_work, work);
2598  
2599         down_write(&work->mm->mmap_sem);
2600 -       work->mm->locked_vm -= work->num_pages;
2601 +       vx_vmlocked_sub(work->mm, work->num_pages);
2602         up_write(&work->mm->mmap_sem);
2603         mmput(work->mm);
2604         kfree(work);
2605 diff -Nurp linux-2.6.22.18/drivers/md/dm.c linux-2.6.22.18-vs2.3.0.32/drivers/md/dm.c
2606 --- linux-2.6.22.18/drivers/md/dm.c     2007-08-12 03:54:36.000000000 +0200
2607 +++ linux-2.6.22.18-vs2.3.0.32/drivers/md/dm.c  2008-02-11 12:35:33.000000000 +0100
2608 @@ -21,6 +21,7 @@
2609  #include <linux/hdreg.h>
2610  #include <linux/blktrace_api.h>
2611  #include <linux/smp_lock.h>
2612 +#include <linux/vs_base.h>
2613  
2614  #define DM_MSG_PREFIX "core"
2615  
2616 @@ -77,6 +78,7 @@ struct mapped_device {
2617         rwlock_t map_lock;
2618         atomic_t holders;
2619         atomic_t open_count;
2620 +       xid_t xid;
2621  
2622         unsigned long flags;
2623  
2624 @@ -223,6 +225,7 @@ static void __exit dm_exit(void)
2625  static int dm_blk_open(struct inode *inode, struct file *file)
2626  {
2627         struct mapped_device *md;
2628 +       int ret = -ENXIO;
2629  
2630         spin_lock(&_minor_lock);
2631  
2632 @@ -231,18 +234,19 @@ static int dm_blk_open(struct inode *ino
2633                 goto out;
2634  
2635         if (test_bit(DMF_FREEING, &md->flags) ||
2636 -           test_bit(DMF_DELETING, &md->flags)) {
2637 -               md = NULL;
2638 +           test_bit(DMF_DELETING, &md->flags))
2639 +               goto out;
2640 +
2641 +       ret = -EACCES;
2642 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
2643                 goto out;
2644 -       }
2645  
2646         dm_get(md);
2647         atomic_inc(&md->open_count);
2648 -
2649 +       ret = 0;
2650  out:
2651         spin_unlock(&_minor_lock);
2652 -
2653 -       return md ? 0 : -ENXIO;
2654 +       return ret;
2655  }
2656  
2657  static int dm_blk_close(struct inode *inode, struct file *file)
2658 @@ -438,6 +442,14 @@ int dm_set_geometry(struct mapped_device
2659         return 0;
2660  }
2661  
2662 +/*
2663 + * Get the xid associated with a dm device
2664 + */
2665 +xid_t dm_get_xid(struct mapped_device *md)
2666 +{
2667 +       return md->xid;
2668 +}
2669 +
2670  /*-----------------------------------------------------------------
2671   * CRUD START:
2672   *   A more elegant soln is in the works that uses the queue
2673 @@ -1000,6 +1012,7 @@ static struct mapped_device *alloc_dev(i
2674         atomic_set(&md->holders, 1);
2675         atomic_set(&md->open_count, 0);
2676         atomic_set(&md->event_nr, 0);
2677 +       md->xid = vx_current_xid();
2678  
2679         md->queue = blk_alloc_queue(GFP_KERNEL);
2680         if (!md->queue)
2681 diff -Nurp linux-2.6.22.18/drivers/md/dm.h linux-2.6.22.18-vs2.3.0.32/drivers/md/dm.h
2682 --- linux-2.6.22.18/drivers/md/dm.h     2007-05-04 15:58:08.000000000 +0200
2683 +++ linux-2.6.22.18-vs2.3.0.32/drivers/md/dm.h  2008-02-11 12:35:33.000000000 +0100
2684 @@ -91,6 +91,8 @@ void dm_put_target_type(struct target_ty
2685  int dm_target_iterate(void (*iter_func)(struct target_type *tt,
2686                                         void *param), void *param);
2687  
2688 +xid_t dm_get_xid(struct mapped_device *md);
2689 +
2690  /*-----------------------------------------------------------------
2691   * Useful inlines.
2692   *---------------------------------------------------------------*/
2693 diff -Nurp linux-2.6.22.18/drivers/md/dm-ioctl.c linux-2.6.22.18-vs2.3.0.32/drivers/md/dm-ioctl.c
2694 --- linux-2.6.22.18/drivers/md/dm-ioctl.c       2007-07-21 23:58:29.000000000 +0200
2695 +++ linux-2.6.22.18-vs2.3.0.32/drivers/md/dm-ioctl.c    2008-02-11 12:35:33.000000000 +0100
2696 @@ -15,6 +15,7 @@
2697  #include <linux/slab.h>
2698  #include <linux/dm-ioctl.h>
2699  #include <linux/hdreg.h>
2700 +#include <linux/vs_context.h>
2701  
2702  #include <asm/uaccess.h>
2703  
2704 @@ -100,7 +101,8 @@ static struct hash_cell *__get_name_cell
2705         unsigned int h = hash_str(str);
2706  
2707         list_for_each_entry (hc, _name_buckets + h, name_list)
2708 -               if (!strcmp(hc->name, str)) {
2709 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
2710 +                       !strcmp(hc->name, str)) {
2711                         dm_get(hc->md);
2712                         return hc;
2713                 }
2714 @@ -114,7 +116,8 @@ static struct hash_cell *__get_uuid_cell
2715         unsigned int h = hash_str(str);
2716  
2717         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
2718 -               if (!strcmp(hc->uuid, str)) {
2719 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
2720 +                       !strcmp(hc->uuid, str)) {
2721                         dm_get(hc->md);
2722                         return hc;
2723                 }
2724 @@ -349,6 +352,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
2725  
2726  static int remove_all(struct dm_ioctl *param, size_t param_size)
2727  {
2728 +       if (!vx_check(0, VS_ADMIN))
2729 +               return -EPERM;
2730 +
2731         dm_hash_remove_all(1);
2732         param->data_size = 0;
2733         return 0;
2734 @@ -396,6 +402,8 @@ static int list_devices(struct dm_ioctl 
2735          */
2736         for (i = 0; i < NUM_BUCKETS; i++) {
2737                 list_for_each_entry (hc, _name_buckets + i, name_list) {
2738 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
2739 +                               continue;
2740                         needed += sizeof(struct dm_name_list);
2741                         needed += strlen(hc->name) + 1;
2742                         needed += ALIGN_MASK;
2743 @@ -419,6 +427,8 @@ static int list_devices(struct dm_ioctl 
2744          */
2745         for (i = 0; i < NUM_BUCKETS; i++) {
2746                 list_for_each_entry (hc, _name_buckets + i, name_list) {
2747 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
2748 +                               continue;
2749                         if (old_nl)
2750                                 old_nl->next = (uint32_t) ((void *) nl -
2751                                                            (void *) old_nl);
2752 @@ -609,10 +619,11 @@ static struct hash_cell *__find_device_h
2753         if (!md)
2754                 goto out;
2755  
2756 -       mdptr = dm_get_mdptr(md);
2757 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
2758 +               mdptr = dm_get_mdptr(md);
2759 +
2760         if (!mdptr)
2761                 dm_put(md);
2762 -
2763  out:
2764         return mdptr;
2765  }
2766 @@ -1409,8 +1420,8 @@ static int ctl_ioctl(struct inode *inode
2767         ioctl_fn fn = NULL;
2768         size_t param_size;
2769  
2770 -       /* only root can play with this */
2771 -       if (!capable(CAP_SYS_ADMIN))
2772 +       /* only root and certain contexts can play with this */
2773 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
2774                 return -EACCES;
2775  
2776         if (_IOC_TYPE(command) != DM_IOCTL)
2777 diff -Nurp linux-2.6.22.18/fs/attr.c linux-2.6.22.18-vs2.3.0.32/fs/attr.c
2778 --- linux-2.6.22.18/fs/attr.c   2007-07-22 00:00:15.000000000 +0200
2779 +++ linux-2.6.22.18-vs2.3.0.32/fs/attr.c        2008-02-11 12:35:33.000000000 +0100
2780 @@ -14,6 +14,9 @@
2781  #include <linux/fcntl.h>
2782  #include <linux/quotaops.h>
2783  #include <linux/security.h>
2784 +#include <linux/proc_fs.h>
2785 +#include <linux/devpts_fs.h>
2786 +#include <linux/vs_base.h>
2787  
2788  /* Taken over from the old code... */
2789  
2790 @@ -55,6 +58,27 @@ int inode_change_ok(struct inode *inode,
2791                 if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
2792                         goto error;
2793         }
2794 +
2795 +       /* Check for evil vserver activity */
2796 +       if (vx_check(0, VS_ADMIN))
2797 +               goto fine;
2798 +
2799 +       if (IS_BARRIER(inode)) {
2800 +               vxwprintk_task(1, "messing with the barrier.");
2801 +               goto error;
2802 +       }
2803 +       switch (inode->i_sb->s_magic) {
2804 +               case PROC_SUPER_MAGIC:
2805 +                       /* maybe allow that in the future? */
2806 +                       vxwprintk_task(1, "messing with the procfs.");
2807 +                       goto error;
2808 +               case DEVPTS_SUPER_MAGIC:
2809 +                       /* devpts is xid tagged */
2810 +                       if (vx_check((xid_t)inode->i_tag, VS_IDENT))
2811 +                               goto fine;
2812 +                       vxwprintk_task(1, "messing with the devpts.");
2813 +                       goto error;
2814 +       }
2815  fine:
2816         retval = 0;
2817  error:
2818 @@ -78,6 +102,8 @@ int inode_setattr(struct inode * inode, 
2819                 inode->i_uid = attr->ia_uid;
2820         if (ia_valid & ATTR_GID)
2821                 inode->i_gid = attr->ia_gid;
2822 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2823 +               inode->i_tag = attr->ia_tag;
2824         if (ia_valid & ATTR_ATIME)
2825                 inode->i_atime = timespec_trunc(attr->ia_atime,
2826                                                 inode->i_sb->s_time_gran);
2827 @@ -152,7 +178,8 @@ int notify_change(struct dentry * dentry
2828                         error = security_inode_setattr(dentry, attr);
2829                 if (!error) {
2830                         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
2831 -                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
2832 +                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
2833 +                           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag))
2834                                 error = DQUOT_TRANSFER(inode, attr) ? -EDQUOT : 0;
2835                         if (!error)
2836                                 error = inode_setattr(inode, attr);
2837 diff -Nurp linux-2.6.22.18/fs/binfmt_aout.c linux-2.6.22.18-vs2.3.0.32/fs/binfmt_aout.c
2838 --- linux-2.6.22.18/fs/binfmt_aout.c    2007-05-04 15:58:21.000000000 +0200
2839 +++ linux-2.6.22.18-vs2.3.0.32/fs/binfmt_aout.c 2008-02-11 12:35:33.000000000 +0100
2840 @@ -24,6 +24,7 @@
2841  #include <linux/binfmts.h>
2842  #include <linux/personality.h>
2843  #include <linux/init.h>
2844 +#include <linux/vs_memory.h>
2845  
2846  #include <asm/system.h>
2847  #include <asm/uaccess.h>
2848 diff -Nurp linux-2.6.22.18/fs/binfmt_elf.c linux-2.6.22.18-vs2.3.0.32/fs/binfmt_elf.c
2849 --- linux-2.6.22.18/fs/binfmt_elf.c     2007-07-22 00:00:15.000000000 +0200
2850 +++ linux-2.6.22.18-vs2.3.0.32/fs/binfmt_elf.c  2008-02-11 12:35:33.000000000 +0100
2851 @@ -39,6 +39,7 @@
2852  #include <linux/random.h>
2853  #include <linux/elf.h>
2854  #include <linux/utsname.h>
2855 +#include <linux/vs_memory.h>
2856  #include <asm/uaccess.h>
2857  #include <asm/param.h>
2858  #include <asm/page.h>
2859 diff -Nurp linux-2.6.22.18/fs/binfmt_flat.c linux-2.6.22.18-vs2.3.0.32/fs/binfmt_flat.c
2860 --- linux-2.6.22.18/fs/binfmt_flat.c    2007-07-22 00:00:15.000000000 +0200
2861 +++ linux-2.6.22.18-vs2.3.0.32/fs/binfmt_flat.c 2008-02-11 12:35:33.000000000 +0100
2862 @@ -36,6 +36,7 @@
2863  #include <linux/init.h>
2864  #include <linux/flat.h>
2865  #include <linux/syscalls.h>
2866 +#include <linux/vs_memory.h>
2867  
2868  #include <asm/byteorder.h>
2869  #include <asm/system.h>
2870 diff -Nurp linux-2.6.22.18/fs/binfmt_som.c linux-2.6.22.18-vs2.3.0.32/fs/binfmt_som.c
2871 --- linux-2.6.22.18/fs/binfmt_som.c     2007-05-04 15:57:29.000000000 +0200
2872 +++ linux-2.6.22.18-vs2.3.0.32/fs/binfmt_som.c  2008-02-11 12:35:33.000000000 +0100
2873 @@ -28,6 +28,7 @@
2874  #include <linux/shm.h>
2875  #include <linux/personality.h>
2876  #include <linux/init.h>
2877 +#include <linux/vs_memory.h>
2878  
2879  #include <asm/a.out.h>
2880  #include <asm/uaccess.h>
2881 diff -Nurp linux-2.6.22.18/fs/block_dev.c linux-2.6.22.18-vs2.3.0.32/fs/block_dev.c
2882 --- linux-2.6.22.18/fs/block_dev.c      2007-07-22 00:00:15.000000000 +0200
2883 +++ linux-2.6.22.18-vs2.3.0.32/fs/block_dev.c   2008-02-11 12:35:33.000000000 +0100
2884 @@ -23,6 +23,7 @@
2885  #include <linux/uio.h>
2886  #include <linux/namei.h>
2887  #include <linux/log2.h>
2888 +#include <linux/vs_device.h>
2889  #include <asm/uaccess.h>
2890  #include "internal.h"
2891  
2892 @@ -572,6 +573,7 @@ struct block_device *bdget(dev_t dev)
2893                 bdev->bd_invalidated = 0;
2894                 inode->i_mode = S_IFBLK;
2895                 inode->i_rdev = dev;
2896 +               inode->i_mdev = dev;
2897                 inode->i_bdev = bdev;
2898                 inode->i_data.a_ops = &def_blk_aops;
2899                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
2900 @@ -610,6 +612,11 @@ EXPORT_SYMBOL(bdput);
2901  static struct block_device *bd_acquire(struct inode *inode)
2902  {
2903         struct block_device *bdev;
2904 +       dev_t mdev;
2905 +
2906 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
2907 +               return NULL;
2908 +       inode->i_mdev = mdev;
2909  
2910         spin_lock(&bdev_lock);
2911         bdev = inode->i_bdev;
2912 @@ -620,7 +627,7 @@ static struct block_device *bd_acquire(s
2913         }
2914         spin_unlock(&bdev_lock);
2915  
2916 -       bdev = bdget(inode->i_rdev);
2917 +       bdev = bdget(mdev);
2918         if (bdev) {
2919                 spin_lock(&bdev_lock);
2920                 if (!inode->i_bdev) {
2921 diff -Nurp linux-2.6.22.18/fs/char_dev.c linux-2.6.22.18-vs2.3.0.32/fs/char_dev.c
2922 --- linux-2.6.22.18/fs/char_dev.c       2007-07-21 23:58:44.000000000 +0200
2923 +++ linux-2.6.22.18-vs2.3.0.32/fs/char_dev.c    2008-02-11 12:35:33.000000000 +0100
2924 @@ -21,6 +21,7 @@
2925  #include <linux/cdev.h>
2926  #include <linux/mutex.h>
2927  #include <linux/backing-dev.h>
2928 +#include <linux/vs_device.h>
2929  
2930  #ifdef CONFIG_KMOD
2931  #include <linux/kmod.h>
2932 @@ -363,14 +364,21 @@ int chrdev_open(struct inode * inode, st
2933         struct cdev *p;
2934         struct cdev *new = NULL;
2935         int ret = 0;
2936 +       dev_t mdev;
2937 +
2938 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2939 +               return -EPERM;
2940 +       inode->i_mdev = mdev;
2941  
2942         spin_lock(&cdev_lock);
2943         p = inode->i_cdev;
2944         if (!p) {
2945                 struct kobject *kobj;
2946                 int idx;
2947 +
2948                 spin_unlock(&cdev_lock);
2949 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2950 +
2951 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2952                 if (!kobj)
2953                         return -ENXIO;
2954                 new = container_of(kobj, struct cdev, kobj);
2955 diff -Nurp linux-2.6.22.18/fs/dcache.c linux-2.6.22.18-vs2.3.0.32/fs/dcache.c
2956 --- linux-2.6.22.18/fs/dcache.c 2007-07-22 00:00:15.000000000 +0200
2957 +++ linux-2.6.22.18-vs2.3.0.32/fs/dcache.c      2008-02-11 12:35:33.000000000 +0100
2958 @@ -31,6 +31,7 @@
2959  #include <linux/seqlock.h>
2960  #include <linux/swap.h>
2961  #include <linux/bootmem.h>
2962 +#include <linux/vs_limit.h>
2963  #include "internal.h"
2964  
2965  
2966 @@ -176,6 +177,7 @@ void dput(struct dentry *dentry)
2967         if (!dentry)
2968                 return;
2969  
2970 +       vx_dentry_dec(dentry);
2971  repeat:
2972         if (atomic_read(&dentry->d_count) == 1)
2973                 might_sleep();
2974 @@ -189,6 +191,8 @@ repeat:
2975                 return;
2976         }
2977  
2978 +       vx_dentry_dec(dentry);
2979 +
2980         /*
2981          * AV: ->d_delete() is _NOT_ allowed to block now.
2982          */
2983 @@ -288,6 +292,7 @@ static inline struct dentry * __dget_loc
2984         if (!list_empty(&dentry->d_lru)) {
2985                 dentry_stat.nr_unused--;
2986                 list_del_init(&dentry->d_lru);
2987 +               vx_dentry_inc(dentry);
2988         }
2989         return dentry;
2990  }
2991 @@ -898,6 +903,9 @@ struct dentry *d_alloc(struct dentry * p
2992         struct dentry *dentry;
2993         char *dname;
2994  
2995 +       if (!vx_dentry_avail(1))
2996 +               return NULL;
2997 +
2998         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL); 
2999         if (!dentry)
3000                 return NULL;
3001 @@ -946,6 +954,7 @@ struct dentry *d_alloc(struct dentry * p
3002         if (parent)
3003                 list_add(&dentry->d_u.d_child, &parent->d_subdirs);
3004         dentry_stat.nr_dentry++;
3005 +       vx_dentry_inc(dentry);
3006         spin_unlock(&dcache_lock);
3007  
3008         return dentry;
3009 @@ -1295,6 +1304,7 @@ struct dentry * __d_lookup(struct dentry
3010  
3011                 if (!d_unhashed(dentry)) {
3012                         atomic_inc(&dentry->d_count);
3013 +                       vx_dentry_inc(dentry);
3014                         found = dentry;
3015                 }
3016                 spin_unlock(&dentry->d_lock);
3017 diff -Nurp linux-2.6.22.18/fs/devpts/inode.c linux-2.6.22.18-vs2.3.0.32/fs/devpts/inode.c
3018 --- linux-2.6.22.18/fs/devpts/inode.c   2007-07-22 00:00:15.000000000 +0200
3019 +++ linux-2.6.22.18-vs2.3.0.32/fs/devpts/inode.c        2008-02-11 12:35:33.000000000 +0100
3020 @@ -17,11 +17,26 @@
3021  #include <linux/namei.h>
3022  #include <linux/mount.h>
3023  #include <linux/tty.h>
3024 +#include <linux/magic.h>
3025  #include <linux/devpts_fs.h>
3026  #include <linux/parser.h>
3027  #include <linux/fsnotify.h>
3028 +#include <linux/vs_base.h>
3029  
3030 -#define DEVPTS_SUPER_MAGIC 0x1cd1
3031 +
3032 +static int devpts_permission(struct inode *inode, int mask, struct nameidata *nd)
3033 +{
3034 +       int ret = -EACCES;
3035 +
3036 +       /* devpts is xid tagged */
3037 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
3038 +               ret = generic_permission(inode, mask, NULL);
3039 +       return ret;
3040 +}
3041 +
3042 +static struct inode_operations devpts_file_inode_operations = {
3043 +       .permission     = devpts_permission,
3044 +};
3045  
3046  static struct vfsmount *devpts_mnt;
3047  static struct dentry *devpts_root;
3048 @@ -92,6 +107,25 @@ static int devpts_remount(struct super_b
3049         return 0;
3050  }
3051  
3052 +static int devpts_filter(struct dentry *de)
3053 +{
3054 +       /* devpts is xid tagged */
3055 +       return vx_check((xid_t)de->d_inode->i_tag, VS_WATCH_P | VS_IDENT);
3056 +}
3057 +
3058 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
3059 +{
3060 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
3061 +}
3062 +
3063 +static struct file_operations devpts_dir_operations = {
3064 +       .open           = dcache_dir_open,
3065 +       .release        = dcache_dir_close,
3066 +       .llseek         = dcache_dir_lseek,
3067 +       .read           = generic_read_dir,
3068 +       .readdir        = devpts_readdir,
3069 +};
3070 +
3071  static const struct super_operations devpts_sops = {
3072         .statfs         = simple_statfs,
3073         .remount_fs     = devpts_remount,
3074 @@ -117,8 +151,10 @@ devpts_fill_super(struct super_block *s,
3075         inode->i_uid = inode->i_gid = 0;
3076         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
3077         inode->i_op = &simple_dir_inode_operations;
3078 -       inode->i_fop = &simple_dir_operations;
3079 +       inode->i_fop = &devpts_dir_operations;
3080         inode->i_nlink = 2;
3081 +       /* devpts is xid tagged */
3082 +       inode->i_tag = (tag_t)vx_current_xid();
3083  
3084         devpts_root = s->s_root = d_alloc_root(inode);
3085         if (s->s_root)
3086 @@ -176,6 +212,9 @@ int devpts_pty_new(struct tty_struct *tt
3087         inode->i_gid = config.setgid ? config.gid : current->fsgid;
3088         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
3089         init_special_inode(inode, S_IFCHR|config.mode, device);
3090 +       /* devpts is xid tagged */
3091 +       inode->i_tag = (tag_t)vx_current_xid();
3092 +       inode->i_op = &devpts_file_inode_operations;
3093         inode->i_private = tty;
3094  
3095         dentry = get_node(number);
3096 diff -Nurp linux-2.6.22.18/fs/ecryptfs/inode.c linux-2.6.22.18-vs2.3.0.32/fs/ecryptfs/inode.c
3097 --- linux-2.6.22.18/fs/ecryptfs/inode.c 2007-08-12 03:54:36.000000000 +0200
3098 +++ linux-2.6.22.18-vs2.3.0.32/fs/ecryptfs/inode.c      2008-02-11 12:35:33.000000000 +0100
3099 @@ -423,7 +423,7 @@ static int ecryptfs_link(struct dentry *
3100         dget(lower_new_dentry);
3101         lower_dir_dentry = lock_parent(lower_new_dentry);
3102         rc = vfs_link(lower_old_dentry, lower_dir_dentry->d_inode,
3103 -                     lower_new_dentry);
3104 +                     lower_new_dentry, NULL);
3105         if (rc || !lower_new_dentry->d_inode)
3106                 goto out_lock;
3107         rc = ecryptfs_interpose(lower_new_dentry, new_dentry, dir->i_sb, 0);
3108 @@ -451,7 +451,7 @@ static int ecryptfs_unlink(struct inode 
3109         struct inode *lower_dir_inode = ecryptfs_inode_to_lower(dir);
3110  
3111         lock_parent(lower_dentry);
3112 -       rc = vfs_unlink(lower_dir_inode, lower_dentry);
3113 +       rc = vfs_unlink(lower_dir_inode, lower_dentry, NULL);
3114         if (rc) {
3115                 printk(KERN_ERR "Error in vfs_unlink; rc = [%d]\n", rc);
3116                 goto out_unlock;
3117 @@ -488,7 +488,7 @@ static int ecryptfs_symlink(struct inode
3118                 goto out_lock;
3119         }
3120         rc = vfs_symlink(lower_dir_dentry->d_inode, lower_dentry,
3121 -                        encoded_symname, mode);
3122 +                        encoded_symname, mode, NULL);
3123         kfree(encoded_symname);
3124         if (rc || !lower_dentry->d_inode)
3125                 goto out_lock;
3126 @@ -513,7 +513,7 @@ static int ecryptfs_mkdir(struct inode *
3127  
3128         lower_dentry = ecryptfs_dentry_to_lower(dentry);
3129         lower_dir_dentry = lock_parent(lower_dentry);
3130 -       rc = vfs_mkdir(lower_dir_dentry->d_inode, lower_dentry, mode);
3131 +       rc = vfs_mkdir(lower_dir_dentry->d_inode, lower_dentry, mode, NULL);
3132         if (rc || !lower_dentry->d_inode)
3133                 goto out;
3134         rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0);
3135 @@ -539,7 +539,7 @@ static int ecryptfs_rmdir(struct inode *
3136         dget(dentry);
3137         lower_dir_dentry = lock_parent(lower_dentry);
3138         dget(lower_dentry);
3139 -       rc = vfs_rmdir(lower_dir_dentry->d_inode, lower_dentry);
3140 +       rc = vfs_rmdir(lower_dir_dentry->d_inode, lower_dentry, NULL);
3141         dput(lower_dentry);
3142         if (!rc)
3143                 d_delete(lower_dentry);
3144 @@ -561,7 +561,7 @@ ecryptfs_mknod(struct inode *dir, struct
3145  
3146         lower_dentry = ecryptfs_dentry_to_lower(dentry);
3147         lower_dir_dentry = lock_parent(lower_dentry);
3148 -       rc = vfs_mknod(lower_dir_dentry->d_inode, lower_dentry, mode, dev);
3149 +       rc = vfs_mknod(lower_dir_dentry->d_inode, lower_dentry, mode, dev, NULL);
3150         if (rc || !lower_dentry->d_inode)
3151                 goto out;
3152         rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0);
3153 diff -Nurp linux-2.6.22.18/fs/exec.c linux-2.6.22.18-vs2.3.0.32/fs/exec.c
3154 --- linux-2.6.22.18/fs/exec.c   2008-02-11 12:34:20.000000000 +0100
3155 +++ linux-2.6.22.18-vs2.3.0.32/fs/exec.c        2008-02-11 12:35:33.000000000 +0100
3156 @@ -51,6 +51,7 @@
3157  #include <linux/cn_proc.h>
3158  #include <linux/audit.h>
3159  #include <linux/signalfd.h>
3160 +#include <linux/vs_memory.h>
3161  
3162  #include <asm/uaccess.h>
3163  #include <asm/mmu_context.h>
3164 @@ -440,7 +441,8 @@ int setup_arg_pages(struct linux_binprm 
3165                         kmem_cache_free(vm_area_cachep, mpnt);
3166                         return ret;
3167                 }
3168 -               mm->stack_vm = mm->total_vm = vma_pages(mpnt);
3169 +               vx_vmpages_sub(mm, mm->total_vm - vma_pages(mpnt));
3170 +               mm->stack_vm = mm->total_vm;
3171         }
3172  
3173         for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
3174 @@ -1336,7 +1338,7 @@ static int format_corename(char *corenam
3175                         /* UNIX time of coredump */
3176                         case 't': {
3177                                 struct timeval tv;
3178 -                               do_gettimeofday(&tv);
3179 +                               vx_gettimeofday(&tv);
3180                                 rc = snprintf(out_ptr, out_end - out_ptr,
3181                                               "%lu", tv.tv_sec);
3182                                 if (rc > out_end - out_ptr)
3183 diff -Nurp linux-2.6.22.18/fs/ext2/balloc.c linux-2.6.22.18-vs2.3.0.32/fs/ext2/balloc.c
3184 --- linux-2.6.22.18/fs/ext2/balloc.c    2007-07-21 23:58:45.000000000 +0200
3185 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext2/balloc.c 2008-02-11 12:35:33.000000000 +0100
3186 @@ -16,6 +16,8 @@
3187  #include <linux/sched.h>
3188  #include <linux/buffer_head.h>
3189  #include <linux/capability.h>
3190 +#include <linux/vs_dlimit.h>
3191 +#include <linux/vs_tag.h>
3192  
3193  /*
3194   * balloc.c contains the blocks allocation and deallocation routines
3195 @@ -102,12 +104,13 @@ static int reserve_blocks(struct super_b
3196  {
3197         struct ext2_sb_info *sbi = EXT2_SB(sb);
3198         struct ext2_super_block *es = sbi->s_es;
3199 -       unsigned free_blocks;
3200 -       unsigned root_blocks;
3201 +       unsigned long long free_blocks, root_blocks;
3202  
3203         free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
3204         root_blocks = le32_to_cpu(es->s_r_blocks_count);
3205  
3206 +       DLIMIT_ADJUST_BLOCK(sb, dx_current_tag(), &free_blocks, &root_blocks);
3207 +
3208         if (free_blocks < count)
3209                 count = free_blocks;
3210  
3211 @@ -258,6 +261,7 @@ do_more:
3212         }
3213  error_return:
3214         brelse(bitmap_bh);
3215 +       DLIMIT_FREE_BLOCK(inode, freed);
3216         release_blocks(sb, freed);
3217         DQUOT_FREE_BLOCK(inode, freed);
3218  }
3219 @@ -361,6 +365,10 @@ int ext2_new_block(struct inode *inode, 
3220                 *err = -ENOSPC;
3221                 goto out_dquot;
3222         }
3223 +       if (DLIMIT_ALLOC_BLOCK(inode, es_alloc)) {
3224 +               *err = -ENOSPC;
3225 +               goto out_dlimit;
3226 +       }
3227  
3228         ext2_debug ("goal=%lu.\n", goal);
3229  
3230 @@ -508,6 +516,8 @@ got_block:
3231         *err = 0;
3232  out_release:
3233         group_release_blocks(sb, group_no, desc, gdp_bh, group_alloc);
3234 +       DLIMIT_FREE_BLOCK(inode, es_alloc);
3235 +out_dlimit:
3236         release_blocks(sb, es_alloc);
3237  out_dquot:
3238         DQUOT_FREE_BLOCK(inode, dq_alloc);
3239 diff -Nurp linux-2.6.22.18/fs/ext2/ext2.h linux-2.6.22.18-vs2.3.0.32/fs/ext2/ext2.h
3240 --- linux-2.6.22.18/fs/ext2/ext2.h      2007-07-22 00:00:15.000000000 +0200
3241 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext2/ext2.h   2008-02-11 12:35:33.000000000 +0100
3242 @@ -167,6 +167,7 @@ extern const struct file_operations ext2
3243  extern const struct address_space_operations ext2_aops;
3244  extern const struct address_space_operations ext2_aops_xip;
3245  extern const struct address_space_operations ext2_nobh_aops;
3246 +extern int ext2_sync_flags(struct inode *inode);
3247  
3248  /* namei.c */
3249  extern const struct inode_operations ext2_dir_inode_operations;
3250 diff -Nurp linux-2.6.22.18/fs/ext2/file.c linux-2.6.22.18-vs2.3.0.32/fs/ext2/file.c
3251 --- linux-2.6.22.18/fs/ext2/file.c      2007-07-21 23:58:45.000000000 +0200
3252 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext2/file.c   2008-02-11 12:35:33.000000000 +0100
3253 @@ -85,4 +85,5 @@ const struct inode_operations ext2_file_
3254  #endif
3255         .setattr        = ext2_setattr,
3256         .permission     = ext2_permission,
3257 +       .sync_flags     = ext2_sync_flags,
3258  };
3259 diff -Nurp linux-2.6.22.18/fs/ext2/ialloc.c linux-2.6.22.18-vs2.3.0.32/fs/ext2/ialloc.c
3260 --- linux-2.6.22.18/fs/ext2/ialloc.c    2007-05-04 15:57:35.000000000 +0200
3261 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext2/ialloc.c 2008-02-11 12:35:33.000000000 +0100
3262 @@ -17,6 +17,8 @@
3263  #include <linux/backing-dev.h>
3264  #include <linux/buffer_head.h>
3265  #include <linux/random.h>
3266 +#include <linux/vs_dlimit.h>
3267 +#include <linux/vs_tag.h>
3268  #include "ext2.h"
3269  #include "xattr.h"
3270  #include "acl.h"
3271 @@ -125,6 +127,7 @@ void ext2_free_inode (struct inode * ino
3272                 ext2_xattr_delete_inode(inode);
3273                 DQUOT_FREE_INODE(inode);
3274                 DQUOT_DROP(inode);
3275 +               DLIMIT_FREE_INODE(inode);
3276         }
3277  
3278         es = EXT2_SB(sb)->s_es;
3279 @@ -464,6 +467,11 @@ struct inode *ext2_new_inode(struct inod
3280         if (!inode)
3281                 return ERR_PTR(-ENOMEM);
3282  
3283 +       inode->i_tag = dx_current_fstag(sb);
3284 +       if (DLIMIT_ALLOC_INODE(inode)) {
3285 +               err = -ENOSPC;
3286 +               goto fail_dlim;
3287 +       }
3288         ei = EXT2_I(inode);
3289         sbi = EXT2_SB(sb);
3290         es = sbi->s_es;
3291 @@ -577,7 +585,8 @@ got:
3292         inode->i_blocks = 0;
3293         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
3294         memset(ei->i_data, 0, sizeof(ei->i_data));
3295 -       ei->i_flags = EXT2_I(dir)->i_flags & ~EXT2_BTREE_FL;
3296 +       ei->i_flags = EXT2_I(dir)->i_flags &
3297 +               ~(EXT2_BTREE_FL|EXT2_IUNLINK_FL|EXT2_BARRIER_FL);
3298         if (S_ISLNK(mode))
3299                 ei->i_flags &= ~(EXT2_IMMUTABLE_FL|EXT2_APPEND_FL);
3300         /* dirsync is only applied to directories */
3301 @@ -625,12 +634,15 @@ fail_free_drop:
3302  
3303  fail_drop:
3304         DQUOT_DROP(inode);
3305 +       DLIMIT_FREE_INODE(inode);
3306         inode->i_flags |= S_NOQUOTA;
3307         inode->i_nlink = 0;
3308         iput(inode);
3309         return ERR_PTR(err);
3310  
3311  fail:
3312 +       DLIMIT_FREE_INODE(inode);
3313 +fail_dlim:
3314         make_bad_inode(inode);
3315         iput(inode);
3316         return ERR_PTR(err);
3317 diff -Nurp linux-2.6.22.18/fs/ext2/inode.c linux-2.6.22.18-vs2.3.0.32/fs/ext2/inode.c
3318 --- linux-2.6.22.18/fs/ext2/inode.c     2007-07-22 00:00:15.000000000 +0200
3319 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext2/inode.c  2008-02-11 12:35:33.000000000 +0100
3320 @@ -31,6 +31,7 @@
3321  #include <linux/writeback.h>
3322  #include <linux/buffer_head.h>
3323  #include <linux/mpage.h>
3324 +#include <linux/vs_tag.h>
3325  #include "ext2.h"
3326  #include "acl.h"
3327  #include "xip.h"
3328 @@ -913,7 +914,7 @@ void ext2_truncate (struct inode * inode
3329                 return;
3330         if (ext2_inode_is_fast_symlink(inode))
3331                 return;
3332 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3333 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3334                 return;
3335  
3336         ext2_discard_prealloc(inode);
3337 @@ -1042,13 +1043,20 @@ void ext2_set_inode_flags(struct inode *
3338  {
3339         unsigned int flags = EXT2_I(inode)->i_flags;
3340  
3341 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3342 +       inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
3343 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3344 +
3345 +       if (flags & EXT2_IMMUTABLE_FL)
3346 +               inode->i_flags |= S_IMMUTABLE;
3347 +       if (flags & EXT2_IUNLINK_FL)
3348 +               inode->i_flags |= S_IUNLINK;
3349 +       if (flags & EXT2_BARRIER_FL)
3350 +               inode->i_flags |= S_BARRIER;
3351 +
3352         if (flags & EXT2_SYNC_FL)
3353                 inode->i_flags |= S_SYNC;
3354         if (flags & EXT2_APPEND_FL)
3355                 inode->i_flags |= S_APPEND;
3356 -       if (flags & EXT2_IMMUTABLE_FL)
3357 -               inode->i_flags |= S_IMMUTABLE;
3358         if (flags & EXT2_NOATIME_FL)
3359                 inode->i_flags |= S_NOATIME;
3360         if (flags & EXT2_DIRSYNC_FL)
3361 @@ -1074,12 +1082,37 @@ void ext2_get_inode_flags(struct ext2_in
3362                 ei->i_flags |= EXT2_DIRSYNC_FL;
3363  }
3364  
3365 +int ext2_sync_flags(struct inode *inode)
3366 +{
3367 +       unsigned int oldflags, newflags;
3368 +
3369 +       oldflags = EXT2_I(inode)->i_flags;
3370 +       newflags = oldflags & ~(EXT2_IMMUTABLE_FL |
3371 +               EXT2_IUNLINK_FL | EXT2_BARRIER_FL);
3372 +
3373 +       if (IS_IMMUTABLE(inode))
3374 +               newflags |= EXT2_IMMUTABLE_FL;
3375 +       if (IS_IUNLINK(inode))
3376 +               newflags |= EXT2_IUNLINK_FL;
3377 +       if (IS_BARRIER(inode))
3378 +               newflags |= EXT2_BARRIER_FL;
3379 +
3380 +       if (oldflags ^ newflags) {
3381 +               EXT2_I(inode)->i_flags = newflags;
3382 +               inode->i_ctime = CURRENT_TIME;
3383 +               mark_inode_dirty(inode);
3384 +       }
3385 +       return 0;
3386 +}
3387 +
3388  void ext2_read_inode (struct inode * inode)
3389  {
3390         struct ext2_inode_info *ei = EXT2_I(inode);
3391         ino_t ino = inode->i_ino;
3392         struct buffer_head * bh;
3393         struct ext2_inode * raw_inode = ext2_get_inode(inode->i_sb, ino, &bh);
3394 +       uid_t uid;
3395 +       gid_t gid;
3396         int n;
3397  
3398  #ifdef CONFIG_EXT2_FS_POSIX_ACL
3399 @@ -1090,12 +1123,17 @@ void ext2_read_inode (struct inode * ino
3400                 goto bad_inode;
3401  
3402         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3403 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3404 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3405 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3406 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3407         if (!(test_opt (inode->i_sb, NO_UID32))) {
3408 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3409 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3410 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3411 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3412         }
3413 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3414 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3415 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3416 +               le16_to_cpu(raw_inode->i_raw_tag));
3417 +
3418         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3419         inode->i_size = le32_to_cpu(raw_inode->i_size);
3420         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3421 @@ -1192,8 +1230,8 @@ static int ext2_update_inode(struct inod
3422         struct ext2_inode_info *ei = EXT2_I(inode);
3423         struct super_block *sb = inode->i_sb;
3424         ino_t ino = inode->i_ino;
3425 -       uid_t uid = inode->i_uid;
3426 -       gid_t gid = inode->i_gid;
3427 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3428 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3429         struct buffer_head * bh;
3430         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
3431         int n;
3432 @@ -1229,6 +1267,9 @@ static int ext2_update_inode(struct inod
3433                 raw_inode->i_uid_high = 0;
3434                 raw_inode->i_gid_high = 0;
3435         }
3436 +#ifdef CONFIG_TAGGING_INTERN
3437 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3438 +#endif
3439         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3440         raw_inode->i_size = cpu_to_le32(inode->i_size);
3441         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3442 @@ -1315,7 +1356,8 @@ int ext2_setattr(struct dentry *dentry, 
3443         if (error)
3444                 return error;
3445         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
3446 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
3447 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
3448 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
3449                 error = DQUOT_TRANSFER(inode, iattr) ? -EDQUOT : 0;
3450                 if (error)
3451                         return error;
3452 diff -Nurp linux-2.6.22.18/fs/ext2/ioctl.c linux-2.6.22.18-vs2.3.0.32/fs/ext2/ioctl.c
3453 --- linux-2.6.22.18/fs/ext2/ioctl.c     2007-07-22 00:00:15.000000000 +0200
3454 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext2/ioctl.c  2008-02-11 12:35:33.000000000 +0100
3455 @@ -13,6 +13,7 @@
3456  #include <linux/sched.h>
3457  #include <linux/compat.h>
3458  #include <linux/smp_lock.h>
3459 +#include <linux/mount.h>
3460  #include <asm/current.h>
3461  #include <asm/uaccess.h>
3462  
3463 @@ -33,7 +34,8 @@ int ext2_ioctl (struct inode * inode, st
3464         case EXT2_IOC_SETFLAGS: {
3465                 unsigned int oldflags;
3466  
3467 -               if (IS_RDONLY(inode))
3468 +               if (IS_RDONLY(inode) ||
3469 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
3470                         return -EROFS;
3471  
3472                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
3473 @@ -54,7 +56,9 @@ int ext2_ioctl (struct inode * inode, st
3474                  *
3475                  * This test looks nicer. Thanks to Pauline Middelink
3476                  */
3477 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
3478 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
3479 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
3480 +                       EXT2_IMMUTABLE_FL | EXT2_IUNLINK_FL))) {
3481                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3482                                 mutex_unlock(&inode->i_mutex);
3483                                 return -EPERM;
3484 @@ -76,7 +80,8 @@ int ext2_ioctl (struct inode * inode, st
3485         case EXT2_IOC_SETVERSION:
3486                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
3487                         return -EPERM;
3488 -               if (IS_RDONLY(inode))
3489 +               if (IS_RDONLY(inode) ||
3490 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
3491                         return -EROFS;
3492                 if (get_user(inode->i_generation, (int __user *) arg))
3493                         return -EFAULT; 
3494 diff -Nurp linux-2.6.22.18/fs/ext2/namei.c linux-2.6.22.18-vs2.3.0.32/fs/ext2/namei.c
3495 --- linux-2.6.22.18/fs/ext2/namei.c     2007-07-21 23:58:45.000000000 +0200
3496 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext2/namei.c  2008-02-11 12:35:33.000000000 +0100
3497 @@ -31,6 +31,7 @@
3498   */
3499  
3500  #include <linux/pagemap.h>
3501 +#include <linux/vs_tag.h>
3502  #include "ext2.h"
3503  #include "xattr.h"
3504  #include "acl.h"
3505 @@ -66,6 +67,7 @@ static struct dentry *ext2_lookup(struct
3506                 inode = iget(dir->i_sb, ino);
3507                 if (!inode)
3508                         return ERR_PTR(-EACCES);
3509 +               dx_propagate_tag(nd, inode);
3510         }
3511         return d_splice_alias(inode, dentry);
3512  }
3513 @@ -391,6 +393,7 @@ const struct inode_operations ext2_dir_i
3514  #endif
3515         .setattr        = ext2_setattr,
3516         .permission     = ext2_permission,
3517 +       .sync_flags     = ext2_sync_flags,
3518  };
3519  
3520  const struct inode_operations ext2_special_inode_operations = {
3521 @@ -402,4 +405,5 @@ const struct inode_operations ext2_speci
3522  #endif
3523         .setattr        = ext2_setattr,
3524         .permission     = ext2_permission,
3525 +       .sync_flags     = ext2_sync_flags,
3526  };
3527 diff -Nurp linux-2.6.22.18/fs/ext2/super.c linux-2.6.22.18-vs2.3.0.32/fs/ext2/super.c
3528 --- linux-2.6.22.18/fs/ext2/super.c     2007-07-22 00:00:15.000000000 +0200
3529 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext2/super.c  2008-02-11 12:35:33.000000000 +0100
3530 @@ -321,7 +321,7 @@ enum {
3531         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
3532         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
3533         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
3534 -       Opt_usrquota, Opt_grpquota
3535 +       Opt_usrquota, Opt_grpquota, Opt_tag, Opt_notag, Opt_tagid
3536  };
3537  
3538  static match_table_t tokens = {
3539 @@ -349,6 +349,9 @@ static match_table_t tokens = {
3540         {Opt_acl, "acl"},
3541         {Opt_noacl, "noacl"},
3542         {Opt_xip, "xip"},
3543 +       {Opt_tag, "tag"},
3544 +       {Opt_notag, "notag"},
3545 +       {Opt_tagid, "tagid=%u"},
3546         {Opt_grpquota, "grpquota"},
3547         {Opt_ignore, "noquota"},
3548         {Opt_quota, "quota"},
3549 @@ -417,6 +420,20 @@ static int parse_options (char * options
3550                 case Opt_nouid32:
3551                         set_opt (sbi->s_mount_opt, NO_UID32);
3552                         break;
3553 +#ifndef CONFIG_TAGGING_NONE
3554 +               case Opt_tag:
3555 +                       set_opt (sbi->s_mount_opt, TAGGED);
3556 +                       break;
3557 +               case Opt_notag:
3558 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3559 +                       break;
3560 +#endif
3561 +#ifdef CONFIG_PROPAGATE
3562 +               case Opt_tagid:
3563 +                       /* use args[0] */
3564 +                       set_opt (sbi->s_mount_opt, TAGGED);
3565 +                       break;
3566 +#endif
3567                 case Opt_nocheck:
3568                         clear_opt (sbi->s_mount_opt, CHECK);
3569                         break;
3570 @@ -727,6 +744,8 @@ static int ext2_fill_super(struct super_
3571         if (!parse_options ((char *) data, sbi))
3572                 goto failed_mount;
3573  
3574 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
3575 +               sb->s_flags |= MS_TAGGED;
3576         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3577                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
3578                  MS_POSIXACL : 0);
3579 @@ -1035,6 +1054,13 @@ static int ext2_remount (struct super_bl
3580                 goto restore_opts;
3581         }
3582  
3583 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
3584 +               !(sb->s_flags & MS_TAGGED)) {
3585 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
3586 +                      sb->s_id);
3587 +               return -EINVAL;
3588 +       }
3589 +
3590         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3591                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3592  
3593 diff -Nurp linux-2.6.22.18/fs/ext2/symlink.c linux-2.6.22.18-vs2.3.0.32/fs/ext2/symlink.c
3594 --- linux-2.6.22.18/fs/ext2/symlink.c   2007-07-21 23:58:45.000000000 +0200
3595 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext2/symlink.c        2008-02-11 12:35:33.000000000 +0100
3596 @@ -38,6 +38,7 @@ const struct inode_operations ext2_symli
3597         .listxattr      = ext2_listxattr,
3598         .removexattr    = generic_removexattr,
3599  #endif
3600 +       .sync_flags     = ext2_sync_flags,
3601  };
3602   
3603  const struct inode_operations ext2_fast_symlink_inode_operations = {
3604 @@ -49,4 +50,5 @@ const struct inode_operations ext2_fast_
3605         .listxattr      = ext2_listxattr,
3606         .removexattr    = generic_removexattr,
3607  #endif
3608 +       .sync_flags     = ext2_sync_flags,
3609  };
3610 diff -Nurp linux-2.6.22.18/fs/ext2/xattr.c linux-2.6.22.18-vs2.3.0.32/fs/ext2/xattr.c
3611 --- linux-2.6.22.18/fs/ext2/xattr.c     2007-05-04 15:58:21.000000000 +0200
3612 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext2/xattr.c  2008-02-11 12:35:33.000000000 +0100
3613 @@ -60,6 +60,7 @@
3614  #include <linux/mbcache.h>
3615  #include <linux/quotaops.h>
3616  #include <linux/rwsem.h>
3617 +#include <linux/vs_dlimit.h>
3618  #include "ext2.h"
3619  #include "xattr.h"
3620  #include "acl.h"
3621 @@ -641,8 +642,12 @@ ext2_xattr_set2(struct inode *inode, str
3622                                    the inode.  */
3623                                 ea_bdebug(new_bh, "reusing block");
3624  
3625 +                               error = -ENOSPC;
3626 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
3627 +                                       goto cleanup;
3628                                 error = -EDQUOT;
3629                                 if (DQUOT_ALLOC_BLOCK(inode, 1)) {
3630 +                                       DLIMIT_FREE_BLOCK(inode, 1);
3631                                         unlock_buffer(new_bh);
3632                                         goto cleanup;
3633                                 }
3634 @@ -736,6 +741,7 @@ ext2_xattr_set2(struct inode *inode, str
3635                                 le32_to_cpu(HDR(old_bh)->h_refcount) - 1);
3636                         if (ce)
3637                                 mb_cache_entry_release(ce);
3638 +                       DLIMIT_FREE_BLOCK(inode, 1);
3639                         DQUOT_FREE_BLOCK(inode, 1);
3640                         mark_buffer_dirty(old_bh);
3641                         ea_bdebug(old_bh, "refcount now=%d",
3642 @@ -800,6 +806,7 @@ ext2_xattr_delete_inode(struct inode *in
3643                 mark_buffer_dirty(bh);
3644                 if (IS_SYNC(inode))
3645                         sync_dirty_buffer(bh);
3646 +               DLIMIT_FREE_BLOCK(inode, 1);
3647                 DQUOT_FREE_BLOCK(inode, 1);
3648         }
3649         EXT2_I(inode)->i_file_acl = 0;
3650 diff -Nurp linux-2.6.22.18/fs/ext3/balloc.c linux-2.6.22.18-vs2.3.0.32/fs/ext3/balloc.c
3651 --- linux-2.6.22.18/fs/ext3/balloc.c    2007-07-21 23:58:45.000000000 +0200
3652 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext3/balloc.c 2008-02-11 12:35:33.000000000 +0100
3653 @@ -19,6 +19,8 @@
3654  #include <linux/ext3_jbd.h>
3655  #include <linux/quotaops.h>
3656  #include <linux/buffer_head.h>
3657 +#include <linux/vs_dlimit.h>
3658 +#include <linux/vs_tag.h>
3659  
3660  /*
3661   * balloc.c contains the blocks allocation and deallocation routines
3662 @@ -613,8 +615,10 @@ void ext3_free_blocks(handle_t *handle, 
3663                 return;
3664         }
3665         ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
3666 -       if (dquot_freed_blocks)
3667 +       if (dquot_freed_blocks) {
3668 +               DLIMIT_FREE_BLOCK(inode, dquot_freed_blocks);
3669                 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
3670 +       }
3671         return;
3672  }
3673  
3674 @@ -1353,18 +1357,33 @@ out:
3675   *
3676   * Check if filesystem has at least 1 free block available for allocation.
3677   */
3678 -static int ext3_has_free_blocks(struct ext3_sb_info *sbi)
3679 +static int ext3_has_free_blocks(struct super_block *sb)
3680  {
3681 -       ext3_fsblk_t free_blocks, root_blocks;
3682 +       struct ext3_sb_info *sbi = EXT3_SB(sb);
3683 +       unsigned long long free_blocks, root_blocks;
3684 +       int cond;
3685  
3686         free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
3687         root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
3688 -       if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
3689 +
3690 +       vxdprintk(VXD_CBIT(dlim, 3),
3691 +               "ext3_has_free_blocks(%p): free=%llu, root=%llu",
3692 +               sb, free_blocks, root_blocks);
3693 +
3694 +       DLIMIT_ADJUST_BLOCK(sb, dx_current_tag(), &free_blocks, &root_blocks);
3695 +
3696 +       cond = (free_blocks < root_blocks + 1 &&
3697 +               !capable(CAP_SYS_RESOURCE) &&
3698                 sbi->s_resuid != current->fsuid &&
3699 -               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
3700 -               return 0;
3701 -       }
3702 -       return 1;
3703 +               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)));
3704 +
3705 +       vxdprintk(VXD_CBIT(dlim, 3),
3706 +               "ext3_has_free_blocks(%p): %llu<%llu+1, %c, %u!=%u r=%d",
3707 +               sb, free_blocks, root_blocks,
3708 +               !capable(CAP_SYS_RESOURCE)?'1':'0',
3709 +               sbi->s_resuid, current->fsuid, cond?0:1);
3710 +
3711 +       return (cond ? 0 : 1);
3712  }
3713  
3714  /**
3715 @@ -1381,7 +1400,7 @@ static int ext3_has_free_blocks(struct e
3716   */
3717  int ext3_should_retry_alloc(struct super_block *sb, int *retries)
3718  {
3719 -       if (!ext3_has_free_blocks(EXT3_SB(sb)) || (*retries)++ > 3)
3720 +       if (!ext3_has_free_blocks(sb) || (*retries)++ > 3)
3721                 return 0;
3722  
3723         jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id);
3724 @@ -1444,6 +1463,8 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
3725                 *errp = -EDQUOT;
3726                 return 0;
3727         }
3728 +       if (DLIMIT_ALLOC_BLOCK(inode, num))
3729 +           goto out_dlimit;
3730  
3731         sbi = EXT3_SB(sb);
3732         es = EXT3_SB(sb)->s_es;
3733 @@ -1460,7 +1481,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
3734         if (block_i && ((windowsz = block_i->rsv_window_node.rsv_goal_size) > 0))
3735                 my_rsv = &block_i->rsv_window_node;
3736  
3737 -       if (!ext3_has_free_blocks(sbi)) {
3738 +       if (!ext3_has_free_blocks(sb)) {
3739                 *errp = -ENOSPC;
3740                 goto out;
3741         }
3742 @@ -1647,12 +1668,16 @@ allocated:
3743         *errp = 0;
3744         brelse(bitmap_bh);
3745         DQUOT_FREE_BLOCK(inode, *count-num);
3746 +       DLIMIT_FREE_BLOCK(inode, *count-num);
3747         *count = num;
3748         return ret_block;
3749  
3750  io_error:
3751         *errp = -EIO;
3752  out:
3753 +       if (!performed_allocation)
3754 +               DLIMIT_FREE_BLOCK(inode, *count);
3755 +out_dlimit:
3756         if (fatal) {
3757                 *errp = fatal;
3758                 ext3_std_error(sb, fatal);
3759 diff -Nurp linux-2.6.22.18/fs/ext3/file.c linux-2.6.22.18-vs2.3.0.32/fs/ext3/file.c
3760 --- linux-2.6.22.18/fs/ext3/file.c      2007-07-21 23:58:45.000000000 +0200
3761 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext3/file.c   2008-02-11 12:35:33.000000000 +0100
3762 @@ -135,5 +135,6 @@ const struct inode_operations ext3_file_
3763         .removexattr    = generic_removexattr,
3764  #endif
3765         .permission     = ext3_permission,
3766 +       .sync_flags     = ext3_sync_flags,
3767  };
3768  
3769 diff -Nurp linux-2.6.22.18/fs/ext3/ialloc.c linux-2.6.22.18-vs2.3.0.32/fs/ext3/ialloc.c
3770 --- linux-2.6.22.18/fs/ext3/ialloc.c    2007-05-04 15:57:35.000000000 +0200
3771 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext3/ialloc.c 2008-02-11 12:35:33.000000000 +0100
3772 @@ -23,6 +23,8 @@
3773  #include <linux/buffer_head.h>
3774  #include <linux/random.h>
3775  #include <linux/bitops.h>
3776 +#include <linux/vs_dlimit.h>
3777 +#include <linux/vs_tag.h>
3778  
3779  #include <asm/byteorder.h>
3780  
3781 @@ -127,6 +129,7 @@ void ext3_free_inode (handle_t *handle, 
3782         ext3_xattr_delete_inode(handle, inode);
3783         DQUOT_FREE_INODE(inode);
3784         DQUOT_DROP(inode);
3785 +       DLIMIT_FREE_INODE(inode);
3786  
3787         is_directory = S_ISDIR(inode->i_mode);
3788  
3789 @@ -445,6 +448,12 @@ struct inode *ext3_new_inode(handle_t *h
3790         inode = new_inode(sb);
3791         if (!inode)
3792                 return ERR_PTR(-ENOMEM);
3793 +
3794 +       inode->i_tag = dx_current_fstag(sb);
3795 +       if (DLIMIT_ALLOC_INODE(inode)) {
3796 +               err = -ENOSPC;
3797 +               goto out_dlimit;
3798 +       }
3799         ei = EXT3_I(inode);
3800  
3801         sbi = EXT3_SB(sb);
3802 @@ -566,7 +575,8 @@ got:
3803         ei->i_dir_start_lookup = 0;
3804         ei->i_disksize = 0;
3805  
3806 -       ei->i_flags = EXT3_I(dir)->i_flags & ~EXT3_INDEX_FL;
3807 +       ei->i_flags = EXT3_I(dir)->i_flags &
3808 +               ~(EXT3_INDEX_FL|EXT3_IUNLINK_FL|EXT3_BARRIER_FL);
3809         if (S_ISLNK(mode))
3810                 ei->i_flags &= ~(EXT3_IMMUTABLE_FL|EXT3_APPEND_FL);
3811         /* dirsync only applies to directories */
3812 @@ -621,6 +631,8 @@ got:
3813  fail:
3814         ext3_std_error(sb, err);
3815  out:
3816 +       DLIMIT_FREE_INODE(inode);
3817 +out_dlimit:
3818         iput(inode);
3819         ret = ERR_PTR(err);
3820  really_out:
3821 @@ -632,6 +644,7 @@ fail_free_drop:
3822  
3823  fail_drop:
3824         DQUOT_DROP(inode);
3825 +       DLIMIT_FREE_INODE(inode);
3826         inode->i_flags |= S_NOQUOTA;
3827         inode->i_nlink = 0;
3828         iput(inode);
3829 diff -Nurp linux-2.6.22.18/fs/ext3/inode.c linux-2.6.22.18-vs2.3.0.32/fs/ext3/inode.c
3830 --- linux-2.6.22.18/fs/ext3/inode.c     2007-07-22 00:00:15.000000000 +0200
3831 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext3/inode.c  2008-02-11 12:35:33.000000000 +0100
3832 @@ -36,6 +36,7 @@
3833  #include <linux/mpage.h>
3834  #include <linux/uio.h>
3835  #include <linux/bio.h>
3836 +#include <linux/vs_tag.h>
3837  #include "xattr.h"
3838  #include "acl.h"
3839  
3840 @@ -2237,7 +2238,7 @@ void ext3_truncate(struct inode *inode)
3841                 return;
3842         if (ext3_inode_is_fast_symlink(inode))
3843                 return;
3844 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3845 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3846                 return;
3847  
3848         /*
3849 @@ -2559,13 +2560,20 @@ void ext3_set_inode_flags(struct inode *
3850  {
3851         unsigned int flags = EXT3_I(inode)->i_flags;
3852  
3853 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3854 +       inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
3855 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3856 +
3857 +       if (flags & EXT3_IMMUTABLE_FL)
3858 +               inode->i_flags |= S_IMMUTABLE;
3859 +       if (flags & EXT3_IUNLINK_FL)
3860 +               inode->i_flags |= S_IUNLINK;
3861 +       if (flags & EXT3_BARRIER_FL)
3862 +               inode->i_flags |= S_BARRIER;
3863 +
3864         if (flags & EXT3_SYNC_FL)
3865                 inode->i_flags |= S_SYNC;
3866         if (flags & EXT3_APPEND_FL)
3867                 inode->i_flags |= S_APPEND;
3868 -       if (flags & EXT3_IMMUTABLE_FL)
3869 -               inode->i_flags |= S_IMMUTABLE;
3870         if (flags & EXT3_NOATIME_FL)
3871                 inode->i_flags |= S_NOATIME;
3872         if (flags & EXT3_DIRSYNC_FL)
3873 @@ -2591,6 +2599,45 @@ void ext3_get_inode_flags(struct ext3_in
3874                 ei->i_flags |= EXT3_DIRSYNC_FL;
3875  }
3876  
3877 +int ext3_sync_flags(struct inode *inode)
3878 +{
3879 +       unsigned int oldflags, newflags;
3880 +       int err = 0;
3881 +
3882 +       oldflags = EXT3_I(inode)->i_flags;
3883 +       newflags = oldflags & ~(EXT3_IMMUTABLE_FL |
3884 +               EXT3_IUNLINK_FL | EXT3_BARRIER_FL);
3885 +
3886 +       if (IS_IMMUTABLE(inode))
3887 +               newflags |= EXT3_IMMUTABLE_FL;
3888 +       if (IS_IUNLINK(inode))
3889 +               newflags |= EXT3_IUNLINK_FL;
3890 +       if (IS_BARRIER(inode))
3891 +               newflags |= EXT3_BARRIER_FL;
3892 +
3893 +       if (oldflags ^ newflags) {
3894 +               handle_t *handle;
3895 +               struct ext3_iloc iloc;
3896 +
3897 +               handle = ext3_journal_start(inode, 1);
3898 +               if (IS_ERR(handle))
3899 +                       return PTR_ERR(handle);
3900 +               if (IS_SYNC(inode))
3901 +                       handle->h_sync = 1;
3902 +               err = ext3_reserve_inode_write(handle, inode, &iloc);
3903 +               if (err)
3904 +                       goto flags_err;
3905 +
3906 +               EXT3_I(inode)->i_flags = newflags;
3907 +               inode->i_ctime = CURRENT_TIME;
3908 +
3909 +               err = ext3_mark_iloc_dirty(handle, inode, &iloc);
3910 +       flags_err:
3911 +               ext3_journal_stop(handle);
3912 +       }
3913 +       return err;
3914 +}
3915 +
3916  void ext3_read_inode(struct inode * inode)
3917  {
3918         struct ext3_iloc iloc;
3919 @@ -2598,6 +2645,8 @@ void ext3_read_inode(struct inode * inod
3920         struct ext3_inode_info *ei = EXT3_I(inode);
3921         struct buffer_head *bh;
3922         int block;
3923 +       uid_t uid;
3924 +       gid_t gid;
3925  
3926  #ifdef CONFIG_EXT3_FS_POSIX_ACL
3927         ei->i_acl = EXT3_ACL_NOT_CACHED;
3928 @@ -2610,12 +2659,17 @@ void ext3_read_inode(struct inode * inod
3929         bh = iloc.bh;
3930         raw_inode = ext3_raw_inode(&iloc);
3931         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3932 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3933 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3934 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3935 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3936         if(!(test_opt (inode->i_sb, NO_UID32))) {
3937 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3938 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3939 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3940 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3941         }
3942 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3943 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3944 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3945 +               le16_to_cpu(raw_inode->i_raw_tag));
3946 +
3947         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3948         inode->i_size = le32_to_cpu(raw_inode->i_size);
3949         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3950 @@ -2741,6 +2795,8 @@ static int ext3_do_update_inode(handle_t
3951         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
3952         struct ext3_inode_info *ei = EXT3_I(inode);
3953         struct buffer_head *bh = iloc->bh;
3954 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3955 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3956         int err = 0, rc, block;
3957  
3958         /* For fields not not tracking in the in-memory inode,
3959 @@ -2751,29 +2807,32 @@ static int ext3_do_update_inode(handle_t
3960         ext3_get_inode_flags(ei);
3961         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3962         if(!(test_opt(inode->i_sb, NO_UID32))) {
3963 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3964 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3965 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3966 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3967  /*
3968   * Fix up interoperability with old kernels. Otherwise, old inodes get
3969   * re-used with the upper 16 bits of the uid/gid intact
3970   */
3971                 if(!ei->i_dtime) {
3972                         raw_inode->i_uid_high =
3973 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3974 +                               cpu_to_le16(high_16_bits(uid));
3975                         raw_inode->i_gid_high =
3976 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3977 +                               cpu_to_le16(high_16_bits(gid));
3978                 } else {
3979                         raw_inode->i_uid_high = 0;
3980                         raw_inode->i_gid_high = 0;
3981                 }
3982         } else {
3983                 raw_inode->i_uid_low =
3984 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3985 +                       cpu_to_le16(fs_high2lowuid(uid));
3986                 raw_inode->i_gid_low =
3987 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3988 +                       cpu_to_le16(fs_high2lowgid(gid));
3989                 raw_inode->i_uid_high = 0;
3990                 raw_inode->i_gid_high = 0;
3991         }
3992 +#ifdef CONFIG_TAGGING_INTERN
3993 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3994 +#endif
3995         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3996         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
3997         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3998 @@ -2926,7 +2985,8 @@ int ext3_setattr(struct dentry *dentry, 
3999                 return error;
4000  
4001         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
4002 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
4003 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
4004 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
4005                 handle_t *handle;
4006  
4007                 /* (user+group)*(old+new) structure, inode write (sb,
4008 @@ -2948,6 +3008,8 @@ int ext3_setattr(struct dentry *dentry, 
4009                         inode->i_uid = attr->ia_uid;
4010                 if (attr->ia_valid & ATTR_GID)
4011                         inode->i_gid = attr->ia_gid;
4012 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
4013 +                       inode->i_tag = attr->ia_tag;
4014                 error = ext3_mark_inode_dirty(handle, inode);
4015                 ext3_journal_stop(handle);
4016         }
4017 diff -Nurp linux-2.6.22.18/fs/ext3/ioctl.c linux-2.6.22.18-vs2.3.0.32/fs/ext3/ioctl.c
4018 --- linux-2.6.22.18/fs/ext3/ioctl.c     2007-07-22 00:00:15.000000000 +0200
4019 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext3/ioctl.c  2008-02-11 12:35:34.000000000 +0100
4020 @@ -8,6 +8,7 @@
4021   */
4022  
4023  #include <linux/fs.h>
4024 +#include <linux/mount.h>
4025  #include <linux/jbd.h>
4026  #include <linux/capability.h>
4027  #include <linux/ext3_fs.h>
4028 @@ -15,6 +16,7 @@
4029  #include <linux/time.h>
4030  #include <linux/compat.h>
4031  #include <linux/smp_lock.h>
4032 +#include <linux/vs_tag.h>
4033  #include <asm/uaccess.h>
4034  
4035  int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
4036 @@ -38,7 +40,8 @@ int ext3_ioctl (struct inode * inode, st
4037                 unsigned int oldflags;
4038                 unsigned int jflag;
4039  
4040 -               if (IS_RDONLY(inode))
4041 +               if (IS_RDONLY(inode) ||
4042 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4043                         return -EROFS;
4044  
4045                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
4046 @@ -62,7 +65,9 @@ int ext3_ioctl (struct inode * inode, st
4047                  *
4048                  * This test looks nicer. Thanks to Pauline Middelink
4049                  */
4050 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
4051 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
4052 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
4053 +                       EXT3_IMMUTABLE_FL | EXT3_IUNLINK_FL))) {
4054                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4055                                 mutex_unlock(&inode->i_mutex);
4056                                 return -EPERM;
4057 @@ -124,7 +129,8 @@ flags_err:
4058  
4059                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
4060                         return -EPERM;
4061 -               if (IS_RDONLY(inode))
4062 +               if (IS_RDONLY(inode) ||
4063 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4064                         return -EROFS;
4065                 if (get_user(generation, (int __user *) arg))
4066                         return -EFAULT;
4067 @@ -178,7 +184,8 @@ flags_err:
4068                 if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode))
4069                         return -ENOTTY;
4070  
4071 -               if (IS_RDONLY(inode))
4072 +               if (IS_RDONLY(inode) ||
4073 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4074                         return -EROFS;
4075  
4076                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
4077 @@ -213,7 +220,8 @@ flags_err:
4078                 if (!capable(CAP_SYS_RESOURCE))
4079                         return -EPERM;
4080  
4081 -               if (IS_RDONLY(inode))
4082 +               if (IS_RDONLY(inode) ||
4083 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4084                         return -EROFS;
4085  
4086                 if (get_user(n_blocks_count, (__u32 __user *)arg))
4087 @@ -234,7 +242,8 @@ flags_err:
4088                 if (!capable(CAP_SYS_RESOURCE))
4089                         return -EPERM;
4090  
4091 -               if (IS_RDONLY(inode))
4092 +               if (IS_RDONLY(inode) ||
4093 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4094                         return -EROFS;
4095  
4096                 if (copy_from_user(&input, (struct ext3_new_group_input __user *)arg,
4097 diff -Nurp linux-2.6.22.18/fs/ext3/namei.c linux-2.6.22.18-vs2.3.0.32/fs/ext3/namei.c
4098 --- linux-2.6.22.18/fs/ext3/namei.c     2007-09-29 14:11:49.000000000 +0200
4099 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext3/namei.c  2008-02-11 12:35:34.000000000 +0100
4100 @@ -36,6 +36,7 @@
4101  #include <linux/quotaops.h>
4102  #include <linux/buffer_head.h>
4103  #include <linux/bio.h>
4104 +#include <linux/vs_tag.h>
4105  
4106  #include "namei.h"
4107  #include "xattr.h"
4108 @@ -1052,6 +1053,7 @@ static struct dentry *ext3_lookup(struct
4109  
4110                 if (!inode)
4111                         return ERR_PTR(-EACCES);
4112 +               dx_propagate_tag(nd, inode);
4113         }
4114         return d_splice_alias(inode, dentry);
4115  }
4116 @@ -2443,6 +2445,7 @@ const struct inode_operations ext3_dir_i
4117         .removexattr    = generic_removexattr,
4118  #endif
4119         .permission     = ext3_permission,
4120 +       .sync_flags     = ext3_sync_flags,
4121  };
4122  
4123  const struct inode_operations ext3_special_inode_operations = {
4124 @@ -2454,4 +2457,5 @@ const struct inode_operations ext3_speci
4125         .removexattr    = generic_removexattr,
4126  #endif
4127         .permission     = ext3_permission,
4128 +       .sync_flags     = ext3_sync_flags,
4129  };
4130 diff -Nurp linux-2.6.22.18/fs/ext3/super.c linux-2.6.22.18-vs2.3.0.32/fs/ext3/super.c
4131 --- linux-2.6.22.18/fs/ext3/super.c     2007-07-22 00:00:15.000000000 +0200
4132 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext3/super.c  2008-02-11 12:35:34.000000000 +0100
4133 @@ -674,7 +674,7 @@ enum {
4134         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
4135         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
4136         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
4137 -       Opt_grpquota
4138 +       Opt_grpquota, Opt_tag, Opt_notag, Opt_tagid
4139  };
4140  
4141  static match_table_t tokens = {
4142 @@ -724,6 +724,9 @@ static match_table_t tokens = {
4143         {Opt_quota, "quota"},
4144         {Opt_usrquota, "usrquota"},
4145         {Opt_barrier, "barrier=%u"},
4146 +       {Opt_tag, "tag"},
4147 +       {Opt_notag, "notag"},
4148 +       {Opt_tagid, "tagid=%u"},
4149         {Opt_err, NULL},
4150         {Opt_resize, "resize"},
4151  };
4152 @@ -817,6 +820,20 @@ static int parse_options (char *options,
4153                 case Opt_nouid32:
4154                         set_opt (sbi->s_mount_opt, NO_UID32);
4155                         break;
4156 +#ifndef CONFIG_TAGGING_NONE
4157 +               case Opt_tag:
4158 +                       set_opt (sbi->s_mount_opt, TAGGED);
4159 +                       break;
4160 +               case Opt_notag:
4161 +                       clear_opt (sbi->s_mount_opt, TAGGED);
4162 +                       break;
4163 +#endif
4164 +#ifdef CONFIG_PROPAGATE
4165 +               case Opt_tagid:
4166 +                       /* use args[0] */
4167 +                       set_opt (sbi->s_mount_opt, TAGGED);
4168 +                       break;
4169 +#endif
4170                 case Opt_nocheck:
4171                         clear_opt (sbi->s_mount_opt, CHECK);
4172                         break;
4173 @@ -1487,6 +1504,9 @@ static int ext3_fill_super (struct super
4174                             NULL, 0))
4175                 goto failed_mount;
4176  
4177 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
4178 +               sb->s_flags |= MS_TAGGED;
4179 +
4180         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4181                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
4182  
4183 @@ -2302,6 +2322,12 @@ static int ext3_remount (struct super_bl
4184  
4185         if (sbi->s_mount_opt & EXT3_MOUNT_ABORT)
4186                 ext3_abort(sb, __FUNCTION__, "Abort forced by user");
4187 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
4188 +               !(sb->s_flags & MS_TAGGED)) {
4189 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
4190 +                       sb->s_id);
4191 +               return -EINVAL;
4192 +       }
4193  
4194         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4195                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
4196 diff -Nurp linux-2.6.22.18/fs/ext3/symlink.c linux-2.6.22.18-vs2.3.0.32/fs/ext3/symlink.c
4197 --- linux-2.6.22.18/fs/ext3/symlink.c   2007-07-21 23:58:45.000000000 +0200
4198 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext3/symlink.c        2008-02-11 12:35:34.000000000 +0100
4199 @@ -40,6 +40,7 @@ const struct inode_operations ext3_symli
4200         .listxattr      = ext3_listxattr,
4201         .removexattr    = generic_removexattr,
4202  #endif
4203 +       .sync_flags     = ext3_sync_flags,
4204  };
4205  
4206  const struct inode_operations ext3_fast_symlink_inode_operations = {
4207 @@ -51,4 +52,5 @@ const struct inode_operations ext3_fast_
4208         .listxattr      = ext3_listxattr,
4209         .removexattr    = generic_removexattr,
4210  #endif
4211 +       .sync_flags     = ext3_sync_flags,
4212  };
4213 diff -Nurp linux-2.6.22.18/fs/ext3/xattr.c linux-2.6.22.18-vs2.3.0.32/fs/ext3/xattr.c
4214 --- linux-2.6.22.18/fs/ext3/xattr.c     2007-07-21 23:58:45.000000000 +0200
4215 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext3/xattr.c  2008-02-11 12:35:34.000000000 +0100
4216 @@ -58,6 +58,7 @@
4217  #include <linux/mbcache.h>
4218  #include <linux/quotaops.h>
4219  #include <linux/rwsem.h>
4220 +#include <linux/vs_dlimit.h>
4221  #include "xattr.h"
4222  #include "acl.h"
4223  
4224 @@ -497,6 +498,7 @@ ext3_xattr_release_block(handle_t *handl
4225                 error = ext3_journal_dirty_metadata(handle, bh);
4226                 if (IS_SYNC(inode))
4227                         handle->h_sync = 1;
4228 +                       DLIMIT_FREE_BLOCK(inode, 1);
4229                 DQUOT_FREE_BLOCK(inode, 1);
4230                 ea_bdebug(bh, "refcount now=%d; releasing",
4231                           le32_to_cpu(BHDR(bh)->h_refcount));
4232 @@ -771,11 +773,14 @@ inserted:
4233                         if (new_bh == bs->bh)
4234                                 ea_bdebug(new_bh, "keeping");
4235                         else {
4236 +                               error = -ENOSPC;
4237 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
4238 +                                       goto cleanup;
4239                                 /* The old block is released after updating
4240                                    the inode. */
4241                                 error = -EDQUOT;
4242                                 if (DQUOT_ALLOC_BLOCK(inode, 1))
4243 -                                       goto cleanup;
4244 +                                       goto cleanup_dlimit;
4245                                 error = ext3_journal_get_write_access(handle,
4246                                                                       new_bh);
4247                                 if (error)
4248 @@ -852,6 +857,8 @@ cleanup:
4249  
4250  cleanup_dquot:
4251         DQUOT_FREE_BLOCK(inode, 1);
4252 +cleanup_dlimit:
4253 +       DLIMIT_FREE_BLOCK(inode, 1);
4254         goto cleanup;
4255  
4256  bad_block:
4257 diff -Nurp linux-2.6.22.18/fs/ext4/balloc.c linux-2.6.22.18-vs2.3.0.32/fs/ext4/balloc.c
4258 --- linux-2.6.22.18/fs/ext4/balloc.c    2007-07-22 00:00:15.000000000 +0200
4259 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext4/balloc.c 2008-02-11 12:35:34.000000000 +0100
4260 @@ -19,6 +19,8 @@
4261  #include <linux/ext4_jbd2.h>
4262  #include <linux/quotaops.h>
4263  #include <linux/buffer_head.h>
4264 +#include <linux/vs_dlimit.h>
4265 +#include <linux/vs_tag.h>
4266  
4267  /*
4268   * balloc.c contains the blocks allocation and deallocation routines
4269 @@ -630,8 +632,10 @@ void ext4_free_blocks(handle_t *handle, 
4270                 return;
4271         }
4272         ext4_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
4273 -       if (dquot_freed_blocks)
4274 +       if (dquot_freed_blocks) {
4275 +               DLIMIT_FREE_BLOCK(inode, dquot_freed_blocks);
4276                 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
4277 +       }
4278         return;
4279  }
4280  
4281 @@ -1370,18 +1374,33 @@ out:
4282   *
4283   * Check if filesystem has at least 1 free block available for allocation.
4284   */
4285 -static int ext4_has_free_blocks(struct ext4_sb_info *sbi)
4286 +static int ext4_has_free_blocks(struct super_block *sb)
4287  {
4288 +       struct ext4_sb_info *sbi = EXT4_SB(sb);
4289         ext4_fsblk_t free_blocks, root_blocks;
4290 +       int cond;
4291  
4292         free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
4293         root_blocks = ext4_r_blocks_count(sbi->s_es);
4294 -       if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
4295 +
4296 +       vxdprintk(VXD_CBIT(dlim, 3),
4297 +               "ext4_has_free_blocks(%p): free=%llu, root=%llu",
4298 +               sb, free_blocks, root_blocks);
4299 +
4300 +       DLIMIT_ADJUST_BLOCK(sb, dx_current_tag(), &free_blocks, &root_blocks);
4301 +
4302 +       cond = (free_blocks < root_blocks + 1 &&
4303 +               !capable(CAP_SYS_RESOURCE) &&
4304                 sbi->s_resuid != current->fsuid &&
4305 -               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
4306 -               return 0;
4307 -       }
4308 -       return 1;
4309 +               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)));
4310 +
4311 +       vxdprintk(VXD_CBIT(dlim, 3),
4312 +               "ext4_has_free_blocks(%p): %llu<%llu+1, %c, %u!=%u r=%d",
4313 +               sb, free_blocks, root_blocks,
4314 +               !capable(CAP_SYS_RESOURCE)?'1':'0',
4315 +               sbi->s_resuid, current->fsuid, cond?0:1);
4316 +
4317 +       return (cond ? 0 : 1);
4318  }
4319  
4320  /**
4321 @@ -1398,7 +1417,7 @@ static int ext4_has_free_blocks(struct e
4322   */
4323  int ext4_should_retry_alloc(struct super_block *sb, int *retries)
4324  {
4325 -       if (!ext4_has_free_blocks(EXT4_SB(sb)) || (*retries)++ > 3)
4326 +       if (!ext4_has_free_blocks(sb) || (*retries)++ > 3)
4327                 return 0;
4328  
4329         jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id);
4330 @@ -1461,6 +1480,8 @@ ext4_fsblk_t ext4_new_blocks(handle_t *h
4331                 *errp = -EDQUOT;
4332                 return 0;
4333         }
4334 +       if (DLIMIT_ALLOC_BLOCK(inode, num))
4335 +           goto out_dlimit;
4336  
4337         sbi = EXT4_SB(sb);
4338         es = EXT4_SB(sb)->s_es;
4339 @@ -1477,7 +1498,7 @@ ext4_fsblk_t ext4_new_blocks(handle_t *h
4340         if (block_i && ((windowsz = block_i->rsv_window_node.rsv_goal_size) > 0))
4341                 my_rsv = &block_i->rsv_window_node;
4342  
4343 -       if (!ext4_has_free_blocks(sbi)) {
4344 +       if (!ext4_has_free_blocks(sb)) {
4345                 *errp = -ENOSPC;
4346                 goto out;
4347         }
4348 @@ -1661,12 +1682,16 @@ allocated:
4349         *errp = 0;
4350         brelse(bitmap_bh);
4351         DQUOT_FREE_BLOCK(inode, *count-num);
4352 +       DLIMIT_FREE_BLOCK(inode, *count-num);
4353         *count = num;
4354         return ret_block;
4355  
4356  io_error:
4357         *errp = -EIO;
4358  out:
4359 +       if (!performed_allocation)
4360 +               DLIMIT_FREE_BLOCK(inode, *count);
4361 +out_dlimit:
4362         if (fatal) {
4363                 *errp = fatal;
4364                 ext4_std_error(sb, fatal);
4365 diff -Nurp linux-2.6.22.18/fs/ext4/file.c linux-2.6.22.18-vs2.3.0.32/fs/ext4/file.c
4366 --- linux-2.6.22.18/fs/ext4/file.c      2007-07-21 23:58:45.000000000 +0200
4367 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext4/file.c   2008-02-11 12:35:34.000000000 +0100
4368 @@ -135,5 +135,6 @@ const struct inode_operations ext4_file_
4369         .removexattr    = generic_removexattr,
4370  #endif
4371         .permission     = ext4_permission,
4372 +       .sync_flags     = ext4_sync_flags,
4373  };
4374  
4375 diff -Nurp linux-2.6.22.18/fs/ext4/ialloc.c linux-2.6.22.18-vs2.3.0.32/fs/ext4/ialloc.c
4376 --- linux-2.6.22.18/fs/ext4/ialloc.c    2007-05-04 15:57:35.000000000 +0200
4377 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext4/ialloc.c 2008-02-11 12:35:34.000000000 +0100
4378 @@ -24,6 +24,8 @@
4379  #include <linux/random.h>
4380  #include <linux/bitops.h>
4381  #include <linux/blkdev.h>
4382 +#include <linux/vs_dlimit.h>
4383 +#include <linux/vs_tag.h>
4384  #include <asm/byteorder.h>
4385  
4386  #include "xattr.h"
4387 @@ -127,6 +129,7 @@ void ext4_free_inode (handle_t *handle, 
4388         ext4_xattr_delete_inode(handle, inode);
4389         DQUOT_FREE_INODE(inode);
4390         DQUOT_DROP(inode);
4391 +       DLIMIT_FREE_INODE(inode);
4392  
4393         is_directory = S_ISDIR(inode->i_mode);
4394  
4395 @@ -448,6 +451,12 @@ struct inode *ext4_new_inode(handle_t *h
4396         inode = new_inode(sb);
4397         if (!inode)
4398                 return ERR_PTR(-ENOMEM);
4399 +
4400 +       inode->i_tag = dx_current_fstag(sb);
4401 +       if (DLIMIT_ALLOC_INODE(inode)) {
4402 +               err = -ENOSPC;
4403 +               goto out_dlimit;
4404 +       }
4405         ei = EXT4_I(inode);
4406  
4407         sbi = EXT4_SB(sb);
4408 @@ -569,7 +578,8 @@ got:
4409         ei->i_dir_start_lookup = 0;
4410         ei->i_disksize = 0;
4411  
4412 -       ei->i_flags = EXT4_I(dir)->i_flags & ~EXT4_INDEX_FL;
4413 +       ei->i_flags = EXT4_I(dir)->i_flags &
4414 +               ~(EXT4_INDEX_FL|EXT4_IUNLINK_FL|EXT4_BARRIER_FL);
4415         if (S_ISLNK(mode))
4416                 ei->i_flags &= ~(EXT4_IMMUTABLE_FL|EXT4_APPEND_FL);
4417         /* dirsync only applies to directories */
4418 @@ -635,6 +645,8 @@ got:
4419  fail:
4420         ext4_std_error(sb, err);
4421  out:
4422 +       DLIMIT_FREE_INODE(inode);
4423 +out_dlimit:
4424         iput(inode);
4425         ret = ERR_PTR(err);
4426  really_out:
4427 @@ -646,6 +658,7 @@ fail_free_drop:
4428  
4429  fail_drop:
4430         DQUOT_DROP(inode);
4431 +       DLIMIT_FREE_INODE(inode);
4432         inode->i_flags |= S_NOQUOTA;
4433         inode->i_nlink = 0;
4434         iput(inode);
4435 diff -Nurp linux-2.6.22.18/fs/ext4/inode.c linux-2.6.22.18-vs2.3.0.32/fs/ext4/inode.c
4436 --- linux-2.6.22.18/fs/ext4/inode.c     2007-07-22 00:00:15.000000000 +0200
4437 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext4/inode.c  2008-02-11 12:35:34.000000000 +0100
4438 @@ -36,6 +36,7 @@
4439  #include <linux/mpage.h>
4440  #include <linux/uio.h>
4441  #include <linux/bio.h>
4442 +#include <linux/vs_tag.h>
4443  #include "xattr.h"
4444  #include "acl.h"
4445  
4446 @@ -2244,7 +2245,7 @@ void ext4_truncate(struct inode *inode)
4447                 return;
4448         if (ext4_inode_is_fast_symlink(inode))
4449                 return;
4450 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4451 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4452                 return;
4453  
4454         /*
4455 @@ -2570,19 +2571,65 @@ void ext4_set_inode_flags(struct inode *
4456  {
4457         unsigned int flags = EXT4_I(inode)->i_flags;
4458  
4459 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
4460 +       inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
4461 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4462 +
4463 +       if (flags & EXT4_IMMUTABLE_FL)
4464 +               inode->i_flags |= S_IMMUTABLE;
4465 +       if (flags & EXT4_IUNLINK_FL)
4466 +               inode->i_flags |= S_IUNLINK;
4467 +       if (flags & EXT4_BARRIER_FL)
4468 +               inode->i_flags |= S_BARRIER;
4469 +
4470         if (flags & EXT4_SYNC_FL)
4471                 inode->i_flags |= S_SYNC;
4472         if (flags & EXT4_APPEND_FL)
4473                 inode->i_flags |= S_APPEND;
4474 -       if (flags & EXT4_IMMUTABLE_FL)
4475 -               inode->i_flags |= S_IMMUTABLE;
4476         if (flags & EXT4_NOATIME_FL)
4477                 inode->i_flags |= S_NOATIME;
4478         if (flags & EXT4_DIRSYNC_FL)
4479                 inode->i_flags |= S_DIRSYNC;
4480  }
4481  
4482 +int ext4_sync_flags(struct inode *inode)
4483 +{
4484 +       unsigned int oldflags, newflags;
4485 +       int err = 0;
4486 +
4487 +       oldflags = EXT4_I(inode)->i_flags;
4488 +       newflags = oldflags & ~(EXT4_IMMUTABLE_FL |
4489 +               EXT4_IUNLINK_FL | EXT4_BARRIER_FL);
4490 +
4491 +       if (IS_IMMUTABLE(inode))
4492 +               newflags |= EXT4_IMMUTABLE_FL;
4493 +       if (IS_IUNLINK(inode))
4494 +               newflags |= EXT4_IUNLINK_FL;
4495 +       if (IS_BARRIER(inode))
4496 +               newflags |= EXT4_BARRIER_FL;
4497 +
4498 +       if (oldflags ^ newflags) {
4499 +               handle_t *handle;
4500 +               struct ext4_iloc iloc;
4501 +
4502 +               handle = ext4_journal_start(inode, 1);
4503 +               if (IS_ERR(handle))
4504 +                       return PTR_ERR(handle);
4505 +               if (IS_SYNC(inode))
4506 +                       handle->h_sync = 1;
4507 +               err = ext4_reserve_inode_write(handle, inode, &iloc);
4508 +               if (err)
4509 +                       goto flags_err;
4510 +
4511 +               EXT4_I(inode)->i_flags = newflags;
4512 +               inode->i_ctime = CURRENT_TIME;
4513 +
4514 +               err = ext4_mark_iloc_dirty(handle, inode, &iloc);
4515 +       flags_err:
4516 +               ext4_journal_stop(handle);
4517 +       }
4518 +       return err;
4519 +}
4520 +
4521  void ext4_read_inode(struct inode * inode)
4522  {
4523         struct ext4_iloc iloc;
4524 @@ -2590,6 +2637,8 @@ void ext4_read_inode(struct inode * inod
4525         struct ext4_inode_info *ei = EXT4_I(inode);
4526         struct buffer_head *bh;
4527         int block;
4528 +       uid_t uid;
4529 +       gid_t gid;
4530  
4531  #ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
4532         ei->i_acl = EXT4_ACL_NOT_CACHED;
4533 @@ -2602,12 +2651,17 @@ void ext4_read_inode(struct inode * inod
4534         bh = iloc.bh;
4535         raw_inode = ext4_raw_inode(&iloc);
4536         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
4537 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
4538 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
4539 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
4540 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
4541         if(!(test_opt (inode->i_sb, NO_UID32))) {
4542 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
4543 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
4544 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
4545 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
4546         }
4547 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
4548 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
4549 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
4550 +               le16_to_cpu(raw_inode->i_raw_tag));
4551 +
4552         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
4553         inode->i_size = le32_to_cpu(raw_inode->i_size);
4554         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
4555 @@ -2737,6 +2791,8 @@ static int ext4_do_update_inode(handle_t
4556         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
4557         struct ext4_inode_info *ei = EXT4_I(inode);
4558         struct buffer_head *bh = iloc->bh;
4559 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
4560 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
4561         int err = 0, rc, block;
4562  
4563         /* For fields not not tracking in the in-memory inode,
4564 @@ -2746,29 +2802,32 @@ static int ext4_do_update_inode(handle_t
4565  
4566         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
4567         if(!(test_opt(inode->i_sb, NO_UID32))) {
4568 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
4569 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
4570 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
4571 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
4572  /*
4573   * Fix up interoperability with old kernels. Otherwise, old inodes get
4574   * re-used with the upper 16 bits of the uid/gid intact
4575   */
4576                 if(!ei->i_dtime) {
4577                         raw_inode->i_uid_high =
4578 -                               cpu_to_le16(high_16_bits(inode->i_uid));
4579 +                               cpu_to_le16(high_16_bits(uid));
4580                         raw_inode->i_gid_high =
4581 -                               cpu_to_le16(high_16_bits(inode->i_gid));
4582 +                               cpu_to_le16(high_16_bits(gid));
4583                 } else {
4584                         raw_inode->i_uid_high = 0;
4585                         raw_inode->i_gid_high = 0;
4586                 }
4587         } else {
4588                 raw_inode->i_uid_low =
4589 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
4590 +                       cpu_to_le16(fs_high2lowuid(uid));
4591                 raw_inode->i_gid_low =
4592 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
4593 +                       cpu_to_le16(fs_high2lowgid(gid));
4594                 raw_inode->i_uid_high = 0;
4595                 raw_inode->i_gid_high = 0;
4596         }
4597 +#ifdef CONFIG_TAGGING_INTERN
4598 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
4599 +#endif
4600         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
4601         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
4602         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
4603 @@ -2925,7 +2984,8 @@ int ext4_setattr(struct dentry *dentry, 
4604                 return error;
4605  
4606         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
4607 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
4608 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
4609 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
4610                 handle_t *handle;
4611  
4612                 /* (user+group)*(old+new) structure, inode write (sb,
4613 @@ -2947,6 +3007,8 @@ int ext4_setattr(struct dentry *dentry, 
4614                         inode->i_uid = attr->ia_uid;
4615                 if (attr->ia_valid & ATTR_GID)
4616                         inode->i_gid = attr->ia_gid;
4617 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
4618 +                       inode->i_tag = attr->ia_tag;
4619                 error = ext4_mark_inode_dirty(handle, inode);
4620                 ext4_journal_stop(handle);
4621         }
4622 diff -Nurp linux-2.6.22.18/fs/ext4/ioctl.c linux-2.6.22.18-vs2.3.0.32/fs/ext4/ioctl.c
4623 --- linux-2.6.22.18/fs/ext4/ioctl.c     2007-05-04 15:58:21.000000000 +0200
4624 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext4/ioctl.c  2008-02-11 12:35:34.000000000 +0100
4625 @@ -8,6 +8,7 @@
4626   */
4627  
4628  #include <linux/fs.h>
4629 +#include <linux/mount.h>
4630  #include <linux/jbd2.h>
4631  #include <linux/capability.h>
4632  #include <linux/ext4_fs.h>
4633 @@ -15,6 +16,7 @@
4634  #include <linux/time.h>
4635  #include <linux/compat.h>
4636  #include <linux/smp_lock.h>
4637 +#include <linux/vs_tag.h>
4638  #include <asm/uaccess.h>
4639  
4640  int ext4_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
4641 @@ -37,7 +39,8 @@ int ext4_ioctl (struct inode * inode, st
4642                 unsigned int oldflags;
4643                 unsigned int jflag;
4644  
4645 -               if (IS_RDONLY(inode))
4646 +               if (IS_RDONLY(inode) ||
4647 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4648                         return -EROFS;
4649  
4650                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
4651 @@ -61,7 +64,9 @@ int ext4_ioctl (struct inode * inode, st
4652                  *
4653                  * This test looks nicer. Thanks to Pauline Middelink
4654                  */
4655 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
4656 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
4657 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
4658 +                       EXT4_IMMUTABLE_FL | EXT4_IUNLINK_FL))) {
4659                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4660                                 mutex_unlock(&inode->i_mutex);
4661                                 return -EPERM;
4662 @@ -123,7 +128,8 @@ flags_err:
4663  
4664                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
4665                         return -EPERM;
4666 -               if (IS_RDONLY(inode))
4667 +               if (IS_RDONLY(inode) ||
4668 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4669                         return -EROFS;
4670                 if (get_user(generation, (int __user *) arg))
4671                         return -EFAULT;
4672 @@ -177,7 +183,8 @@ flags_err:
4673                 if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode))
4674                         return -ENOTTY;
4675  
4676 -               if (IS_RDONLY(inode))
4677 +               if (IS_RDONLY(inode) ||
4678 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4679                         return -EROFS;
4680  
4681                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
4682 @@ -212,7 +219,8 @@ flags_err:
4683                 if (!capable(CAP_SYS_RESOURCE))
4684                         return -EPERM;
4685  
4686 -               if (IS_RDONLY(inode))
4687 +               if (IS_RDONLY(inode) ||
4688 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4689                         return -EROFS;
4690  
4691                 if (get_user(n_blocks_count, (__u32 __user *)arg))
4692 @@ -233,7 +241,8 @@ flags_err:
4693                 if (!capable(CAP_SYS_RESOURCE))
4694                         return -EPERM;
4695  
4696 -               if (IS_RDONLY(inode))
4697 +               if (IS_RDONLY(inode) ||
4698 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4699                         return -EROFS;
4700  
4701                 if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg,
4702 diff -Nurp linux-2.6.22.18/fs/ext4/namei.c linux-2.6.22.18-vs2.3.0.32/fs/ext4/namei.c
4703 --- linux-2.6.22.18/fs/ext4/namei.c     2007-09-29 14:11:49.000000000 +0200
4704 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext4/namei.c  2008-02-11 12:35:34.000000000 +0100
4705 @@ -36,6 +36,7 @@
4706  #include <linux/quotaops.h>
4707  #include <linux/buffer_head.h>
4708  #include <linux/bio.h>
4709 +#include <linux/vs_tag.h>
4710  
4711  #include "namei.h"
4712  #include "xattr.h"
4713 @@ -1050,6 +1051,7 @@ static struct dentry *ext4_lookup(struct
4714  
4715                 if (!inode)
4716                         return ERR_PTR(-EACCES);
4717 +               dx_propagate_tag(nd, inode);
4718         }
4719         return d_splice_alias(inode, dentry);
4720  }
4721 @@ -2441,6 +2443,7 @@ const struct inode_operations ext4_dir_i
4722         .removexattr    = generic_removexattr,
4723  #endif
4724         .permission     = ext4_permission,
4725 +       .sync_flags     = ext4_sync_flags,
4726  };
4727  
4728  const struct inode_operations ext4_special_inode_operations = {
4729 @@ -2452,4 +2455,5 @@ const struct inode_operations ext4_speci
4730         .removexattr    = generic_removexattr,
4731  #endif
4732         .permission     = ext4_permission,
4733 +       .sync_flags     = ext4_sync_flags,
4734  };
4735 diff -Nurp linux-2.6.22.18/fs/ext4/super.c linux-2.6.22.18-vs2.3.0.32/fs/ext4/super.c
4736 --- linux-2.6.22.18/fs/ext4/super.c     2007-07-22 00:00:15.000000000 +0200
4737 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext4/super.c  2008-02-11 12:35:34.000000000 +0100
4738 @@ -725,7 +725,7 @@ enum {
4739         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
4740         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
4741         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
4742 -       Opt_grpquota, Opt_extents,
4743 +       Opt_grpquota, Opt_extents, Opt_tag, Opt_notag, Opt_tagid
4744  };
4745  
4746  static match_table_t tokens = {
4747 @@ -776,6 +776,9 @@ static match_table_t tokens = {
4748         {Opt_usrquota, "usrquota"},
4749         {Opt_barrier, "barrier=%u"},
4750         {Opt_extents, "extents"},
4751 +       {Opt_tag, "tag"},
4752 +       {Opt_notag, "notag"},
4753 +       {Opt_tagid, "tagid=%u"},
4754         {Opt_err, NULL},
4755         {Opt_resize, "resize"},
4756  };
4757 @@ -869,6 +872,20 @@ static int parse_options (char *options,
4758                 case Opt_nouid32:
4759                         set_opt (sbi->s_mount_opt, NO_UID32);
4760                         break;
4761 +#ifndef CONFIG_TAGGING_NONE
4762 +               case Opt_tag:
4763 +                       set_opt (sbi->s_mount_opt, TAGGED);
4764 +                       break;
4765 +               case Opt_notag:
4766 +                       clear_opt (sbi->s_mount_opt, TAGGED);
4767 +                       break;
4768 +#endif
4769 +#ifdef CONFIG_PROPAGATE
4770 +               case Opt_tagid:
4771 +                       /* use args[0] */
4772 +                       set_opt (sbi->s_mount_opt, TAGGED);
4773 +                       break;
4774 +#endif
4775                 case Opt_nocheck:
4776                         clear_opt (sbi->s_mount_opt, CHECK);
4777                         break;
4778 @@ -1546,6 +1563,9 @@ static int ext4_fill_super (struct super
4779                             NULL, 0))
4780                 goto failed_mount;
4781  
4782 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
4783 +               sb->s_flags |= MS_TAGGED;
4784 +
4785         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4786                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
4787  
4788 @@ -2377,6 +2397,12 @@ static int ext4_remount (struct super_bl
4789  
4790         if (sbi->s_mount_opt & EXT4_MOUNT_ABORT)
4791                 ext4_abort(sb, __FUNCTION__, "Abort forced by user");
4792 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
4793 +               !(sb->s_flags & MS_TAGGED)) {
4794 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
4795 +                       sb->s_id);
4796 +               return -EINVAL;
4797 +       }
4798  
4799         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4800                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
4801 diff -Nurp linux-2.6.22.18/fs/ext4/symlink.c linux-2.6.22.18-vs2.3.0.32/fs/ext4/symlink.c
4802 --- linux-2.6.22.18/fs/ext4/symlink.c   2007-07-21 23:58:45.000000000 +0200
4803 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext4/symlink.c        2008-02-11 12:35:34.000000000 +0100
4804 @@ -40,6 +40,7 @@ const struct inode_operations ext4_symli
4805         .listxattr      = ext4_listxattr,
4806         .removexattr    = generic_removexattr,
4807  #endif
4808 +       .sync_flags     = ext4_sync_flags,
4809  };
4810  
4811  const struct inode_operations ext4_fast_symlink_inode_operations = {
4812 @@ -51,4 +52,5 @@ const struct inode_operations ext4_fast_
4813         .listxattr      = ext4_listxattr,
4814         .removexattr    = generic_removexattr,
4815  #endif
4816 +       .sync_flags     = ext4_sync_flags,
4817  };
4818 diff -Nurp linux-2.6.22.18/fs/ext4/xattr.c linux-2.6.22.18-vs2.3.0.32/fs/ext4/xattr.c
4819 --- linux-2.6.22.18/fs/ext4/xattr.c     2007-07-21 23:58:45.000000000 +0200
4820 +++ linux-2.6.22.18-vs2.3.0.32/fs/ext4/xattr.c  2008-02-11 12:35:34.000000000 +0100
4821 @@ -58,6 +58,7 @@
4822  #include <linux/mbcache.h>
4823  #include <linux/quotaops.h>
4824  #include <linux/rwsem.h>
4825 +#include <linux/vs_dlimit.h>
4826  #include "xattr.h"
4827  #include "acl.h"
4828  
4829 @@ -496,6 +497,7 @@ ext4_xattr_release_block(handle_t *handl
4830                 error = ext4_journal_dirty_metadata(handle, bh);
4831                 if (IS_SYNC(inode))
4832                         handle->h_sync = 1;
4833 +                       DLIMIT_FREE_BLOCK(inode, 1);
4834                 DQUOT_FREE_BLOCK(inode, 1);
4835                 ea_bdebug(bh, "refcount now=%d; releasing",
4836                           le32_to_cpu(BHDR(bh)->h_refcount));
4837 @@ -769,11 +771,14 @@ inserted:
4838                         if (new_bh == bs->bh)
4839                                 ea_bdebug(new_bh, "keeping");
4840                         else {
4841 +                               error = -ENOSPC;
4842 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
4843 +                                       goto cleanup;
4844                                 /* The old block is released after updating
4845                                    the inode. */
4846                                 error = -EDQUOT;
4847                                 if (DQUOT_ALLOC_BLOCK(inode, 1))
4848 -                                       goto cleanup;
4849 +                                       goto cleanup_dlimit;
4850                                 error = ext4_journal_get_write_access(handle,
4851                                                                       new_bh);
4852                                 if (error)
4853 @@ -850,6 +855,8 @@ cleanup:
4854  
4855  cleanup_dquot:
4856         DQUOT_FREE_BLOCK(inode, 1);
4857 +cleanup_dlimit:
4858 +       DLIMIT_FREE_BLOCK(inode, 1);
4859         goto cleanup;
4860  
4861  bad_block:
4862 diff -Nurp linux-2.6.22.18/fs/fcntl.c linux-2.6.22.18-vs2.3.0.32/fs/fcntl.c
4863 --- linux-2.6.22.18/fs/fcntl.c  2007-05-04 15:58:21.000000000 +0200
4864 +++ linux-2.6.22.18-vs2.3.0.32/fs/fcntl.c       2008-02-11 12:35:34.000000000 +0100
4865 @@ -18,6 +18,7 @@
4866  #include <linux/ptrace.h>
4867  #include <linux/signal.h>
4868  #include <linux/rcupdate.h>
4869 +#include <linux/vs_limit.h>
4870  
4871  #include <asm/poll.h>
4872  #include <asm/siginfo.h>
4873 @@ -84,6 +85,8 @@ repeat:
4874         error = -EMFILE;
4875         if (newfd >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
4876                 goto out;
4877 +       if (!vx_files_avail(1))
4878 +               goto out;
4879  
4880         error = expand_files(files, newfd);
4881         if (error < 0)
4882 @@ -124,6 +127,7 @@ static int dupfd(struct file *file, unsi
4883                 FD_SET(fd, fdt->open_fds);
4884                 FD_CLR(fd, fdt->close_on_exec);
4885                 spin_unlock(&files->file_lock);
4886 +               vx_openfd_inc(fd);
4887                 fd_install(fd, file);
4888         } else {
4889                 spin_unlock(&files->file_lock);
4890 @@ -176,6 +180,9 @@ asmlinkage long sys_dup2(unsigned int ol
4891  
4892         if (tofree)
4893                 filp_close(tofree, files);
4894 +       else
4895 +               vx_openfd_inc(newfd);   /* fd was unused */
4896 +
4897         err = newfd;
4898  out:
4899         return err;
4900 diff -Nurp linux-2.6.22.18/fs/file_table.c linux-2.6.22.18-vs2.3.0.32/fs/file_table.c
4901 --- linux-2.6.22.18/fs/file_table.c     2007-07-22 00:00:15.000000000 +0200
4902 +++ linux-2.6.22.18-vs2.3.0.32/fs/file_table.c  2008-02-11 12:35:34.000000000 +0100
4903 @@ -20,6 +20,8 @@
4904  #include <linux/fsnotify.h>
4905  #include <linux/sysctl.h>
4906  #include <linux/percpu_counter.h>
4907 +#include <linux/vs_limit.h>
4908 +#include <linux/vs_context.h>
4909  
4910  #include <asm/atomic.h>
4911  
4912 @@ -119,6 +121,8 @@ struct file *get_empty_filp(void)
4913         f->f_gid = tsk->fsgid;
4914         eventpoll_init_file(f);
4915         /* f->f_version: 0 */
4916 +       f->f_xid = vx_current_xid();
4917 +       vx_files_inc(f);
4918         return f;
4919  
4920  over:
4921 @@ -174,6 +178,8 @@ void fastcall __fput(struct file *file)
4922         if (file->f_mode & FMODE_WRITE)
4923                 put_write_access(inode);
4924         put_pid(file->f_owner.pid);
4925 +       vx_files_dec(file);
4926 +       file->f_xid = 0;
4927         file_kill(file);
4928         file->f_path.dentry = NULL;
4929         file->f_path.mnt = NULL;
4930 @@ -239,6 +245,8 @@ void put_filp(struct file *file)
4931  {
4932         if (atomic_dec_and_test(&file->f_count)) {
4933                 security_file_free(file);
4934 +               vx_files_dec(file);
4935 +               file->f_xid = 0;
4936                 file_kill(file);
4937                 file_free(file);
4938         }
4939 diff -Nurp linux-2.6.22.18/fs/hfsplus/ioctl.c linux-2.6.22.18-vs2.3.0.32/fs/hfsplus/ioctl.c
4940 --- linux-2.6.22.18/fs/hfsplus/ioctl.c  2007-05-04 15:57:35.000000000 +0200
4941 +++ linux-2.6.22.18-vs2.3.0.32/fs/hfsplus/ioctl.c       2008-02-11 12:35:34.000000000 +0100
4942 @@ -16,6 +16,7 @@
4943  #include <linux/fs.h>
4944  #include <linux/sched.h>
4945  #include <linux/xattr.h>
4946 +#include <linux/mount.h>
4947  #include <asm/uaccess.h>
4948  #include "hfsplus_fs.h"
4949  
4950 @@ -35,7 +36,8 @@ int hfsplus_ioctl(struct inode *inode, s
4951                         flags |= FS_NODUMP_FL; /* EXT2_NODUMP_FL */
4952                 return put_user(flags, (int __user *)arg);
4953         case HFSPLUS_IOC_EXT2_SETFLAGS: {
4954 -               if (IS_RDONLY(inode))
4955 +               if (IS_RDONLY(inode) ||
4956 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4957                         return -EROFS;
4958  
4959                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
4960 diff -Nurp linux-2.6.22.18/fs/inode.c linux-2.6.22.18-vs2.3.0.32/fs/inode.c
4961 --- linux-2.6.22.18/fs/inode.c  2007-07-22 00:00:16.000000000 +0200
4962 +++ linux-2.6.22.18-vs2.3.0.32/fs/inode.c       2008-02-11 12:35:34.000000000 +0100
4963 @@ -115,6 +115,9 @@ static struct inode *alloc_inode(struct 
4964                 struct address_space * const mapping = &inode->i_data;
4965  
4966                 inode->i_sb = sb;
4967 +
4968 +               /* essential because of inode slab reuse */
4969 +               inode->i_tag = 0;
4970                 inode->i_blkbits = sb->s_blocksize_bits;
4971                 inode->i_flags = 0;
4972                 atomic_set(&inode->i_count, 1);
4973 @@ -133,6 +136,7 @@ static struct inode *alloc_inode(struct 
4974                 inode->i_bdev = NULL;
4975                 inode->i_cdev = NULL;
4976                 inode->i_rdev = 0;
4977 +               inode->i_mdev = 0;
4978                 inode->dirtied_when = 0;
4979                 if (security_inode_alloc(inode)) {
4980                         if (inode->i_sb->s_op->destroy_inode)
4981 @@ -231,6 +235,8 @@ void __iget(struct inode * inode)
4982         inodes_stat.nr_unused--;
4983  }
4984  
4985 +EXPORT_SYMBOL_GPL(__iget);
4986 +
4987  /**
4988   * clear_inode - clear an inode
4989   * @inode: inode to clear
4990 @@ -1405,9 +1411,11 @@ void init_special_inode(struct inode *in
4991         if (S_ISCHR(mode)) {
4992                 inode->i_fop = &def_chr_fops;
4993                 inode->i_rdev = rdev;
4994 +               inode->i_mdev = rdev;
4995         } else if (S_ISBLK(mode)) {
4996                 inode->i_fop = &def_blk_fops;
4997                 inode->i_rdev = rdev;
4998 +               inode->i_mdev = rdev;
4999         } else if (S_ISFIFO(mode))
5000                 inode->i_fop = &def_fifo_fops;
5001         else if (S_ISSOCK(mode))
5002 diff -Nurp linux-2.6.22.18/fs/ioctl.c linux-2.6.22.18-vs2.3.0.32/fs/ioctl.c
5003 --- linux-2.6.22.18/fs/ioctl.c  2007-07-22 00:00:16.000000000 +0200
5004 +++ linux-2.6.22.18-vs2.3.0.32/fs/ioctl.c       2008-02-11 12:35:34.000000000 +0100
5005 @@ -13,6 +13,9 @@
5006  #include <linux/security.h>
5007  #include <linux/module.h>
5008  #include <linux/kallsyms.h>
5009 +#include <linux/proc_fs.h>
5010 +#include <linux/vserver/inode.h>
5011 +#include <linux/vs_tag.h>
5012  
5013  #include <asm/uaccess.h>
5014  #include <asm/ioctls.h>
5015 diff -Nurp linux-2.6.22.18/fs/ioprio.c linux-2.6.22.18-vs2.3.0.32/fs/ioprio.c
5016 --- linux-2.6.22.18/fs/ioprio.c 2007-07-21 23:58:45.000000000 +0200
5017 +++ linux-2.6.22.18-vs2.3.0.32/fs/ioprio.c      2008-02-11 12:35:34.000000000 +0100
5018 @@ -25,6 +25,7 @@
5019  #include <linux/capability.h>
5020  #include <linux/syscalls.h>
5021  #include <linux/security.h>
5022 +#include <linux/vs_base.h>
5023  
5024  static int set_task_ioprio(struct task_struct *task, int ioprio)
5025  {
5026 @@ -103,6 +104,8 @@ asmlinkage long sys_ioprio_set(int which
5027                         else
5028                                 pgrp = find_pid(who);
5029                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
5030 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
5031 +                                       continue;
5032                                 ret = set_task_ioprio(p, ioprio);
5033                                 if (ret)
5034                                         break;
5035 @@ -112,7 +115,7 @@ asmlinkage long sys_ioprio_set(int which
5036                         if (!who)
5037                                 user = current->user;
5038                         else
5039 -                               user = find_user(who);
5040 +                               user = find_user(vx_current_xid(), who);
5041  
5042                         if (!user)
5043                                 break;
5044 @@ -190,6 +193,8 @@ asmlinkage long sys_ioprio_get(int which
5045                         else
5046                                 pgrp = find_pid(who);
5047                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
5048 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
5049 +                                       continue;
5050                                 tmpio = get_task_ioprio(p);
5051                                 if (tmpio < 0)
5052                                         continue;
5053 @@ -203,7 +208,7 @@ asmlinkage long sys_ioprio_get(int which
5054                         if (!who)
5055                                 user = current->user;
5056                         else
5057 -                               user = find_user(who);
5058 +                               user = find_user(vx_current_xid(), who);
5059  
5060                         if (!user)
5061                                 break;
5062 diff -Nurp linux-2.6.22.18/fs/jffs2/dir.c linux-2.6.22.18-vs2.3.0.32/fs/jffs2/dir.c
5063 --- linux-2.6.22.18/fs/jffs2/dir.c      2007-07-22 00:00:17.000000000 +0200
5064 +++ linux-2.6.22.18-vs2.3.0.32/fs/jffs2/dir.c   2008-02-11 12:35:34.000000000 +0100
5065 @@ -32,7 +32,9 @@ static int jffs2_mkdir (struct inode *,s
5066  static int jffs2_rmdir (struct inode *,struct dentry *);
5067  static int jffs2_mknod (struct inode *,struct dentry *,int,dev_t);
5068  static int jffs2_rename (struct inode *, struct dentry *,
5069 -                        struct inode *, struct dentry *);
5070 +                        struct inode *, struct dentry *);
5071 +
5072 +extern int jffs2_sync_flags(struct inode *);
5073  
5074  const struct file_operations jffs2_dir_operations =
5075  {
5076 @@ -56,6 +58,7 @@ const struct inode_operations jffs2_dir_
5077         .rename =       jffs2_rename,
5078         .permission =   jffs2_permission,
5079         .setattr =      jffs2_setattr,
5080 +       .sync_flags =   jffs2_sync_flags,
5081         .setxattr =     jffs2_setxattr,
5082         .getxattr =     jffs2_getxattr,
5083         .listxattr =    jffs2_listxattr,
5084 diff -Nurp linux-2.6.22.18/fs/jffs2/file.c linux-2.6.22.18-vs2.3.0.32/fs/jffs2/file.c
5085 --- linux-2.6.22.18/fs/jffs2/file.c     2007-07-22 00:00:17.000000000 +0200
5086 +++ linux-2.6.22.18-vs2.3.0.32/fs/jffs2/file.c  2008-02-11 12:35:34.000000000 +0100
5087 @@ -17,6 +17,7 @@
5088  #include <linux/highmem.h>
5089  #include <linux/crc32.h>
5090  #include <linux/jffs2.h>
5091 +#include <linux/vs_tag.h>
5092  #include "nodelist.h"
5093  
5094  static int jffs2_commit_write (struct file *filp, struct page *pg,
5095 @@ -25,6 +26,9 @@ static int jffs2_prepare_write (struct f
5096                                 unsigned start, unsigned end);
5097  static int jffs2_readpage (struct file *filp, struct page *pg);
5098  
5099 +extern int jffs2_sync_flags(struct inode *);
5100 +
5101 +
5102  int jffs2_fsync(struct file *filp, struct dentry *dentry, int datasync)
5103  {
5104         struct inode *inode = dentry->d_inode;
5105 @@ -47,7 +51,9 @@ const struct file_operations jffs2_file_
5106         .ioctl =        jffs2_ioctl,
5107         .mmap =         generic_file_readonly_mmap,
5108         .fsync =        jffs2_fsync,
5109 -       .sendfile =     generic_file_sendfile
5110 +       .sendfile =     generic_file_sendfile,
5111 +       .splice_read =  generic_file_splice_read,
5112 +       .splice_write = generic_file_splice_write
5113  };
5114  
5115  /* jffs2_file_inode_operations */
5116 @@ -56,6 +62,7 @@ const struct inode_operations jffs2_file
5117  {
5118         .permission =   jffs2_permission,
5119         .setattr =      jffs2_setattr,
5120 +       .sync_flags =   jffs2_sync_flags,
5121         .setxattr =     jffs2_setxattr,
5122         .getxattr =     jffs2_getxattr,
5123         .listxattr =    jffs2_listxattr,
5124 @@ -157,12 +164,14 @@ static int jffs2_prepare_write (struct f
5125                 ri.mode = cpu_to_jemode(inode->i_mode);
5126                 ri.uid = cpu_to_je16(inode->i_uid);
5127                 ri.gid = cpu_to_je16(inode->i_gid);
5128 +               ri.tag = cpu_to_je16(TAGINO_TAG(DX_TAG(inode), inode->i_tag));
5129                 ri.isize = cpu_to_je32(max((uint32_t)inode->i_size, pageofs));
5130                 ri.atime = ri.ctime = ri.mtime = cpu_to_je32(get_seconds());
5131                 ri.offset = cpu_to_je32(inode->i_size);
5132                 ri.dsize = cpu_to_je32(pageofs - inode->i_size);
5133                 ri.csize = cpu_to_je32(0);
5134                 ri.compr = JFFS2_COMPR_ZERO;
5135 +               ri.flags = cpu_to_je16(f->flags);
5136                 ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8));
5137                 ri.data_crc = cpu_to_je32(0);
5138  
5139 @@ -248,8 +257,10 @@ static int jffs2_commit_write (struct fi
5140         ri->mode = cpu_to_jemode(inode->i_mode);
5141         ri->uid = cpu_to_je16(inode->i_uid);
5142         ri->gid = cpu_to_je16(inode->i_gid);
5143 +       ri->tag = cpu_to_je16(TAGINO_TAG(DX_TAG(inode), inode->i_tag));
5144         ri->isize = cpu_to_je32((uint32_t)inode->i_size);
5145         ri->atime = ri->ctime = ri->mtime = cpu_to_je32(get_seconds());
5146 +       ri->flags = cpu_to_je16(f->flags);
5147  
5148         /* In 2.4, it was already kmapped by generic_file_write(). Doesn't
5149            hurt to do it again. The alternative is ifdefs, which are ugly. */
5150 diff -Nurp linux-2.6.22.18/fs/jffs2/fs.c linux-2.6.22.18-vs2.3.0.32/fs/jffs2/fs.c
5151 --- linux-2.6.22.18/fs/jffs2/fs.c       2007-09-29 14:11:49.000000000 +0200
5152 +++ linux-2.6.22.18-vs2.3.0.32/fs/jffs2/fs.c    2008-02-11 12:35:34.000000000 +0100
5153 @@ -20,6 +20,7 @@
5154  #include <linux/vmalloc.h>
5155  #include <linux/vfs.h>
5156  #include <linux/crc32.h>
5157 +#include <linux/vs_tag.h>
5158  #include "nodelist.h"
5159  
5160  static int jffs2_flash_setup(struct jffs2_sb_info *c);
5161 @@ -97,6 +98,7 @@ static int jffs2_do_setattr (struct inod
5162  
5163         ri->uid = cpu_to_je16((ivalid & ATTR_UID)?iattr->ia_uid:inode->i_uid);
5164         ri->gid = cpu_to_je16((ivalid & ATTR_GID)?iattr->ia_gid:inode->i_gid);
5165 +       ri->tag = cpu_to_je16((ivalid & ATTR_TAG)?iattr->ia_tag:inode->i_tag);
5166  
5167         if (ivalid & ATTR_MODE)
5168                 if (iattr->ia_mode & S_ISGID &&
5169 @@ -116,6 +118,8 @@ static int jffs2_do_setattr (struct inod
5170         ri->offset = cpu_to_je32(0);
5171         ri->csize = ri->dsize = cpu_to_je32(mdatalen);
5172         ri->compr = JFFS2_COMPR_NONE;
5173 +       ri->flags = cpu_to_je16(f->flags);
5174 +
5175         if (ivalid & ATTR_SIZE && inode->i_size < iattr->ia_size) {
5176                 /* It's an extension. Make it a hole node */
5177                 ri->compr = JFFS2_COMPR_ZERO;
5178 @@ -145,6 +149,7 @@ static int jffs2_do_setattr (struct inod
5179         inode->i_mode = jemode_to_cpu(ri->mode);
5180         inode->i_uid = je16_to_cpu(ri->uid);
5181         inode->i_gid = je16_to_cpu(ri->gid);
5182 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), 0, 0, je16_to_cpu(ri->tag));
5183  
5184  
5185         old_metadata = f->metadata;
5186 @@ -179,6 +184,48 @@ static int jffs2_do_setattr (struct inod
5187         return 0;
5188  }
5189  
5190 +void jffs2_set_inode_flags(struct inode *inode)
5191 +{
5192 +       struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
5193 +       unsigned int flags = f->flags;
5194 +
5195 +       inode->i_flags &= ~(JFFS2_INO_FLAG_IMMUTABLE |
5196 +               JFFS2_INO_FLAG_IUNLINK | JFFS2_INO_FLAG_BARRIER);
5197 +
5198 +       if (flags & JFFS2_INO_FLAG_IMMUTABLE)
5199 +               inode->i_flags |= S_IMMUTABLE;
5200 +       if (flags & JFFS2_INO_FLAG_IUNLINK)
5201 +               inode->i_flags |= S_IUNLINK;
5202 +       if (flags & JFFS2_INO_FLAG_BARRIER)
5203 +               inode->i_flags |= S_BARRIER;
5204 +}
5205 +
5206 +int jffs2_sync_flags(struct inode *inode)
5207 +{
5208 +       struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
5209 +       unsigned int oldflags, newflags;
5210 +
5211 +       oldflags = f->flags;
5212 +       newflags = oldflags & ~(JFFS2_INO_FLAG_IMMUTABLE |
5213 +               JFFS2_INO_FLAG_IUNLINK | JFFS2_INO_FLAG_BARRIER);
5214 +
5215 +       if (IS_IMMUTABLE(inode))
5216 +               newflags |= JFFS2_INO_FLAG_IMMUTABLE;
5217 +       if (IS_IUNLINK(inode))
5218 +               newflags |= JFFS2_INO_FLAG_IUNLINK;
5219 +       if (IS_BARRIER(inode))
5220 +               newflags |= JFFS2_INO_FLAG_BARRIER;
5221 +
5222 +       if (oldflags ^ newflags) {
5223 +               f->flags = newflags;
5224 +               inode->i_ctime = CURRENT_TIME;
5225 +               /* strange requirement, see jffs2_dirty_inode() */
5226 +               inode->i_state |= I_DIRTY_DATASYNC;
5227 +               mark_inode_dirty(inode);
5228 +       }
5229 +       return 0;
5230 +}
5231 +
5232  int jffs2_setattr(struct dentry *dentry, struct iattr *iattr)
5233  {
5234         int rc;
5235 @@ -254,6 +301,8 @@ void jffs2_read_inode (struct inode *ino
5236         inode->i_mode = jemode_to_cpu(latest_node.mode);
5237         inode->i_uid = je16_to_cpu(latest_node.uid);
5238         inode->i_gid = je16_to_cpu(latest_node.gid);
5239 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), 0, 0,
5240 +               je16_to_cpu(latest_node.tag));
5241         inode->i_size = je32_to_cpu(latest_node.isize);
5242         inode->i_atime = ITIME(je32_to_cpu(latest_node.atime));
5243         inode->i_mtime = ITIME(je32_to_cpu(latest_node.mtime));
5244 @@ -285,6 +334,7 @@ void jffs2_read_inode (struct inode *ino
5245  
5246                 inode->i_op = &jffs2_dir_inode_operations;
5247                 inode->i_fop = &jffs2_dir_operations;
5248 +               f->flags = je16_to_cpu(latest_node.flags);
5249                 break;
5250         }
5251         case S_IFREG:
5252 @@ -292,6 +342,7 @@ void jffs2_read_inode (struct inode *ino
5253                 inode->i_fop = &jffs2_file_operations;
5254                 inode->i_mapping->a_ops = &jffs2_file_address_operations;
5255                 inode->i_mapping->nrpages = 0;
5256 +               f->flags = je16_to_cpu(latest_node.flags);
5257                 break;
5258  
5259         case S_IFBLK:
5260 @@ -328,7 +379,7 @@ void jffs2_read_inode (struct inode *ino
5261         default:
5262                 printk(KERN_WARNING "jffs2_read_inode(): Bogus imode %o for ino %lu\n", inode->i_mode, (unsigned long)inode->i_ino);
5263         }
5264 -
5265 +       jffs2_set_inode_flags(inode);
5266         up(&f->sem);
5267  
5268         D1(printk(KERN_DEBUG "jffs2_read_inode() returning\n"));
5269 @@ -345,10 +396,11 @@ void jffs2_dirty_inode(struct inode *ino
5270  
5271         D1(printk(KERN_DEBUG "jffs2_dirty_inode() calling setattr() for ino #%lu\n", inode->i_ino));
5272  
5273 -       iattr.ia_valid = ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_ATIME|ATTR_MTIME|ATTR_CTIME;
5274 +       iattr.ia_valid = ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_ATIME|ATTR_MTIME|ATTR_CTIME|ATTR_TAG;
5275         iattr.ia_mode = inode->i_mode;
5276         iattr.ia_uid = inode->i_uid;
5277         iattr.ia_gid = inode->i_gid;
5278 +       iattr.ia_tag = inode->i_tag;
5279         iattr.ia_atime = inode->i_atime;
5280         iattr.ia_mtime = inode->i_mtime;
5281         iattr.ia_ctime = inode->i_ctime;
5282 @@ -422,6 +474,7 @@ struct inode *jffs2_new_inode (struct in
5283  
5284         memset(ri, 0, sizeof(*ri));
5285         /* Set OS-specific defaults for new inodes */
5286 +       ri->tag = cpu_to_je16(dx_current_tag());
5287         ri->uid = cpu_to_je16(current->fsuid);
5288  
5289         if (dir_i->i_mode & S_ISGID) {
5290 @@ -443,14 +496,16 @@ struct inode *jffs2_new_inode (struct in
5291         inode->i_mode = jemode_to_cpu(ri->mode);
5292         inode->i_gid = je16_to_cpu(ri->gid);
5293         inode->i_uid = je16_to_cpu(ri->uid);
5294 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), 0, 0, je16_to_cpu(ri->tag));
5295         inode->i_atime = inode->i_ctime = inode->i_mtime = CURRENT_TIME_SEC;
5296         ri->atime = ri->mtime = ri->ctime = cpu_to_je32(I_SEC(inode->i_mtime));
5297  
5298         inode->i_blocks = 0;
5299         inode->i_size = 0;
5300  
5301 +       f->flags = je16_to_cpu(ri->flags);
5302 +       jffs2_set_inode_flags(inode);
5303         insert_inode_hash(inode);
5304 -
5305         return inode;
5306  }
5307  
5308 diff -Nurp linux-2.6.22.18/fs/jffs2/gc.c linux-2.6.22.18-vs2.3.0.32/fs/jffs2/gc.c
5309 --- linux-2.6.22.18/fs/jffs2/gc.c       2007-07-22 00:00:17.000000000 +0200
5310 +++ linux-2.6.22.18-vs2.3.0.32/fs/jffs2/gc.c    2008-02-11 12:35:34.000000000 +0100
5311 @@ -735,6 +735,7 @@ static int jffs2_garbage_collect_metadat
5312         ri.mode = cpu_to_jemode(JFFS2_F_I_MODE(f));
5313         ri.uid = cpu_to_je16(JFFS2_F_I_UID(f));
5314         ri.gid = cpu_to_je16(JFFS2_F_I_GID(f));
5315 +       ri.tag = cpu_to_je16(JFFS2_F_I_TAG(f));
5316         ri.isize = cpu_to_je32(ilen);
5317         ri.atime = cpu_to_je32(JFFS2_F_I_ATIME(f));
5318         ri.ctime = cpu_to_je32(JFFS2_F_I_CTIME(f));
5319 @@ -998,6 +999,7 @@ static int jffs2_garbage_collect_hole(st
5320         ri.mode = cpu_to_jemode(JFFS2_F_I_MODE(f));
5321         ri.uid = cpu_to_je16(JFFS2_F_I_UID(f));
5322         ri.gid = cpu_to_je16(JFFS2_F_I_GID(f));
5323 +       ri.tag = cpu_to_je16(JFFS2_F_I_TAG(f));
5324         ri.isize = cpu_to_je32(ilen);
5325         ri.atime = cpu_to_je32(JFFS2_F_I_ATIME(f));
5326         ri.ctime = cpu_to_je32(JFFS2_F_I_CTIME(f));
5327 @@ -1256,6 +1258,7 @@ static int jffs2_garbage_collect_dnode(s
5328                 ri.mode = cpu_to_jemode(JFFS2_F_I_MODE(f));
5329                 ri.uid = cpu_to_je16(JFFS2_F_I_UID(f));
5330                 ri.gid = cpu_to_je16(JFFS2_F_I_GID(f));
5331 +               ri.tag = cpu_to_je16(JFFS2_F_I_TAG(f));
5332                 ri.isize = cpu_to_je32(JFFS2_F_I_SIZE(f));
5333                 ri.atime = cpu_to_je32(JFFS2_F_I_ATIME(f));
5334                 ri.ctime = cpu_to_je32(JFFS2_F_I_CTIME(f));
5335 diff -Nurp linux-2.6.22.18/fs/jffs2/ioctl.c linux-2.6.22.18-vs2.3.0.32/fs/jffs2/ioctl.c
5336 --- linux-2.6.22.18/fs/jffs2/ioctl.c    2007-07-22 00:00:17.000000000 +0200
5337 +++ linux-2.6.22.18-vs2.3.0.32/fs/jffs2/ioctl.c 2008-02-11 12:35:34.000000000 +0100
5338 @@ -10,12 +10,67 @@
5339   */
5340  
5341  #include <linux/fs.h>
5342 +#include <linux/types.h>
5343 +#include <linux/mount.h>
5344 +#include <linux/jffs2.h>
5345 +#include <linux/uaccess.h>
5346 +#include <linux/vs_base.h>
5347 +#include "jffs2_fs_sb.h"
5348 +#include "jffs2_fs_i.h"
5349 +#include "acl.h"
5350 +#include "os-linux.h"
5351 +
5352 +extern void jffs2_set_inode_flags(struct inode *);
5353  
5354  int jffs2_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
5355                 unsigned long arg)
5356  {
5357 -       /* Later, this will provide for lsattr.jffs2 and chattr.jffs2, which
5358 -          will include compression support etc. */
5359 -       return -ENOTTY;
5360 +       struct jffs2_inode_info *j = JFFS2_INODE_INFO(inode);
5361 +       unsigned int flags, oldflags, newflags;
5362 +
5363 +       switch (cmd) {
5364 +       case JFFS2_IOC_GETFLAGS:
5365 +               flags = j->flags & JFFS2_USER_VISIBLE;
5366 +               return put_user(flags, (int __user *) arg);
5367 +
5368 +       case JFFS2_IOC_SETFLAGS:
5369 +               if (IS_RDONLY(inode) ||
5370 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
5371 +                       return -EROFS;
5372 +
5373 +               if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
5374 +                       return -EACCES;
5375 +
5376 +               if (get_user(flags, (int __user *) arg))
5377 +                       return -EFAULT;
5378 +
5379 +               oldflags = j->flags;
5380 +               newflags = flags & JFFS2_USER_MODIFIABLE;
5381 +               newflags |= oldflags & ~JFFS2_USER_MODIFIABLE;
5382 +
5383 +               /*
5384 +                * The IMMUTABLE flags can only be changed by
5385 +                * the relevant capability.
5386 +                */
5387 +               if (((oldflags ^ newflags) &
5388 +                       (JFFS2_INO_FLAG_IMMUTABLE | JFFS2_INO_FLAG_IUNLINK)) ||
5389 +                       (oldflags & JFFS2_INO_FLAG_IMMUTABLE)) {
5390 +                       if (!capable(CAP_LINUX_IMMUTABLE))
5391 +                               return -EPERM;
5392 +               }
5393 +
5394 +               if (oldflags ^ newflags) {
5395 +                       j->flags = newflags;
5396 +                       inode->i_ctime = CURRENT_TIME;
5397 +                       /* strange requirement, see jffs2_dirty_inode() */
5398 +                       inode->i_state |= I_DIRTY_DATASYNC;
5399 +                       mark_inode_dirty(inode);
5400 +                       jffs2_set_inode_flags(inode);
5401 +               }
5402 +               return 0;
5403 +
5404 +       default:
5405 +               return -ENOTTY;
5406 +       }
5407  }
5408  
5409 diff -Nurp linux-2.6.22.18/fs/jffs2/jffs2_fs_sb.h linux-2.6.22.18-vs2.3.0.32/fs/jffs2/jffs2_fs_sb.h
5410 --- linux-2.6.22.18/fs/jffs2/jffs2_fs_sb.h      2007-07-22 00:00:17.000000000 +0200
5411 +++ linux-2.6.22.18-vs2.3.0.32/fs/jffs2/jffs2_fs_sb.h   2008-02-11 12:35:34.000000000 +0100
5412 @@ -39,6 +39,7 @@ struct jffs2_sb_info {
5413         uint32_t checked_ino;
5414  
5415         unsigned int flags;
5416 +       unsigned int s_mount_opt;
5417  
5418         struct task_struct *gc_task;    /* GC task struct */
5419         struct completion gc_thread_start; /* GC thread start completion */
5420 diff -Nurp linux-2.6.22.18/fs/jffs2/nodelist.h linux-2.6.22.18-vs2.3.0.32/fs/jffs2/nodelist.h
5421 --- linux-2.6.22.18/fs/jffs2/nodelist.h 2007-07-22 00:00:17.000000000 +0200
5422 +++ linux-2.6.22.18-vs2.3.0.32/fs/jffs2/nodelist.h      2008-02-11 12:35:34.000000000 +0100
5423 @@ -47,25 +47,25 @@
5424  #elif defined(JFFS2_BIG_ENDIAN)
5425  #define cpu_to_je16(x) ((jint16_t){cpu_to_be16(x)})
5426  #define cpu_to_je32(x) ((jint32_t){cpu_to_be32(x)})
5427 -#define cpu_to_jemode(x) ((jmode_t){cpu_to_be32(os_to_jffs2_mode(x))})
5428 +#define cpu_to_jemode(x) ((jmode_t){cpu_to_be16(os_to_jffs2_mode(x))})
5429  
5430  #define constant_cpu_to_je16(x) ((jint16_t){__constant_cpu_to_be16(x)})
5431  #define constant_cpu_to_je32(x) ((jint32_t){__constant_cpu_to_be32(x)})
5432  
5433  #define je16_to_cpu(x) (be16_to_cpu(x.v16))
5434  #define je32_to_cpu(x) (be32_to_cpu(x.v32))
5435 -#define jemode_to_cpu(x) (be32_to_cpu(jffs2_to_os_mode((x).m)))
5436 +#define jemode_to_cpu(x) (be16_to_cpu(jffs2_to_os_mode((x).m)))
5437  #elif defined(JFFS2_LITTLE_ENDIAN)
5438  #define cpu_to_je16(x) ((jint16_t){cpu_to_le16(x)})
5439  #define cpu_to_je32(x) ((jint32_t){cpu_to_le32(x)})
5440 -#define cpu_to_jemode(x) ((jmode_t){cpu_to_le32(os_to_jffs2_mode(x))})
5441 +#define cpu_to_jemode(x) ((jmode_t){cpu_to_le16(os_to_jffs2_mode(x))})
5442  
5443  #define constant_cpu_to_je16(x) ((jint16_t){__constant_cpu_to_le16(x)})
5444  #define constant_cpu_to_je32(x) ((jint32_t){__constant_cpu_to_le32(x)})
5445  
5446  #define je16_to_cpu(x) (le16_to_cpu(x.v16))
5447  #define je32_to_cpu(x) (le32_to_cpu(x.v32))
5448 -#define jemode_to_cpu(x) (le32_to_cpu(jffs2_to_os_mode((x).m)))
5449 +#define jemode_to_cpu(x) (le16_to_cpu(jffs2_to_os_mode((x).m)))
5450  #else
5451  #error wibble
5452  #endif
5453 diff -Nurp linux-2.6.22.18/fs/jffs2/os-linux.h linux-2.6.22.18-vs2.3.0.32/fs/jffs2/os-linux.h
5454 --- linux-2.6.22.18/fs/jffs2/os-linux.h 2007-07-22 00:00:17.000000000 +0200
5455 +++ linux-2.6.22.18-vs2.3.0.32/fs/jffs2/os-linux.h      2008-02-11 12:35:34.000000000 +0100
5456 @@ -29,6 +29,7 @@ struct kvec;
5457  #define JFFS2_F_I_MODE(f) (OFNI_EDONI_2SFFJ(f)->i_mode)
5458  #define JFFS2_F_I_UID(f) (OFNI_EDONI_2SFFJ(f)->i_uid)
5459  #define JFFS2_F_I_GID(f) (OFNI_EDONI_2SFFJ(f)->i_gid)
5460 +#define JFFS2_F_I_TAG(f) (OFNI_EDONI_2SFFJ(f)->i_tag)
5461  #define JFFS2_F_I_RDEV(f) (OFNI_EDONI_2SFFJ(f)->i_rdev)
5462  
5463  #define ITIME(sec) ((struct timespec){sec, 0})
5464 @@ -204,6 +205,9 @@ int jffs2_flash_direct_writev(struct jff
5465  int jffs2_flash_direct_write(struct jffs2_sb_info *c, loff_t ofs, size_t len,
5466                         size_t *retlen, const u_char *buf);
5467  
5468 +#define JFFS2_IOC_GETFLAGS             FS_IOC_GETFLAGS
5469 +#define JFFS2_IOC_SETFLAGS             FS_IOC_SETFLAGS
5470 +
5471  #endif /* __JFFS2_OS_LINUX_H__ */
5472  
5473  
5474 diff -Nurp linux-2.6.22.18/fs/jffs2/readinode.c linux-2.6.22.18-vs2.3.0.32/fs/jffs2/readinode.c
5475 --- linux-2.6.22.18/fs/jffs2/readinode.c        2007-07-22 00:00:17.000000000 +0200
5476 +++ linux-2.6.22.18-vs2.3.0.32/fs/jffs2/readinode.c     2008-02-11 12:35:34.000000000 +0100
5477 @@ -1182,6 +1182,8 @@ static int jffs2_do_read_inode_internal(
5478                 latest_node->isize = cpu_to_je32(0);
5479                 latest_node->gid = cpu_to_je16(0);
5480                 latest_node->uid = cpu_to_je16(0);
5481 +               latest_node->tag = cpu_to_je16(0);
5482 +               latest_node->flags = cpu_to_je16(0);
5483                 if (f->inocache->state == INO_STATE_READING)
5484                         jffs2_set_inocache_state(c, f->inocache, INO_STATE_PRESENT);
5485                 return 0;
5486 diff -Nurp linux-2.6.22.18/fs/jffs2/super.c linux-2.6.22.18-vs2.3.0.32/fs/jffs2/super.c
5487 --- linux-2.6.22.18/fs/jffs2/super.c    2007-07-22 00:00:17.000000000 +0200
5488 +++ linux-2.6.22.18-vs2.3.0.32/fs/jffs2/super.c 2008-02-11 12:35:34.000000000 +0100
5489 @@ -22,6 +22,7 @@
5490  #include <linux/mtd/super.h>
5491  #include <linux/ctype.h>
5492  #include <linux/namei.h>
5493 +#include <linux/parser.h>
5494  #include "compr.h"
5495  #include "nodelist.h"
5496  
5497 @@ -75,6 +76,49 @@ static const struct super_operations jff
5498         .sync_fs =      jffs2_sync_fs,
5499  };
5500  
5501 +enum {
5502 +       Opt_tag, Opt_notag, Opt_ignore, Opt_err
5503 +};
5504 +
5505 +static match_table_t tokens = {
5506 +       {Opt_tag, "tag"},
5507 +       {Opt_notag, "notag"},
5508 +       {Opt_err, NULL}
5509 +};
5510 +
5511 +static int parse_options (char * options,
5512 +                         struct jffs2_sb_info *sbi)
5513 +{
5514 +       char * p;
5515 +       substring_t args[MAX_OPT_ARGS];
5516 +
5517 +       if (!options)
5518 +               return 1;
5519 +
5520 +       while ((p = strsep (&options, ",")) != NULL) {
5521 +               int token;
5522 +               if (!*p)
5523 +                       continue;
5524 +
5525 +               token = match_token(p, tokens, args);
5526 +               switch (token) {
5527 +#ifndef CONFIG_TAGGING_NONE
5528 +               case Opt_tag:
5529 +                       set_opt (sbi->s_mount_opt, TAGGED);
5530 +                       break;
5531 +               case Opt_notag:
5532 +                       clear_opt (sbi->s_mount_opt, TAGGED);
5533 +                       break;
5534 +#endif
5535 +               case Opt_ignore:
5536 +                       break;
5537 +               default:
5538 +                       return 0;
5539 +               }
5540 +       }
5541 +       return 1;
5542 +}
5543 +
5544  /*
5545   * fill in the superblock
5546   */
5547 @@ -109,6 +153,12 @@ static int jffs2_fill_super(struct super
5548  #ifdef CONFIG_JFFS2_FS_POSIX_ACL
5549         sb->s_flags |= MS_POSIXACL;
5550  #endif
5551 +       if (!parse_options ((char *) data, c))
5552 +               return -EINVAL;
5553 +
5554 +       if (c->s_mount_opt & JFFS2_MOUNT_TAGGED)
5555 +               sb->s_flags |= MS_TAGGED;
5556 +
5557         return jffs2_do_fill_super(sb, data, silent);
5558  }
5559  
5560 diff -Nurp linux-2.6.22.18/fs/jffs2/write.c linux-2.6.22.18-vs2.3.0.32/fs/jffs2/write.c
5561 --- linux-2.6.22.18/fs/jffs2/write.c    2007-08-26 03:38:36.000000000 +0200
5562 +++ linux-2.6.22.18-vs2.3.0.32/fs/jffs2/write.c 2008-02-11 12:35:34.000000000 +0100
5563 @@ -44,6 +44,7 @@ int jffs2_do_new_inode(struct jffs2_sb_i
5564         ri->totlen = cpu_to_je32(PAD(sizeof(*ri)));
5565         ri->hdr_crc = cpu_to_je32(crc32(0, ri, sizeof(struct jffs2_unknown_node)-4));
5566         ri->mode = cpu_to_jemode(mode);
5567 +       ri->flags = cpu_to_je16(0);
5568  
5569         f->highest_version = 1;
5570         ri->version = cpu_to_je32(f->highest_version);
5571 diff -Nurp linux-2.6.22.18/fs/jfs/acl.c linux-2.6.22.18-vs2.3.0.32/fs/jfs/acl.c
5572 --- linux-2.6.22.18/fs/jfs/acl.c        2007-05-04 15:57:35.000000000 +0200
5573 +++ linux-2.6.22.18-vs2.3.0.32/fs/jfs/acl.c     2008-02-11 12:35:34.000000000 +0100
5574 @@ -232,7 +232,8 @@ int jfs_setattr(struct dentry *dentry, s
5575                 return rc;
5576  
5577         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
5578 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
5579 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
5580 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
5581                 if (DQUOT_TRANSFER(inode, iattr))
5582                         return -EDQUOT;
5583         }
5584 diff -Nurp linux-2.6.22.18/fs/jfs/file.c linux-2.6.22.18-vs2.3.0.32/fs/jfs/file.c
5585 --- linux-2.6.22.18/fs/jfs/file.c       2007-07-21 23:58:46.000000000 +0200
5586 +++ linux-2.6.22.18-vs2.3.0.32/fs/jfs/file.c    2008-02-11 12:35:34.000000000 +0100
5587 @@ -98,6 +98,7 @@ const struct inode_operations jfs_file_i
5588         .setattr        = jfs_setattr,
5589         .permission     = jfs_permission,
5590  #endif
5591 +       .sync_flags     = jfs_sync_flags,
5592  };
5593  
5594  const struct file_operations jfs_file_operations = {
5595 diff -Nurp linux-2.6.22.18/fs/jfs/inode.c linux-2.6.22.18-vs2.3.0.32/fs/jfs/inode.c
5596 --- linux-2.6.22.18/fs/jfs/inode.c      2007-07-22 00:00:17.000000000 +0200
5597 +++ linux-2.6.22.18-vs2.3.0.32/fs/jfs/inode.c   2008-02-11 12:35:34.000000000 +0100
5598 @@ -22,6 +22,7 @@
5599  #include <linux/buffer_head.h>
5600  #include <linux/pagemap.h>
5601  #include <linux/quotaops.h>
5602 +#include <linux/vs_dlimit.h>
5603  #include "jfs_incore.h"
5604  #include "jfs_inode.h"
5605  #include "jfs_filsys.h"
5606 @@ -143,6 +144,7 @@ void jfs_delete_inode(struct inode *inod
5607                 DQUOT_INIT(inode);
5608                 DQUOT_FREE_INODE(inode);
5609                 DQUOT_DROP(inode);
5610 +               DLIMIT_FREE_INODE(inode);
5611         }
5612  
5613         clear_inode(inode);
5614 diff -Nurp linux-2.6.22.18/fs/jfs/ioctl.c linux-2.6.22.18-vs2.3.0.32/fs/jfs/ioctl.c
5615 --- linux-2.6.22.18/fs/jfs/ioctl.c      2007-07-22 00:00:17.000000000 +0200
5616 +++ linux-2.6.22.18-vs2.3.0.32/fs/jfs/ioctl.c   2008-02-11 12:35:34.000000000 +0100
5617 @@ -10,6 +10,7 @@
5618  #include <linux/capability.h>
5619  #include <linux/time.h>
5620  #include <linux/sched.h>
5621 +#include <linux/mount.h>
5622  #include <asm/current.h>
5623  #include <asm/uaccess.h>
5624  
5625 @@ -66,7 +67,8 @@ int jfs_ioctl(struct inode * inode, stru
5626         case JFS_IOC_SETFLAGS: {
5627                 unsigned int oldflags;
5628  
5629 -               if (IS_RDONLY(inode))
5630 +               if (IS_RDONLY(inode) ||
5631 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
5632                         return -EROFS;
5633  
5634                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
5635 @@ -87,8 +89,8 @@ int jfs_ioctl(struct inode * inode, stru
5636                  * the relevant capability.
5637                  */
5638                 if ((oldflags & JFS_IMMUTABLE_FL) ||
5639 -                       ((flags ^ oldflags) &
5640 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
5641 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
5642 +                       JFS_IMMUTABLE_FL | JFS_IUNLINK_FL))) {
5643                         if (!capable(CAP_LINUX_IMMUTABLE))
5644                                 return -EPERM;
5645                 }
5646 diff -Nurp linux-2.6.22.18/fs/jfs/jfs_dinode.h linux-2.6.22.18-vs2.3.0.32/fs/jfs/jfs_dinode.h
5647 --- linux-2.6.22.18/fs/jfs/jfs_dinode.h 2007-05-04 15:57:35.000000000 +0200
5648 +++ linux-2.6.22.18-vs2.3.0.32/fs/jfs/jfs_dinode.h      2008-02-11 12:35:34.000000000 +0100
5649 @@ -162,9 +162,12 @@ struct dinode {
5650  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
5651  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
5652  
5653 -#define JFS_FL_USER_VISIBLE    0x03F80000
5654 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
5655 +#define JFS_IUNLINK_FL         0x08000000 /* Immutable unlink */
5656 +
5657 +#define JFS_FL_USER_VISIBLE    0x0FF80000
5658  #define JFS_FL_USER_MODIFIABLE 0x03F80000
5659 -#define JFS_FL_INHERIT         0x03C80000
5660 +#define JFS_FL_INHERIT         0x0BC80000
5661  
5662  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
5663  #define JFS_IOC_GETFLAGS       _IOR('f', 1, long)
5664 diff -Nurp linux-2.6.22.18/fs/jfs/jfs_dtree.c linux-2.6.22.18-vs2.3.0.32/fs/jfs/jfs_dtree.c
5665 --- linux-2.6.22.18/fs/jfs/jfs_dtree.c  2007-05-04 15:58:21.000000000 +0200
5666 +++ linux-2.6.22.18-vs2.3.0.32/fs/jfs/jfs_dtree.c       2008-02-11 12:35:34.000000000 +0100
5667 @@ -102,6 +102,7 @@
5668  
5669  #include <linux/fs.h>
5670  #include <linux/quotaops.h>
5671 +#include <linux/vs_dlimit.h>
5672  #include "jfs_incore.h"
5673  #include "jfs_superblock.h"
5674  #include "jfs_filsys.h"
5675 @@ -383,10 +384,10 @@ static u32 add_index(tid_t tid, struct i
5676                  */
5677                 if (DQUOT_ALLOC_BLOCK(ip, sbi->nbperpage))
5678                         goto clean_up;
5679 -               if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr)) {
5680 -                       DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
5681 -                       goto clean_up;
5682 -               }
5683 +               if (DLIMIT_ALLOC_BLOCK(ip, sbi->nbperpage))
5684 +                       goto clean_up_dquot;
5685 +               if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr))
5686 +                       goto clean_up_dlimit;
5687  
5688                 /*
5689                  * Save the table, we're going to overwrite it with the
5690 @@ -479,6 +480,12 @@ static u32 add_index(tid_t tid, struct i
5691  
5692         return index;
5693  
5694 +      clean_up_dlimit:
5695 +       DLIMIT_FREE_BLOCK(ip, sbi->nbperpage);
5696 +
5697 +      clean_up_dquot:
5698 +       DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
5699 +
5700        clean_up:
5701  
5702         jfs_ip->next_index--;
5703 @@ -952,6 +959,7 @@ static int dtSplitUp(tid_t tid,
5704         struct tlock *tlck;
5705         struct lv *lv;
5706         int quota_allocation = 0;
5707 +       int dlimit_allocation = 0;
5708  
5709         /* get split page */
5710         smp = split->mp;
5711 @@ -1036,6 +1044,12 @@ static int dtSplitUp(tid_t tid,
5712                 }
5713                 quota_allocation += n;
5714  
5715 +               if (DLIMIT_ALLOC_BLOCK(ip, n)) {
5716 +                       rc = -ENOSPC;
5717 +                       goto extendOut;
5718 +               }
5719 +               dlimit_allocation += n;
5720 +
5721                 if ((rc = dbReAlloc(sbi->ipbmap, xaddr, (s64) xlen,
5722                                     (s64) n, &nxaddr)))
5723                         goto extendOut;
5724 @@ -1309,6 +1323,9 @@ static int dtSplitUp(tid_t tid,
5725        freeKeyName:
5726         kfree(key.name);
5727  
5728 +       /* Rollback dlimit allocation */
5729 +       if (rc && dlimit_allocation)
5730 +               DLIMIT_FREE_BLOCK(ip, dlimit_allocation);
5731         /* Rollback quota allocation */
5732         if (rc && quota_allocation)
5733                 DQUOT_FREE_BLOCK(ip, quota_allocation);
5734 @@ -1376,6 +1393,12 @@ static int dtSplitPage(tid_t tid, struct
5735                 release_metapage(rmp);
5736                 return -EDQUOT;
5737         }
5738 +       /* Allocate blocks to dlimit. */
5739 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
5740 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
5741 +               release_metapage(rmp);
5742 +               return -ENOSPC;
5743 +       }
5744  
5745         jfs_info("dtSplitPage: ip:0x%p smp:0x%p rmp:0x%p", ip, smp, rmp);
5746  
5747 @@ -1926,6 +1949,12 @@ static int dtSplitRoot(tid_t tid,
5748                 release_metapage(rmp);
5749                 return -EDQUOT;
5750         }
5751 +       /* Allocate blocks to dlimit. */
5752 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
5753 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
5754 +               release_metapage(rmp);
5755 +               return -ENOSPC;
5756 +       }
5757  
5758         BT_MARK_DIRTY(rmp, ip);
5759         /*
5760 @@ -2292,6 +2321,8 @@ static int dtDeleteUp(tid_t tid, struct 
5761  
5762         xlen = lengthPXD(&fp->header.self);
5763  
5764 +       /* Free dlimit allocation. */
5765 +       DLIMIT_FREE_BLOCK(ip, xlen);
5766         /* Free quota allocation. */
5767         DQUOT_FREE_BLOCK(ip, xlen);
5768  
5769 @@ -2368,6 +2399,8 @@ static int dtDeleteUp(tid_t tid, struct 
5770  
5771                                 xlen = lengthPXD(&p->header.self);
5772  
5773 +                               /* Free dlimit allocation */
5774 +                               DLIMIT_FREE_BLOCK(ip, xlen);
5775                                 /* Free quota allocation */
5776                                 DQUOT_FREE_BLOCK(ip, xlen);
5777  
5778 diff -Nurp linux-2.6.22.18/fs/jfs/jfs_extent.c linux-2.6.22.18-vs2.3.0.32/fs/jfs/jfs_extent.c
5779 --- linux-2.6.22.18/fs/jfs/jfs_extent.c 2007-05-04 15:57:36.000000000 +0200
5780 +++ linux-2.6.22.18-vs2.3.0.32/fs/jfs/jfs_extent.c      2008-02-11 12:35:34.000000000 +0100
5781 @@ -18,6 +18,7 @@
5782  
5783  #include <linux/fs.h>
5784  #include <linux/quotaops.h>
5785 +#include <linux/vs_dlimit.h>
5786  #include "jfs_incore.h"
5787  #include "jfs_inode.h"
5788  #include "jfs_superblock.h"
5789 @@ -147,6 +148,14 @@ extAlloc(struct inode *ip, s64 xlen, s64
5790                 return -EDQUOT;
5791         }
5792  
5793 +       /* Allocate blocks to dlimit. */
5794 +       if (DLIMIT_ALLOC_BLOCK(ip, nxlen)) {
5795 +               DQUOT_FREE_BLOCK(ip, nxlen);
5796 +               dbFree(ip, nxaddr, (s64) nxlen);
5797 +               mutex_unlock(&JFS_IP(ip)->commit_mutex);
5798 +               return -ENOSPC;
5799 +       }
5800 +
5801         /* determine the value of the extent flag */
5802         xflag = abnr ? XAD_NOTRECORDED : 0;
5803  
5804 @@ -164,6 +173,7 @@ extAlloc(struct inode *ip, s64 xlen, s64
5805          */
5806         if (rc) {
5807                 dbFree(ip, nxaddr, nxlen);
5808 +               DLIMIT_FREE_BLOCK(ip, nxlen);
5809                 DQUOT_FREE_BLOCK(ip, nxlen);
5810                 mutex_unlock(&JFS_IP(ip)->commit_mutex);
5811                 return (rc);
5812 @@ -261,6 +271,13 @@ int extRealloc(struct inode *ip, s64 nxl
5813                 mutex_unlock(&JFS_IP(ip)->commit_mutex);
5814                 return -EDQUOT;
5815         }
5816 +       /* Allocate blocks to dlimit. */
5817 +       if (DLIMIT_ALLOC_BLOCK(ip, nxlen)) {
5818 +               DQUOT_FREE_BLOCK(ip, nxlen);
5819 +               dbFree(ip, nxaddr, (s64) nxlen);
5820 +               up(&JFS_IP(ip)->commit_sem);
5821 +               return -ENOSPC;
5822 +       }
5823  
5824         delta = nxlen - xlen;
5825  
5826 @@ -297,6 +314,7 @@ int extRealloc(struct inode *ip, s64 nxl
5827                 /* extend the extent */
5828                 if ((rc = xtExtend(0, ip, xoff + xlen, (int) nextend, 0))) {
5829                         dbFree(ip, xaddr + xlen, delta);
5830 +                       DLIMIT_FREE_BLOCK(ip, nxlen);
5831                         DQUOT_FREE_BLOCK(ip, nxlen);
5832                         goto exit;
5833                 }
5834 @@ -308,6 +326,7 @@ int extRealloc(struct inode *ip, s64 nxl
5835                  */
5836                 if ((rc = xtTailgate(0, ip, xoff, (int) ntail, nxaddr, 0))) {
5837                         dbFree(ip, nxaddr, nxlen);
5838 +                       DLIMIT_FREE_BLOCK(ip, nxlen);
5839                         DQUOT_FREE_BLOCK(ip, nxlen);
5840                         goto exit;
5841                 }
5842 diff -Nurp linux-2.6.22.18/fs/jfs/jfs_filsys.h linux-2.6.22.18-vs2.3.0.32/fs/jfs/jfs_filsys.h
5843 --- linux-2.6.22.18/fs/jfs/jfs_filsys.h 2007-05-04 15:58:21.000000000 +0200
5844 +++ linux-2.6.22.18-vs2.3.0.32/fs/jfs/jfs_filsys.h      2008-02-11 12:35:34.000000000 +0100
5845 @@ -264,6 +264,7 @@
5846  #define JFS_NAME_MAX   255
5847  #define JFS_PATH_MAX   BPSIZE
5848  
5849 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
5850  
5851  /*
5852   *     file system state (superblock state)
5853 diff -Nurp linux-2.6.22.18/fs/jfs/jfs_imap.c linux-2.6.22.18-vs2.3.0.32/fs/jfs/jfs_imap.c
5854 --- linux-2.6.22.18/fs/jfs/jfs_imap.c   2007-07-22 00:00:17.000000000 +0200
5855 +++ linux-2.6.22.18-vs2.3.0.32/fs/jfs/jfs_imap.c        2008-02-11 12:35:34.000000000 +0100
5856 @@ -45,6 +45,7 @@
5857  #include <linux/buffer_head.h>
5858  #include <linux/pagemap.h>
5859  #include <linux/quotaops.h>
5860 +#include <linux/vs_tag.h>
5861  
5862  #include "jfs_incore.h"
5863  #include "jfs_inode.h"
5864 @@ -3075,6 +3076,8 @@ static int copy_from_dinode(struct dinod
5865  {
5866         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
5867         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
5868 +       uid_t uid;
5869 +       gid_t gid;
5870  
5871         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
5872         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
5873 @@ -3095,14 +3098,18 @@ static int copy_from_dinode(struct dinod
5874         }
5875         ip->i_nlink = le32_to_cpu(dip->di_nlink);
5876  
5877 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
5878 +       uid = le32_to_cpu(dip->di_uid);
5879 +       gid = le32_to_cpu(dip->di_gid);
5880 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
5881 +
5882 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
5883         if (sbi->uid == -1)
5884                 ip->i_uid = jfs_ip->saved_uid;
5885         else {
5886                 ip->i_uid = sbi->uid;
5887         }
5888  
5889 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
5890 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
5891         if (sbi->gid == -1)
5892                 ip->i_gid = jfs_ip->saved_gid;
5893         else {
5894 @@ -3167,14 +3174,12 @@ static void copy_to_dinode(struct dinode
5895         dip->di_size = cpu_to_le64(ip->i_size);
5896         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
5897         dip->di_nlink = cpu_to_le32(ip->i_nlink);
5898 -       if (sbi->uid == -1)
5899 -               dip->di_uid = cpu_to_le32(ip->i_uid);
5900 -       else
5901 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
5902 -       if (sbi->gid == -1)
5903 -               dip->di_gid = cpu_to_le32(ip->i_gid);
5904 -       else
5905 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
5906 +
5907 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
5908 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
5909 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
5910 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
5911 +
5912         jfs_get_inode_flags(jfs_ip);
5913         /*
5914          * mode2 is only needed for storing the higher order bits.
5915 diff -Nurp linux-2.6.22.18/fs/jfs/jfs_inode.c linux-2.6.22.18-vs2.3.0.32/fs/jfs/jfs_inode.c
5916 --- linux-2.6.22.18/fs/jfs/jfs_inode.c  2007-07-22 00:00:17.000000000 +0200
5917 +++ linux-2.6.22.18-vs2.3.0.32/fs/jfs/jfs_inode.c       2008-02-11 12:35:34.000000000 +0100
5918 @@ -18,6 +18,8 @@
5919  
5920  #include <linux/fs.h>
5921  #include <linux/quotaops.h>
5922 +#include <linux/vs_dlimit.h>
5923 +#include <linux/vs_tag.h>
5924  #include "jfs_incore.h"
5925  #include "jfs_inode.h"
5926  #include "jfs_filsys.h"
5927 @@ -30,19 +32,47 @@ void jfs_set_inode_flags(struct inode *i
5928  {
5929         unsigned int flags = JFS_IP(inode)->mode2;
5930  
5931 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
5932 -               S_NOATIME | S_DIRSYNC | S_SYNC);
5933 +       inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
5934 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5935  
5936         if (flags & JFS_IMMUTABLE_FL)
5937                 inode->i_flags |= S_IMMUTABLE;
5938 +       if (flags & JFS_IUNLINK_FL)
5939 +               inode->i_flags |= S_IUNLINK;
5940 +       if (flags & JFS_BARRIER_FL)
5941 +               inode->i_flags |= S_BARRIER;
5942 +
5943 +       if (flags & JFS_SYNC_FL)
5944 +               inode->i_flags |= S_SYNC;
5945         if (flags & JFS_APPEND_FL)
5946                 inode->i_flags |= S_APPEND;
5947         if (flags & JFS_NOATIME_FL)
5948                 inode->i_flags |= S_NOATIME;
5949         if (flags & JFS_DIRSYNC_FL)
5950                 inode->i_flags |= S_DIRSYNC;
5951 -       if (flags & JFS_SYNC_FL)
5952 -               inode->i_flags |= S_SYNC;
5953 +}
5954 +
5955 +int jfs_sync_flags(struct inode *inode)
5956 +{
5957 +       unsigned int oldflags, newflags;
5958 +
5959 +       oldflags = JFS_IP(inode)->mode2;
5960 +       newflags = oldflags & ~(JFS_IMMUTABLE_FL |
5961 +               JFS_IUNLINK_FL | JFS_BARRIER_FL);
5962 +
5963 +       if (IS_IMMUTABLE(inode))
5964 +               newflags |= JFS_IMMUTABLE_FL;
5965 +       if (IS_IUNLINK(inode))
5966 +               newflags |= JFS_IUNLINK_FL;
5967 +       if (IS_BARRIER(inode))
5968 +               newflags |= JFS_BARRIER_FL;
5969 +
5970 +       if (oldflags ^ newflags) {
5971 +               JFS_IP(inode)->mode2 = newflags;
5972 +               inode->i_ctime = CURRENT_TIME;
5973 +               mark_inode_dirty(inode);
5974 +       }
5975 +       return 0;
5976  }
5977  
5978  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
5979 @@ -108,10 +138,17 @@ struct inode *ialloc(struct inode *paren
5980         jfs_inode->saved_uid = inode->i_uid;
5981         jfs_inode->saved_gid = inode->i_gid;
5982  
5983 +       inode->i_tag = dx_current_fstag(sb);
5984 +       if (DLIMIT_ALLOC_INODE(inode)) {
5985 +               iput(inode);
5986 +               return ERR_PTR(-ENOSPC);
5987 +       }
5988 +
5989         /*
5990          * Allocate inode to quota.
5991          */
5992         if (DQUOT_ALLOC_INODE(inode)) {
5993 +               DLIMIT_FREE_INODE(inode);
5994                 DQUOT_DROP(inode);
5995                 inode->i_flags |= S_NOQUOTA;
5996                 inode->i_nlink = 0;
5997 diff -Nurp linux-2.6.22.18/fs/jfs/jfs_inode.h linux-2.6.22.18-vs2.3.0.32/fs/jfs/jfs_inode.h
5998 --- linux-2.6.22.18/fs/jfs/jfs_inode.h  2007-07-22 00:00:17.000000000 +0200
5999 +++ linux-2.6.22.18-vs2.3.0.32/fs/jfs/jfs_inode.h       2008-02-11 12:35:34.000000000 +0100
6000 @@ -33,6 +33,7 @@ extern void jfs_free_zero_link(struct in
6001  extern struct dentry *jfs_get_parent(struct dentry *dentry);
6002  extern void jfs_get_inode_flags(struct jfs_inode_info *);
6003  extern void jfs_set_inode_flags(struct inode *);
6004 +extern int jfs_sync_flags(struct inode *);
6005  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
6006  
6007  extern const struct address_space_operations jfs_aops;
6008 diff -Nurp linux-2.6.22.18/fs/jfs/jfs_xtree.c linux-2.6.22.18-vs2.3.0.32/fs/jfs/jfs_xtree.c
6009 --- linux-2.6.22.18/fs/jfs/jfs_xtree.c  2007-07-21 23:58:46.000000000 +0200
6010 +++ linux-2.6.22.18-vs2.3.0.32/fs/jfs/jfs_xtree.c       2008-02-11 12:35:34.000000000 +0100
6011 @@ -21,6 +21,7 @@
6012  
6013  #include <linux/fs.h>
6014  #include <linux/quotaops.h>
6015 +#include <linux/vs_dlimit.h>
6016  #include "jfs_incore.h"
6017  #include "jfs_filsys.h"
6018  #include "jfs_metapage.h"
6019 @@ -846,7 +847,12 @@ int xtInsert(tid_t tid,            /* transaction 
6020                         hint = 0;
6021                 if ((rc = DQUOT_ALLOC_BLOCK(ip, xlen)))
6022                         goto out;
6023 +               if ((rc = DLIMIT_ALLOC_BLOCK(ip, xlen))) {
6024 +                       DQUOT_FREE_BLOCK(ip, xlen);
6025 +                       goto out;
6026 +               }
6027                 if ((rc = dbAlloc(ip, hint, (s64) xlen, &xaddr))) {
6028 +                       DLIMIT_FREE_BLOCK(ip, xlen);
6029                         DQUOT_FREE_BLOCK(ip, xlen);
6030                         goto out;
6031                 }
6032 @@ -876,6 +882,7 @@ int xtInsert(tid_t tid,             /* transaction 
6033                         /* undo data extent allocation */
6034                         if (*xaddrp == 0) {
6035                                 dbFree(ip, xaddr, (s64) xlen);
6036 +                               DLIMIT_FREE_BLOCK(ip, xlen);
6037                                 DQUOT_FREE_BLOCK(ip, xlen);
6038                         }
6039                         return rc;
6040 @@ -1236,6 +1243,7 @@ xtSplitPage(tid_t tid, struct inode *ip,
6041         struct tlock *tlck;
6042         struct xtlock *sxtlck = NULL, *rxtlck = NULL;
6043         int quota_allocation = 0;
6044 +       int dlimit_allocation = 0;
6045  
6046         smp = split->mp;
6047         sp = XT_PAGE(ip, smp);
6048 @@ -1255,6 +1263,13 @@ xtSplitPage(tid_t tid, struct inode *ip,
6049  
6050         quota_allocation += lengthPXD(pxd);
6051  
6052 +       /* Allocate blocks to dlimit. */
6053 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
6054 +              rc = -ENOSPC;
6055 +              goto clean_up;
6056 +       }
6057 +       dlimit_allocation += lengthPXD(pxd);
6058 +
6059         /*
6060          * allocate the new right page for the split
6061          */
6062 @@ -1456,6 +1471,9 @@ xtSplitPage(tid_t tid, struct inode *ip,
6063  
6064        clean_up:
6065  
6066 +       /* Rollback dlimit allocation. */
6067 +       if (dlimit_allocation)
6068 +               DLIMIT_FREE_BLOCK(ip, dlimit_allocation);
6069         /* Rollback quota allocation. */
6070         if (quota_allocation)
6071                 DQUOT_FREE_BLOCK(ip, quota_allocation);
6072 @@ -1520,6 +1538,12 @@ xtSplitRoot(tid_t tid,
6073                 release_metapage(rmp);
6074                 return -EDQUOT;
6075         }
6076 +       /* Allocate blocks to dlimit. */
6077 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
6078 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
6079 +               release_metapage(rmp);
6080 +               return -ENOSPC;
6081 +       }
6082  
6083         jfs_info("xtSplitRoot: ip:0x%p rmp:0x%p", ip, rmp);
6084  
6085 @@ -3951,6 +3975,8 @@ s64 xtTruncate(tid_t tid, struct inode *
6086         else
6087                 ip->i_size = newsize;
6088  
6089 +       /* update dlimit allocation to reflect freed blocks */
6090 +       DLIMIT_FREE_BLOCK(ip, nfreed);
6091         /* update quota allocation to reflect freed blocks */
6092         DQUOT_FREE_BLOCK(ip, nfreed);
6093  
6094 diff -Nurp linux-2.6.22.18/fs/jfs/namei.c linux-2.6.22.18-vs2.3.0.32/fs/jfs/namei.c
6095 --- linux-2.6.22.18/fs/jfs/namei.c      2007-07-21 23:58:46.000000000 +0200
6096 +++ linux-2.6.22.18-vs2.3.0.32/fs/jfs/namei.c   2008-02-11 12:35:34.000000000 +0100
6097 @@ -20,6 +20,7 @@
6098  #include <linux/fs.h>
6099  #include <linux/ctype.h>
6100  #include <linux/quotaops.h>
6101 +#include <linux/vs_tag.h>
6102  #include "jfs_incore.h"
6103  #include "jfs_superblock.h"
6104  #include "jfs_inode.h"
6105 @@ -1469,6 +1470,7 @@ static struct dentry *jfs_lookup(struct 
6106                 return ERR_PTR(-EACCES);
6107         }
6108  
6109 +       dx_propagate_tag(nd, ip);
6110         dentry = d_splice_alias(ip, dentry);
6111  
6112         if (dentry && (JFS_SBI(dip->i_sb)->mntflag & JFS_OS2))
6113 @@ -1521,6 +1523,7 @@ const struct inode_operations jfs_dir_in
6114         .setattr        = jfs_setattr,
6115         .permission     = jfs_permission,
6116  #endif
6117 +       .sync_flags     = jfs_sync_flags,
6118  };
6119  
6120  const struct file_operations jfs_dir_operations = {
6121 diff -Nurp linux-2.6.22.18/fs/jfs/super.c linux-2.6.22.18-vs2.3.0.32/fs/jfs/super.c
6122 --- linux-2.6.22.18/fs/jfs/super.c      2007-07-22 00:00:17.000000000 +0200
6123 +++ linux-2.6.22.18-vs2.3.0.32/fs/jfs/super.c   2008-02-11 12:35:34.000000000 +0100
6124 @@ -194,7 +194,8 @@ static void jfs_put_super(struct super_b
6125  enum {
6126         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
6127         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
6128 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
6129 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
6130 +       Opt_tag, Opt_notag, Opt_tagid
6131  };
6132  
6133  static match_table_t tokens = {
6134 @@ -204,6 +205,10 @@ static match_table_t tokens = {
6135         {Opt_resize, "resize=%u"},
6136         {Opt_resize_nosize, "resize"},
6137         {Opt_errors, "errors=%s"},
6138 +       {Opt_tag, "tag"},
6139 +       {Opt_notag, "notag"},
6140 +       {Opt_tagid, "tagid=%u"},
6141 +       {Opt_tag, "tagxid"},
6142         {Opt_ignore, "noquota"},
6143         {Opt_ignore, "quota"},
6144         {Opt_usrquota, "usrquota"},
6145 @@ -338,6 +343,20 @@ static int parse_options(char *options, 
6146                         }
6147                         break;
6148                 }
6149 +#ifndef CONFIG_TAGGING_NONE
6150 +               case Opt_tag:
6151 +                       *flag |= JFS_TAGGED;
6152 +                       break;
6153 +               case Opt_notag:
6154 +                       *flag &= JFS_TAGGED;
6155 +                       break;
6156 +#endif
6157 +#ifdef CONFIG_PROPAGATE
6158 +               case Opt_tagid:
6159 +                       /* use args[0] */
6160 +                       *flag |= JFS_TAGGED;
6161 +                       break;
6162 +#endif
6163                 default:
6164                         printk("jfs: Unrecognized mount option \"%s\" "
6165                                         " or missing value\n", p);
6166 @@ -368,6 +387,13 @@ static int jfs_remount(struct super_bloc
6167         if (!parse_options(data, sb, &newLVSize, &flag)) {
6168                 return -EINVAL;
6169         }
6170 +
6171 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
6172 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
6173 +                       sb->s_id);
6174 +               return -EINVAL;
6175 +       }
6176 +
6177         if (newLVSize) {
6178                 if (sb->s_flags & MS_RDONLY) {
6179                         printk(KERN_ERR
6180 @@ -439,6 +465,9 @@ static int jfs_fill_super(struct super_b
6181  #ifdef CONFIG_JFS_POSIX_ACL
6182         sb->s_flags |= MS_POSIXACL;
6183  #endif
6184 +       /* map mount option tagxid */
6185 +       if (sbi->flag & JFS_TAGGED)
6186 +               sb->s_flags |= MS_TAGGED;
6187  
6188         if (newLVSize) {
6189                 printk(KERN_ERR "resize option for remount only\n");
6190 diff -Nurp linux-2.6.22.18/fs/jfs/xattr.c linux-2.6.22.18-vs2.3.0.32/fs/jfs/xattr.c
6191 --- linux-2.6.22.18/fs/jfs/xattr.c      2007-05-04 15:57:36.000000000 +0200
6192 +++ linux-2.6.22.18-vs2.3.0.32/fs/jfs/xattr.c   2008-02-11 12:35:34.000000000 +0100
6193 @@ -23,6 +23,7 @@
6194  #include <linux/posix_acl_xattr.h>
6195  #include <linux/quotaops.h>
6196  #include <linux/security.h>
6197 +#include <linux/vs_dlimit.h>
6198  #include "jfs_incore.h"
6199  #include "jfs_superblock.h"
6200  #include "jfs_dmap.h"
6201 @@ -263,9 +264,16 @@ static int ea_write(struct inode *ip, st
6202         if (DQUOT_ALLOC_BLOCK(ip, nblocks)) {
6203                 return -EDQUOT;
6204         }
6205 +       /* Allocate new blocks to dlimit. */
6206 +       if (DLIMIT_ALLOC_BLOCK(ip, nblocks)) {
6207 +               DQUOT_FREE_BLOCK(ip, nblocks);
6208 +               return -ENOSPC;
6209 +       }
6210  
6211         rc = dbAlloc(ip, INOHINT(ip), nblocks, &blkno);
6212         if (rc) {
6213 +               /*Rollback dlimit allocation. */
6214 +               DLIMIT_FREE_BLOCK(ip, nblocks);
6215                 /*Rollback quota allocation. */
6216                 DQUOT_FREE_BLOCK(ip, nblocks);
6217                 return rc;
6218 @@ -332,6 +340,8 @@ static int ea_write(struct inode *ip, st
6219  
6220        failed:
6221         /* Rollback quota allocation. */
6222 +       DLIMIT_FREE_BLOCK(ip, nblocks);
6223 +       /* Rollback quota allocation. */
6224         DQUOT_FREE_BLOCK(ip, nblocks);
6225  
6226         dbFree(ip, blkno, nblocks);
6227 @@ -468,6 +478,7 @@ static int ea_get(struct inode *inode, s
6228         s64 blkno;
6229         int rc;
6230         int quota_allocation = 0;
6231 +       int dlimit_allocation = 0;
6232  
6233         /* When fsck.jfs clears a bad ea, it doesn't clear the size */
6234         if (ji->ea.flag == 0)
6235 @@ -543,6 +554,12 @@ static int ea_get(struct inode *inode, s
6236  
6237                 quota_allocation = blocks_needed;
6238  
6239 +               /* Allocate new blocks to dlimit. */
6240 +               rc = -ENOSPC;
6241 +               if (DLIMIT_ALLOC_BLOCK(inode, blocks_needed))
6242 +                       goto clean_up;
6243 +               dlimit_allocation = blocks_needed;
6244 +
6245                 rc = dbAlloc(inode, INOHINT(inode), (s64) blocks_needed,
6246                              &blkno);
6247                 if (rc)
6248 @@ -599,6 +616,9 @@ static int ea_get(struct inode *inode, s
6249         return ea_size;
6250  
6251        clean_up:
6252 +       /* Rollback dlimit allocation */
6253 +       if (dlimit_allocation)
6254 +               DLIMIT_FREE_BLOCK(inode, dlimit_allocation);
6255         /* Rollback quota allocation */
6256         if (quota_allocation)
6257                 DQUOT_FREE_BLOCK(inode, quota_allocation);
6258 @@ -675,8 +695,10 @@ static int ea_put(tid_t tid, struct inod
6259         }
6260  
6261         /* If old blocks exist, they must be removed from quota allocation. */
6262 -       if (old_blocks)
6263 +       if (old_blocks) {
6264 +               DLIMIT_FREE_BLOCK(inode, old_blocks);
6265                 DQUOT_FREE_BLOCK(inode, old_blocks);
6266 +       }
6267  
6268         inode->i_ctime = CURRENT_TIME;
6269  
6270 diff -Nurp linux-2.6.22.18/fs/Kconfig linux-2.6.22.18-vs2.3.0.32/fs/Kconfig
6271 --- linux-2.6.22.18/fs/Kconfig  2007-07-22 00:00:15.000000000 +0200
6272 +++ linux-2.6.22.18-vs2.3.0.32/fs/Kconfig       2008-02-11 12:35:33.000000000 +0100
6273 @@ -2026,7 +2026,7 @@ config CODA_FS_OLD_API
6274  
6275  config AFS_FS
6276         tristate "Andrew File System support (AFS) (EXPERIMENTAL)"
6277 -       depends on INET && EXPERIMENTAL
6278 +       depends on INET && EXPERIMENTAL && !VSERVER_SECURITY
6279         select AF_RXRPC
6280         help
6281           If you say Y here, you will get an experimental Andrew File System
6282 diff -Nurp linux-2.6.22.18/fs/libfs.c linux-2.6.22.18-vs2.3.0.32/fs/libfs.c
6283 --- linux-2.6.22.18/fs/libfs.c  2007-07-22 00:00:17.000000000 +0200
6284 +++ linux-2.6.22.18-vs2.3.0.32/fs/libfs.c       2008-02-11 12:35:34.000000000 +0100
6285 @@ -124,7 +124,8 @@ static inline unsigned char dt_type(stru
6286   * both impossible due to the lock on directory.
6287   */
6288  
6289 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
6290 +static inline int do_dcache_readdir_filter(struct file *filp,
6291 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
6292  {
6293         struct dentry *dentry = filp->f_path.dentry;
6294         struct dentry *cursor = filp->private_data;
6295 @@ -157,6 +158,8 @@ int dcache_readdir(struct file * filp, v
6296                                 next = list_entry(p, struct dentry, d_u.d_child);
6297                                 if (d_unhashed(next) || !next->d_inode)
6298                                         continue;
6299 +                               if (filter && !filter(next))
6300 +                                       continue;
6301  
6302                                 spin_unlock(&dcache_lock);
6303                                 if (filldir(dirent, next->d_name.name, 
6304 @@ -175,6 +178,18 @@ int dcache_readdir(struct file * filp, v
6305         return 0;
6306  }
6307  
6308 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
6309 +{
6310 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
6311 +}
6312 +
6313 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
6314 +       int (*filter)(struct dentry *))
6315 +{
6316 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
6317 +}
6318 +
6319 +
6320  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
6321  {
6322         return -EISDIR;
6323 @@ -640,6 +655,7 @@ EXPORT_SYMBOL(dcache_dir_close);
6324  EXPORT_SYMBOL(dcache_dir_lseek);
6325  EXPORT_SYMBOL(dcache_dir_open);
6326  EXPORT_SYMBOL(dcache_readdir);
6327 +EXPORT_SYMBOL(dcache_readdir_filter);
6328  EXPORT_SYMBOL(generic_read_dir);
6329  EXPORT_SYMBOL(get_sb_pseudo);
6330  EXPORT_SYMBOL(simple_commit_write);
6331 diff -Nurp linux-2.6.22.18/fs/locks.c linux-2.6.22.18-vs2.3.0.32/fs/locks.c
6332 --- linux-2.6.22.18/fs/locks.c  2007-09-29 14:11:49.000000000 +0200
6333 +++ linux-2.6.22.18-vs2.3.0.32/fs/locks.c       2008-02-11 12:35:34.000000000 +0100
6334 @@ -125,6 +125,8 @@
6335  #include <linux/syscalls.h>
6336  #include <linux/time.h>
6337  #include <linux/rcupdate.h>
6338 +#include <linux/vs_base.h>
6339 +#include <linux/vs_limit.h>
6340  
6341  #include <asm/semaphore.h>
6342  #include <asm/uaccess.h>
6343 @@ -147,6 +149,8 @@ static struct kmem_cache *filelock_cache
6344  /* Allocate an empty lock structure. */
6345  static struct file_lock *locks_alloc_lock(void)
6346  {
6347 +       if (!vx_locks_avail(1))
6348 +               return NULL;
6349         return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
6350  }
6351  
6352 @@ -172,6 +176,7 @@ static void locks_free_lock(struct file_
6353         BUG_ON(!list_empty(&fl->fl_block));
6354         BUG_ON(!list_empty(&fl->fl_link));
6355  
6356 +       vx_locks_dec(fl);
6357         locks_release_private(fl);
6358         kmem_cache_free(filelock_cache, fl);
6359  }
6360 @@ -191,6 +196,7 @@ void locks_init_lock(struct file_lock *f
6361         fl->fl_start = fl->fl_end = 0;
6362         fl->fl_ops = NULL;
6363         fl->fl_lmops = NULL;
6364 +       fl->fl_xid = -1;
6365  }
6366  
6367  EXPORT_SYMBOL(locks_init_lock);
6368 @@ -244,6 +250,7 @@ void locks_copy_lock(struct file_lock *n
6369         new->fl_file = fl->fl_file;
6370         new->fl_ops = fl->fl_ops;
6371         new->fl_lmops = fl->fl_lmops;
6372 +       new->fl_xid = fl->fl_xid;
6373  
6374         locks_copy_private(new, fl);
6375  }
6376 @@ -282,6 +289,11 @@ static int flock_make_lock(struct file *
6377         fl->fl_flags = FL_FLOCK;
6378         fl->fl_type = type;
6379         fl->fl_end = OFFSET_MAX;
6380 +
6381 +       vxd_assert(filp->f_xid == vx_current_xid(),
6382 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
6383 +       fl->fl_xid = filp->f_xid;
6384 +       vx_locks_inc(fl);
6385         
6386         *lock = fl;
6387         return 0;
6388 @@ -447,6 +459,7 @@ static int lease_init(struct file *filp,
6389  
6390         fl->fl_owner = current->files;
6391         fl->fl_pid = current->tgid;
6392 +       fl->fl_xid = vx_current_xid();
6393  
6394         fl->fl_file = filp;
6395         fl->fl_flags = FL_LEASE;
6396 @@ -466,6 +479,11 @@ static int lease_alloc(struct file *filp
6397         if (fl == NULL)
6398                 goto out;
6399  
6400 +       fl->fl_xid = vx_current_xid();
6401 +       if (filp)
6402 +               vxd_assert(filp->f_xid == fl->fl_xid,
6403 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
6404 +       vx_locks_inc(fl);
6405         error = lease_init(filp, type, fl);
6406         if (error) {
6407                 locks_free_lock(fl);
6408 @@ -769,6 +787,7 @@ static int flock_lock_file(struct file *
6409         if (found)
6410                 cond_resched();
6411  
6412 +       new_fl->fl_xid = -1;
6413  find_conflict:
6414         for_each_lock(inode, before) {
6415                 struct file_lock *fl = *before;
6416 @@ -787,6 +806,7 @@ find_conflict:
6417                 goto out;
6418         locks_copy_lock(new_fl, request);
6419         locks_insert_lock(before, new_fl);
6420 +       vx_locks_inc(new_fl);
6421         new_fl = NULL;
6422         error = 0;
6423  
6424 @@ -797,7 +817,8 @@ out:
6425         return error;
6426  }
6427  
6428 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
6429 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
6430 +       struct file_lock *conflock, xid_t xid)
6431  {
6432         struct file_lock *fl;
6433         struct file_lock *new_fl = NULL;
6434 @@ -807,6 +828,8 @@ static int __posix_lock_file(struct inod
6435         struct file_lock **before;
6436         int error, added = 0;
6437  
6438 +       vxd_assert(xid == vx_current_xid(),
6439 +               "xid(%d) == current(%d)", xid, vx_current_xid());
6440         /*
6441          * We may need two file_lock structures for this operation,
6442          * so we get them in advance to avoid races.
6443 @@ -817,7 +840,11 @@ static int __posix_lock_file(struct inod
6444             (request->fl_type != F_UNLCK ||
6445              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
6446                 new_fl = locks_alloc_lock();
6447 +               new_fl->fl_xid = xid;
6448 +               vx_locks_inc(new_fl);
6449                 new_fl2 = locks_alloc_lock();
6450 +               new_fl2->fl_xid = xid;
6451 +               vx_locks_inc(new_fl2);
6452         }
6453  
6454         lock_kernel();
6455 @@ -1016,7 +1043,8 @@ static int __posix_lock_file(struct inod
6456  int posix_lock_file(struct file *filp, struct file_lock *fl,
6457                         struct file_lock *conflock)
6458  {
6459 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
6460 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
6461 +               fl, conflock, filp->f_xid);
6462  }
6463  EXPORT_SYMBOL(posix_lock_file);
6464  
6465 @@ -1106,7 +1134,7 @@ int locks_mandatory_area(int read_write,
6466         fl.fl_end = offset + count - 1;
6467  
6468         for (;;) {
6469 -               error = __posix_lock_file(inode, &fl, NULL);
6470 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
6471                 if (error != -EAGAIN)
6472                         break;
6473                 if (!(fl.fl_flags & FL_SLEEP))
6474 @@ -1410,8 +1438,8 @@ static int __setlease(struct file *filp,
6475                 goto out;
6476  
6477         locks_copy_lock(fl, lease);
6478 -
6479         locks_insert_lock(before, fl);
6480 +       vx_locks_inc(fl);
6481  
6482         *flp = fl;
6483         error = 0;
6484 @@ -1738,6 +1766,11 @@ int fcntl_setlk(unsigned int fd, struct 
6485         if (file_lock == NULL)
6486                 return -ENOLCK;
6487  
6488 +       vxd_assert(filp->f_xid == vx_current_xid(),
6489 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
6490 +       file_lock->fl_xid = filp->f_xid;
6491 +       vx_locks_inc(file_lock);
6492 +
6493         /*
6494          * This might block, so we do it before checking the inode.
6495          */
6496 @@ -1864,6 +1897,11 @@ int fcntl_setlk64(unsigned int fd, struc
6497         if (file_lock == NULL)
6498                 return -ENOLCK;
6499  
6500 +       vxd_assert(filp->f_xid == vx_current_xid(),
6501 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
6502 +       file_lock->fl_xid = filp->f_xid;
6503 +       vx_locks_inc(file_lock);
6504 +
6505         /*
6506          * This might block, so we do it before checking the inode.
6507          */
6508 @@ -2168,6 +2206,10 @@ int get_locks_status(char *buffer, char 
6509         list_for_each(tmp, &file_lock_list) {
6510                 struct list_head *btmp;
6511                 struct file_lock *fl = list_entry(tmp, struct file_lock, fl_link);
6512 +
6513 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
6514 +                       continue;
6515 +
6516                 lock_get_status(q, fl, ++i, "");
6517                 move_lock_status(&q, &pos, offset);
6518  
6519 diff -Nurp linux-2.6.22.18/fs/namei.c linux-2.6.22.18-vs2.3.0.32/fs/namei.c
6520 --- linux-2.6.22.18/fs/namei.c  2008-01-15 16:00:53.000000000 +0100
6521 +++ linux-2.6.22.18-vs2.3.0.32/fs/namei.c       2008-02-11 12:35:34.000000000 +0100
6522 @@ -31,6 +31,13 @@
6523  #include <linux/file.h>
6524  #include <linux/fcntl.h>
6525  #include <linux/namei.h>
6526 +#include <linux/proc_fs.h>
6527 +#include <linux/vserver/inode.h>
6528 +#include <linux/vs_base.h>
6529 +#include <linux/vs_tag.h>
6530 +#include <linux/vs_cowbl.h>
6531 +#include <linux/vs_device.h>
6532 +#include <linux/vs_context.h>
6533  #include <asm/namei.h>
6534  #include <asm/uaccess.h>
6535  
6536 @@ -224,6 +231,28 @@ int generic_permission(struct inode *ino
6537         return -EACCES;
6538  }
6539  
6540 +static inline int dx_barrier(struct inode *inode)
6541 +{
6542 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN)) {
6543 +               vxwprintk_task(1, "did hit the barrier.");
6544 +               return 1;
6545 +       }
6546 +       return 0;
6547 +}
6548 +
6549 +static inline int dx_permission(struct inode *inode, int mask, struct nameidata *nd)
6550 +{
6551 +       if (dx_barrier(inode))
6552 +               return -EACCES;
6553 +       if (dx_notagcheck(nd) ||
6554 +           dx_check(inode->i_tag, DX_HOSTID|DX_ADMIN|DX_WATCH|DX_IDENT))
6555 +               return 0;
6556 +
6557 +       vxwprintk_task(1, "denied access to %p[#%d,%lu] Â»%s«.",
6558 +               inode, inode->i_tag, inode->i_ino, vxd_cond_path(nd));
6559 +       return -EACCES;
6560 +}
6561 +
6562  int permission(struct inode *inode, int mask, struct nameidata *nd)
6563  {
6564         umode_t mode = inode->i_mode;
6565 @@ -234,14 +263,14 @@ int permission(struct inode *inode, int 
6566                 /*
6567                  * Nobody gets write access to a read-only fs.
6568                  */
6569 -               if (IS_RDONLY(inode) &&
6570 +               if ((IS_RDONLY(inode) || (nd && MNT_IS_RDONLY(nd->mnt))) &&
6571                     (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)))
6572                         return -EROFS;
6573  
6574                 /*
6575                  * Nobody gets write access to an immutable file.
6576                  */
6577 -               if (IS_IMMUTABLE(inode))
6578 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
6579                         return -EACCES;
6580         }
6581  
6582 @@ -257,6 +286,12 @@ int permission(struct inode *inode, int 
6583  
6584         /* Ordinary permission routines do not understand MAY_APPEND. */
6585         submask = mask & ~MAY_APPEND;
6586 +
6587 +       if ((inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC) &&
6588 +               (inode->i_sb->s_magic != PROC_SUPER_MAGIC) &&
6589 +               (retval = dx_permission(inode, mask, nd)))
6590 +               return retval;
6591 +
6592         if (inode->i_op && inode->i_op->permission)
6593                 retval = inode->i_op->permission(inode, submask, nd);
6594         else
6595 @@ -432,6 +467,8 @@ static int exec_permission_lite(struct i
6596  {
6597         umode_t mode = inode->i_mode;
6598  
6599 +       if (dx_barrier(inode))
6600 +               return -EACCES;
6601         if (inode->i_op && inode->i_op->permission)
6602                 return -EAGAIN;
6603  
6604 @@ -732,7 +769,8 @@ static __always_inline void follow_dotdo
6605                 if (nd->dentry == fs->root &&
6606                     nd->mnt == fs->rootmnt) {
6607                          read_unlock(&fs->lock);
6608 -                       break;
6609 +                       /* for sane '/' avoid follow_mount() */
6610 +                       return;
6611                 }
6612                  read_unlock(&fs->lock);
6613                 spin_lock(&dcache_lock);
6614 @@ -769,16 +807,39 @@ static int do_lookup(struct nameidata *n
6615  {
6616         struct vfsmount *mnt = nd->mnt;
6617         struct dentry *dentry = __d_lookup(nd->dentry, name);
6618 +       struct inode *inode;
6619  
6620         if (!dentry)
6621                 goto need_lookup;
6622         if (dentry->d_op && dentry->d_op->d_revalidate)
6623                 goto need_revalidate;
6624 +       inode = dentry->d_inode;
6625 +       if (!inode)
6626 +               goto done;
6627 +
6628 +       if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
6629 +               struct proc_dir_entry *de = PDE(inode);
6630 +
6631 +               if (de && !vx_hide_check(0, de->vx_flags))
6632 +                       goto hidden;
6633 +       } else if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
6634 +               if (!vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
6635 +                       goto hidden;
6636 +       } else {
6637 +               if (!dx_notagcheck(nd) && !dx_check(inode->i_tag,
6638 +                       DX_WATCH | DX_ADMIN | DX_HOSTID | DX_IDENT))
6639 +                       goto hidden;
6640 +       }
6641  done:
6642         path->mnt = mnt;
6643         path->dentry = dentry;
6644         __follow_mount(path);
6645         return 0;
6646 +hidden:
6647 +       vxwprintk_task(1, "did lookup hidden %p[#%d,%lu] Â»%s«.",
6648 +               inode, inode->i_tag, inode->i_ino, vxd_path(dentry, mnt));
6649 +       dput(dentry);
6650 +       return -ENOENT;
6651  
6652  need_lookup:
6653         dentry = real_lookup(nd->dentry, name, nd);
6654 @@ -1399,7 +1460,8 @@ static inline int check_sticky(struct in
6655   * 10. We don't allow removal of NFS sillyrenamed files; it's handled by
6656   *     nfs_async_unlink().
6657   */
6658 -static int may_delete(struct inode *dir,struct dentry *victim,int isdir)
6659 +static int may_delete(struct inode *dir, struct dentry *victim,
6660 +       int isdir, struct nameidata *nd)
6661  {
6662         int error;
6663  
6664 @@ -1409,13 +1471,13 @@ static int may_delete(struct inode *dir,
6665         BUG_ON(victim->d_parent->d_inode != dir);
6666         audit_inode_child(victim->d_name.name, victim->d_inode, dir);
6667  
6668 -       error = permission(dir,MAY_WRITE | MAY_EXEC, NULL);
6669 +       error = permission(dir,MAY_WRITE | MAY_EXEC, nd);
6670         if (error)
6671                 return error;
6672         if (IS_APPEND(dir))
6673                 return -EPERM;
6674         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
6675 -           IS_IMMUTABLE(victim->d_inode))
6676 +               IS_IXORUNLINK(victim->d_inode))
6677                 return -EPERM;
6678         if (isdir) {
6679                 if (!S_ISDIR(victim->d_inode->i_mode))
6680 @@ -1546,6 +1608,14 @@ int may_open(struct nameidata *nd, int a
6681         if (S_ISDIR(inode->i_mode) && (acc_mode & MAY_WRITE))
6682                 return -EISDIR;
6683  
6684 +#ifdef CONFIG_VSERVER_COWBL
6685 +       if (IS_COW(inode) && (acc_mode & MAY_WRITE)) {
6686 +               if (IS_COW_LINK(inode))
6687 +                       return -EMLINK;
6688 +               inode->i_flags &= ~(S_IUNLINK|S_IMMUTABLE);
6689 +               mark_inode_dirty(inode);
6690 +       }
6691 +#endif
6692         error = vfs_permission(nd, acc_mode);
6693         if (error)
6694                 return error;
6695 @@ -1562,7 +1632,8 @@ int may_open(struct nameidata *nd, int a
6696                         return -EACCES;
6697  
6698                 flag &= ~O_TRUNC;
6699 -       } else if (IS_RDONLY(inode) && (acc_mode & MAY_WRITE))
6700 +       } else if ((IS_RDONLY(inode) || MNT_IS_RDONLY(nd->mnt))
6701 +               && (acc_mode & MAY_WRITE))
6702                 return -EROFS;
6703         /*
6704          * An append-only file must be opened in append mode for writing.
6705 @@ -1650,6 +1721,11 @@ int open_namei(int dfd, const char *path
6706         struct dentry *dir;
6707         int count = 0;
6708  
6709 +#ifdef CONFIG_VSERVER_COWBL
6710 +       int rflag = flag;
6711 +       int rmode = mode;
6712 +restart:
6713 +#endif
6714         acc_mode = ACC_MODE(flag);
6715  
6716         /* O_TRUNC implies we need access checks for write permissions */
6717 @@ -1743,6 +1819,22 @@ do_last:
6718                 goto exit;
6719  ok:
6720         error = may_open(nd, acc_mode, flag);
6721 +#ifdef CONFIG_VSERVER_COWBL
6722 +       if (error == -EMLINK) {
6723 +               struct dentry *dentry;
6724 +               dentry = cow_break_link(pathname);
6725 +               if (IS_ERR(dentry)) {
6726 +                       error = PTR_ERR(dentry);
6727 +                       goto exit;
6728 +               }
6729 +               dput(dentry);
6730 +               release_open_intent(nd);
6731 +               path_release(nd);
6732 +               flag = rflag;
6733 +               mode = rmode;
6734 +               goto restart;
6735 +       }
6736 +#endif
6737         if (error)
6738                 goto exit;
6739         return 0;
6740 @@ -1854,16 +1946,25 @@ fail:
6741  }
6742  EXPORT_SYMBOL_GPL(lookup_create);
6743  
6744 -int vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
6745 +int vfs_mknod(struct inode *dir, struct dentry *dentry,
6746 +       int mode, dev_t dev, struct nameidata *nd)
6747  {
6748 -       int error = may_create(dir, dentry, NULL);
6749 +       int error = may_create(dir, dentry, nd);
6750  
6751         if (error)
6752                 return error;
6753  
6754 -       if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
6755 +       if (!(S_ISCHR(mode) || S_ISBLK(mode)))
6756 +               goto okay;
6757 +
6758 +       if (!capable(CAP_MKNOD))
6759                 return -EPERM;
6760  
6761 +       if (S_ISCHR(mode) && !vs_chrdev_perm(dev, DATTR_CREATE))
6762 +               return -EPERM;
6763 +       if (S_ISBLK(mode) && !vs_blkdev_perm(dev, DATTR_CREATE))
6764 +               return -EPERM;
6765 +okay:
6766         if (!dir->i_op || !dir->i_op->mknod)
6767                 return -EPERM;
6768  
6769 @@ -1906,11 +2007,12 @@ asmlinkage long sys_mknodat(int dfd, con
6770                         error = vfs_create(nd.dentry->d_inode,dentry,mode,&nd);
6771                         break;
6772                 case S_IFCHR: case S_IFBLK:
6773 -                       error = vfs_mknod(nd.dentry->d_inode,dentry,mode,
6774 -                                       new_decode_dev(dev));
6775 +                       error = vfs_mknod(nd.dentry->d_inode, dentry, mode,
6776 +                                       new_decode_dev(dev), &nd);
6777                         break;
6778                 case S_IFIFO: case S_IFSOCK:
6779 -                       error = vfs_mknod(nd.dentry->d_inode,dentry,mode,0);
6780 +                       error = vfs_mknod(nd.dentry->d_inode, dentry, mode,
6781 +                                       0, &nd);
6782                         break;
6783                 case S_IFDIR:
6784                         error = -EPERM;
6785 @@ -1933,9 +2035,10 @@ asmlinkage long sys_mknod(const char __u
6786         return sys_mknodat(AT_FDCWD, filename, mode, dev);
6787  }
6788  
6789 -int vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
6790 +int vfs_mkdir(struct inode *dir, struct dentry *dentry,
6791 +       int mode, struct nameidata *nd)
6792  {
6793 -       int error = may_create(dir, dentry, NULL);
6794 +       int error = may_create(dir, dentry, nd);
6795  
6796         if (error)
6797                 return error;
6798 @@ -1977,7 +2080,7 @@ asmlinkage long sys_mkdirat(int dfd, con
6799  
6800         if (!IS_POSIXACL(nd.dentry->d_inode))
6801                 mode &= ~current->fs->umask;
6802 -       error = vfs_mkdir(nd.dentry->d_inode, dentry, mode);
6803 +       error = vfs_mkdir(nd.dentry->d_inode, dentry, mode, &nd);
6804         dput(dentry);
6805  out_unlock:
6806         mutex_unlock(&nd.dentry->d_inode->i_mutex);
6807 @@ -2020,9 +2123,10 @@ void dentry_unhash(struct dentry *dentry
6808         spin_unlock(&dcache_lock);
6809  }
6810  
6811 -int vfs_rmdir(struct inode *dir, struct dentry *dentry)
6812 +int vfs_rmdir(struct inode *dir, struct dentry *dentry,
6813 +       struct nameidata *nd)
6814  {
6815 -       int error = may_delete(dir, dentry, 1);
6816 +       int error = may_delete(dir, dentry, 1, nd);
6817  
6818         if (error)
6819                 return error;
6820 @@ -2084,7 +2188,7 @@ static long do_rmdir(int dfd, const char
6821         error = PTR_ERR(dentry);
6822         if (IS_ERR(dentry))
6823                 goto exit2;
6824 -       error = vfs_rmdir(nd.dentry->d_inode, dentry);
6825 +       error = vfs_rmdir(nd.dentry->d_inode, dentry, &nd);
6826         dput(dentry);
6827  exit2:
6828         mutex_unlock(&nd.dentry->d_inode->i_mutex);
6829 @@ -2100,9 +2204,10 @@ asmlinkage long sys_rmdir(const char __u
6830         return do_rmdir(AT_FDCWD, pathname);
6831  }
6832  
6833 -int vfs_unlink(struct inode *dir, struct dentry *dentry)
6834 +int vfs_unlink(struct inode *dir, struct dentry *dentry,
6835 +       struct nameidata *nd)
6836  {
6837 -       int error = may_delete(dir, dentry, 0);
6838 +       int error = may_delete(dir, dentry, 0, nd);
6839  
6840         if (error)
6841                 return error;
6842 @@ -2164,7 +2269,7 @@ static long do_unlinkat(int dfd, const c
6843                 inode = dentry->d_inode;
6844                 if (inode)
6845                         atomic_inc(&inode->i_count);
6846 -               error = vfs_unlink(nd.dentry->d_inode, dentry);
6847 +               error = vfs_unlink(nd.dentry->d_inode, dentry, &nd);
6848         exit2:
6849                 dput(dentry);
6850         }
6851 @@ -2199,9 +2304,10 @@ asmlinkage long sys_unlink(const char __
6852         return do_unlinkat(AT_FDCWD, pathname);
6853  }
6854  
6855 -int vfs_symlink(struct inode *dir, struct dentry *dentry, const char *oldname, int mode)
6856 +int vfs_symlink(struct inode *dir, struct dentry *dentry,
6857 +       const char *oldname, int mode, struct nameidata *nd)
6858  {
6859 -       int error = may_create(dir, dentry, NULL);
6860 +       int error = may_create(dir, dentry, nd);
6861  
6862         if (error)
6863                 return error;
6864 @@ -2245,7 +2351,7 @@ asmlinkage long sys_symlinkat(const char
6865         if (IS_ERR(dentry))
6866                 goto out_unlock;
6867  
6868 -       error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO);
6869 +       error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO, &nd);
6870         dput(dentry);
6871  out_unlock:
6872         mutex_unlock(&nd.dentry->d_inode->i_mutex);
6873 @@ -2262,7 +2368,8 @@ asmlinkage long sys_symlink(const char _
6874         return sys_symlinkat(oldname, AT_FDCWD, newname);
6875  }
6876  
6877 -int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry)
6878 +int vfs_link(struct dentry *old_dentry, struct inode *dir,
6879 +       struct dentry *new_dentry, struct nameidata *nd)
6880  {
6881         struct inode *inode = old_dentry->d_inode;
6882         int error;
6883 @@ -2270,7 +2377,7 @@ int vfs_link(struct dentry *old_dentry, 
6884         if (!inode)
6885                 return -ENOENT;
6886  
6887 -       error = may_create(dir, new_dentry, NULL);
6888 +       error = may_create(dir, new_dentry, nd);
6889         if (error)
6890                 return error;
6891  
6892 @@ -2280,7 +2387,7 @@ int vfs_link(struct dentry *old_dentry, 
6893         /*
6894          * A link to an append-only or immutable file cannot be created.
6895          */
6896 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
6897 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
6898                 return -EPERM;
6899         if (!dir->i_op || !dir->i_op->link)
6900                 return -EPERM;
6901 @@ -2340,7 +2447,7 @@ asmlinkage long sys_linkat(int olddfd, c
6902         error = PTR_ERR(new_dentry);
6903         if (IS_ERR(new_dentry))
6904                 goto out_unlock;
6905 -       error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry);
6906 +       error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry, &nd);
6907         dput(new_dentry);
6908  out_unlock:
6909         mutex_unlock(&nd.dentry->d_inode->i_mutex);
6910 @@ -2472,14 +2579,14 @@ int vfs_rename(struct inode *old_dir, st
6911         if (old_dentry->d_inode == new_dentry->d_inode)
6912                 return 0;
6913   
6914 -       error = may_delete(old_dir, old_dentry, is_dir);
6915 +       error = may_delete(old_dir, old_dentry, is_dir, NULL);
6916         if (error)
6917                 return error;
6918  
6919         if (!new_dentry->d_inode)
6920                 error = may_create(new_dir, new_dentry, NULL);
6921         else
6922 -               error = may_delete(new_dir, new_dentry, is_dir);
6923 +               error = may_delete(new_dir, new_dentry, is_dir, NULL);
6924         if (error)
6925                 return error;
6926  
6927 @@ -2557,6 +2664,9 @@ static int do_rename(int olddfd, const c
6928         error = -EINVAL;
6929         if (old_dentry == trap)
6930                 goto exit4;
6931 +       error = -EROFS;
6932 +       if (MNT_IS_RDONLY(newnd.mnt))
6933 +               goto exit4;
6934         new_dentry = lookup_hash(&newnd);
6935         error = PTR_ERR(new_dentry);
6936         if (IS_ERR(new_dentry))
6937 @@ -2650,6 +2760,216 @@ int vfs_follow_link(struct nameidata *nd
6938         return __vfs_follow_link(nd, link);
6939  }
6940  
6941 +
6942 +#ifdef CONFIG_VSERVER_COWBL
6943 +
6944 +#include <linux/file.h>
6945 +
6946 +static inline
6947 +long do_cow_splice(struct file *in, struct file *out, size_t len)
6948 +{
6949 +       loff_t ppos = 0;
6950 +
6951 +       return do_splice_direct(in, &ppos, out, len, 0);
6952 +}
6953 +
6954 +struct dentry *cow_break_link(const char *pathname)
6955 +{
6956 +       int ret, mode, pathlen, redo = 0;
6957 +       struct nameidata old_nd, dir_nd;
6958 +       struct dentry *old_dentry, *new_dentry;
6959 +       struct dentry *dir, *res = NULL;
6960 +       struct vfsmount *old_mnt, *new_mnt;
6961 +       struct file *old_file;
6962 +       struct file *new_file;
6963 +       char *to, *path, pad='\251';
6964 +       loff_t size;
6965 +
6966 +       vxdprintk(VXD_CBIT(misc, 1), "cow_break_link(»%s«)", pathname);
6967 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
6968 +       ret = -ENOMEM;
6969 +       if (!path)
6970 +               goto out;
6971 +
6972 +       /* old_nd will have refs to dentry and mnt */
6973 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
6974 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
6975 +       if (ret < 0)
6976 +               goto out_free_path;
6977 +
6978 +       old_dentry = old_nd.dentry;
6979 +       old_mnt = old_nd.mnt;
6980 +       mode = old_dentry->d_inode->i_mode;
6981 +
6982 +       to = d_path(old_dentry, old_mnt, path, PATH_MAX-2);
6983 +       pathlen = strlen(to);
6984 +       vxdprintk(VXD_CBIT(misc, 2), "old path Â»%s« [»%.*s«:%d]", to,
6985 +               old_dentry->d_name.len, old_dentry->d_name.name,
6986 +               old_dentry->d_name.len);
6987 +
6988 +       to[pathlen + 1] = 0;
6989 +retry:
6990 +       to[pathlen] = pad--;
6991 +       ret = -EMLINK;
6992 +       if (pad <= '\240')
6993 +               goto out_rel_old;
6994 +
6995 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy Â»%s«", to);
6996 +       /* dir_nd will have refs to dentry and mnt */
6997 +       ret = path_lookup(to,
6998 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
6999 +       vxdprintk(VXD_CBIT(misc, 2),
7000 +               "path_lookup(new): %d", ret);
7001 +       if (ret < 0)
7002 +               goto retry;
7003 +
7004 +       /* this puppy downs the inode mutex */
7005 +       new_dentry = lookup_create(&dir_nd, 0);
7006 +       vxdprintk(VXD_CBIT(misc, 2),
7007 +               "lookup_create(new): %p [»%.*s«:%d]", new_dentry,
7008 +               new_dentry->d_name.len, new_dentry->d_name.name,
7009 +               new_dentry->d_name.len);
7010 +       if (!new_dentry || IS_ERR(new_dentry)) {
7011 +               path_release(&dir_nd);
7012 +               goto retry;
7013 +       }
7014 +       dir = dir_nd.dentry;
7015 +
7016 +       ret = vfs_create(dir_nd.dentry->d_inode, new_dentry, mode, &dir_nd);
7017 +       vxdprintk(VXD_CBIT(misc, 2),
7018 +               "vfs_create(new): %d", ret);
7019 +       if (ret == -EEXIST) {
7020 +               mutex_unlock(&dir->d_inode->i_mutex);
7021 +               dput(new_dentry);
7022 +               path_release(&dir_nd);
7023 +               goto retry;
7024 +       }
7025 +       else if (ret < 0)
7026 +               goto out_unlock_new;
7027 +
7028 +       /* drop out early, ret passes ENOENT */
7029 +       ret = -ENOENT;
7030 +       if ((redo = d_unhashed(old_dentry)))
7031 +               goto out_unlock_new;
7032 +
7033 +       new_mnt = dir_nd.mnt;
7034 +       dget(old_dentry);
7035 +       mntget(old_mnt);
7036 +       /* this one cleans up the dentry/mnt in case of failure */
7037 +       old_file = dentry_open(old_dentry, old_mnt, O_RDONLY);
7038 +       vxdprintk(VXD_CBIT(misc, 2),
7039 +               "dentry_open(old): %p", old_file);
7040 +       if (!old_file || IS_ERR(old_file)) {
7041 +               res = IS_ERR(old_file) ? (void *) old_file : res;
7042 +               goto out_unlock_new;
7043 +       }
7044 +
7045 +       dget(new_dentry);
7046 +       mntget(new_mnt);
7047 +       /* this one cleans up the dentry/mnt in case of failure */
7048 +       new_file = dentry_open(new_dentry, new_mnt, O_WRONLY);
7049 +       vxdprintk(VXD_CBIT(misc, 2),
7050 +               "dentry_open(new): %p", new_file);
7051 +
7052 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
7053 +       if (!new_file || IS_ERR(new_file))
7054 +               goto out_fput_old;
7055 +
7056 +       size = i_size_read(old_file->f_dentry->d_inode);
7057 +       ret = do_cow_splice(old_file, new_file, size);
7058 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
7059 +       if (ret < 0) {
7060 +               goto out_fput_both;
7061 +       } else if (ret < size) {
7062 +               ret = -ENOSPC;
7063 +               goto out_fput_both;
7064 +       } else {
7065 +               struct inode *old_inode = old_dentry->d_inode;
7066 +               struct inode *new_inode = new_dentry->d_inode;
7067 +               struct iattr attr = {
7068 +                       .ia_uid = old_inode->i_uid,
7069 +                       .ia_gid = old_inode->i_gid,
7070 +                       .ia_valid = ATTR_UID | ATTR_GID
7071 +                       };
7072 +
7073 +               ret = inode_setattr(new_inode, &attr);
7074 +               if (ret)
7075 +                       goto out_fput_both;
7076 +       }
7077 +
7078 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
7079 +
7080 +       /* drop out late */
7081 +       ret = -ENOENT;
7082 +       if ((redo = d_unhashed(old_dentry)))
7083 +               goto out_unlock;
7084 +
7085 +       vxdprintk(VXD_CBIT(misc, 2),
7086 +               "vfs_rename: [»%*s«:%d] -> [»%*s«:%d]",
7087 +               new_dentry->d_name.len, new_dentry->d_name.name,
7088 +               new_dentry->d_name.len,
7089 +               old_dentry->d_name.len, old_dentry->d_name.name,
7090 +               old_dentry->d_name.len);
7091 +       ret = vfs_rename(dir_nd.dentry->d_inode, new_dentry,
7092 +               old_nd.dentry->d_parent->d_inode, old_dentry);
7093 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
7094 +       res = new_dentry;
7095 +
7096 +out_unlock:
7097 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
7098 +
7099 +out_fput_both:
7100 +       vxdprintk(VXD_CBIT(misc, 3),
7101 +               "fput(new_file=%p[#%d])", new_file,
7102 +               atomic_read(&new_file->f_count));
7103 +       fput(new_file);
7104 +
7105 +out_fput_old:
7106 +       vxdprintk(VXD_CBIT(misc, 3),
7107 +               "fput(old_file=%p[#%d])", old_file,
7108 +               atomic_read(&old_file->f_count));
7109 +       fput(old_file);
7110 +
7111 +out_unlock_new:
7112 +       mutex_unlock(&dir->d_inode->i_mutex);
7113 +       if (!ret)
7114 +               goto out_redo;
7115 +
7116 +       /* error path cleanup */
7117 +       vfs_unlink(dir->d_inode, new_dentry, &dir_nd);
7118 +       dput(new_dentry);
7119 +
7120 +out_redo:
7121 +       if (!redo)
7122 +               goto out_rel_both;
7123 +       /* lookup dentry once again */
7124 +       path_release(&old_nd);
7125 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
7126 +       if (ret)
7127 +               goto out_rel_both;
7128 +
7129 +       new_dentry = old_nd.dentry;
7130 +       vxdprintk(VXD_CBIT(misc, 2),
7131 +               "path_lookup(redo): %p [»%.*s«:%d]", new_dentry,
7132 +               new_dentry->d_name.len, new_dentry->d_name.name,
7133 +               new_dentry->d_name.len);
7134 +       dget(new_dentry);
7135 +       res = new_dentry;
7136 +
7137 +out_rel_both:
7138 +       path_release(&dir_nd);
7139 +out_rel_old:
7140 +       path_release(&old_nd);
7141 +out_free_path:
7142 +       kfree(path);
7143 +out:
7144 +       if (ret)
7145 +               res = ERR_PTR(ret);
7146 +       return res;
7147 +}
7148 +
7149 +#endif
7150 +
7151  /* get the link contents into pagecache */
7152  static char *page_getlink(struct dentry * dentry, struct page **ppage)
7153  {
7154 diff -Nurp linux-2.6.22.18/fs/namespace.c linux-2.6.22.18-vs2.3.0.32/fs/namespace.c
7155 --- linux-2.6.22.18/fs/namespace.c      2007-07-22 00:00:17.000000000 +0200
7156 +++ linux-2.6.22.18-vs2.3.0.32/fs/namespace.c   2008-02-11 12:35:34.000000000 +0100
7157 @@ -25,6 +25,11 @@
7158  #include <linux/security.h>
7159  #include <linux/mount.h>
7160  #include <linux/ramfs.h>
7161 +#include <linux/vs_base.h>
7162 +#include <linux/vs_context.h>
7163 +#include <linux/vs_tag.h>
7164 +#include <linux/vserver/space.h>
7165 +#include <linux/vserver/global.h>
7166  #include <asm/uaccess.h>
7167  #include <asm/unistd.h>
7168  #include "pnode.h"
7169 @@ -240,6 +245,7 @@ static struct vfsmount *clone_mnt(struct
7170                 mnt->mnt_root = dget(root);
7171                 mnt->mnt_mountpoint = mnt->mnt_root;
7172                 mnt->mnt_parent = mnt;
7173 +               mnt->mnt_tag = old->mnt_tag;
7174  
7175                 if (flag & CL_SLAVE) {
7176                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
7177 @@ -348,48 +354,91 @@ static inline void mangle(struct seq_fil
7178         seq_escape(m, s, " \t\n\\");
7179  }
7180  
7181 +static int mnt_is_reachable(struct vfsmount *mnt)
7182 +{
7183 +       struct vfsmount *root_mnt;
7184 +       struct dentry *root, *point;
7185 +       int ret;
7186 +
7187 +       if (mnt == mnt->mnt_ns->root)
7188 +               return 1;
7189 +
7190 +       spin_lock(&vfsmount_lock);
7191 +       root_mnt = current->fs->rootmnt;
7192 +       root = current->fs->root;
7193 +       point = root;
7194 +
7195 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
7196 +               point = mnt->mnt_mountpoint;
7197 +               mnt = mnt->mnt_parent;
7198 +       }
7199 +
7200 +       ret = (mnt == root_mnt) && is_subdir(point, root);
7201 +
7202 +       spin_unlock(&vfsmount_lock);
7203 +
7204 +       return ret;
7205 +}
7206 +
7207  static int show_vfsmnt(struct seq_file *m, void *v)
7208  {
7209         struct vfsmount *mnt = v;
7210         int err = 0;
7211         static struct proc_fs_info {
7212 -               int flag;
7213 -               char *str;
7214 +               int s_flag;
7215 +               int mnt_flag;
7216 +               char *set_str;
7217 +               char *unset_str;
7218         } fs_info[] = {
7219 -               { MS_SYNCHRONOUS, ",sync" },
7220 -               { MS_DIRSYNC, ",dirsync" },
7221 -               { MS_MANDLOCK, ",mand" },
7222 -               { 0, NULL }
7223 -       };
7224 -       static struct proc_fs_info mnt_info[] = {
7225 -               { MNT_NOSUID, ",nosuid" },
7226 -               { MNT_NODEV, ",nodev" },
7227 -               { MNT_NOEXEC, ",noexec" },
7228 -               { MNT_NOATIME, ",noatime" },
7229 -               { MNT_NODIRATIME, ",nodiratime" },
7230 -               { MNT_RELATIME, ",relatime" },
7231 -               { 0, NULL }
7232 +               { MS_RDONLY, MNT_RDONLY, "ro", "rw" },
7233 +               { MS_SYNCHRONOUS, 0, ",sync", NULL },
7234 +               { MS_DIRSYNC, 0, ",dirsync", NULL },
7235 +               { MS_MANDLOCK, 0, ",mand", NULL },
7236 +               { MS_TAGGED, 0, ",tag", NULL },
7237 +               { MS_NOATIME, MNT_NOATIME, ",noatime", NULL },
7238 +               { MS_NODIRATIME, MNT_NODIRATIME, ",nodiratime", NULL },
7239 +               { MS_RELATIME, MNT_RELATIME, ",relatime", NULL },
7240 +               { 0, MNT_NOSUID, ",nosuid", NULL },
7241 +               { 0, MNT_NODEV, ",nodev", NULL },
7242 +               { 0, MNT_NOEXEC, ",noexec", NULL },
7243 +               { 0, 0, NULL, NULL }
7244         };
7245 -       struct proc_fs_info *fs_infop;
7246 +       struct proc_fs_info *p;
7247 +       unsigned long s_flags = mnt->mnt_sb->s_flags;
7248 +       int mnt_flags = mnt->mnt_flags;
7249  
7250 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
7251 -       seq_putc(m, ' ');
7252 -       seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
7253 -       seq_putc(m, ' ');
7254 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
7255 +               return 0;
7256 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
7257 +               return 0;
7258 +
7259 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
7260 +               mnt == current->fs->rootmnt) {
7261 +               seq_puts(m, "/dev/root / ");
7262 +       } else {
7263 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
7264 +               seq_putc(m, ' ');
7265 +               seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
7266 +               seq_putc(m, ' ');
7267 +
7268 +               if (mnt->mnt_sb->s_subtype && mnt->mnt_sb->s_subtype[0]) {
7269 +                       seq_putc(m, '.');
7270 +                       mangle(m, mnt->mnt_sb->s_subtype);
7271 +               }
7272 +       }
7273         mangle(m, mnt->mnt_sb->s_type->name);
7274 -       if (mnt->mnt_sb->s_subtype && mnt->mnt_sb->s_subtype[0]) {
7275 -               seq_putc(m, '.');
7276 -               mangle(m, mnt->mnt_sb->s_subtype);
7277 -       }
7278 -       seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? " ro" : " rw");
7279 -       for (fs_infop = fs_info; fs_infop->flag; fs_infop++) {
7280 -               if (mnt->mnt_sb->s_flags & fs_infop->flag)
7281 -                       seq_puts(m, fs_infop->str);
7282 -       }
7283 -       for (fs_infop = mnt_info; fs_infop->flag; fs_infop++) {
7284 -               if (mnt->mnt_flags & fs_infop->flag)
7285 -                       seq_puts(m, fs_infop->str);
7286 +       seq_putc(m, ' ');
7287 +       for (p = fs_info; (p->s_flag | p->mnt_flag) ; p++) {
7288 +               if ((s_flags & p->s_flag) || (mnt_flags & p->mnt_flag)) {
7289 +                       if (p->set_str)
7290 +                               seq_puts(m, p->set_str);
7291 +               } else {
7292 +                       if (p->unset_str)
7293 +                               seq_puts(m, p->unset_str);
7294 +               }
7295         }
7296 +       if (mnt->mnt_flags & MNT_TAGID)
7297 +               seq_printf(m, ",tag=%d", mnt->mnt_tag);
7298         if (mnt->mnt_sb->s_op->show_options)
7299                 err = mnt->mnt_sb->s_op->show_options(m, mnt);
7300         seq_puts(m, " 0 0\n");
7301 @@ -408,17 +457,27 @@ static int show_vfsstat(struct seq_file 
7302         struct vfsmount *mnt = v;
7303         int err = 0;
7304  
7305 -       /* device */
7306 -       if (mnt->mnt_devname) {
7307 -               seq_puts(m, "device ");
7308 -               mangle(m, mnt->mnt_devname);
7309 -       } else
7310 -               seq_puts(m, "no device");
7311 -
7312 -       /* mount point */
7313 -       seq_puts(m, " mounted on ");
7314 -       seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
7315 -       seq_putc(m, ' ');
7316 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
7317 +               return 0;
7318 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
7319 +               return 0;
7320 +
7321 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
7322 +               mnt == current->fs->rootmnt) {
7323 +               seq_puts(m, "device /dev/root mounted on / ");
7324 +       } else {
7325 +               /* device */
7326 +               if (mnt->mnt_devname) {
7327 +                       seq_puts(m, "device ");
7328 +                       mangle(m, mnt->mnt_devname);
7329 +               } else
7330 +                       seq_puts(m, "no device");
7331 +
7332 +               /* mount point */
7333 +               seq_puts(m, " mounted on ");
7334 +               seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
7335 +               seq_putc(m, ' ');
7336 +       }
7337  
7338         /* file system type */
7339         seq_puts(m, "with fstype ");
7340 @@ -648,7 +707,7 @@ asmlinkage long sys_umount(char __user *
7341                 goto dput_and_out;
7342  
7343         retval = -EPERM;
7344 -       if (!capable(CAP_SYS_ADMIN))
7345 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
7346                 goto dput_and_out;
7347  
7348         retval = do_umount(nd.mnt, flags);
7349 @@ -672,7 +731,7 @@ asmlinkage long sys_oldumount(char __use
7350  
7351  static int mount_is_safe(struct nameidata *nd)
7352  {
7353 -       if (capable(CAP_SYS_ADMIN))
7354 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
7355                 return 0;
7356         return -EPERM;
7357  #ifdef notyet
7358 @@ -904,11 +963,13 @@ static int do_change_type(struct nameida
7359  /*
7360   * do loopback mount.
7361   */
7362 -static int do_loopback(struct nameidata *nd, char *old_name, int recurse)
7363 +static int do_loopback(struct nameidata *nd, char *old_name, tag_t tag,
7364 +       unsigned long flags, int mnt_flags)
7365  {
7366         struct nameidata old_nd;
7367         struct vfsmount *mnt = NULL;
7368         int err = mount_is_safe(nd);
7369 +       int recurse = flags & MS_REC;
7370         if (err)
7371                 return err;
7372         if (!old_name || !*old_name)
7373 @@ -934,6 +995,12 @@ static int do_loopback(struct nameidata 
7374         if (!mnt)
7375                 goto out;
7376  
7377 +       mnt->mnt_flags = mnt_flags;
7378 +       if (flags & MS_TAGID) {
7379 +               mnt->mnt_tag = tag;
7380 +               mnt->mnt_flags |= MNT_TAGID;
7381 +       }
7382 +
7383         err = graft_tree(mnt, nd);
7384         if (err) {
7385                 LIST_HEAD(umount_list);
7386 @@ -942,6 +1009,7 @@ static int do_loopback(struct nameidata 
7387                 spin_unlock(&vfsmount_lock);
7388                 release_mounts(&umount_list);
7389         }
7390 +       mnt->mnt_flags = mnt_flags;
7391  
7392  out:
7393         up_write(&namespace_sem);
7394 @@ -955,12 +1023,12 @@ out:
7395   * on it - tough luck.
7396   */
7397  static int do_remount(struct nameidata *nd, int flags, int mnt_flags,
7398 -                     void *data)
7399 +                     void *data, xid_t xid)
7400  {
7401         int err;
7402         struct super_block *sb = nd->mnt->mnt_sb;
7403  
7404 -       if (!capable(CAP_SYS_ADMIN))
7405 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
7406                 return -EPERM;
7407  
7408         if (!check_mnt(nd->mnt))
7409 @@ -994,7 +1062,7 @@ static int do_move_mount(struct nameidat
7410         struct nameidata old_nd, parent_nd;
7411         struct vfsmount *p;
7412         int err = 0;
7413 -       if (!capable(CAP_SYS_ADMIN))
7414 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
7415                 return -EPERM;
7416         if (!old_name || !*old_name)
7417                 return -EINVAL;
7418 @@ -1074,7 +1142,7 @@ static int do_new_mount(struct nameidata
7419                 return -EINVAL;
7420  
7421         /* we need capabilities... */
7422 -       if (!capable(CAP_SYS_ADMIN))
7423 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
7424                 return -EPERM;
7425  
7426         mnt = do_kern_mount(type, flags, name, data);
7427 @@ -1386,6 +1454,7 @@ long do_mount(char *dev_name, char *dir_
7428         struct nameidata nd;
7429         int retval = 0;
7430         int mnt_flags = 0;
7431 +       tag_t tag = 0;
7432  
7433         /* Discard magic */
7434         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
7435 @@ -1401,7 +1470,17 @@ long do_mount(char *dev_name, char *dir_
7436         if (data_page)
7437                 ((char *)data_page)[PAGE_SIZE - 1] = 0;
7438  
7439 +       retval = dx_parse_tag(data_page, &tag, 1);
7440 +       if (retval) {
7441 +               mnt_flags |= retval;
7442 +               /* FIXME: bind and re-mounts get the tag flag? */
7443 +               if (flags & (MS_BIND|MS_REMOUNT))
7444 +                       flags |= MS_TAGID;
7445 +       }
7446 +
7447         /* Separate the per-mountpoint flags */
7448 +       if (flags & MS_RDONLY)
7449 +               mnt_flags |= MNT_RDONLY;
7450         if (flags & MS_NOSUID)
7451                 mnt_flags |= MNT_NOSUID;
7452         if (flags & MS_NODEV)
7453 @@ -1415,6 +1494,8 @@ long do_mount(char *dev_name, char *dir_
7454         if (flags & MS_RELATIME)
7455                 mnt_flags |= MNT_RELATIME;
7456  
7457 +       if (!capable(CAP_SYS_ADMIN))
7458 +               mnt_flags |= MNT_NODEV;
7459         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
7460                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME);
7461  
7462 @@ -1429,9 +1510,9 @@ long do_mount(char *dev_name, char *dir_
7463  
7464         if (flags & MS_REMOUNT)
7465                 retval = do_remount(&nd, flags & ~MS_REMOUNT, mnt_flags,
7466 -                                   data_page);
7467 +                                   data_page, tag);
7468         else if (flags & MS_BIND)
7469 -               retval = do_loopback(&nd, dev_name, flags & MS_REC);
7470 +               retval = do_loopback(&nd, dev_name, tag, flags, mnt_flags);
7471         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
7472                 retval = do_change_type(&nd, flags);
7473         else if (flags & MS_MOVE)
7474 @@ -1504,6 +1585,7 @@ static struct mnt_namespace *dup_mnt_ns(
7475                 q = next_mnt(q, new_ns->root);
7476         }
7477         up_write(&namespace_sem);
7478 +       atomic_inc(&vs_global_mnt_ns);
7479  
7480         if (rootmnt)
7481                 mntput(rootmnt);
7482 @@ -1866,5 +1948,6 @@ void __put_mnt_ns(struct mnt_namespace *
7483         spin_unlock(&vfsmount_lock);
7484         up_write(&namespace_sem);
7485         release_mounts(&umount_list);
7486 +       atomic_dec(&vs_global_mnt_ns);
7487         kfree(ns);
7488  }
7489 diff -Nurp linux-2.6.22.18/fs/nfs/client.c linux-2.6.22.18-vs2.3.0.32/fs/nfs/client.c
7490 --- linux-2.6.22.18/fs/nfs/client.c     2007-07-22 00:00:17.000000000 +0200
7491 +++ linux-2.6.22.18-vs2.3.0.32/fs/nfs/client.c  2008-02-11 12:35:34.000000000 +0100
7492 @@ -521,6 +521,9 @@ static int nfs_init_server_rpcclient(str
7493         if (server->flags & NFS4_MOUNT_INTR)
7494                 server->client->cl_intr = 1;
7495  
7496 +       server->client->cl_tag = 0;
7497 +       if (server->flags & NFS_MOUNT_TAGGED)
7498 +               server->client->cl_tag = 1;
7499         return 0;
7500  }
7501  
7502 @@ -678,6 +681,10 @@ static void nfs_server_set_fsinfo(struct
7503                 server->acdirmin = server->acdirmax = 0;
7504         }
7505  
7506 +       /* FIXME: needs fsinfo
7507 +       if (server->flags & NFS_MOUNT_TAGGED)
7508 +               sb->s_flags |= MS_TAGGED;       */
7509 +
7510         server->maxfilesize = fsinfo->maxfilesize;
7511  
7512         /* We're airborne Set socket buffersize */
7513 diff -Nurp linux-2.6.22.18/fs/nfs/dir.c linux-2.6.22.18-vs2.3.0.32/fs/nfs/dir.c
7514 --- linux-2.6.22.18/fs/nfs/dir.c        2007-07-22 00:00:17.000000000 +0200
7515 +++ linux-2.6.22.18-vs2.3.0.32/fs/nfs/dir.c     2008-02-11 12:35:34.000000000 +0100
7516 @@ -34,6 +34,7 @@
7517  #include <linux/namei.h>
7518  #include <linux/mount.h>
7519  #include <linux/sched.h>
7520 +#include <linux/vs_tag.h>
7521  
7522  #include "nfs4_fs.h"
7523  #include "delegation.h"
7524 @@ -956,6 +957,7 @@ static struct dentry *nfs_lookup(struct 
7525         if (IS_ERR(res))
7526                 goto out_unlock;
7527  
7528 +       dx_propagate_tag(nd, inode);
7529  no_entry:
7530         res = d_materialise_unique(dentry, inode);
7531         if (res != NULL) {
7532 @@ -998,7 +1000,8 @@ static int is_atomic_open(struct inode *
7533         if (nd->flags & LOOKUP_DIRECTORY)
7534                 return 0;
7535         /* Are we trying to write to a read only partition? */
7536 -       if (IS_RDONLY(dir) && (nd->intent.open.flags & (O_CREAT|O_TRUNC|FMODE_WRITE)))
7537 +       if ((IS_RDONLY(dir) || MNT_IS_RDONLY(nd->mnt)) &&
7538 +               (nd->intent.open.flags & (O_CREAT|O_TRUNC|FMODE_WRITE)))
7539                 return 0;
7540         return 1;
7541  }
7542 diff -Nurp linux-2.6.22.18/fs/nfs/inode.c linux-2.6.22.18-vs2.3.0.32/fs/nfs/inode.c
7543 --- linux-2.6.22.18/fs/nfs/inode.c      2007-07-22 00:00:17.000000000 +0200
7544 +++ linux-2.6.22.18-vs2.3.0.32/fs/nfs/inode.c   2008-02-11 12:35:34.000000000 +0100
7545 @@ -37,6 +37,7 @@
7546  #include <linux/vfs.h>
7547  #include <linux/inet.h>
7548  #include <linux/nfs_xdr.h>
7549 +#include <linux/vs_tag.h>
7550  
7551  #include <asm/system.h>
7552  #include <asm/uaccess.h>
7553 @@ -285,8 +286,10 @@ nfs_fhget(struct super_block *sb, struct
7554                         nfsi->change_attr = fattr->change_attr;
7555                 inode->i_size = nfs_size_to_loff_t(fattr->size);
7556                 inode->i_nlink = fattr->nlink;
7557 -               inode->i_uid = fattr->uid;
7558 -               inode->i_gid = fattr->gid;
7559 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
7560 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
7561 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
7562 +                                        /* maybe fattr->xid someday */
7563                 if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
7564                         /*
7565                          * report the blocks in 512byte units
7566 @@ -377,6 +380,8 @@ void nfs_setattr_update_inode(struct ino
7567                         inode->i_uid = attr->ia_uid;
7568                 if ((attr->ia_valid & ATTR_GID) != 0)
7569                         inode->i_gid = attr->ia_gid;
7570 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
7571 +                       inode->i_tag = attr->ia_tag;
7572                 spin_lock(&inode->i_lock);
7573                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
7574                 spin_unlock(&inode->i_lock);
7575 @@ -825,6 +830,9 @@ static int nfs_check_inode_attributes(st
7576         struct nfs_inode *nfsi = NFS_I(inode);
7577         loff_t cur_size, new_isize;
7578         int data_unstable;
7579 +       uid_t uid;
7580 +       gid_t gid;
7581 +       tag_t tag;
7582  
7583  
7584         /* Has the inode gone and changed behind our back? */
7585 @@ -852,10 +860,15 @@ static int nfs_check_inode_attributes(st
7586         if (cur_size != new_isize && nfsi->npages == 0)
7587                 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
7588  
7589 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
7590 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
7591 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
7592 +
7593         /* Have any file permissions changed? */
7594         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)
7595 -                       || inode->i_uid != fattr->uid
7596 -                       || inode->i_gid != fattr->gid)
7597 +                       || inode->i_uid != uid
7598 +                       || inode->i_gid != gid
7599 +                       || inode->i_tag != tag)
7600                 nfsi->cache_validity |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
7601  
7602         /* Has the link count changed? */
7603 @@ -946,6 +959,9 @@ static int nfs_update_inode(struct inode
7604         unsigned int    invalid = 0;
7605         unsigned long now = jiffies;
7606         int data_stable;
7607 +       uid_t uid;
7608 +       gid_t gid;
7609 +       tag_t tag;
7610  
7611         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
7612                         __FUNCTION__, inode->i_sb->s_id, inode->i_ino,
7613 @@ -1022,15 +1038,21 @@ static int nfs_update_inode(struct inode
7614         }
7615         memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
7616  
7617 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
7618 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
7619 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
7620 +
7621         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO) ||
7622 -           inode->i_uid != fattr->uid ||
7623 -           inode->i_gid != fattr->gid)
7624 +           inode->i_uid != uid ||
7625 +           inode->i_gid != gid ||
7626 +           inode->i_tag != tag)
7627                 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
7628  
7629         inode->i_mode = fattr->mode;
7630         inode->i_nlink = fattr->nlink;
7631 -       inode->i_uid = fattr->uid;
7632 -       inode->i_gid = fattr->gid;
7633 +       inode->i_uid = uid;
7634 +       inode->i_gid = gid;
7635 +       inode->i_tag = tag;
7636  
7637         if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
7638                 /*
7639 diff -Nurp linux-2.6.22.18/fs/nfs/nfs3xdr.c linux-2.6.22.18-vs2.3.0.32/fs/nfs/nfs3xdr.c
7640 --- linux-2.6.22.18/fs/nfs/nfs3xdr.c    2007-07-22 00:00:17.000000000 +0200
7641 +++ linux-2.6.22.18-vs2.3.0.32/fs/nfs/nfs3xdr.c 2008-02-11 12:35:34.000000000 +0100
7642 @@ -22,6 +22,7 @@
7643  #include <linux/nfs3.h>
7644  #include <linux/nfs_fs.h>
7645  #include <linux/nfsacl.h>
7646 +#include <linux/vs_tag.h>
7647  #include "internal.h"
7648  
7649  #define NFSDBG_FACILITY                NFSDBG_XDR
7650 @@ -178,7 +179,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
7651  }
7652  
7653  static inline __be32 *
7654 -xdr_encode_sattr(__be32 *p, struct iattr *attr)
7655 +xdr_encode_sattr(__be32 *p, struct iattr *attr, int tag)
7656  {
7657         if (attr->ia_valid & ATTR_MODE) {
7658                 *p++ = xdr_one;
7659 @@ -186,15 +187,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
7660         } else {
7661                 *p++ = xdr_zero;
7662         }
7663 -       if (attr->ia_valid & ATTR_UID) {
7664 +       if (attr->ia_valid & ATTR_UID ||
7665 +               (tag && (attr->ia_valid & ATTR_TAG))) {
7666                 *p++ = xdr_one;
7667 -               *p++ = htonl(attr->ia_uid);
7668 +               *p++ = htonl(TAGINO_UID(tag, attr->ia_uid, attr->ia_tag));
7669         } else {
7670                 *p++ = xdr_zero;
7671         }
7672 -       if (attr->ia_valid & ATTR_GID) {
7673 +       if (attr->ia_valid & ATTR_GID ||
7674 +               (tag && (attr->ia_valid & ATTR_TAG))) {
7675                 *p++ = xdr_one;
7676 -               *p++ = htonl(attr->ia_gid);
7677 +               *p++ = htonl(TAGINO_GID(tag, attr->ia_gid, attr->ia_tag));
7678         } else {
7679                 *p++ = xdr_zero;
7680         }
7681 @@ -279,7 +282,8 @@ static int
7682  nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args)
7683  {
7684         p = xdr_encode_fhandle(p, args->fh);
7685 -       p = xdr_encode_sattr(p, args->sattr);
7686 +       p = xdr_encode_sattr(p, args->sattr,
7687 +               req->rq_task->tk_client->cl_tag);
7688         *p++ = htonl(args->guard);
7689         if (args->guard)
7690                 p = xdr_encode_time3(p, &args->guardtime);
7691 @@ -370,7 +374,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
7692                 *p++ = args->verifier[0];
7693                 *p++ = args->verifier[1];
7694         } else
7695 -               p = xdr_encode_sattr(p, args->sattr);
7696 +               p = xdr_encode_sattr(p, args->sattr,
7697 +                       req->rq_task->tk_client->cl_tag);
7698  
7699         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
7700         return 0;
7701 @@ -384,7 +389,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
7702  {
7703         p = xdr_encode_fhandle(p, args->fh);
7704         p = xdr_encode_array(p, args->name, args->len);
7705 -       p = xdr_encode_sattr(p, args->sattr);
7706 +       p = xdr_encode_sattr(p, args->sattr,
7707 +               req->rq_task->tk_client->cl_tag);
7708         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
7709         return 0;
7710  }
7711 @@ -397,7 +403,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
7712  {
7713         p = xdr_encode_fhandle(p, args->fromfh);
7714         p = xdr_encode_array(p, args->fromname, args->fromlen);
7715 -       p = xdr_encode_sattr(p, args->sattr);
7716 +       p = xdr_encode_sattr(p, args->sattr,
7717 +               req->rq_task->tk_client->cl_tag);
7718         *p++ = htonl(args->pathlen);
7719         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
7720  
7721 @@ -415,7 +422,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
7722         p = xdr_encode_fhandle(p, args->fh);
7723         p = xdr_encode_array(p, args->name, args->len);
7724         *p++ = htonl(args->type);
7725 -       p = xdr_encode_sattr(p, args->sattr);
7726 +       p = xdr_encode_sattr(p, args->sattr,
7727 +               req->rq_task->tk_client->cl_tag);
7728         if (args->type == NF3CHR || args->type == NF3BLK) {
7729                 *p++ = htonl(MAJOR(args->rdev));
7730                 *p++ = htonl(MINOR(args->rdev));
7731 diff -Nurp linux-2.6.22.18/fs/nfs/nfsroot.c linux-2.6.22.18-vs2.3.0.32/fs/nfs/nfsroot.c
7732 --- linux-2.6.22.18/fs/nfs/nfsroot.c    2007-07-22 00:00:17.000000000 +0200
7733 +++ linux-2.6.22.18-vs2.3.0.32/fs/nfs/nfsroot.c 2008-02-11 12:35:34.000000000 +0100
7734 @@ -118,12 +118,12 @@ static int mount_port __initdata = 0;             /
7735  enum {
7736         /* Options that take integer arguments */
7737         Opt_port, Opt_rsize, Opt_wsize, Opt_timeo, Opt_retrans, Opt_acregmin,
7738 -       Opt_acregmax, Opt_acdirmin, Opt_acdirmax,
7739 +       Opt_acregmax, Opt_acdirmin, Opt_acdirmax, Opt_tagid,
7740         /* Options that take no arguments */
7741         Opt_soft, Opt_hard, Opt_intr,
7742         Opt_nointr, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac, 
7743         Opt_noac, Opt_lock, Opt_nolock, Opt_v2, Opt_v3, Opt_udp, Opt_tcp,
7744 -       Opt_acl, Opt_noacl,
7745 +       Opt_acl, Opt_noacl, Opt_tag, Opt_notag,
7746         /* Error token */
7747         Opt_err
7748  };
7749 @@ -160,6 +160,9 @@ static match_table_t __initdata tokens =
7750         {Opt_tcp, "tcp"},
7751         {Opt_acl, "acl"},
7752         {Opt_noacl, "noacl"},
7753 +       {Opt_tag, "tag"},
7754 +       {Opt_notag, "notag"},
7755 +       {Opt_tagid, "tagid=%u"},
7756         {Opt_err, NULL}
7757         
7758  };
7759 @@ -274,6 +277,20 @@ static int __init root_nfs_parse(char *n
7760                         case Opt_noacl:
7761                                 nfs_data.flags |= NFS_MOUNT_NOACL;
7762                                 break;
7763 +#ifndef CONFIG_TAGGING_NONE
7764 +                       case Opt_tag:
7765 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
7766 +                               break;
7767 +                       case Opt_notag:
7768 +                               nfs_data.flags &= ~NFS_MOUNT_TAGGED;
7769 +                               break;
7770 +#endif
7771 +#ifdef CONFIG_PROPAGATE
7772 +                       case Opt_tagid:
7773 +                               /* use args[0] */
7774 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
7775 +                               break;
7776 +#endif
7777                         default:
7778                                 printk(KERN_WARNING "Root-NFS: unknown "
7779                                         "option: %s\n", p);
7780 diff -Nurp linux-2.6.22.18/fs/nfs/super.c linux-2.6.22.18-vs2.3.0.32/fs/nfs/super.c
7781 --- linux-2.6.22.18/fs/nfs/super.c      2007-09-29 14:11:49.000000000 +0200
7782 +++ linux-2.6.22.18-vs2.3.0.32/fs/nfs/super.c   2008-02-11 12:35:34.000000000 +0100
7783 @@ -45,6 +45,7 @@
7784  #include <linux/inet.h>
7785  #include <linux/nfs_xdr.h>
7786  #include <linux/magic.h>
7787 +#include <linux/vs_tag.h>
7788  
7789  #include <asm/system.h>
7790  #include <asm/uaccess.h>
7791 @@ -291,6 +292,7 @@ static void nfs_show_mount_options(struc
7792                 { NFS_MOUNT_NONLM, ",nolock", "" },
7793                 { NFS_MOUNT_NOACL, ",noacl", "" },
7794                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
7795 +               { NFS_MOUNT_TAGGED, ",tag", "" },
7796                 { 0, NULL, NULL }
7797         };
7798         const struct proc_nfs_info *nfs_infop;
7799 diff -Nurp linux-2.6.22.18/fs/nfsd/auth.c linux-2.6.22.18-vs2.3.0.32/fs/nfsd/auth.c
7800 --- linux-2.6.22.18/fs/nfsd/auth.c      2006-06-18 03:49:35.000000000 +0200
7801 +++ linux-2.6.22.18-vs2.3.0.32/fs/nfsd/auth.c   2008-02-11 12:35:34.000000000 +0100
7802 @@ -9,6 +9,7 @@
7803  #include <linux/sunrpc/svc.h>
7804  #include <linux/sunrpc/svcauth.h>
7805  #include <linux/nfsd/nfsd.h>
7806 +#include <linux/vs_tag.h>
7807  
7808  #define        CAP_NFSD_MASK (CAP_FS_MASK|CAP_TO_MASK(CAP_SYS_RESOURCE))
7809  
7810 @@ -41,19 +42,22 @@ int nfsd_setuser(struct svc_rqst *rqstp,
7811                 get_group_info(cred.cr_group_info);
7812  
7813         if (cred.cr_uid != (uid_t) -1)
7814 -               current->fsuid = cred.cr_uid;
7815 +               current->fsuid = INOTAG_UID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid);
7816         else
7817                 current->fsuid = exp->ex_anon_uid;
7818         if (cred.cr_gid != (gid_t) -1)
7819 -               current->fsgid = cred.cr_gid;
7820 +               current->fsgid = INOTAG_GID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid);
7821         else
7822                 current->fsgid = exp->ex_anon_gid;
7823  
7824 +       /* this desperately needs a tag :) */
7825 +       current->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
7826 +
7827         if (!cred.cr_group_info)
7828                 return -ENOMEM;
7829         ret = set_current_groups(cred.cr_group_info);
7830         put_group_info(cred.cr_group_info);
7831 -       if ((cred.cr_uid)) {
7832 +       if (INOTAG_UID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid)) {
7833                 cap_t(current->cap_effective) &= ~CAP_NFSD_MASK;
7834         } else {
7835                 cap_t(current->cap_effective) |= (CAP_NFSD_MASK &
7836 diff -Nurp linux-2.6.22.18/fs/nfsd/nfs3xdr.c linux-2.6.22.18-vs2.3.0.32/fs/nfsd/nfs3xdr.c
7837 --- linux-2.6.22.18/fs/nfsd/nfs3xdr.c   2007-07-22 00:00:17.000000000 +0200
7838 +++ linux-2.6.22.18-vs2.3.0.32/fs/nfsd/nfs3xdr.c        2008-02-11 12:35:34.000000000 +0100
7839 @@ -21,6 +21,7 @@
7840  #include <linux/sunrpc/svc.h>
7841  #include <linux/nfsd/nfsd.h>
7842  #include <linux/nfsd/xdr3.h>
7843 +#include <linux/vs_tag.h>
7844  
7845  #define NFSDDBG_FACILITY               NFSDDBG_XDR
7846  
7847 @@ -107,6 +108,8 @@ static __be32 *
7848  decode_sattr3(__be32 *p, struct iattr *iap)
7849  {
7850         u32     tmp;
7851 +       uid_t   uid = 0;
7852 +       gid_t   gid = 0;
7853  
7854         iap->ia_valid = 0;
7855  
7856 @@ -116,12 +119,15 @@ decode_sattr3(__be32 *p, struct iattr *i
7857         }
7858         if (*p++) {
7859                 iap->ia_valid |= ATTR_UID;
7860 -               iap->ia_uid = ntohl(*p++);
7861 +               uid = ntohl(*p++);
7862         }
7863         if (*p++) {
7864                 iap->ia_valid |= ATTR_GID;
7865 -               iap->ia_gid = ntohl(*p++);
7866 +               gid = ntohl(*p++);
7867         }
7868 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
7869 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
7870 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
7871         if (*p++) {
7872                 u64     newsize;
7873  
7874 @@ -180,8 +186,10 @@ encode_fattr3(struct svc_rqst *rqstp, __
7875         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
7876         *p++ = htonl((u32) stat->mode);
7877         *p++ = htonl((u32) stat->nlink);
7878 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
7879 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
7880 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
7881 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
7882 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
7883 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
7884         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
7885                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
7886         } else {
7887 diff -Nurp linux-2.6.22.18/fs/nfsd/nfs4recover.c linux-2.6.22.18-vs2.3.0.32/fs/nfsd/nfs4recover.c
7888 --- linux-2.6.22.18/fs/nfsd/nfs4recover.c       2007-07-22 00:00:17.000000000 +0200
7889 +++ linux-2.6.22.18-vs2.3.0.32/fs/nfsd/nfs4recover.c    2008-02-11 12:35:34.000000000 +0100
7890 @@ -156,7 +156,7 @@ nfsd4_create_clid_dir(struct nfs4_client
7891                 dprintk("NFSD: nfsd4_create_clid_dir: DIRECTORY EXISTS\n");
7892                 goto out_put;
7893         }
7894 -       status = vfs_mkdir(rec_dir.dentry->d_inode, dentry, S_IRWXU);
7895 +       status = vfs_mkdir(rec_dir.dentry->d_inode, dentry, S_IRWXU, NULL);
7896  out_put:
7897         dput(dentry);
7898  out_unlock:
7899 @@ -260,7 +260,7 @@ nfsd4_remove_clid_file(struct dentry *di
7900                 return -EINVAL;
7901         }
7902         mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
7903 -       status = vfs_unlink(dir->d_inode, dentry);
7904 +       status = vfs_unlink(dir->d_inode, dentry, NULL);
7905         mutex_unlock(&dir->d_inode->i_mutex);
7906         return status;
7907  }
7908 @@ -275,7 +275,7 @@ nfsd4_clear_clid_dir(struct dentry *dir,
7909          * a kernel from the future.... */
7910         nfsd4_list_rec_dir(dentry, nfsd4_remove_clid_file);
7911         mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
7912 -       status = vfs_rmdir(dir->d_inode, dentry);
7913 +       status = vfs_rmdir(dir->d_inode, dentry, NULL);
7914         mutex_unlock(&dir->d_inode->i_mutex);
7915         return status;
7916  }
7917 diff -Nurp linux-2.6.22.18/fs/nfsd/nfs4xdr.c linux-2.6.22.18-vs2.3.0.32/fs/nfsd/nfs4xdr.c
7918 --- linux-2.6.22.18/fs/nfsd/nfs4xdr.c   2007-07-22 00:00:17.000000000 +0200
7919 +++ linux-2.6.22.18-vs2.3.0.32/fs/nfsd/nfs4xdr.c        2008-02-11 12:35:34.000000000 +0100
7920 @@ -56,6 +56,7 @@
7921  #include <linux/nfsd_idmap.h>
7922  #include <linux/nfs4.h>
7923  #include <linux/nfs4_acl.h>
7924 +#include <linux/vs_tag.h>
7925  
7926  #define NFSDDBG_FACILITY               NFSDDBG_XDR
7927  
7928 @@ -1727,14 +1728,18 @@ out_acl:
7929                 WRITE32(stat.nlink);
7930         }
7931         if (bmval1 & FATTR4_WORD1_OWNER) {
7932 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
7933 +               status = nfsd4_encode_user(rqstp,
7934 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
7935 +                       stat.uid, stat.tag), &p, &buflen);
7936                 if (status == nfserr_resource)
7937                         goto out_resource;
7938                 if (status)
7939                         goto out;
7940         }
7941         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
7942 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
7943 +               status = nfsd4_encode_group(rqstp,
7944 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
7945 +                       stat.gid, stat.tag), &p, &buflen);
7946                 if (status == nfserr_resource)
7947                         goto out_resource;
7948                 if (status)
7949 diff -Nurp linux-2.6.22.18/fs/nfsd/nfsxdr.c linux-2.6.22.18-vs2.3.0.32/fs/nfsd/nfsxdr.c
7950 --- linux-2.6.22.18/fs/nfsd/nfsxdr.c    2007-07-22 00:00:17.000000000 +0200
7951 +++ linux-2.6.22.18-vs2.3.0.32/fs/nfsd/nfsxdr.c 2008-02-11 12:35:34.000000000 +0100
7952 @@ -15,6 +15,7 @@
7953  #include <linux/nfsd/nfsd.h>
7954  #include <linux/nfsd/xdr.h>
7955  #include <linux/mm.h>
7956 +#include <linux/vs_tag.h>
7957  
7958  #define NFSDDBG_FACILITY               NFSDDBG_XDR
7959  
7960 @@ -97,6 +98,8 @@ static __be32 *
7961  decode_sattr(__be32 *p, struct iattr *iap)
7962  {
7963         u32     tmp, tmp1;
7964 +       uid_t   uid = 0;
7965 +       gid_t   gid = 0;
7966  
7967         iap->ia_valid = 0;
7968  
7969 @@ -110,12 +113,15 @@ decode_sattr(__be32 *p, struct iattr *ia
7970         }
7971         if ((tmp = ntohl(*p++)) != (u32)-1) {
7972                 iap->ia_valid |= ATTR_UID;
7973 -               iap->ia_uid = tmp;
7974 +               uid = tmp;
7975         }
7976         if ((tmp = ntohl(*p++)) != (u32)-1) {
7977                 iap->ia_valid |= ATTR_GID;
7978 -               iap->ia_gid = tmp;
7979 +               gid = tmp;
7980         }
7981 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
7982 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
7983 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
7984         if ((tmp = ntohl(*p++)) != (u32)-1) {
7985                 iap->ia_valid |= ATTR_SIZE;
7986                 iap->ia_size = tmp;
7987 @@ -160,8 +166,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
7988         *p++ = htonl(nfs_ftypes[type >> 12]);
7989         *p++ = htonl((u32) stat->mode);
7990         *p++ = htonl((u32) stat->nlink);
7991 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
7992 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
7993 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
7994 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
7995 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
7996 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
7997  
7998         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
7999                 *p++ = htonl(NFS_MAXPATHLEN);
8000 diff -Nurp linux-2.6.22.18/fs/nfsd/vfs.c linux-2.6.22.18-vs2.3.0.32/fs/nfsd/vfs.c
8001 --- linux-2.6.22.18/fs/nfsd/vfs.c       2007-08-12 03:54:36.000000000 +0200
8002 +++ linux-2.6.22.18-vs2.3.0.32/fs/nfsd/vfs.c    2008-02-11 12:35:34.000000000 +0100
8003 @@ -1186,13 +1186,13 @@ nfsd_create(struct svc_rqst *rqstp, stru
8004                 host_err = vfs_create(dirp, dchild, iap->ia_mode, NULL);
8005                 break;
8006         case S_IFDIR:
8007 -               host_err = vfs_mkdir(dirp, dchild, iap->ia_mode);
8008 +               host_err = vfs_mkdir(dirp, dchild, iap->ia_mode, NULL);
8009                 break;
8010         case S_IFCHR:
8011         case S_IFBLK:
8012         case S_IFIFO:
8013         case S_IFSOCK:
8014 -               host_err = vfs_mknod(dirp, dchild, iap->ia_mode, rdev);
8015 +               host_err = vfs_mknod(dirp, dchild, iap->ia_mode, rdev, NULL);
8016                 break;
8017         default:
8018                 printk("nfsd: bad file type %o in nfsd_create\n", type);
8019 @@ -1466,11 +1466,13 @@ nfsd_symlink(struct svc_rqst *rqstp, str
8020                 else {
8021                         strncpy(path_alloced, path, plen);
8022                         path_alloced[plen] = 0;
8023 -                       host_err = vfs_symlink(dentry->d_inode, dnew, path_alloced, mode);
8024 +                       host_err = vfs_symlink(dentry->d_inode, dnew,
8025 +                               path_alloced, mode, NULL);
8026                         kfree(path_alloced);
8027                 }
8028         } else
8029 -               host_err = vfs_symlink(dentry->d_inode, dnew, path, mode);
8030 +               host_err = vfs_symlink(dentry->d_inode, dnew,
8031 +                       path, mode, NULL);
8032  
8033         if (!host_err) {
8034                 if (EX_ISSYNC(fhp->fh_export))
8035 @@ -1529,7 +1531,7 @@ nfsd_link(struct svc_rqst *rqstp, struct
8036         dold = tfhp->fh_dentry;
8037         dest = dold->d_inode;
8038  
8039 -       host_err = vfs_link(dold, dirp, dnew);
8040 +       host_err = vfs_link(dold, dirp, dnew, NULL);
8041         if (!host_err) {
8042                 if (EX_ISSYNC(ffhp->fh_export)) {
8043                         err = nfserrno(nfsd_sync_dir(ddir));
8044 @@ -1694,9 +1696,9 @@ nfsd_unlink(struct svc_rqst *rqstp, stru
8045                         host_err = -EPERM;
8046                 } else
8047  #endif
8048 -               host_err = vfs_unlink(dirp, rdentry);
8049 +               host_err = vfs_unlink(dirp, rdentry, NULL);
8050         } else { /* It's RMDIR */
8051 -               host_err = vfs_rmdir(dirp, rdentry);
8052 +               host_err = vfs_rmdir(dirp, rdentry, NULL);
8053         }
8054  
8055         dput(rdentry);
8056 @@ -1807,7 +1809,8 @@ nfsd_permission(struct svc_export *exp, 
8057          */
8058         if (!(acc & MAY_LOCAL_ACCESS))
8059                 if (acc & (MAY_WRITE | MAY_SATTR | MAY_TRUNC)) {
8060 -                       if (EX_RDONLY(exp) || IS_RDONLY(inode))
8061 +                       if (EX_RDONLY(exp) || IS_RDONLY(inode)
8062 +                               || MNT_IS_RDONLY(exp->ex_mnt))
8063                                 return nfserr_rofs;
8064                         if (/* (acc & MAY_WRITE) && */ IS_IMMUTABLE(inode))
8065                                 return nfserr_perm;
8066 diff -Nurp linux-2.6.22.18/fs/ocfs2/dlm/dlmfs.c linux-2.6.22.18-vs2.3.0.32/fs/ocfs2/dlm/dlmfs.c
8067 --- linux-2.6.22.18/fs/ocfs2/dlm/dlmfs.c        2007-07-22 00:00:17.000000000 +0200
8068 +++ linux-2.6.22.18-vs2.3.0.32/fs/ocfs2/dlm/dlmfs.c     2008-02-11 12:35:34.000000000 +0100
8069 @@ -43,6 +43,7 @@
8070  #include <linux/init.h>
8071  #include <linux/string.h>
8072  #include <linux/backing-dev.h>
8073 +#include <linux/vs_tag.h>
8074  
8075  #include <asm/uaccess.h>
8076  
8077 @@ -331,6 +332,7 @@ static struct inode *dlmfs_get_root_inod
8078                 inode->i_mode = mode;
8079                 inode->i_uid = current->fsuid;
8080                 inode->i_gid = current->fsgid;
8081 +               inode->i_tag = dx_current_fstag(sb);
8082                 inode->i_blocks = 0;
8083                 inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
8084                 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
8085 @@ -357,6 +359,7 @@ static struct inode *dlmfs_get_inode(str
8086         inode->i_mode = mode;
8087         inode->i_uid = current->fsuid;
8088         inode->i_gid = current->fsgid;
8089 +       inode->i_tag = dx_current_fstag(sb);
8090         inode->i_blocks = 0;
8091         inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
8092         inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
8093 diff -Nurp linux-2.6.22.18/fs/ocfs2/dlmglue.c linux-2.6.22.18-vs2.3.0.32/fs/ocfs2/dlmglue.c
8094 --- linux-2.6.22.18/fs/ocfs2/dlmglue.c  2007-07-22 00:00:18.000000000 +0200
8095 +++ linux-2.6.22.18-vs2.3.0.32/fs/ocfs2/dlmglue.c       2008-02-11 12:35:34.000000000 +0100
8096 @@ -1475,6 +1475,7 @@ static void __ocfs2_stuff_meta_lvb(struc
8097         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
8098         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
8099         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
8100 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
8101         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
8102         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
8103         lvb->lvb_iatime_packed  =
8104 @@ -1527,6 +1528,7 @@ static void ocfs2_refresh_inode_from_lvb
8105  
8106         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
8107         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
8108 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
8109         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
8110         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
8111         ocfs2_unpack_timespec(&inode->i_atime,
8112 diff -Nurp linux-2.6.22.18/fs/ocfs2/dlmglue.h linux-2.6.22.18-vs2.3.0.32/fs/ocfs2/dlmglue.h
8113 --- linux-2.6.22.18/fs/ocfs2/dlmglue.h  2007-07-22 00:00:18.000000000 +0200
8114 +++ linux-2.6.22.18-vs2.3.0.32/fs/ocfs2/dlmglue.h       2008-02-11 12:35:34.000000000 +0100
8115 @@ -34,7 +34,7 @@
8116  struct ocfs2_meta_lvb {
8117         __u8         lvb_version;
8118         __u8         lvb_reserved0;
8119 -       __be16       lvb_reserved1;
8120 +       __be16       lvb_itag;
8121         __be32       lvb_iclusters;
8122         __be32       lvb_iuid;
8123         __be32       lvb_igid;
8124 diff -Nurp linux-2.6.22.18/fs/ocfs2/file.c linux-2.6.22.18-vs2.3.0.32/fs/ocfs2/file.c
8125 --- linux-2.6.22.18/fs/ocfs2/file.c     2007-09-05 07:07:59.000000000 +0200
8126 +++ linux-2.6.22.18-vs2.3.0.32/fs/ocfs2/file.c  2008-02-11 12:35:34.000000000 +0100
8127 @@ -943,13 +943,15 @@ int ocfs2_setattr(struct dentry *dentry,
8128                 mlog(0, "uid change: %d\n", attr->ia_uid);
8129         if (attr->ia_valid & ATTR_GID)
8130                 mlog(0, "gid change: %d\n", attr->ia_gid);
8131 +       if (attr->ia_valid & ATTR_TAG)
8132 +               mlog(0, "tag change: %d\n", attr->ia_tag);
8133         if (attr->ia_valid & ATTR_SIZE)
8134                 mlog(0, "size change...\n");
8135         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
8136                 mlog(0, "time change...\n");
8137  
8138  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
8139 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
8140 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
8141         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
8142                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
8143                 return 0;
8144 @@ -1805,6 +1807,7 @@ bail:
8145  const struct inode_operations ocfs2_file_iops = {
8146         .setattr        = ocfs2_setattr,
8147         .getattr        = ocfs2_getattr,
8148 +       .sync_flags     = ocfs2_sync_flags,
8149         .permission     = ocfs2_permission,
8150  };
8151  
8152 diff -Nurp linux-2.6.22.18/fs/ocfs2/inode.c linux-2.6.22.18-vs2.3.0.32/fs/ocfs2/inode.c
8153 --- linux-2.6.22.18/fs/ocfs2/inode.c    2007-07-22 00:00:18.000000000 +0200
8154 +++ linux-2.6.22.18-vs2.3.0.32/fs/ocfs2/inode.c 2008-02-11 12:35:34.000000000 +0100
8155 @@ -28,6 +28,7 @@
8156  #include <linux/slab.h>
8157  #include <linux/highmem.h>
8158  #include <linux/pagemap.h>
8159 +#include <linux/vs_tag.h>
8160  
8161  #include <asm/byteorder.h>
8162  
8163 @@ -42,6 +43,7 @@
8164  #include "file.h"
8165  #include "heartbeat.h"
8166  #include "inode.h"
8167 +#include "ioctl.h"
8168  #include "journal.h"
8169  #include "namei.h"
8170  #include "suballoc.h"
8171 @@ -77,6 +79,10 @@ void ocfs2_set_inode_flags(struct inode 
8172  
8173         if (flags & OCFS2_IMMUTABLE_FL)
8174                 inode->i_flags |= S_IMMUTABLE;
8175 +       if (flags & OCFS2_IUNLINK_FL)
8176 +               inode->i_flags |= S_IUNLINK;
8177 +       if (flags & OCFS2_BARRIER_FL)
8178 +               inode->i_flags |= S_BARRIER;
8179  
8180         if (flags & OCFS2_SYNC_FL)
8181                 inode->i_flags |= S_SYNC;
8182 @@ -107,6 +113,27 @@ void ocfs2_get_inode_flags(struct ocfs2_
8183                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
8184  }
8185  
8186 +int ocfs2_sync_flags(struct inode *inode)
8187 +{
8188 +       unsigned int oldflags, newflags;
8189 +
8190 +       oldflags = OCFS2_I(inode)->ip_flags;
8191 +       newflags = oldflags & ~(OCFS2_IMMUTABLE_FL |
8192 +               OCFS2_IUNLINK_FL | OCFS2_BARRIER_FL);
8193 +
8194 +       if (IS_IMMUTABLE(inode))
8195 +               newflags |= OCFS2_IMMUTABLE_FL;
8196 +       if (IS_IUNLINK(inode))
8197 +               newflags |= OCFS2_IUNLINK_FL;
8198 +       if (IS_BARRIER(inode))
8199 +               newflags |= OCFS2_BARRIER_FL;
8200 +
8201 +       if (oldflags ^ newflags)
8202 +               return ocfs2_set_inode_attr(inode,
8203 +                       newflags, OCFS2_FL_MASK);
8204 +       return 0;
8205 +}
8206 +
8207  struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 blkno, int flags)
8208  {
8209         struct inode *inode = NULL;
8210 @@ -212,6 +239,8 @@ int ocfs2_populate_inode(struct inode *i
8211         struct super_block *sb;
8212         struct ocfs2_super *osb;
8213         int status = -EINVAL;
8214 +       uid_t uid;
8215 +       gid_t gid;
8216  
8217         mlog_entry("(0x%p, size:%llu)\n", inode,
8218                    (unsigned long long)le64_to_cpu(fe->i_size));
8219 @@ -246,8 +275,12 @@ int ocfs2_populate_inode(struct inode *i
8220         inode->i_generation = le32_to_cpu(fe->i_generation);
8221         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
8222         inode->i_mode = le16_to_cpu(fe->i_mode);
8223 -       inode->i_uid = le32_to_cpu(fe->i_uid);
8224 -       inode->i_gid = le32_to_cpu(fe->i_gid);
8225 +       uid = le32_to_cpu(fe->i_uid);
8226 +       gid = le32_to_cpu(fe->i_gid);
8227 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
8228 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
8229 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
8230 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
8231  
8232         /* Fast symlinks will have i_size but no allocated clusters. */
8233         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
8234 @@ -1224,8 +1257,11 @@ int ocfs2_mark_inode_dirty(handle_t *han
8235  
8236         fe->i_size = cpu_to_le64(i_size_read(inode));
8237         fe->i_links_count = cpu_to_le16(inode->i_nlink);
8238 -       fe->i_uid = cpu_to_le32(inode->i_uid);
8239 -       fe->i_gid = cpu_to_le32(inode->i_gid);
8240 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode),
8241 +               inode->i_uid, inode->i_tag));
8242 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode),
8243 +               inode->i_gid, inode->i_tag));
8244 +       /* i_tag = = cpu_to_le16(inode->i_tag); */
8245         fe->i_mode = cpu_to_le16(inode->i_mode);
8246         fe->i_atime = cpu_to_le64(inode->i_atime.tv_sec);
8247         fe->i_atime_nsec = cpu_to_le32(inode->i_atime.tv_nsec);
8248 @@ -1253,15 +1289,24 @@ leave:
8249  void ocfs2_refresh_inode(struct inode *inode,
8250                          struct ocfs2_dinode *fe)
8251  {
8252 +       uid_t uid;
8253 +       gid_t gid;
8254 +
8255         spin_lock(&OCFS2_I(inode)->ip_lock);
8256  
8257         OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters);
8258         OCFS2_I(inode)->ip_attr = le32_to_cpu(fe->i_attr);
8259 +       /* OCFS2_I(inode)->ip_flags &= ~OCFS2_FL_MASK;
8260 +          OCFS2_I(inode)->ip_flags |= le32_to_cpu(fe->i_flags) & OCFS2_FL_MASK; */
8261         ocfs2_set_inode_flags(inode);
8262         i_size_write(inode, le64_to_cpu(fe->i_size));
8263         inode->i_nlink = le16_to_cpu(fe->i_links_count);
8264 -       inode->i_uid = le32_to_cpu(fe->i_uid);
8265 -       inode->i_gid = le32_to_cpu(fe->i_gid);
8266 +       uid = le32_to_cpu(fe->i_uid);
8267 +       gid = le32_to_cpu(fe->i_gid);
8268 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
8269 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
8270 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
8271 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
8272         inode->i_mode = le16_to_cpu(fe->i_mode);
8273         if (S_ISLNK(inode->i_mode) && le32_to_cpu(fe->i_clusters) == 0)
8274                 inode->i_blocks = 0;
8275 diff -Nurp linux-2.6.22.18/fs/ocfs2/inode.h linux-2.6.22.18-vs2.3.0.32/fs/ocfs2/inode.h
8276 --- linux-2.6.22.18/fs/ocfs2/inode.h    2007-07-22 00:00:18.000000000 +0200
8277 +++ linux-2.6.22.18-vs2.3.0.32/fs/ocfs2/inode.h 2008-02-11 12:35:34.000000000 +0100
8278 @@ -142,6 +142,7 @@ int ocfs2_aio_write(struct file *file, s
8279  
8280  void ocfs2_set_inode_flags(struct inode *inode);
8281  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
8282 +int ocfs2_sync_flags(struct inode *inode);
8283  
8284  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
8285  {
8286 diff -Nurp linux-2.6.22.18/fs/ocfs2/ioctl.c linux-2.6.22.18-vs2.3.0.32/fs/ocfs2/ioctl.c
8287 --- linux-2.6.22.18/fs/ocfs2/ioctl.c    2007-07-22 00:00:18.000000000 +0200
8288 +++ linux-2.6.22.18-vs2.3.0.32/fs/ocfs2/ioctl.c 2008-02-11 12:35:34.000000000 +0100
8289 @@ -39,7 +39,8 @@ static int ocfs2_get_inode_attr(struct i
8290         return status;
8291  }
8292  
8293 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
8294 +/* Called with inode->i_mutex locked */
8295 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
8296                                 unsigned mask)
8297  {
8298         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
8299 @@ -49,8 +50,6 @@ static int ocfs2_set_inode_attr(struct i
8300         unsigned oldflags;
8301         int status;
8302  
8303 -       mutex_lock(&inode->i_mutex);
8304 -
8305         status = ocfs2_meta_lock(inode, &bh, 1);
8306         if (status < 0) {
8307                 mlog_errno(status);
8308 @@ -101,8 +100,6 @@ static int ocfs2_set_inode_attr(struct i
8309  bail_unlock:
8310         ocfs2_meta_unlock(inode, 1);
8311  bail:
8312 -       mutex_unlock(&inode->i_mutex);
8313 -
8314         if (bh)
8315                 brelse(bh);
8316  
8317 @@ -110,6 +107,16 @@ bail:
8318         return status;
8319  }
8320  
8321 +static inline int ocfs2_set_inode_attr_lock(struct inode *inode,
8322 +       unsigned flags, unsigned mask)
8323 +{
8324 +       int ret;
8325 +       mutex_lock(&inode->i_mutex);
8326 +       ret = ocfs2_set_inode_attr(inode, flags, mask);
8327 +       mutex_unlock(&inode->i_mutex);
8328 +       return ret;
8329 +}
8330 +
8331  int ocfs2_ioctl(struct inode * inode, struct file * filp,
8332         unsigned int cmd, unsigned long arg)
8333  {
8334 @@ -128,7 +135,7 @@ int ocfs2_ioctl(struct inode * inode, st
8335                 if (get_user(flags, (int __user *) arg))
8336                         return -EFAULT;
8337  
8338 -               return ocfs2_set_inode_attr(inode, flags,
8339 +               return ocfs2_set_inode_attr_lock(inode, flags,
8340                         OCFS2_FL_MODIFIABLE);
8341         default:
8342                 return -ENOTTY;
8343 diff -Nurp linux-2.6.22.18/fs/ocfs2/ioctl.h linux-2.6.22.18-vs2.3.0.32/fs/ocfs2/ioctl.h
8344 --- linux-2.6.22.18/fs/ocfs2/ioctl.h    2007-07-22 00:00:18.000000000 +0200
8345 +++ linux-2.6.22.18-vs2.3.0.32/fs/ocfs2/ioctl.h 2008-02-11 12:35:34.000000000 +0100
8346 @@ -10,6 +10,9 @@
8347  #ifndef OCFS2_IOCTL_H
8348  #define OCFS2_IOCTL_H
8349  
8350 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
8351 +                               unsigned mask);
8352 +
8353  int ocfs2_ioctl(struct inode * inode, struct file * filp,
8354         unsigned int cmd, unsigned long arg);
8355  long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg);
8356 diff -Nurp linux-2.6.22.18/fs/ocfs2/namei.c linux-2.6.22.18-vs2.3.0.32/fs/ocfs2/namei.c
8357 --- linux-2.6.22.18/fs/ocfs2/namei.c    2007-07-22 00:00:18.000000000 +0200
8358 +++ linux-2.6.22.18-vs2.3.0.32/fs/ocfs2/namei.c 2008-02-11 12:35:34.000000000 +0100
8359 @@ -40,6 +40,7 @@
8360  #include <linux/types.h>
8361  #include <linux/slab.h>
8362  #include <linux/highmem.h>
8363 +#include <linux/vs_tag.h>
8364  
8365  #define MLOG_MASK_PREFIX ML_NAMEI
8366  #include <cluster/masklog.h>
8367 @@ -483,6 +484,9 @@ static int ocfs2_mknod_locked(struct ocf
8368         u64 fe_blkno = 0;
8369         u16 suballoc_bit;
8370         struct inode *inode = NULL;
8371 +       uid_t uid;
8372 +       gid_t gid;
8373 +       tag_t tag;
8374  
8375         mlog_entry("(0x%p, 0x%p, %d, %lu, '%.*s')\n", dir, dentry, mode,
8376                    (unsigned long)dev, dentry->d_name.len,
8377 @@ -542,13 +546,19 @@ static int ocfs2_mknod_locked(struct ocf
8378         fe->i_blkno = cpu_to_le64(fe_blkno);
8379         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
8380         fe->i_suballoc_slot = cpu_to_le16(osb->slot_num);
8381 -       fe->i_uid = cpu_to_le32(current->fsuid);
8382 +
8383 +       tag = dx_current_fstag(osb->sb);
8384 +       uid = current->fsuid;
8385         if (dir->i_mode & S_ISGID) {
8386 -               fe->i_gid = cpu_to_le32(dir->i_gid);
8387 +               gid = dir->i_gid;
8388                 if (S_ISDIR(mode))
8389                         mode |= S_ISGID;
8390         } else
8391 -               fe->i_gid = cpu_to_le32(current->fsgid);
8392 +               gid = current->fsgid;
8393 +
8394 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), uid, tag));
8395 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), gid, tag));
8396 +       inode->i_tag = tag;
8397         fe->i_mode = cpu_to_le16(mode);
8398         if (S_ISCHR(mode) || S_ISBLK(mode))
8399                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
8400 @@ -2316,5 +2326,6 @@ const struct inode_operations ocfs2_dir_
8401         .rename         = ocfs2_rename,
8402         .setattr        = ocfs2_setattr,
8403         .getattr        = ocfs2_getattr,
8404 +       .sync_flags     = ocfs2_sync_flags,
8405         .permission     = ocfs2_permission,
8406  };
8407 diff -Nurp linux-2.6.22.18/fs/ocfs2/ocfs2_fs.h linux-2.6.22.18-vs2.3.0.32/fs/ocfs2/ocfs2_fs.h
8408 --- linux-2.6.22.18/fs/ocfs2/ocfs2_fs.h 2007-07-22 00:00:18.000000000 +0200
8409 +++ linux-2.6.22.18-vs2.3.0.32/fs/ocfs2/ocfs2_fs.h      2008-02-11 12:35:34.000000000 +0100
8410 @@ -152,8 +152,12 @@
8411  #define OCFS2_NOATIME_FL       (0x00000080)    /* do not update atime */
8412  #define OCFS2_DIRSYNC_FL       (0x00010000)    /* dirsync behaviour (directories only) */
8413  
8414 +#define OCFS2_BARRIER_FL       (0x04000000)    /* Barrier for chroot() */
8415 +#define OCFS2_IUNLINK_FL       (0x08000000)    /* Immutable unlink */
8416 +
8417  #define OCFS2_FL_VISIBLE       (0x000100FF)    /* User visible flags */
8418  #define OCFS2_FL_MODIFIABLE    (0x000100FF)    /* User modifiable flags */
8419 +#define OCFS2_FL_MASK          (0x0F0100FF)
8420  
8421  /*
8422   * Extent record flags (e_node.leaf.flags)
8423 diff -Nurp linux-2.6.22.18/fs/ocfs2/ocfs2.h linux-2.6.22.18-vs2.3.0.32/fs/ocfs2/ocfs2.h
8424 --- linux-2.6.22.18/fs/ocfs2/ocfs2.h    2007-07-22 00:00:18.000000000 +0200
8425 +++ linux-2.6.22.18-vs2.3.0.32/fs/ocfs2/ocfs2.h 2008-02-11 12:35:34.000000000 +0100
8426 @@ -170,6 +170,7 @@ enum ocfs2_mount_options
8427         OCFS2_MOUNT_NOINTR  = 1 << 2,   /* Don't catch signals */
8428         OCFS2_MOUNT_ERRORS_PANIC = 1 << 3, /* Panic on errors */
8429         OCFS2_MOUNT_DATA_WRITEBACK = 1 << 4, /* No data ordering */
8430 +       OCFS2_MOUNT_TAGGED = 1 << 8, /* use tagging */
8431  };
8432  
8433  #define OCFS2_OSB_SOFT_RO      0x0001
8434 diff -Nurp linux-2.6.22.18/fs/ocfs2/super.c linux-2.6.22.18-vs2.3.0.32/fs/ocfs2/super.c
8435 --- linux-2.6.22.18/fs/ocfs2/super.c    2007-07-22 00:00:18.000000000 +0200
8436 +++ linux-2.6.22.18-vs2.3.0.32/fs/ocfs2/super.c 2008-02-11 12:35:34.000000000 +0100
8437 @@ -140,6 +140,7 @@ enum {
8438         Opt_data_ordered,
8439         Opt_data_writeback,
8440         Opt_atime_quantum,
8441 +       Opt_tag, Opt_notag, Opt_tagid,
8442         Opt_err,
8443  };
8444  
8445 @@ -154,6 +155,9 @@ static match_table_t tokens = {
8446         {Opt_data_ordered, "data=ordered"},
8447         {Opt_data_writeback, "data=writeback"},
8448         {Opt_atime_quantum, "atime_quantum=%u"},
8449 +       {Opt_tag, "tag"},
8450 +       {Opt_notag, "notag"},
8451 +       {Opt_tagid, "tagid=%u"},
8452         {Opt_err, NULL}
8453  };
8454  
8455 @@ -362,6 +366,13 @@ static int ocfs2_remount(struct super_bl
8456                 goto out;
8457         }
8458  
8459 +       if ((parsed_options & OCFS2_MOUNT_TAGGED) &&
8460 +               !(sb->s_flags & MS_TAGGED)) {
8461 +               ret = -EINVAL;
8462 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
8463 +               goto out;
8464 +       }
8465 +
8466         if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
8467             (parsed_options & OCFS2_MOUNT_HB_LOCAL)) {
8468                 ret = -EINVAL;
8469 @@ -654,6 +665,9 @@ static int ocfs2_fill_super(struct super
8470  
8471         ocfs2_complete_mount_recovery(osb);
8472  
8473 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
8474 +               sb->s_flags |= MS_TAGGED;
8475 +
8476         if (ocfs2_mount_local(osb))
8477                 snprintf(nodestr, sizeof(nodestr), "local");
8478         else
8479 @@ -782,6 +796,20 @@ static int ocfs2_parse_options(struct su
8480                         else
8481                                 osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
8482                         break;
8483 +#ifndef CONFIG_TAGGING_NONE
8484 +               case Opt_tag:
8485 +                       *mount_opt |= OCFS2_MOUNT_TAGGED;
8486 +                       break;
8487 +               case Opt_notag:
8488 +                       *mount_opt &= ~OCFS2_MOUNT_TAGGED;
8489 +                       break;
8490 +#endif
8491 +#ifdef CONFIG_PROPAGATE
8492 +               case Opt_tagid:
8493 +                       /* use args[0] */
8494 +                       *mount_opt |= OCFS2_MOUNT_TAGGED;
8495 +                       break;
8496 +#endif
8497                 default:
8498                         mlog(ML_ERROR,
8499                              "Unrecognized mount option \"%s\" "
8500 diff -Nurp linux-2.6.22.18/fs/open.c linux-2.6.22.18-vs2.3.0.32/fs/open.c
8501 --- linux-2.6.22.18/fs/open.c   2007-07-22 00:00:18.000000000 +0200
8502 +++ linux-2.6.22.18-vs2.3.0.32/fs/open.c        2008-02-11 12:35:34.000000000 +0100
8503 @@ -26,22 +26,31 @@
8504  #include <linux/syscalls.h>
8505  #include <linux/rcupdate.h>
8506  #include <linux/audit.h>
8507 +#include <linux/vs_base.h>
8508 +#include <linux/vs_limit.h>
8509 +#include <linux/vs_dlimit.h>
8510 +#include <linux/vs_tag.h>
8511 +#include <linux/vs_cowbl.h>
8512  
8513  int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
8514  {
8515         int retval = -ENODEV;
8516  
8517         if (dentry) {
8518 +               struct super_block *sb = dentry->d_sb;
8519 +
8520                 retval = -ENOSYS;
8521 -               if (dentry->d_sb->s_op->statfs) {
8522 +               if (sb->s_op->statfs) {
8523                         memset(buf, 0, sizeof(*buf));
8524                         retval = security_sb_statfs(dentry);
8525                         if (retval)
8526                                 return retval;
8527 -                       retval = dentry->d_sb->s_op->statfs(dentry, buf);
8528 +                       retval = sb->s_op->statfs(dentry, buf);
8529                         if (retval == 0 && buf->f_frsize == 0)
8530                                 buf->f_frsize = buf->f_bsize;
8531                 }
8532 +               if (!vx_check(0, VS_ADMIN|VS_WATCH))
8533 +                       vx_vsi_statfs(sb, buf);
8534         }
8535         return retval;
8536  }
8537 @@ -248,7 +257,7 @@ static long do_sys_truncate(const char _
8538                 goto dput_and_out;
8539  
8540         error = -EROFS;
8541 -       if (IS_RDONLY(inode))
8542 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(nd.mnt))
8543                 goto dput_and_out;
8544  
8545         error = -EPERM;
8546 @@ -397,7 +406,7 @@ asmlinkage long sys_faccessat(int dfd, c
8547            special_file(nd.dentry->d_inode->i_mode))
8548                 goto out_path_release;
8549  
8550 -       if(IS_RDONLY(nd.dentry->d_inode))
8551 +       if(IS_RDONLY(nd.dentry->d_inode) || MNT_IS_RDONLY(nd.mnt))
8552                 res = -EROFS;
8553  
8554  out_path_release:
8555 @@ -511,7 +520,7 @@ asmlinkage long sys_fchmod(unsigned int 
8556         audit_inode(NULL, inode);
8557  
8558         err = -EROFS;
8559 -       if (IS_RDONLY(inode))
8560 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(file->f_vfsmnt))
8561                 goto out_putf;
8562         err = -EPERM;
8563         if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
8564 @@ -541,11 +550,11 @@ asmlinkage long sys_fchmodat(int dfd, co
8565         error = __user_walk_fd(dfd, filename, LOOKUP_FOLLOW, &nd);
8566         if (error)
8567                 goto out;
8568 -       inode = nd.dentry->d_inode;
8569  
8570 -       error = -EROFS;
8571 -       if (IS_RDONLY(inode))
8572 +       error = cow_check_and_break(&nd);
8573 +       if (error)
8574                 goto dput_and_out;
8575 +       inode = nd.dentry->d_inode;
8576  
8577         error = -EPERM;
8578         if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
8579 @@ -570,7 +579,8 @@ asmlinkage long sys_chmod(const char __u
8580         return sys_fchmodat(AT_FDCWD, filename, mode);
8581  }
8582  
8583 -static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
8584 +static int chown_common(struct dentry *dentry, struct vfsmount *mnt,
8585 +       uid_t user, gid_t group)
8586  {
8587         struct inode * inode;
8588         int error;
8589 @@ -582,7 +592,7 @@ static int chown_common(struct dentry * 
8590                 goto out;
8591         }
8592         error = -EROFS;
8593 -       if (IS_RDONLY(inode))
8594 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(mnt))
8595                 goto out;
8596         error = -EPERM;
8597         if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
8598 @@ -590,11 +600,11 @@ static int chown_common(struct dentry * 
8599         newattrs.ia_valid =  ATTR_CTIME;
8600         if (user != (uid_t) -1) {
8601                 newattrs.ia_valid |= ATTR_UID;
8602 -               newattrs.ia_uid = user;
8603 +               newattrs.ia_uid = dx_map_uid(user);
8604         }
8605         if (group != (gid_t) -1) {
8606                 newattrs.ia_valid |= ATTR_GID;
8607 -               newattrs.ia_gid = group;
8608 +               newattrs.ia_gid = dx_map_gid(group);
8609         }
8610         if (!S_ISDIR(inode->i_mode))
8611                 newattrs.ia_valid |= ATTR_KILL_SUID|ATTR_KILL_SGID;
8612 @@ -613,7 +623,11 @@ asmlinkage long sys_chown(const char __u
8613         error = user_path_walk(filename, &nd);
8614         if (error)
8615                 goto out;
8616 -       error = chown_common(nd.dentry, user, group);
8617 +#ifdef CONFIG_VSERVER_COWBL
8618 +       error = cow_check_and_break(&nd);
8619 +       if (!error)
8620 +#endif
8621 +               error = chown_common(nd.dentry, nd.mnt, user, group);
8622         path_release(&nd);
8623  out:
8624         return error;
8625 @@ -633,7 +647,11 @@ asmlinkage long sys_fchownat(int dfd, co
8626         error = __user_walk_fd(dfd, filename, follow, &nd);
8627         if (error)
8628                 goto out;
8629 -       error = chown_common(nd.dentry, user, group);
8630 +#ifdef CONFIG_VSERVER_COWBL
8631 +       error = cow_check_and_break(&nd);
8632 +       if (!error)
8633 +#endif
8634 +               error = chown_common(nd.dentry, nd.mnt, user, group);
8635         path_release(&nd);
8636  out:
8637         return error;
8638 @@ -647,7 +665,11 @@ asmlinkage long sys_lchown(const char __
8639         error = user_path_walk_link(filename, &nd);
8640         if (error)
8641                 goto out;
8642 -       error = chown_common(nd.dentry, user, group);
8643 +#ifdef CONFIG_VSERVER_COWBL
8644 +       error = cow_check_and_break(&nd);
8645 +       if (!error)
8646 +#endif
8647 +               error = chown_common(nd.dentry, nd.mnt, user, group);
8648         path_release(&nd);
8649  out:
8650         return error;
8651 @@ -666,7 +688,7 @@ asmlinkage long sys_fchown(unsigned int 
8652  
8653         dentry = file->f_path.dentry;
8654         audit_inode(NULL, dentry->d_inode);
8655 -       error = chown_common(dentry, user, group);
8656 +       error = chown_common(dentry, file->f_vfsmnt, user, group);
8657         fput(file);
8658  out:
8659         return error;
8660 @@ -893,6 +915,7 @@ repeat:
8661         FD_SET(fd, fdt->open_fds);
8662         FD_CLR(fd, fdt->close_on_exec);
8663         files->next_fd = fd + 1;
8664 +       vx_openfd_inc(fd);
8665  #if 1
8666         /* Sanity check */
8667         if (fdt->fd[fd] != NULL) {
8668 @@ -915,6 +938,7 @@ static void __put_unused_fd(struct files
8669         __FD_CLR(fd, fdt->open_fds);
8670         if (fd < files->next_fd)
8671                 files->next_fd = fd;
8672 +       vx_openfd_dec(fd);
8673  }
8674  
8675  void fastcall put_unused_fd(unsigned int fd)
8676 diff -Nurp linux-2.6.22.18/fs/proc/array.c linux-2.6.22.18-vs2.3.0.32/fs/proc/array.c
8677 --- linux-2.6.22.18/fs/proc/array.c     2007-07-22 00:00:18.000000000 +0200
8678 +++ linux-2.6.22.18-vs2.3.0.32/fs/proc/array.c  2008-02-11 12:35:35.000000000 +0100
8679 @@ -75,6 +75,8 @@
8680  #include <linux/cpuset.h>
8681  #include <linux/rcupdate.h>
8682  #include <linux/delayacct.h>
8683 +#include <linux/vs_context.h>
8684 +#include <linux/vs_network.h>
8685  
8686  #include <asm/uaccess.h>
8687  #include <asm/pgtable.h>
8688 @@ -134,8 +136,9 @@ static const char *task_state_array[] = 
8689         "D (disk sleep)",       /*  2 */
8690         "T (stopped)",          /*  4 */
8691         "T (tracing stop)",     /*  8 */
8692 -       "Z (zombie)",           /* 16 */
8693 -       "X (dead)"              /* 32 */
8694 +       "H (on hold)",          /* 16 */
8695 +       "Z (zombie)",           /* 32 */
8696 +       "X (dead)",             /* 64 */
8697  };
8698  
8699  static inline const char * get_task_state(struct task_struct *tsk)
8700 @@ -144,7 +147,8 @@ static inline const char * get_task_stat
8701                                             TASK_INTERRUPTIBLE |
8702                                             TASK_UNINTERRUPTIBLE |
8703                                             TASK_STOPPED |
8704 -                                           TASK_TRACED)) |
8705 +                                          TASK_TRACED |
8706 +                                          TASK_ONHOLD)) |
8707                         (tsk->exit_state & (EXIT_ZOMBIE |
8708                                             EXIT_DEAD));
8709         const char **p = &task_state_array[0];
8710 @@ -161,8 +165,16 @@ static inline char * task_state(struct t
8711         struct group_info *group_info;
8712         int g;
8713         struct fdtable *fdt = NULL;
8714 +       pid_t pid, ptgid, tppid, tgid;
8715  
8716         rcu_read_lock();
8717 +       tgid = vx_map_tgid(p->tgid);
8718 +       pid = vx_map_pid(p->pid);
8719 +       ptgid = vx_map_pid(pid_alive(p) ?
8720 +               rcu_dereference(p->real_parent)->tgid : 0);
8721 +       tppid = vx_map_pid(pid_alive(p) && p->ptrace ?
8722 +               rcu_dereference(p->parent)->pid : 0);
8723 +
8724         buffer += sprintf(buffer,
8725                 "State:\t%s\n"
8726                 "SleepAVG:\t%lu%%\n"
8727 @@ -174,9 +186,7 @@ static inline char * task_state(struct t
8728                 "Gid:\t%d\t%d\t%d\t%d\n",
8729                 get_task_state(p),
8730                 (p->sleep_avg/1024)*100/(1020000000/1024),
8731 -               p->tgid, p->pid,
8732 -               pid_alive(p) ? rcu_dereference(p->real_parent)->tgid : 0,
8733 -               pid_alive(p) && p->ptrace ? rcu_dereference(p->parent)->pid : 0,
8734 +               tgid, pid, (pid > 1) ? ptgid : 0, tppid,
8735                 p->uid, p->euid, p->suid, p->fsuid,
8736                 p->gid, p->egid, p->sgid, p->fsgid);
8737  
8738 @@ -283,12 +293,15 @@ static inline char * task_sig(struct tas
8739  
8740  static inline char *task_cap(struct task_struct *p, char *buffer)
8741  {
8742 -    return buffer + sprintf(buffer, "CapInh:\t%016x\n"
8743 -                           "CapPrm:\t%016x\n"
8744 -                           "CapEff:\t%016x\n",
8745 -                           cap_t(p->cap_inheritable),
8746 -                           cap_t(p->cap_permitted),
8747 -                           cap_t(p->cap_effective));
8748 +       struct vx_info *vxi = p->vx_info;
8749 +
8750 +       return buffer + sprintf(buffer,
8751 +               "CapInh:\t%016x\n"
8752 +               "CapPrm:\t%016x\n"
8753 +               "CapEff:\t%016x\n",
8754 +               (unsigned)vx_info_mbcap(vxi, p->cap_inheritable),
8755 +               (unsigned)vx_info_mbcap(vxi, p->cap_permitted),
8756 +               (unsigned)vx_info_mbcap(vxi, p->cap_effective));
8757  }
8758  
8759  int proc_pid_status(struct task_struct *task, char * buffer)
8760 @@ -306,6 +319,12 @@ int proc_pid_status(struct task_struct *
8761         buffer = task_sig(task, buffer);
8762         buffer = task_cap(task, buffer);
8763         buffer = cpuset_task_status_allowed(task, buffer);
8764 +
8765 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
8766 +               goto skip;
8767 +       buffer += sprintf (buffer,"VxID: %d\n", vx_task_xid(task));
8768 +       buffer += sprintf (buffer,"NxID: %d\n", nx_task_nid(task));
8769 +skip:
8770  #if defined(CONFIG_S390)
8771         buffer = task_show_regs(task, buffer);
8772  #endif
8773 @@ -320,7 +339,7 @@ static int do_task_stat(struct task_stru
8774         sigset_t sigign, sigcatch;
8775         char state;
8776         int res;
8777 -       pid_t ppid = 0, pgid = -1, sid = -1;
8778 +       pid_t pid = 0, ppid = 0, pgid = -1, sid = -1;
8779         int num_threads = 0;
8780         struct mm_struct *mm;
8781         unsigned long long start_time;
8782 @@ -382,8 +401,10 @@ static int do_task_stat(struct task_stru
8783                 }
8784  
8785                 sid = signal_session(sig);
8786 -               pgid = process_group(task);
8787 -               ppid = rcu_dereference(task->real_parent)->tgid;
8788 +               pid = vx_info_map_pid(task->vx_info, task->pid);
8789 +               pgid = vx_info_map_pid(task->vx_info, process_group(task));
8790 +               ppid = (pid > 1) ? vx_info_map_tgid(task->vx_info,
8791 +                       rcu_dereference(task->real_parent)->tgid) : 0;
8792  
8793                 unlock_task_sighand(task, &flags);
8794         }
8795 @@ -410,10 +431,21 @@ static int do_task_stat(struct task_stru
8796         /* convert nsec -> ticks */
8797         start_time = nsec_to_clock_t(start_time);
8798  
8799 +       /* fixup start time for virt uptime */
8800 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
8801 +               unsigned long long bias =
8802 +                       current->vx_info->cvirt.bias_clock;
8803 +
8804 +               if (start_time > bias)
8805 +                       start_time -= bias;
8806 +               else
8807 +                       start_time = 0;
8808 +       }
8809 +
8810         res = sprintf(buffer,"%d (%s) %c %d %d %d %d %d %u %lu \
8811  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
8812  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu\n",
8813 -               task->pid,
8814 +               pid,
8815                 tcomm,
8816                 state,
8817                 ppid,
8818 diff -Nurp linux-2.6.22.18/fs/proc/base.c linux-2.6.22.18-vs2.3.0.32/fs/proc/base.c
8819 --- linux-2.6.22.18/fs/proc/base.c      2007-07-22 00:00:18.000000000 +0200
8820 +++ linux-2.6.22.18-vs2.3.0.32/fs/proc/base.c   2008-02-11 12:35:35.000000000 +0100
8821 @@ -73,6 +73,9 @@
8822  #include <linux/poll.h>
8823  #include <linux/nsproxy.h>
8824  #include <linux/oom.h>
8825 +#include <linux/vs_context.h>
8826 +#include <linux/vs_network.h>
8827 +
8828  #include "internal.h"
8829  
8830  /* NOTE:
8831 @@ -1049,6 +1052,8 @@ static struct inode *proc_pid_make_inode
8832                 inode->i_uid = task->euid;
8833                 inode->i_gid = task->egid;
8834         }
8835 +       /* procfs is xid tagged */
8836 +       inode->i_tag = (tag_t)vx_task_xid(task);
8837         security_task_to_inode(task, inode);
8838  
8839  out:
8840 @@ -1082,6 +1087,8 @@ static int pid_getattr(struct vfsmount *
8841  
8842  /* dentry stuff */
8843  
8844 +static unsigned name_to_int(struct dentry *dentry);
8845 +
8846  /*
8847   *     Exceptional case: normally we are not allowed to unhash a busy
8848   * directory. In this case, however, we can do it - no aliasing problems
8849 @@ -1102,6 +1109,12 @@ static int pid_revalidate(struct dentry 
8850         struct inode *inode = dentry->d_inode;
8851         struct task_struct *task = get_proc_task(inode);
8852         if (task) {
8853 +               unsigned pid = name_to_int(dentry);
8854 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
8855 +                       put_task_struct(task);
8856 +                       goto drop;
8857 +               }
8858 +
8859                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
8860                     task_dumpable(task)) {
8861                         inode->i_uid = task->euid;
8862 @@ -1115,6 +1128,7 @@ static int pid_revalidate(struct dentry 
8863                 put_task_struct(task);
8864                 return 1;
8865         }
8866 +drop:
8867         d_drop(dentry);
8868         return 0;
8869  }
8870 @@ -1595,6 +1609,13 @@ static struct dentry *proc_pident_lookup
8871         if (!task)
8872                 goto out_no_task;
8873  
8874 +       /* TODO: maybe we can come up with a generic approach? */
8875 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
8876 +               (dentry->d_name.len == 5) &&
8877 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
8878 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
8879 +               goto out;
8880 +
8881         /*
8882          * Yes, it does not scale. And it should not. Don't add
8883          * new entries into /proc/<tgid>/ without very good reasons.
8884 @@ -1790,14 +1811,14 @@ static int proc_self_readlink(struct den
8885                               int buflen)
8886  {
8887         char tmp[PROC_NUMBUF];
8888 -       sprintf(tmp, "%d", current->tgid);
8889 +       sprintf(tmp, "%d", vx_map_tgid(current->tgid));
8890         return vfs_readlink(dentry,buffer,buflen,tmp);
8891  }
8892  
8893  static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
8894  {
8895         char tmp[PROC_NUMBUF];
8896 -       sprintf(tmp, "%d", current->tgid);
8897 +       sprintf(tmp, "%d", vx_map_tgid(current->tgid));
8898         return ERR_PTR(vfs_follow_link(nd,tmp));
8899  }
8900  
8901 @@ -1891,7 +1912,7 @@ out_iput:
8902  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
8903  {
8904         struct dentry *error;
8905 -       struct task_struct *task = get_proc_task(dir);
8906 +       struct task_struct *task = get_proc_task_real(dir);
8907         const struct pid_entry *p, *last;
8908  
8909         error = ERR_PTR(-ENOENT);
8910 @@ -1956,6 +1977,9 @@ static int proc_pid_io_accounting(struct
8911  static const struct file_operations proc_task_operations;
8912  static const struct inode_operations proc_task_inode_operations;
8913  
8914 +extern int proc_pid_vx_info(struct task_struct *, char *);
8915 +extern int proc_pid_nx_info(struct task_struct *, char *);
8916 +
8917  static const struct pid_entry tgid_base_stuff[] = {
8918         DIR("task",       S_IRUGO|S_IXUGO, task),
8919         DIR("fd",         S_IRUSR|S_IXUSR, fd),
8920 @@ -1995,6 +2019,8 @@ static const struct pid_entry tgid_base_
8921  #ifdef CONFIG_CPUSETS
8922         REG("cpuset",     S_IRUGO, cpuset),
8923  #endif
8924 +       INF("vinfo",      S_IRUGO, pid_vx_info),
8925 +       INF("ninfo",      S_IRUGO, pid_nx_info),
8926         INF("oom_score",  S_IRUGO, oom_score),
8927         REG("oom_adj",    S_IRUGO|S_IWUSR, oom_adjust),
8928  #ifdef CONFIG_AUDITSYSCALL
8929 @@ -2141,9 +2167,11 @@ struct dentry *proc_pid_lookup(struct in
8930         tgid = name_to_int(dentry);
8931         if (tgid == ~0U)
8932                 goto out;
8933 +       if (vx_current_initpid(tgid))
8934 +               goto out;
8935  
8936         rcu_read_lock();
8937 -       task = find_task_by_pid(tgid);
8938 +       task = vx_find_proc_task_by_pid(tgid);
8939         if (task)
8940                 get_task_struct(task);
8941         rcu_read_unlock();
8942 @@ -2198,7 +2226,7 @@ static int proc_pid_fill_cache(struct fi
8943         struct task_struct *task, int tgid)
8944  {
8945         char name[PROC_NUMBUF];
8946 -       int len = snprintf(name, sizeof(name), "%d", tgid);
8947 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(tgid));
8948         return proc_fill_cache(filp, dirent, filldir, name, len,
8949                                 proc_pid_instantiate, task, NULL);
8950  }
8951 @@ -2207,7 +2235,7 @@ static int proc_pid_fill_cache(struct fi
8952  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
8953  {
8954         unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
8955 -       struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
8956 +       struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
8957         struct task_struct *task;
8958         int tgid;
8959  
8960 @@ -2226,6 +2254,8 @@ int proc_pid_readdir(struct file * filp,
8961              put_task_struct(task), task = next_tgid(tgid + 1)) {
8962                 tgid = task->pid;
8963                 filp->f_pos = tgid + TGID_OFFSET;
8964 +               if (!vx_proc_task_visible(task))
8965 +                       continue;
8966                 if (proc_pid_fill_cache(filp, dirent, filldir, task, tgid) < 0) {
8967                         put_task_struct(task);
8968                         goto out;
8969 @@ -2352,9 +2382,11 @@ static struct dentry *proc_task_lookup(s
8970         tid = name_to_int(dentry);
8971         if (tid == ~0U)
8972                 goto out;
8973 +       if (vx_current_initpid(tid))
8974 +               goto out;
8975  
8976         rcu_read_lock();
8977 -       task = find_task_by_pid(tid);
8978 +       task = vx_find_proc_task_by_pid(tid);
8979         if (task)
8980                 get_task_struct(task);
8981         rcu_read_unlock();
8982 @@ -2499,7 +2531,7 @@ static int proc_task_readdir(struct file
8983         for (task = first_tid(leader, tid, pos - 2);
8984              task;
8985              task = next_tid(task), pos++) {
8986 -               tid = task->pid;
8987 +               tid = vx_map_pid(task->pid);
8988                 if (proc_task_fill_cache(filp, dirent, filldir, task, tid) < 0) {
8989                         /* returning this tgid failed, save it as the first
8990                          * pid for the next readir call */
8991 diff -Nurp linux-2.6.22.18/fs/proc/generic.c linux-2.6.22.18-vs2.3.0.32/fs/proc/generic.c
8992 --- linux-2.6.22.18/fs/proc/generic.c   2007-07-22 00:00:18.000000000 +0200
8993 +++ linux-2.6.22.18-vs2.3.0.32/fs/proc/generic.c        2008-02-11 12:35:35.000000000 +0100
8994 @@ -20,6 +20,7 @@
8995  #include <linux/namei.h>
8996  #include <linux/bitops.h>
8997  #include <linux/spinlock.h>
8998 +#include <linux/vserver/inode.h>
8999  #include <asm/uaccess.h>
9000  
9001  #include "internal.h"
9002 @@ -395,6 +396,8 @@ struct dentry *proc_lookup(struct inode 
9003                 for (de = de->subdir; de ; de = de->next) {
9004                         if (de->namelen != dentry->d_name.len)
9005                                 continue;
9006 +                       if (!vx_hide_check(0, de->vx_flags))
9007 +                               continue;
9008                         if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
9009                                 unsigned int ino = de->low_ino;
9010  
9011 @@ -402,6 +405,8 @@ struct dentry *proc_lookup(struct inode 
9012                                 spin_unlock(&proc_subdir_lock);
9013                                 error = -EINVAL;
9014                                 inode = proc_get_inode(dir->i_sb, ino, de);
9015 +                               /* generic proc entries belong to the host */
9016 +                               inode->i_tag = 0;
9017                                 spin_lock(&proc_subdir_lock);
9018                                 break;
9019                         }
9020 @@ -482,6 +487,8 @@ int proc_readdir(struct file * filp,
9021  
9022                                 /* filldir passes info to user space */
9023                                 de_get(de);
9024 +                               if (!vx_hide_check(0, de->vx_flags))
9025 +                                       goto skip;
9026                                 spin_unlock(&proc_subdir_lock);
9027                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
9028                                             de->low_ino, de->mode >> 12) < 0) {
9029 @@ -489,6 +496,7 @@ int proc_readdir(struct file * filp,
9030                                         goto out;
9031                                 }
9032                                 spin_lock(&proc_subdir_lock);
9033 +                       skip:
9034                                 filp->f_pos++;
9035                                 next = de->next;
9036                                 de_put(de);
9037 @@ -613,6 +621,7 @@ static struct proc_dir_entry *proc_creat
9038         ent->namelen = len;
9039         ent->mode = mode;
9040         ent->nlink = nlink;
9041 +       ent->vx_flags = IATTR_PROC_DEFAULT;
9042   out:
9043         return ent;
9044  }
9045 @@ -633,7 +642,8 @@ struct proc_dir_entry *proc_symlink(cons
9046                                 kfree(ent->data);
9047                                 kfree(ent);
9048                                 ent = NULL;
9049 -                       }
9050 +                       } else
9051 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
9052                 } else {
9053                         kfree(ent);
9054                         ent = NULL;
9055 diff -Nurp linux-2.6.22.18/fs/proc/inode.c linux-2.6.22.18-vs2.3.0.32/fs/proc/inode.c
9056 --- linux-2.6.22.18/fs/proc/inode.c     2007-07-22 00:00:18.000000000 +0200
9057 +++ linux-2.6.22.18-vs2.3.0.32/fs/proc/inode.c  2008-02-11 12:35:35.000000000 +0100
9058 @@ -160,6 +160,8 @@ struct inode *proc_get_inode(struct supe
9059                         inode->i_uid = de->uid;
9060                         inode->i_gid = de->gid;
9061                 }
9062 +               if (de->vx_flags)
9063 +                       PROC_I(inode)->vx_flags = de->vx_flags;
9064                 if (de->size)
9065                         inode->i_size = de->size;
9066                 if (de->nlink)
9067 diff -Nurp linux-2.6.22.18/fs/proc/internal.h linux-2.6.22.18-vs2.3.0.32/fs/proc/internal.h
9068 --- linux-2.6.22.18/fs/proc/internal.h  2007-07-22 00:00:18.000000000 +0200
9069 +++ linux-2.6.22.18-vs2.3.0.32/fs/proc/internal.h       2008-02-11 12:35:35.000000000 +0100
9070 @@ -10,6 +10,7 @@
9071   */
9072  
9073  #include <linux/proc_fs.h>
9074 +#include <linux/vs_pid.h>
9075  
9076  #ifdef CONFIG_PROC_SYSCTL
9077  extern int proc_sys_init(void);
9078 @@ -64,11 +65,16 @@ static inline struct pid *proc_pid(struc
9079         return PROC_I(inode)->pid;
9080  }
9081  
9082 -static inline struct task_struct *get_proc_task(struct inode *inode)
9083 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
9084  {
9085         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
9086  }
9087  
9088 +static inline struct task_struct *get_proc_task(struct inode *inode)
9089 +{
9090 +       return vx_get_proc_task(inode, proc_pid(inode));
9091 +}
9092 +
9093  static inline int proc_fd(struct inode *inode)
9094  {
9095         return PROC_I(inode)->fd;
9096 diff -Nurp linux-2.6.22.18/fs/proc/proc_misc.c linux-2.6.22.18-vs2.3.0.32/fs/proc/proc_misc.c
9097 --- linux-2.6.22.18/fs/proc/proc_misc.c 2007-07-22 00:00:18.000000000 +0200
9098 +++ linux-2.6.22.18-vs2.3.0.32/fs/proc/proc_misc.c      2008-02-11 12:35:35.000000000 +0100
9099 @@ -53,6 +53,8 @@
9100  #include <asm/div64.h>
9101  #include "internal.h"
9102  
9103 +#include <linux/vs_cvirt.h>
9104 +
9105  #define LOAD_INT(x) ((x) >> FSHIFT)
9106  #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
9107  /*
9108 @@ -82,17 +84,32 @@ static int proc_calc_metrics(char *page,
9109  static int loadavg_read_proc(char *page, char **start, off_t off,
9110                                  int count, int *eof, void *data)
9111  {
9112 +       unsigned int running, threads;
9113         int a, b, c;
9114         int len;
9115  
9116 -       a = avenrun[0] + (FIXED_1/200);
9117 -       b = avenrun[1] + (FIXED_1/200);
9118 -       c = avenrun[2] + (FIXED_1/200);
9119 -       len = sprintf(page,"%d.%02d %d.%02d %d.%02d %ld/%d %d\n",
9120 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
9121 +               struct vx_info *vxi = current->vx_info;
9122 +
9123 +               a = vxi->cvirt.load[0] + (FIXED_1/200);
9124 +               b = vxi->cvirt.load[1] + (FIXED_1/200);
9125 +               c = vxi->cvirt.load[2] + (FIXED_1/200);
9126 +
9127 +               running = atomic_read(&vxi->cvirt.nr_running);
9128 +               threads = atomic_read(&vxi->cvirt.nr_threads);
9129 +       } else {
9130 +               a = avenrun[0] + (FIXED_1/200);
9131 +               b = avenrun[1] + (FIXED_1/200);
9132 +               c = avenrun[2] + (FIXED_1/200);
9133 +
9134 +               running = nr_running();
9135 +               threads = nr_threads;
9136 +       }
9137 +       len = sprintf(page,"%d.%02d %d.%02d %d.%02d %d/%d %d\n",
9138                 LOAD_INT(a), LOAD_FRAC(a),
9139                 LOAD_INT(b), LOAD_FRAC(b),
9140                 LOAD_INT(c), LOAD_FRAC(c),
9141 -               nr_running(), nr_threads, current->nsproxy->pid_ns->last_pid);
9142 +               running, threads, current->nsproxy->pid_ns->last_pid);
9143         return proc_calc_metrics(page, start, off, count, eof, len);
9144  }
9145  
9146 @@ -106,6 +123,9 @@ static int uptime_read_proc(char *page, 
9147  
9148         do_posix_clock_monotonic_gettime(&uptime);
9149         cputime_to_timespec(idletime, &idle);
9150 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
9151 +               vx_vsi_uptime(&uptime, &idle);
9152 +
9153         len = sprintf(page,"%lu.%02lu %lu.%02lu\n",
9154                         (unsigned long) uptime.tv_sec,
9155                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
9156 @@ -137,7 +157,7 @@ static int meminfo_read_proc(char *page,
9157  
9158         cached = global_page_state(NR_FILE_PAGES) -
9159                         total_swapcache_pages - i.bufferram;
9160 -       if (cached < 0)
9161 +       if (cached < 0 || vx_flags(VXF_VIRT_MEM, 0))
9162                 cached = 0;
9163  
9164         get_vmalloc_info(&vmi);
9165 diff -Nurp linux-2.6.22.18/fs/proc/root.c linux-2.6.22.18-vs2.3.0.32/fs/proc/root.c
9166 --- linux-2.6.22.18/fs/proc/root.c      2007-07-21 23:58:48.000000000 +0200
9167 +++ linux-2.6.22.18-vs2.3.0.32/fs/proc/root.c   2008-02-11 12:35:35.000000000 +0100
9168 @@ -22,6 +22,9 @@
9169  #include "internal.h"
9170  
9171  struct proc_dir_entry *proc_net, *proc_net_stat, *proc_bus, *proc_root_fs, *proc_root_driver;
9172 +struct proc_dir_entry *proc_virtual;
9173 +
9174 +extern void proc_vx_init(void);
9175  
9176  static int proc_get_sb(struct file_system_type *fs_type,
9177         int flags, const char *dev_name, void *data, struct vfsmount *mnt)
9178 @@ -79,6 +82,7 @@ void __init proc_root_init(void)
9179         proc_device_tree_init();
9180  #endif
9181         proc_bus = proc_mkdir("bus", NULL);
9182 +       proc_vx_init();
9183         proc_sys_init();
9184  }
9185  
9186 diff -Nurp linux-2.6.22.18/fs/quota.c linux-2.6.22.18-vs2.3.0.32/fs/quota.c
9187 --- linux-2.6.22.18/fs/quota.c  2007-07-22 00:00:18.000000000 +0200
9188 +++ linux-2.6.22.18-vs2.3.0.32/fs/quota.c       2008-02-11 12:35:35.000000000 +0100
9189 @@ -16,6 +16,7 @@
9190  #include <linux/buffer_head.h>
9191  #include <linux/capability.h>
9192  #include <linux/quotaops.h>
9193 +#include <linux/vs_context.h>
9194  
9195  /* Check validity of generic quotactl commands */
9196  static int generic_quotactl_valid(struct super_block *sb, int type, int cmd, qid_t id)
9197 @@ -80,11 +81,11 @@ static int generic_quotactl_valid(struct
9198         if (cmd == Q_GETQUOTA) {
9199                 if (((type == USRQUOTA && current->euid != id) ||
9200                      (type == GRPQUOTA && !in_egroup_p(id))) &&
9201 -                   !capable(CAP_SYS_ADMIN))
9202 +                   !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9203                         return -EPERM;
9204         }
9205         else if (cmd != Q_GETFMT && cmd != Q_SYNC && cmd != Q_GETINFO)
9206 -               if (!capable(CAP_SYS_ADMIN))
9207 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9208                         return -EPERM;
9209  
9210         return 0;
9211 @@ -131,10 +132,10 @@ static int xqm_quotactl_valid(struct sup
9212         if (cmd == Q_XGETQUOTA) {
9213                 if (((type == XQM_USRQUOTA && current->euid != id) ||
9214                      (type == XQM_GRPQUOTA && !in_egroup_p(id))) &&
9215 -                    !capable(CAP_SYS_ADMIN))
9216 +                    !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9217                         return -EPERM;
9218         } else if (cmd != Q_XGETQSTAT && cmd != Q_XQUOTASYNC) {
9219 -               if (!capable(CAP_SYS_ADMIN))
9220 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9221                         return -EPERM;
9222         }
9223  
9224 @@ -327,6 +328,46 @@ static int do_quotactl(struct super_bloc
9225         return 0;
9226  }
9227  
9228 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
9229 +
9230 +#include <linux/vroot.h>
9231 +#include <linux/major.h>
9232 +#include <linux/module.h>
9233 +#include <linux/kallsyms.h>
9234 +#include <linux/vserver/debug.h>
9235 +
9236 +static vroot_grb_func *vroot_get_real_bdev = NULL;
9237 +
9238 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
9239 +
9240 +int register_vroot_grb(vroot_grb_func *func) {
9241 +       int ret = -EBUSY;
9242 +
9243 +       spin_lock(&vroot_grb_lock);
9244 +       if (!vroot_get_real_bdev) {
9245 +               vroot_get_real_bdev = func;
9246 +               ret = 0;
9247 +       }
9248 +       spin_unlock(&vroot_grb_lock);
9249 +       return ret;
9250 +}
9251 +EXPORT_SYMBOL(register_vroot_grb);
9252 +
9253 +int unregister_vroot_grb(vroot_grb_func *func) {
9254 +       int ret = -EINVAL;
9255 +
9256 +       spin_lock(&vroot_grb_lock);
9257 +       if (vroot_get_real_bdev) {
9258 +               vroot_get_real_bdev = NULL;
9259 +               ret = 0;
9260 +       }
9261 +       spin_unlock(&vroot_grb_lock);
9262 +       return ret;
9263 +}
9264 +EXPORT_SYMBOL(unregister_vroot_grb);
9265 +
9266 +#endif
9267 +
9268  /*
9269   * look up a superblock on which quota ops will be performed
9270   * - use the name of a block device to find the superblock thereon
9271 @@ -344,6 +385,22 @@ static inline struct super_block *quotac
9272         putname(tmp);
9273         if (IS_ERR(bdev))
9274                 return ERR_PTR(PTR_ERR(bdev));
9275 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
9276 +       if (bdev && bdev->bd_inode &&
9277 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
9278 +               struct block_device *bdnew = (void *)-EINVAL;
9279 +
9280 +               if (vroot_get_real_bdev)
9281 +                       bdnew = vroot_get_real_bdev(bdev);
9282 +               else
9283 +                       vxdprintk(VXD_CBIT(misc, 0),
9284 +                                       "vroot_get_real_bdev not set");
9285 +               bdput(bdev);
9286 +               if (IS_ERR(bdnew))
9287 +                       return ERR_PTR(PTR_ERR(bdnew));
9288 +               bdev = bdnew;
9289 +       }
9290 +#endif
9291         sb = get_super(bdev);
9292         bdput(bdev);
9293         if (!sb)
9294 diff -Nurp linux-2.6.22.18/fs/reiserfs/bitmap.c linux-2.6.22.18-vs2.3.0.32/fs/reiserfs/bitmap.c
9295 --- linux-2.6.22.18/fs/reiserfs/bitmap.c        2007-05-04 15:58:22.000000000 +0200
9296 +++ linux-2.6.22.18-vs2.3.0.32/fs/reiserfs/bitmap.c     2008-02-11 12:35:35.000000000 +0100
9297 @@ -13,6 +13,7 @@
9298  #include <linux/reiserfs_fs_sb.h>
9299  #include <linux/reiserfs_fs_i.h>
9300  #include <linux/quotaops.h>
9301 +#include <linux/vs_dlimit.h>
9302  
9303  #define PREALLOCATION_SIZE 9
9304  
9305 @@ -425,8 +426,10 @@ static void _reiserfs_free_block(struct 
9306         set_sb_free_blocks(rs, sb_free_blocks(rs) + 1);
9307  
9308         journal_mark_dirty(th, s, sbh);
9309 -       if (for_unformatted)
9310 +       if (for_unformatted) {
9311 +               DLIMIT_FREE_BLOCK(inode, 1);
9312                 DQUOT_FREE_BLOCK_NODIRTY(inode, 1);
9313 +       }
9314  }
9315  
9316  void reiserfs_free_block(struct reiserfs_transaction_handle *th,
9317 @@ -1034,6 +1037,7 @@ static inline int blocknrs_and_prealloc_
9318         b_blocknr_t finish = SB_BLOCK_COUNT(s) - 1;
9319         int passno = 0;
9320         int nr_allocated = 0;
9321 +       int blocks;
9322  
9323         determine_prealloc_size(hint);
9324         if (!hint->formatted_node) {
9325 @@ -1043,19 +1047,30 @@ static inline int blocknrs_and_prealloc_
9326                                "reiserquota: allocating %d blocks id=%u",
9327                                amount_needed, hint->inode->i_uid);
9328  #endif
9329 -               quota_ret =
9330 -                   DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode, amount_needed);
9331 -               if (quota_ret)  /* Quota exceeded? */
9332 +               quota_ret = DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode,
9333 +                       amount_needed);
9334 +               if (quota_ret)
9335                         return QUOTA_EXCEEDED;
9336 +               if (DLIMIT_ALLOC_BLOCK(hint->inode, amount_needed)) {
9337 +                       DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
9338 +                               amount_needed);
9339 +                       return NO_DISK_SPACE;
9340 +               }
9341 +
9342                 if (hint->preallocate && hint->prealloc_size) {
9343  #ifdef REISERQUOTA_DEBUG
9344                         reiserfs_debug(s, REISERFS_DEBUG_CODE,
9345                                        "reiserquota: allocating (prealloc) %d blocks id=%u",
9346                                        hint->prealloc_size, hint->inode->i_uid);
9347  #endif
9348 -                       quota_ret =
9349 -                           DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
9350 -                                                        hint->prealloc_size);
9351 +                       quota_ret = DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
9352 +                               hint->prealloc_size);
9353 +                       if (!quota_ret &&
9354 +                               DLIMIT_ALLOC_BLOCK(hint->inode, hint->prealloc_size)) {
9355 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
9356 +                                       hint->prealloc_size);
9357 +                               quota_ret = 1;
9358 +                       }
9359                         if (quota_ret)
9360                                 hint->preallocate = hint->prealloc_size = 0;
9361                 }
9362 @@ -1087,7 +1102,10 @@ static inline int blocknrs_and_prealloc_
9363                                                nr_allocated,
9364                                                hint->inode->i_uid);
9365  #endif
9366 -                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed + hint->prealloc_size - nr_allocated);      /* Free not allocated blocks */
9367 +                               /* Free not allocated blocks */
9368 +                               blocks = amount_needed + hint->prealloc_size - nr_allocated;
9369 +                               DLIMIT_FREE_BLOCK(hint->inode, blocks);
9370 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
9371                         }
9372                         while (nr_allocated--)
9373                                 reiserfs_free_block(hint->th, hint->inode,
9374 @@ -1118,10 +1136,10 @@ static inline int blocknrs_and_prealloc_
9375                                REISERFS_I(hint->inode)->i_prealloc_count,
9376                                hint->inode->i_uid);
9377  #endif
9378 -               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed +
9379 -                                        hint->prealloc_size - nr_allocated -
9380 -                                        REISERFS_I(hint->inode)->
9381 -                                        i_prealloc_count);
9382 +               blocks = amount_needed + hint->prealloc_size - nr_allocated -
9383 +                       REISERFS_I(hint->inode)->i_prealloc_count;
9384 +               DLIMIT_FREE_BLOCK(hint->inode, blocks);
9385 +               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
9386         }
9387  
9388         return CARRY_ON;
9389 diff -Nurp linux-2.6.22.18/fs/reiserfs/file.c linux-2.6.22.18-vs2.3.0.32/fs/reiserfs/file.c
9390 --- linux-2.6.22.18/fs/reiserfs/file.c  2007-07-22 00:00:18.000000000 +0200
9391 +++ linux-2.6.22.18-vs2.3.0.32/fs/reiserfs/file.c       2008-02-11 12:35:35.000000000 +0100
9392 @@ -1546,4 +1546,5 @@ const struct inode_operations reiserfs_f
9393         .listxattr = reiserfs_listxattr,
9394         .removexattr = reiserfs_removexattr,
9395         .permission = reiserfs_permission,
9396 +       .sync_flags = reiserfs_sync_flags,
9397  };
9398 diff -Nurp linux-2.6.22.18/fs/reiserfs/inode.c linux-2.6.22.18-vs2.3.0.32/fs/reiserfs/inode.c
9399 --- linux-2.6.22.18/fs/reiserfs/inode.c 2007-07-22 00:00:18.000000000 +0200
9400 +++ linux-2.6.22.18-vs2.3.0.32/fs/reiserfs/inode.c      2008-02-11 12:35:35.000000000 +0100
9401 @@ -16,6 +16,8 @@
9402  #include <linux/mpage.h>
9403  #include <linux/writeback.h>
9404  #include <linux/quotaops.h>
9405 +#include <linux/vs_dlimit.h>
9406 +#include <linux/vs_tag.h>
9407  
9408  static int reiserfs_commit_write(struct file *f, struct page *page,
9409                                  unsigned from, unsigned to);
9410 @@ -50,6 +52,7 @@ void reiserfs_delete_inode(struct inode 
9411                  * stat data deletion */
9412                 if (!err) 
9413                         DQUOT_FREE_INODE(inode);
9414 +               DLIMIT_FREE_INODE(inode);
9415  
9416                 if (journal_end(&th, inode->i_sb, jbegin_count))
9417                         goto out;
9418 @@ -1112,6 +1115,8 @@ static void init_inode(struct inode *ino
9419         struct buffer_head *bh;
9420         struct item_head *ih;
9421         __u32 rdev;
9422 +       uid_t uid;
9423 +       gid_t gid;
9424         //int version = ITEM_VERSION_1;
9425  
9426         bh = PATH_PLAST_BUFFER(path);
9427 @@ -1135,12 +1140,13 @@ static void init_inode(struct inode *ino
9428                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
9429                 unsigned long blocks;
9430  
9431 +               uid = sd_v1_uid(sd);
9432 +               gid = sd_v1_gid(sd);
9433 +
9434                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
9435                 set_inode_sd_version(inode, STAT_DATA_V1);
9436                 inode->i_mode = sd_v1_mode(sd);
9437                 inode->i_nlink = sd_v1_nlink(sd);
9438 -               inode->i_uid = sd_v1_uid(sd);
9439 -               inode->i_gid = sd_v1_gid(sd);
9440                 inode->i_size = sd_v1_size(sd);
9441                 inode->i_atime.tv_sec = sd_v1_atime(sd);
9442                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
9443 @@ -1182,11 +1188,12 @@ static void init_inode(struct inode *ino
9444                 // (directories and symlinks)
9445                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
9446  
9447 +               uid    = sd_v2_uid(sd);
9448 +               gid    = sd_v2_gid(sd);
9449 +
9450                 inode->i_mode = sd_v2_mode(sd);
9451                 inode->i_nlink = sd_v2_nlink(sd);
9452 -               inode->i_uid = sd_v2_uid(sd);
9453                 inode->i_size = sd_v2_size(sd);
9454 -               inode->i_gid = sd_v2_gid(sd);
9455                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
9456                 inode->i_atime.tv_sec = sd_v2_atime(sd);
9457                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
9458 @@ -1216,6 +1223,10 @@ static void init_inode(struct inode *ino
9459                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
9460         }
9461  
9462 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
9463 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
9464 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
9465 +
9466         pathrelse(path);
9467         if (S_ISREG(inode->i_mode)) {
9468                 inode->i_op = &reiserfs_file_inode_operations;
9469 @@ -1238,13 +1249,15 @@ static void init_inode(struct inode *ino
9470  static void inode2sd(void *sd, struct inode *inode, loff_t size)
9471  {
9472         struct stat_data *sd_v2 = (struct stat_data *)sd;
9473 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
9474 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
9475         __u16 flags;
9476  
9477 +       set_sd_v2_uid(sd_v2, uid);
9478 +       set_sd_v2_gid(sd_v2, gid);
9479         set_sd_v2_mode(sd_v2, inode->i_mode);
9480         set_sd_v2_nlink(sd_v2, inode->i_nlink);
9481 -       set_sd_v2_uid(sd_v2, inode->i_uid);
9482         set_sd_v2_size(sd_v2, size);
9483 -       set_sd_v2_gid(sd_v2, inode->i_gid);
9484         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
9485         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
9486         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
9487 @@ -1775,6 +1788,10 @@ int reiserfs_new_inode(struct reiserfs_t
9488  
9489         BUG_ON(!th->t_trans_id);
9490  
9491 +       if (DLIMIT_ALLOC_INODE(inode)) {
9492 +               err = -ENOSPC;
9493 +               goto out_bad_dlimit;
9494 +       }
9495         if (DQUOT_ALLOC_INODE(inode)) {
9496                 err = -EDQUOT;
9497                 goto out_end_trans;
9498 @@ -1960,6 +1977,9 @@ int reiserfs_new_inode(struct reiserfs_t
9499         DQUOT_FREE_INODE(inode);
9500  
9501        out_end_trans:
9502 +       DLIMIT_FREE_INODE(inode);
9503 +
9504 +      out_bad_dlimit:
9505         journal_end(th, th->t_super, th->t_blocks_allocated);
9506         /* Drop can be outside and it needs more credits so it's better to have it outside */
9507         DQUOT_DROP(inode);
9508 @@ -2690,6 +2710,14 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
9509                         inode->i_flags |= S_IMMUTABLE;
9510                 else
9511                         inode->i_flags &= ~S_IMMUTABLE;
9512 +               if (sd_attrs & REISERFS_IUNLINK_FL)
9513 +                       inode->i_flags |= S_IUNLINK;
9514 +               else
9515 +                       inode->i_flags &= ~S_IUNLINK;
9516 +               if (sd_attrs & REISERFS_BARRIER_FL)
9517 +                       inode->i_flags |= S_BARRIER;
9518 +               else
9519 +                       inode->i_flags &= ~S_BARRIER;
9520                 if (sd_attrs & REISERFS_APPEND_FL)
9521                         inode->i_flags |= S_APPEND;
9522                 else
9523 @@ -2712,6 +2740,14 @@ void i_attrs_to_sd_attrs(struct inode *i
9524                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
9525                 else
9526                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
9527 +               if (inode->i_flags & S_IUNLINK)
9528 +                       *sd_attrs |= REISERFS_IUNLINK_FL;
9529 +               else
9530 +                       *sd_attrs &= ~REISERFS_IUNLINK_FL;
9531 +               if (inode->i_flags & S_BARRIER)
9532 +                       *sd_attrs |= REISERFS_BARRIER_FL;
9533 +               else
9534 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
9535                 if (inode->i_flags & S_SYNC)
9536                         *sd_attrs |= REISERFS_SYNC_FL;
9537                 else
9538 @@ -2891,6 +2927,22 @@ static ssize_t reiserfs_direct_IO(int rw
9539                                   reiserfs_get_blocks_direct_io, NULL);
9540  }
9541  
9542 +int reiserfs_sync_flags(struct inode *inode)
9543 +{
9544 +       u16 oldflags, newflags;
9545 +
9546 +       oldflags = REISERFS_I(inode)->i_attrs;
9547 +       newflags = oldflags;
9548 +       i_attrs_to_sd_attrs(inode, &newflags);
9549 +
9550 +       if (oldflags ^ newflags) {
9551 +               REISERFS_I(inode)->i_attrs = newflags;
9552 +               inode->i_ctime = CURRENT_TIME_SEC;
9553 +               mark_inode_dirty(inode);
9554 +       }
9555 +       return 0;
9556 +}
9557 +
9558  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
9559  {
9560         struct inode *inode = dentry->d_inode;
9561 @@ -2940,9 +2992,11 @@ int reiserfs_setattr(struct dentry *dent
9562         }
9563  
9564         error = inode_change_ok(inode, attr);
9565 +
9566         if (!error) {
9567                 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
9568 -                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
9569 +                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
9570 +                   (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
9571                         error = reiserfs_chown_xattrs(inode, attr);
9572  
9573                         if (!error) {
9574 @@ -2972,6 +3026,9 @@ int reiserfs_setattr(struct dentry *dent
9575                                         inode->i_uid = attr->ia_uid;
9576                                 if (attr->ia_valid & ATTR_GID)
9577                                         inode->i_gid = attr->ia_gid;
9578 +                               if ((attr->ia_valid & ATTR_TAG) &&
9579 +                                       IS_TAGGED(inode))
9580 +                                       inode->i_tag = attr->ia_tag;
9581                                 mark_inode_dirty(inode);
9582                                 error =
9583                                     journal_end(&th, inode->i_sb, jbegin_count);
9584 diff -Nurp linux-2.6.22.18/fs/reiserfs/ioctl.c linux-2.6.22.18-vs2.3.0.32/fs/reiserfs/ioctl.c
9585 --- linux-2.6.22.18/fs/reiserfs/ioctl.c 2007-05-04 15:58:22.000000000 +0200
9586 +++ linux-2.6.22.18-vs2.3.0.32/fs/reiserfs/ioctl.c      2008-02-11 12:35:35.000000000 +0100
9587 @@ -6,6 +6,7 @@
9588  #include <linux/fs.h>
9589  #include <linux/reiserfs_fs.h>
9590  #include <linux/time.h>
9591 +#include <linux/mount.h>
9592  #include <asm/uaccess.h>
9593  #include <linux/pagemap.h>
9594  #include <linux/smp_lock.h>
9595 @@ -24,7 +25,7 @@ static int reiserfs_unpack(struct inode 
9596  int reiserfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
9597                    unsigned long arg)
9598  {
9599 -       unsigned int flags;
9600 +       unsigned int flags, oldflags;
9601  
9602         switch (cmd) {
9603         case REISERFS_IOC_UNPACK:
9604 @@ -43,12 +44,14 @@ int reiserfs_ioctl(struct inode *inode, 
9605  
9606                 flags = REISERFS_I(inode)->i_attrs;
9607                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
9608 +               flags &= REISERFS_FL_USER_VISIBLE;
9609                 return put_user(flags, (int __user *)arg);
9610         case REISERFS_IOC_SETFLAGS:{
9611                         if (!reiserfs_attrs(inode->i_sb))
9612                                 return -ENOTTY;
9613  
9614 -                       if (IS_RDONLY(inode))
9615 +                       if (IS_RDONLY(inode) ||
9616 +                               (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
9617                                 return -EROFS;
9618  
9619                         if ((current->fsuid != inode->i_uid)
9620 @@ -58,10 +61,12 @@ int reiserfs_ioctl(struct inode *inode, 
9621                         if (get_user(flags, (int __user *)arg))
9622                                 return -EFAULT;
9623  
9624 -                       if (((flags ^ REISERFS_I(inode)->
9625 -                             i_attrs) & (REISERFS_IMMUTABLE_FL |
9626 -                                         REISERFS_APPEND_FL))
9627 -                           && !capable(CAP_LINUX_IMMUTABLE))
9628 +                       oldflags = REISERFS_I(inode) -> i_attrs;
9629 +                       if (((oldflags & REISERFS_IMMUTABLE_FL) ||
9630 +                               ((flags ^ oldflags) &
9631 +                               (REISERFS_IMMUTABLE_FL | REISERFS_IUNLINK_FL |
9632 +                                REISERFS_APPEND_FL))) &&
9633 +                               !capable(CAP_LINUX_IMMUTABLE))
9634                                 return -EPERM;
9635  
9636                         if ((flags & REISERFS_NOTAIL_FL) &&
9637 @@ -72,6 +77,9 @@ int reiserfs_ioctl(struct inode *inode, 
9638                                 if (result)
9639                                         return result;
9640                         }
9641 +
9642 +                       flags = flags & REISERFS_FL_USER_MODIFIABLE;
9643 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
9644                         sd_attrs_to_i_attrs(flags, inode);
9645                         REISERFS_I(inode)->i_attrs = flags;
9646                         inode->i_ctime = CURRENT_TIME_SEC;
9647 @@ -83,7 +91,8 @@ int reiserfs_ioctl(struct inode *inode, 
9648         case REISERFS_IOC_SETVERSION:
9649                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
9650                         return -EPERM;
9651 -               if (IS_RDONLY(inode))
9652 +               if (IS_RDONLY(inode) ||
9653 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
9654                         return -EROFS;
9655                 if (get_user(inode->i_generation, (int __user *)arg))
9656                         return -EFAULT;
9657 diff -Nurp linux-2.6.22.18/fs/reiserfs/namei.c linux-2.6.22.18-vs2.3.0.32/fs/reiserfs/namei.c
9658 --- linux-2.6.22.18/fs/reiserfs/namei.c 2007-07-22 00:00:18.000000000 +0200
9659 +++ linux-2.6.22.18-vs2.3.0.32/fs/reiserfs/namei.c      2008-02-11 12:35:35.000000000 +0100
9660 @@ -17,6 +17,7 @@
9661  #include <linux/reiserfs_acl.h>
9662  #include <linux/reiserfs_xattr.h>
9663  #include <linux/quotaops.h>
9664 +#include <linux/vs_tag.h>
9665  
9666  #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; }
9667  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
9668 @@ -360,6 +361,7 @@ static struct dentry *reiserfs_lookup(st
9669                         reiserfs_write_unlock(dir->i_sb);
9670                         return ERR_PTR(-EACCES);
9671                 }
9672 +               dx_propagate_tag(nd, inode);
9673  
9674                 /* Propogate the priv_object flag so we know we're in the priv tree */
9675                 if (is_reiserfs_priv_object(dir))
9676 @@ -595,6 +597,7 @@ static int new_inode_init(struct inode *
9677         } else {
9678                 inode->i_gid = current->fsgid;
9679         }
9680 +       inode->i_tag = dx_current_fstag(inode->i_sb);
9681         DQUOT_INIT(inode);
9682         return 0;
9683  }
9684 @@ -1541,6 +1544,7 @@ const struct inode_operations reiserfs_d
9685         .listxattr = reiserfs_listxattr,
9686         .removexattr = reiserfs_removexattr,
9687         .permission = reiserfs_permission,
9688 +       .sync_flags = reiserfs_sync_flags,
9689  };
9690  
9691  /*
9692 @@ -1557,6 +1561,7 @@ const struct inode_operations reiserfs_s
9693         .listxattr = reiserfs_listxattr,
9694         .removexattr = reiserfs_removexattr,
9695         .permission = reiserfs_permission,
9696 +       .sync_flags = reiserfs_sync_flags,
9697  
9698  };
9699  
9700 @@ -1570,5 +1575,6 @@ const struct inode_operations reiserfs_s
9701         .listxattr = reiserfs_listxattr,
9702         .removexattr = reiserfs_removexattr,
9703         .permission = reiserfs_permission,
9704 +       .sync_flags = reiserfs_sync_flags,
9705  
9706  };
9707 diff -Nurp linux-2.6.22.18/fs/reiserfs/stree.c linux-2.6.22.18-vs2.3.0.32/fs/reiserfs/stree.c
9708 --- linux-2.6.22.18/fs/reiserfs/stree.c 2007-07-22 00:00:18.000000000 +0200
9709 +++ linux-2.6.22.18-vs2.3.0.32/fs/reiserfs/stree.c      2008-02-11 12:35:35.000000000 +0100
9710 @@ -55,6 +55,7 @@
9711  #include <linux/reiserfs_fs.h>
9712  #include <linux/buffer_head.h>
9713  #include <linux/quotaops.h>
9714 +#include <linux/vs_dlimit.h>
9715  
9716  /* Does the buffer contain a disk block which is in the tree. */
9717  inline int B_IS_IN_TREE(const struct buffer_head *p_s_bh)
9718 @@ -1296,6 +1297,7 @@ int reiserfs_delete_item(struct reiserfs
9719                        "reiserquota delete_item(): freeing %u, id=%u type=%c",
9720                        quota_cut_bytes, p_s_inode->i_uid, head2type(&s_ih));
9721  #endif
9722 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
9723         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
9724  
9725         /* Return deleted body length */
9726 @@ -1384,6 +1386,7 @@ void reiserfs_delete_solid_item(struct r
9727  #endif
9728                                 DQUOT_FREE_SPACE_NODIRTY(inode,
9729                                                          quota_cut_bytes);
9730 +                               DLIMIT_FREE_SPACE(inode, quota_cut_bytes);
9731                         }
9732                         break;
9733                 }
9734 @@ -1737,6 +1740,7 @@ int reiserfs_cut_from_item(struct reiser
9735                        "reiserquota cut_from_item(): freeing %u id=%u type=%c",
9736                        quota_cut_bytes, p_s_inode->i_uid, '?');
9737  #endif
9738 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
9739         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
9740         return n_ret_value;
9741  }
9742 @@ -1978,6 +1982,11 @@ int reiserfs_paste_into_item(struct reis
9743                 pathrelse(p_s_search_path);
9744                 return -EDQUOT;
9745         }
9746 +       if (DLIMIT_ALLOC_SPACE(inode, n_pasted_size)) {
9747 +               DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
9748 +               pathrelse(p_s_search_path);
9749 +               return -ENOSPC;
9750 +       }
9751         init_tb_struct(th, &s_paste_balance, th->t_super, p_s_search_path,
9752                        n_pasted_size);
9753  #ifdef DISPLACE_NEW_PACKING_LOCALITIES
9754 @@ -2030,6 +2039,7 @@ int reiserfs_paste_into_item(struct reis
9755                        n_pasted_size, inode->i_uid,
9756                        key2type(&(p_s_key->on_disk_key)));
9757  #endif
9758 +       DLIMIT_FREE_SPACE(inode, n_pasted_size);
9759         DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
9760         return retval;
9761  }
9762 @@ -2067,6 +2077,11 @@ int reiserfs_insert_item(struct reiserfs
9763                         pathrelse(p_s_path);
9764                         return -EDQUOT;
9765                 }
9766 +               if (DLIMIT_ALLOC_SPACE(inode, quota_bytes)) {
9767 +                       DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
9768 +                       pathrelse(p_s_path);
9769 +                       return -ENOSPC;
9770 +               }
9771         }
9772         init_tb_struct(th, &s_ins_balance, th->t_super, p_s_path,
9773                        IH_SIZE + ih_item_len(p_s_ih));
9774 @@ -2114,7 +2129,9 @@ int reiserfs_insert_item(struct reiserfs
9775                        "reiserquota insert_item(): freeing %u id=%u type=%c",
9776                        quota_bytes, inode->i_uid, head2type(p_s_ih));
9777  #endif
9778 -       if (inode)
9779 +       if (inode) {
9780 +               DLIMIT_FREE_SPACE(inode, quota_bytes);
9781                 DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
9782 +       }
9783         return retval;
9784  }
9785 diff -Nurp linux-2.6.22.18/fs/reiserfs/super.c linux-2.6.22.18-vs2.3.0.32/fs/reiserfs/super.c
9786 --- linux-2.6.22.18/fs/reiserfs/super.c 2007-07-22 00:00:18.000000000 +0200
9787 +++ linux-2.6.22.18-vs2.3.0.32/fs/reiserfs/super.c      2008-02-11 12:35:35.000000000 +0100
9788 @@ -882,6 +882,14 @@ static int reiserfs_parse_options(struct
9789                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
9790                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
9791  #endif
9792 +#ifndef CONFIG_TAGGING_NONE
9793 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
9794 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
9795 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
9796 +#endif
9797 +#ifdef CONFIG_PROPAGATE
9798 +               {"tag",.arg_required = 'T',.values = NULL},
9799 +#endif
9800  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
9801                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
9802                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
9803 @@ -1143,6 +1151,12 @@ static int reiserfs_remount(struct super
9804                 return -EINVAL;
9805         }
9806  
9807 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
9808 +               !(s->s_flags & MS_TAGGED)) {
9809 +               reiserfs_warning(s, "reiserfs: tagging not permitted on remount.");
9810 +               return -EINVAL;
9811 +       }
9812 +
9813         handle_attrs(s);
9814  
9815         /* Add options that are safe here */
9816 @@ -1591,6 +1605,10 @@ static int reiserfs_fill_super(struct su
9817                 goto error;
9818         }
9819  
9820 +       /* map mount option tagxid */
9821 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
9822 +               s->s_flags |= MS_TAGGED;
9823 +
9824         rs = SB_DISK_SUPER_BLOCK(s);
9825         /* Let's do basic sanity check to verify that underlying device is not
9826            smaller than the filesystem. If the check fails then abort and scream,
9827 diff -Nurp linux-2.6.22.18/fs/reiserfs/xattr.c linux-2.6.22.18-vs2.3.0.32/fs/reiserfs/xattr.c
9828 --- linux-2.6.22.18/fs/reiserfs/xattr.c 2007-07-22 00:00:18.000000000 +0200
9829 +++ linux-2.6.22.18-vs2.3.0.32/fs/reiserfs/xattr.c      2008-02-11 12:35:35.000000000 +0100
9830 @@ -35,6 +35,7 @@
9831  #include <linux/namei.h>
9832  #include <linux/errno.h>
9833  #include <linux/fs.h>
9834 +#include <linux/mount.h>
9835  #include <linux/file.h>
9836  #include <linux/pagemap.h>
9837  #include <linux/xattr.h>
9838 @@ -775,7 +776,7 @@ int reiserfs_delete_xattrs(struct inode 
9839         if (dir->d_inode->i_nlink <= 2) {
9840                 root = get_xa_root(inode->i_sb, XATTR_REPLACE);
9841                 reiserfs_write_lock_xattrs(inode->i_sb);
9842 -               err = vfs_rmdir(root->d_inode, dir);
9843 +               err = vfs_rmdir(root->d_inode, dir, NULL);
9844                 reiserfs_write_unlock_xattrs(inode->i_sb);
9845                 dput(root);
9846         } else {
9847 diff -Nurp linux-2.6.22.18/fs/stat.c linux-2.6.22.18-vs2.3.0.32/fs/stat.c
9848 --- linux-2.6.22.18/fs/stat.c   2007-07-22 00:00:18.000000000 +0200
9849 +++ linux-2.6.22.18-vs2.3.0.32/fs/stat.c        2008-02-11 12:35:35.000000000 +0100
9850 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
9851         stat->nlink = inode->i_nlink;
9852         stat->uid = inode->i_uid;
9853         stat->gid = inode->i_gid;
9854 +       stat->tag = inode->i_tag;
9855         stat->rdev = inode->i_rdev;
9856         stat->atime = inode->i_atime;
9857         stat->mtime = inode->i_mtime;
9858 diff -Nurp linux-2.6.22.18/fs/super.c linux-2.6.22.18-vs2.3.0.32/fs/super.c
9859 --- linux-2.6.22.18/fs/super.c  2007-07-22 00:00:18.000000000 +0200
9860 +++ linux-2.6.22.18-vs2.3.0.32/fs/super.c       2008-02-11 12:35:35.000000000 +0100
9861 @@ -37,6 +37,9 @@
9862  #include <linux/idr.h>
9863  #include <linux/kobject.h>
9864  #include <linux/mutex.h>
9865 +#include <linux/devpts_fs.h>
9866 +#include <linux/proc_fs.h>
9867 +#include <linux/vs_context.h>
9868  #include <asm/uaccess.h>
9869  
9870  
9871 @@ -860,12 +863,18 @@ struct vfsmount *
9872  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
9873  {
9874         struct vfsmount *mnt;
9875 +       struct super_block *sb;
9876         char *secdata = NULL;
9877         int error;
9878  
9879         if (!type)
9880                 return ERR_PTR(-ENODEV);
9881  
9882 +       error = -EPERM;
9883 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
9884 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
9885 +               goto out;
9886 +
9887         error = -ENOMEM;
9888         mnt = alloc_vfsmnt(name);
9889         if (!mnt)
9890 @@ -885,7 +894,14 @@ vfs_kern_mount(struct file_system_type *
9891         if (error < 0)
9892                 goto out_free_secdata;
9893  
9894 -       error = security_sb_kern_mount(mnt->mnt_sb, secdata);
9895 +       sb = mnt->mnt_sb;
9896 +       error = -EPERM;
9897 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
9898 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
9899 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
9900 +               goto out_sb;
9901 +
9902 +       error = security_sb_kern_mount(sb, secdata);
9903         if (error)
9904                 goto out_sb;
9905  
9906 diff -Nurp linux-2.6.22.18/fs/sysfs/mount.c linux-2.6.22.18-vs2.3.0.32/fs/sysfs/mount.c
9907 --- linux-2.6.22.18/fs/sysfs/mount.c    2007-07-22 00:00:18.000000000 +0200
9908 +++ linux-2.6.22.18-vs2.3.0.32/fs/sysfs/mount.c 2008-02-11 12:35:35.000000000 +0100
9909 @@ -12,8 +12,6 @@
9910  
9911  #include "sysfs.h"
9912  
9913 -/* Random magic number */
9914 -#define SYSFS_MAGIC 0x62656572
9915  
9916  struct vfsmount *sysfs_mount;
9917  struct super_block * sysfs_sb = NULL;
9918 @@ -48,7 +46,7 @@ static int sysfs_fill_super(struct super
9919  
9920         sb->s_blocksize = PAGE_CACHE_SIZE;
9921         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
9922 -       sb->s_magic = SYSFS_MAGIC;
9923 +       sb->s_magic = SYSFS_SUPER_MAGIC;
9924         sb->s_op = &sysfs_ops;
9925         sb->s_time_gran = 1;
9926         sysfs_sb = sb;
9927 diff -Nurp linux-2.6.22.18/fs/utimes.c linux-2.6.22.18-vs2.3.0.32/fs/utimes.c
9928 --- linux-2.6.22.18/fs/utimes.c 2007-07-22 00:00:18.000000000 +0200
9929 +++ linux-2.6.22.18-vs2.3.0.32/fs/utimes.c      2008-02-11 12:35:35.000000000 +0100
9930 @@ -6,6 +6,8 @@
9931  #include <linux/sched.h>
9932  #include <linux/stat.h>
9933  #include <linux/utime.h>
9934 +#include <linux/mount.h>
9935 +#include <linux/vs_cowbl.h>
9936  #include <asm/uaccess.h>
9937  #include <asm/unistd.h>
9938  
9939 @@ -70,11 +72,13 @@ long do_utimes(int dfd, char __user *fil
9940                 if (error)
9941                         goto out;
9942  
9943 +               error = cow_check_and_break(&nd);
9944 +               if (error)
9945 +                       goto dput_and_out;
9946                 dentry = nd.dentry;
9947         }
9948  
9949         inode = dentry->d_inode;
9950 -
9951         error = -EROFS;
9952         if (IS_RDONLY(inode))
9953                 goto dput_and_out;
9954 diff -Nurp linux-2.6.22.18/fs/xattr.c linux-2.6.22.18-vs2.3.0.32/fs/xattr.c
9955 --- linux-2.6.22.18/fs/xattr.c  2007-07-22 00:00:18.000000000 +0200
9956 +++ linux-2.6.22.18-vs2.3.0.32/fs/xattr.c       2008-02-11 12:35:35.000000000 +0100
9957 @@ -17,6 +17,7 @@
9958  #include <linux/module.h>
9959  #include <linux/fsnotify.h>
9960  #include <linux/audit.h>
9961 +#include <linux/mount.h>
9962  #include <asm/uaccess.h>
9963  
9964  
9965 @@ -194,7 +195,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
9966   */
9967  static long
9968  setxattr(struct dentry *d, char __user *name, void __user *value,
9969 -        size_t size, int flags)
9970 +        size_t size, int flags, struct vfsmount *mnt)
9971  {
9972         int error;
9973         void *kvalue = NULL;
9974 @@ -221,6 +222,9 @@ setxattr(struct dentry *d, char __user *
9975                 }
9976         }
9977  
9978 +       if (MNT_IS_RDONLY(mnt))
9979 +               return -EROFS;
9980 +
9981         error = vfs_setxattr(d, kname, kvalue, size, flags);
9982         kfree(kvalue);
9983         return error;
9984 @@ -236,7 +240,7 @@ sys_setxattr(char __user *path, char __u
9985         error = user_path_walk(path, &nd);
9986         if (error)
9987                 return error;
9988 -       error = setxattr(nd.dentry, name, value, size, flags);
9989 +       error = setxattr(nd.dentry, name, value, size, flags, nd.mnt);
9990         path_release(&nd);
9991         return error;
9992  }
9993 @@ -251,7 +255,7 @@ sys_lsetxattr(char __user *path, char __
9994         error = user_path_walk_link(path, &nd);
9995         if (error)
9996                 return error;
9997 -       error = setxattr(nd.dentry, name, value, size, flags);
9998 +       error = setxattr(nd.dentry, name, value, size, flags, nd.mnt);
9999         path_release(&nd);
10000         return error;
10001  }
10002 @@ -269,7 +273,7 @@ sys_fsetxattr(int fd, char __user *name,
10003                 return error;
10004         dentry = f->f_path.dentry;
10005         audit_inode(NULL, dentry->d_inode);
10006 -       error = setxattr(dentry, name, value, size, flags);
10007 +       error = setxattr(dentry, name, value, size, flags, f->f_vfsmnt);
10008         fput(f);
10009         return error;
10010  }
10011 @@ -433,7 +437,7 @@ sys_flistxattr(int fd, char __user *list
10012   * Extended attribute REMOVE operations
10013   */
10014  static long
10015 -removexattr(struct dentry *d, char __user *name)
10016 +removexattr(struct dentry *d, char __user *name, struct vfsmount *mnt)
10017  {
10018         int error;
10019         char kname[XATTR_NAME_MAX + 1];
10020 @@ -444,6 +448,9 @@ removexattr(struct dentry *d, char __use
10021         if (error < 0)
10022                 return error;
10023  
10024 +       if (MNT_IS_RDONLY(mnt))
10025 +               return -EROFS;
10026 +
10027         return vfs_removexattr(d, kname);
10028  }
10029  
10030 @@ -456,7 +463,7 @@ sys_removexattr(char __user *path, char 
10031         error = user_path_walk(path, &nd);
10032         if (error)
10033                 return error;
10034 -       error = removexattr(nd.dentry, name);
10035 +       error = removexattr(nd.dentry, name, nd.mnt);
10036         path_release(&nd);
10037         return error;
10038  }
10039 @@ -470,7 +477,7 @@ sys_lremovexattr(char __user *path, char
10040         error = user_path_walk_link(path, &nd);
10041         if (error)
10042                 return error;
10043 -       error = removexattr(nd.dentry, name);
10044 +       error = removexattr(nd.dentry, name, nd.mnt);
10045         path_release(&nd);
10046         return error;
10047  }
10048 @@ -487,7 +494,7 @@ sys_fremovexattr(int fd, char __user *na
10049                 return error;
10050         dentry = f->f_path.dentry;
10051         audit_inode(NULL, dentry->d_inode);
10052 -       error = removexattr(dentry, name);
10053 +       error = removexattr(dentry, name, f->f_vfsmnt);
10054         fput(f);
10055         return error;
10056  }
10057 diff -Nurp linux-2.6.22.18/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.22.18-vs2.3.0.32/fs/xfs/linux-2.6/xfs_ioctl.c
10058 --- linux-2.6.22.18/fs/xfs/linux-2.6/xfs_ioctl.c        2007-07-21 23:58:49.000000000 +0200
10059 +++ linux-2.6.22.18-vs2.3.0.32/fs/xfs/linux-2.6/xfs_ioctl.c     2008-02-11 12:35:35.000000000 +0100
10060 @@ -1128,6 +1128,10 @@ xfs_di2lxflags(
10061  
10062         if (di_flags & XFS_DIFLAG_IMMUTABLE)
10063                 flags |= FS_IMMUTABLE_FL;
10064 +       if (di_flags & XFS_DIFLAG_IUNLINK)
10065 +               flags |= FS_IUNLINK_FL;
10066 +       if (di_flags & XFS_DIFLAG_BARRIER)
10067 +               flags |= FS_BARRIER_FL;
10068         if (di_flags & XFS_DIFLAG_APPEND)
10069                 flags |= FS_APPEND_FL;
10070         if (di_flags & XFS_DIFLAG_SYNC)
10071 diff -Nurp linux-2.6.22.18/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.22.18-vs2.3.0.32/fs/xfs/linux-2.6/xfs_iops.c
10072 --- linux-2.6.22.18/fs/xfs/linux-2.6/xfs_iops.c 2007-07-21 23:58:49.000000000 +0200
10073 +++ linux-2.6.22.18-vs2.3.0.32/fs/xfs/linux-2.6/xfs_iops.c      2008-02-11 12:35:35.000000000 +0100
10074 @@ -51,6 +51,7 @@
10075  #include <linux/xattr.h>
10076  #include <linux/namei.h>
10077  #include <linux/security.h>
10078 +#include <linux/vs_tag.h>
10079  
10080  /*
10081   * Get a XFS inode from a given vnode.
10082 @@ -400,6 +401,7 @@ xfs_vn_lookup(
10083                 d_add(dentry, NULL);
10084                 return NULL;
10085         }
10086 +       dx_propagate_tag(nd, vn_to_inode(cvp));
10087  
10088         return d_splice_alias(vn_to_inode(cvp), dentry);
10089  }
10090 @@ -657,6 +659,10 @@ xfs_vn_setattr(
10091         int             flags = 0;
10092         int             error;
10093  
10094 +       error = inode_change_ok(inode, attr);
10095 +       if (error)
10096 +               return error;
10097 +
10098         if (ia_valid & ATTR_UID) {
10099                 vattr.va_mask |= XFS_AT_UID;
10100                 vattr.va_uid = attr->ia_uid;
10101 @@ -665,6 +671,10 @@ xfs_vn_setattr(
10102                 vattr.va_mask |= XFS_AT_GID;
10103                 vattr.va_gid = attr->ia_gid;
10104         }
10105 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode)) {
10106 +               vattr.va_mask |= XFS_AT_TAG;
10107 +               vattr.va_tag = attr->ia_tag;
10108 +       }
10109         if (ia_valid & ATTR_SIZE) {
10110                 vattr.va_mask |= XFS_AT_SIZE;
10111                 vattr.va_size = attr->ia_size;
10112 @@ -710,6 +720,42 @@ xfs_vn_truncate(
10113  }
10114  
10115  STATIC int
10116 +xfs_vn_sync_flags(struct inode *inode)
10117 +{
10118 +       unsigned int oldflags, newflags;
10119 +       int             flags = 0;
10120 +       int             error;
10121 +       bhv_vattr_t     vattr;
10122 +       bhv_vnode_t     *vp = vn_from_inode(inode);
10123 +
10124 +       memset(&vattr, 0, sizeof vattr);
10125 +
10126 +       vattr.va_mask = XFS_AT_XFLAGS;
10127 +       error = bhv_vop_getattr(vp, &vattr, 0, NULL);
10128 +
10129 +       if (error)
10130 +               return error;
10131 +       oldflags = vattr.va_xflags;
10132 +       newflags = oldflags & ~(XFS_XFLAG_IMMUTABLE |
10133 +               XFS_XFLAG_IUNLINK | XFS_XFLAG_BARRIER);
10134 +
10135 +       if (IS_IMMUTABLE(inode))
10136 +               newflags |= XFS_XFLAG_IMMUTABLE;
10137 +       if (IS_IUNLINK(inode))
10138 +               newflags |= XFS_XFLAG_IUNLINK;
10139 +       if (IS_BARRIER(inode))
10140 +               newflags |= XFS_XFLAG_BARRIER;
10141 +
10142 +       if (oldflags ^ newflags) {
10143 +               vattr.va_xflags = newflags;
10144 +               vattr.va_mask |= XFS_AT_XFLAGS;
10145 +               error = bhv_vop_setattr(vp, &vattr, flags, NULL);
10146 +       }
10147 +       vn_revalidate(vp);
10148 +       return error;
10149 +}
10150 +
10151 +STATIC int
10152  xfs_vn_setxattr(
10153         struct dentry   *dentry,
10154         const char      *name,
10155 @@ -822,6 +868,7 @@ const struct inode_operations xfs_inode_
10156         .getxattr               = xfs_vn_getxattr,
10157         .listxattr              = xfs_vn_listxattr,
10158         .removexattr            = xfs_vn_removexattr,
10159 +       .sync_flags             = xfs_vn_sync_flags,
10160  };
10161  
10162  const struct inode_operations xfs_dir_inode_operations = {
10163 @@ -841,6 +888,7 @@ const struct inode_operations xfs_dir_in
10164         .getxattr               = xfs_vn_getxattr,
10165         .listxattr              = xfs_vn_listxattr,
10166         .removexattr            = xfs_vn_removexattr,
10167 +       .sync_flags             = xfs_vn_sync_flags,
10168  };
10169  
10170  const struct inode_operations xfs_symlink_inode_operations = {
10171 @@ -854,4 +902,5 @@ const struct inode_operations xfs_symlin
10172         .getxattr               = xfs_vn_getxattr,
10173         .listxattr              = xfs_vn_listxattr,
10174         .removexattr            = xfs_vn_removexattr,
10175 +       .sync_flags             = xfs_vn_sync_flags,
10176  };
10177 diff -Nurp linux-2.6.22.18/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.22.18-vs2.3.0.32/fs/xfs/linux-2.6/xfs_linux.h
10178 --- linux-2.6.22.18/fs/xfs/linux-2.6/xfs_linux.h        2007-07-21 23:58:49.000000000 +0200
10179 +++ linux-2.6.22.18-vs2.3.0.32/fs/xfs/linux-2.6/xfs_linux.h     2008-02-11 12:35:35.000000000 +0100
10180 @@ -129,6 +129,7 @@
10181  #define current_pid()          (current->pid)
10182  #define current_fsuid(cred)    (current->fsuid)
10183  #define current_fsgid(cred)    (current->fsgid)
10184 +#define current_fstag(cred,vp) (dx_current_fstag(vn_to_inode(vp)->i_sb))
10185  #define current_test_flags(f)  (current->flags & (f))
10186  #define current_set_flags_nested(sp, f)                \
10187                 (*(sp) = current->flags, current->flags |= (f))
10188 diff -Nurp linux-2.6.22.18/fs/xfs/linux-2.6/xfs_super.c linux-2.6.22.18-vs2.3.0.32/fs/xfs/linux-2.6/xfs_super.c
10189 --- linux-2.6.22.18/fs/xfs/linux-2.6/xfs_super.c        2007-07-22 00:00:18.000000000 +0200
10190 +++ linux-2.6.22.18-vs2.3.0.32/fs/xfs/linux-2.6/xfs_super.c     2008-02-11 12:35:35.000000000 +0100
10191 @@ -157,6 +157,7 @@ xfs_revalidate_inode(
10192         inode->i_nlink  = ip->i_d.di_nlink;
10193         inode->i_uid    = ip->i_d.di_uid;
10194         inode->i_gid    = ip->i_d.di_gid;
10195 +       inode->i_tag    = ip->i_d.di_tag;
10196  
10197         switch (inode->i_mode & S_IFMT) {
10198         case S_IFBLK:
10199 @@ -184,6 +185,14 @@ xfs_revalidate_inode(
10200                 inode->i_flags |= S_IMMUTABLE;
10201         else
10202                 inode->i_flags &= ~S_IMMUTABLE;
10203 +       if (ip->i_d.di_flags & XFS_DIFLAG_IUNLINK)
10204 +               inode->i_flags |= S_IUNLINK;
10205 +       else
10206 +               inode->i_flags &= ~S_IUNLINK;
10207 +       if (ip->i_d.di_flags & XFS_DIFLAG_BARRIER)
10208 +               inode->i_flags |= S_BARRIER;
10209 +       else
10210 +               inode->i_flags &= ~S_BARRIER;
10211         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
10212                 inode->i_flags |= S_APPEND;
10213         else
10214 @@ -712,6 +721,12 @@ xfs_fs_remount(
10215         int                     error;
10216  
10217         error = bhv_vfs_parseargs(vfsp, options, args, 1);
10218 +       if ((args->flags2 & XFSMNT2_TAGGED) &&
10219 +               !(sb->s_flags & MS_TAGGED)) {
10220 +               printk("XFS: %s: tagging not permitted on remount.\n",
10221 +                       sb->s_id);
10222 +               error = EINVAL;
10223 +       }
10224         if (!error)
10225                 error = bhv_vfs_mntupdate(vfsp, flags, args);
10226         kmem_free(args, sizeof(*args));
10227 diff -Nurp linux-2.6.22.18/fs/xfs/linux-2.6/xfs_vnode.c linux-2.6.22.18-vs2.3.0.32/fs/xfs/linux-2.6/xfs_vnode.c
10228 --- linux-2.6.22.18/fs/xfs/linux-2.6/xfs_vnode.c        2007-07-21 23:58:49.000000000 +0200
10229 +++ linux-2.6.22.18-vs2.3.0.32/fs/xfs/linux-2.6/xfs_vnode.c     2008-02-11 12:35:35.000000000 +0100
10230 @@ -119,6 +119,7 @@ vn_revalidate_core(
10231         inode->i_nlink      = vap->va_nlink;
10232         inode->i_uid        = vap->va_uid;
10233         inode->i_gid        = vap->va_gid;
10234 +       inode->i_tag        = vap->va_tag;
10235         inode->i_blocks     = vap->va_nblocks;
10236         inode->i_mtime      = vap->va_mtime;
10237         inode->i_ctime      = vap->va_ctime;
10238 @@ -126,6 +127,14 @@ vn_revalidate_core(
10239                 inode->i_flags |= S_IMMUTABLE;
10240         else
10241                 inode->i_flags &= ~S_IMMUTABLE;
10242 +       if (vap->va_xflags & XFS_XFLAG_IUNLINK)
10243 +               inode->i_flags |= S_IUNLINK;
10244 +       else
10245 +               inode->i_flags &= ~S_IUNLINK;
10246 +       if (vap->va_xflags & XFS_XFLAG_BARRIER)
10247 +               inode->i_flags |= S_BARRIER;
10248 +       else
10249 +               inode->i_flags &= ~S_BARRIER;
10250         if (vap->va_xflags & XFS_XFLAG_APPEND)
10251                 inode->i_flags |= S_APPEND;
10252         else
10253 diff -Nurp linux-2.6.22.18/fs/xfs/linux-2.6/xfs_vnode.h linux-2.6.22.18-vs2.3.0.32/fs/xfs/linux-2.6/xfs_vnode.h
10254 --- linux-2.6.22.18/fs/xfs/linux-2.6/xfs_vnode.h        2007-07-22 00:00:18.000000000 +0200
10255 +++ linux-2.6.22.18-vs2.3.0.32/fs/xfs/linux-2.6/xfs_vnode.h     2008-02-11 12:35:35.000000000 +0100
10256 @@ -350,6 +350,7 @@ typedef struct bhv_vattr {
10257         xfs_nlink_t     va_nlink;       /* number of references to file */
10258         uid_t           va_uid;         /* owner user id */
10259         gid_t           va_gid;         /* owner group id */
10260 +       tag_t           va_tag;         /* owner group id */
10261         xfs_ino_t       va_nodeid;      /* file id */
10262         xfs_off_t       va_size;        /* file size in bytes */
10263         u_long          va_blocksize;   /* blocksize preferred for i/o */
10264 @@ -398,13 +399,15 @@ typedef struct bhv_vattr {
10265  #define XFS_AT_PROJID          0x04000000
10266  #define XFS_AT_SIZE_NOPERM     0x08000000
10267  #define XFS_AT_GENCOUNT                0x10000000
10268 +#define XFS_AT_TAG             0x20000000
10269  
10270  #define XFS_AT_ALL     (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
10271                 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
10272                 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
10273                 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|XFS_AT_MAC|\
10274                 XFS_AT_ACL|XFS_AT_CAP|XFS_AT_INF|XFS_AT_XFLAGS|XFS_AT_EXTSIZE|\
10275 -               XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_PROJID|XFS_AT_GENCOUNT)
10276 +               XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_PROJID|XFS_AT_GENCOUNT\
10277 +               XFS_AT_TAG)
10278  
10279  #define XFS_AT_STAT    (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
10280                 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
10281 diff -Nurp linux-2.6.22.18/fs/xfs/quota/xfs_qm_syscalls.c linux-2.6.22.18-vs2.3.0.32/fs/xfs/quota/xfs_qm_syscalls.c
10282 --- linux-2.6.22.18/fs/xfs/quota/xfs_qm_syscalls.c      2007-07-22 00:00:18.000000000 +0200
10283 +++ linux-2.6.22.18-vs2.3.0.32/fs/xfs/quota/xfs_qm_syscalls.c   2008-02-11 12:35:35.000000000 +0100
10284 @@ -17,6 +17,7 @@
10285   */
10286  
10287  #include <linux/capability.h>
10288 +#include <linux/vs_context.h>
10289  
10290  #include "xfs.h"
10291  #include "xfs_fs.h"
10292 @@ -211,7 +212,7 @@ xfs_qm_scall_quotaoff(
10293         xfs_qoff_logitem_t      *qoffstart;
10294         int                     nculprits;
10295  
10296 -       if (!force && !capable(CAP_SYS_ADMIN))
10297 +       if (!force && !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
10298                 return XFS_ERROR(EPERM);
10299         /*
10300          * No file system can have quotas enabled on disk but not in core.
10301 @@ -380,7 +381,7 @@ xfs_qm_scall_trunc_qfiles(
10302         int             error;
10303         xfs_inode_t     *qip;
10304  
10305 -       if (!capable(CAP_SYS_ADMIN))
10306 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
10307                 return XFS_ERROR(EPERM);
10308         error = 0;
10309         if (!XFS_SB_VERSION_HASQUOTA(&mp->m_sb) || flags == 0) {
10310 @@ -425,7 +426,7 @@ xfs_qm_scall_quotaon(
10311         uint            accflags;
10312         __int64_t       sbflags;
10313  
10314 -       if (!capable(CAP_SYS_ADMIN))
10315 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
10316                 return XFS_ERROR(EPERM);
10317  
10318         flags &= (XFS_ALL_QUOTA_ACCT | XFS_ALL_QUOTA_ENFD);
10319 @@ -594,7 +595,7 @@ xfs_qm_scall_setqlim(
10320         int                     error;
10321         xfs_qcnt_t              hard, soft;
10322  
10323 -       if (!capable(CAP_SYS_ADMIN))
10324 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
10325                 return XFS_ERROR(EPERM);
10326  
10327         if ((newlim->d_fieldmask &
10328 diff -Nurp linux-2.6.22.18/fs/xfs/xfs_clnt.h linux-2.6.22.18-vs2.3.0.32/fs/xfs/xfs_clnt.h
10329 --- linux-2.6.22.18/fs/xfs/xfs_clnt.h   2006-06-18 03:49:35.000000000 +0200
10330 +++ linux-2.6.22.18-vs2.3.0.32/fs/xfs/xfs_clnt.h        2008-02-11 12:35:35.000000000 +0100
10331 @@ -99,5 +99,7 @@ struct xfs_mount_args {
10332   */
10333  #define XFSMNT2_COMPAT_IOSIZE  0x00000001      /* don't report large preferred
10334                                                  * I/O size in stat(2) */
10335 +#define XFSMNT2_TAGGED         0x80000000      /* context tagging */
10336 +
10337  
10338  #endif /* __XFS_CLNT_H__ */
10339 diff -Nurp linux-2.6.22.18/fs/xfs/xfs_dinode.h linux-2.6.22.18-vs2.3.0.32/fs/xfs/xfs_dinode.h
10340 --- linux-2.6.22.18/fs/xfs/xfs_dinode.h 2007-05-04 15:55:41.000000000 +0200
10341 +++ linux-2.6.22.18-vs2.3.0.32/fs/xfs/xfs_dinode.h      2008-02-11 12:35:35.000000000 +0100
10342 @@ -53,7 +53,8 @@ typedef struct xfs_dinode_core
10343         __uint32_t      di_gid;         /* owner's group id */
10344         __uint32_t      di_nlink;       /* number of links to file */
10345         __uint16_t      di_projid;      /* owner's project id */
10346 -       __uint8_t       di_pad[8];      /* unused, zeroed space */
10347 +       __uint16_t      di_tag;         /* context tagging */
10348 +       __uint8_t       di_pad[6];      /* unused, zeroed space */
10349         __uint16_t      di_flushiter;   /* incremented on flush */
10350         xfs_timestamp_t di_atime;       /* time last accessed */
10351         xfs_timestamp_t di_mtime;       /* time last modified */
10352 @@ -257,6 +258,9 @@ typedef enum xfs_dinode_fmt
10353  #define XFS_DIFLAG_EXTSIZE_BIT      11 /* inode extent size allocator hint */
10354  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
10355  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
10356 +#define XFS_DIFLAG_BARRIER_BIT 14      /* chroot() barrier */
10357 +#define XFS_DIFLAG_IUNLINK_BIT 15      /* immutable unlink */
10358 +
10359  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
10360  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
10361  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
10362 @@ -271,12 +275,15 @@ typedef enum xfs_dinode_fmt
10363  #define XFS_DIFLAG_EXTSIZE       (1 << XFS_DIFLAG_EXTSIZE_BIT)
10364  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
10365  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
10366 +#define XFS_DIFLAG_BARRIER      (1 << XFS_DIFLAG_BARRIER_BIT)
10367 +#define XFS_DIFLAG_IUNLINK      (1 << XFS_DIFLAG_IUNLINK_BIT)
10368  
10369  #define XFS_DIFLAG_ANY \
10370         (XFS_DIFLAG_REALTIME | XFS_DIFLAG_PREALLOC | XFS_DIFLAG_NEWRTBM | \
10371          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
10372          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
10373          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
10374 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG)
10375 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_BARRIER | \
10376 +        XFS_DIFLAG_IUNLINK)
10377  
10378  #endif /* __XFS_DINODE_H__ */
10379 diff -Nurp linux-2.6.22.18/fs/xfs/xfs_fs.h linux-2.6.22.18-vs2.3.0.32/fs/xfs/xfs_fs.h
10380 --- linux-2.6.22.18/fs/xfs/xfs_fs.h     2007-05-04 15:57:37.000000000 +0200
10381 +++ linux-2.6.22.18-vs2.3.0.32/fs/xfs/xfs_fs.h  2008-02-11 12:35:35.000000000 +0100
10382 @@ -66,6 +66,8 @@ struct fsxattr {
10383  #define XFS_XFLAG_EXTSIZE      0x00000800      /* extent size allocator hint */
10384  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
10385  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
10386 +#define XFS_XFLAG_BARRIER      0x00004000      /* chroot() barrier */
10387 +#define XFS_XFLAG_IUNLINK      0x00008000      /* immutable unlink */
10388  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
10389  
10390  /*
10391 @@ -294,7 +296,8 @@ typedef struct xfs_bstat {
10392         __s32           bs_extents;     /* number of extents            */
10393         __u32           bs_gen;         /* generation count             */
10394         __u16           bs_projid;      /* project id                   */
10395 -       unsigned char   bs_pad[14];     /* pad space, unused            */
10396 +       __u16           bs_tag;         /* context tagging              */
10397 +       unsigned char   bs_pad[12];     /* pad space, unused            */
10398         __u32           bs_dmevmask;    /* DMIG event mask              */
10399         __u16           bs_dmstate;     /* DMIG state info              */
10400         __u16           bs_aextents;    /* attribute number of extents  */
10401 diff -Nurp linux-2.6.22.18/fs/xfs/xfs_inode.c linux-2.6.22.18-vs2.3.0.32/fs/xfs/xfs_inode.c
10402 --- linux-2.6.22.18/fs/xfs/xfs_inode.c  2007-07-22 00:00:18.000000000 +0200
10403 +++ linux-2.6.22.18-vs2.3.0.32/fs/xfs/xfs_inode.c       2008-02-11 12:35:35.000000000 +0100
10404 @@ -49,6 +49,7 @@
10405  #include "xfs_quota.h"
10406  #include "xfs_acl.h"
10407  
10408 +#include <linux/vs_tag.h>
10409  
10410  kmem_zone_t *xfs_ifork_zone;
10411  kmem_zone_t *xfs_inode_zone;
10412 @@ -736,20 +737,35 @@ xfs_xlate_dinode_core(
10413         xfs_dinode_core_t       *buf_core = (xfs_dinode_core_t *)buf;
10414         xfs_dinode_core_t       *mem_core = (xfs_dinode_core_t *)dip;
10415         xfs_arch_t              arch = ARCH_CONVERT;
10416 +       uint32_t                uid = 0, gid = 0;
10417 +       uint16_t                tag = 0;
10418  
10419         ASSERT(dir);
10420  
10421 +       if (dir < 0) {
10422 +               tag = mem_core->di_tag;
10423 +               /* FIXME: supposed to use superblock flag */
10424 +               uid = TAGINO_UID(1, mem_core->di_uid, tag);
10425 +               gid = TAGINO_GID(1, mem_core->di_gid, tag);
10426 +               tag = TAGINO_TAG(1, tag);
10427 +       }
10428 +
10429         INT_XLATE(buf_core->di_magic, mem_core->di_magic, dir, arch);
10430         INT_XLATE(buf_core->di_mode, mem_core->di_mode, dir, arch);
10431         INT_XLATE(buf_core->di_version, mem_core->di_version, dir, arch);
10432         INT_XLATE(buf_core->di_format, mem_core->di_format, dir, arch);
10433         INT_XLATE(buf_core->di_onlink, mem_core->di_onlink, dir, arch);
10434 -       INT_XLATE(buf_core->di_uid, mem_core->di_uid, dir, arch);
10435 -       INT_XLATE(buf_core->di_gid, mem_core->di_gid, dir, arch);
10436 +       INT_XLATE(buf_core->di_uid, uid, dir, arch);
10437 +       INT_XLATE(buf_core->di_gid, gid, dir, arch);
10438 +       INT_XLATE(buf_core->di_tag, tag, dir, arch);
10439         INT_XLATE(buf_core->di_nlink, mem_core->di_nlink, dir, arch);
10440         INT_XLATE(buf_core->di_projid, mem_core->di_projid, dir, arch);
10441  
10442         if (dir > 0) {
10443 +               /* FIXME: supposed to use superblock flag */
10444 +               mem_core->di_uid = INOTAG_UID(1, uid, gid);
10445 +               mem_core->di_gid = INOTAG_GID(1, uid, gid);
10446 +               mem_core->di_tag = INOTAG_TAG(1, uid, gid, tag);
10447                 memcpy(mem_core->di_pad, buf_core->di_pad,
10448                         sizeof(buf_core->di_pad));
10449         } else {
10450 @@ -797,6 +813,10 @@ _xfs_dic2xflags(
10451                         flags |= XFS_XFLAG_PREALLOC;
10452                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
10453                         flags |= XFS_XFLAG_IMMUTABLE;
10454 +               if (di_flags & XFS_DIFLAG_IUNLINK)
10455 +                       flags |= XFS_XFLAG_IUNLINK;
10456 +               if (di_flags & XFS_DIFLAG_BARRIER)
10457 +                       flags |= XFS_XFLAG_BARRIER;
10458                 if (di_flags & XFS_DIFLAG_APPEND)
10459                         flags |= XFS_XFLAG_APPEND;
10460                 if (di_flags & XFS_DIFLAG_SYNC)
10461 @@ -1129,6 +1149,7 @@ xfs_ialloc(
10462         ASSERT(ip->i_d.di_nlink == nlink);
10463         ip->i_d.di_uid = current_fsuid(cr);
10464         ip->i_d.di_gid = current_fsgid(cr);
10465 +       ip->i_d.di_tag = current_fstag(cr, vp);
10466         ip->i_d.di_projid = prid;
10467         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
10468  
10469 diff -Nurp linux-2.6.22.18/fs/xfs/xfs_itable.c linux-2.6.22.18-vs2.3.0.32/fs/xfs/xfs_itable.c
10470 --- linux-2.6.22.18/fs/xfs/xfs_itable.c 2007-07-22 00:00:18.000000000 +0200
10471 +++ linux-2.6.22.18-vs2.3.0.32/fs/xfs/xfs_itable.c      2008-02-11 12:35:35.000000000 +0100
10472 @@ -89,6 +89,7 @@ xfs_bulkstat_one_iget(
10473         buf->bs_mode = dic->di_mode;
10474         buf->bs_uid = dic->di_uid;
10475         buf->bs_gid = dic->di_gid;
10476 +       buf->bs_tag = dic->di_tag;
10477         buf->bs_size = dic->di_size;
10478         vn_atime_to_bstime(vp, &buf->bs_atime);
10479         buf->bs_mtime.tv_sec = dic->di_mtime.t_sec;
10480 @@ -163,6 +164,7 @@ xfs_bulkstat_one_dinode(
10481         buf->bs_mode = INT_GET(dic->di_mode, ARCH_CONVERT);
10482         buf->bs_uid = INT_GET(dic->di_uid, ARCH_CONVERT);
10483         buf->bs_gid = INT_GET(dic->di_gid, ARCH_CONVERT);
10484 +       buf->bs_tag = INT_GET(dic->di_tag, ARCH_CONVERT);
10485         buf->bs_size = INT_GET(dic->di_size, ARCH_CONVERT);
10486         buf->bs_atime.tv_sec = INT_GET(dic->di_atime.t_sec, ARCH_CONVERT);
10487         buf->bs_atime.tv_nsec = INT_GET(dic->di_atime.t_nsec, ARCH_CONVERT);
10488 diff -Nurp linux-2.6.22.18/fs/xfs/xfs_mount.h linux-2.6.22.18-vs2.3.0.32/fs/xfs/xfs_mount.h
10489 --- linux-2.6.22.18/fs/xfs/xfs_mount.h  2007-07-21 23:58:49.000000000 +0200
10490 +++ linux-2.6.22.18-vs2.3.0.32/fs/xfs/xfs_mount.h       2008-02-11 12:35:35.000000000 +0100
10491 @@ -464,6 +464,7 @@ typedef struct xfs_mount {
10492  #define XFS_MOUNT_NO_PERCPU_SB (1ULL << 23)    /* don't use per-cpu superblock
10493                                                    counters */
10494  
10495 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
10496  
10497  /*
10498   * Default minimum read and write sizes.
10499 diff -Nurp linux-2.6.22.18/fs/xfs/xfs_vfsops.c linux-2.6.22.18-vs2.3.0.32/fs/xfs/xfs_vfsops.c
10500 --- linux-2.6.22.18/fs/xfs/xfs_vfsops.c 2007-07-22 00:00:18.000000000 +0200
10501 +++ linux-2.6.22.18-vs2.3.0.32/fs/xfs/xfs_vfsops.c      2008-02-11 12:35:35.000000000 +0100
10502 @@ -300,6 +300,8 @@ xfs_start_flags(
10503  
10504         if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
10505                 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
10506 +       if (ap->flags2 & XFSMNT2_TAGGED)
10507 +               mp->m_flags |= XFS_MOUNT_TAGGED;
10508  
10509         /*
10510          * no recovery flag requires a read-only mount
10511 @@ -394,6 +396,8 @@ xfs_finish_flags(
10512                         return XFS_ERROR(EINVAL);
10513         }
10514  
10515 +       if (ap->flags2 & XFSMNT2_TAGGED)
10516 +               vfs->vfs_super->s_flags |= MS_TAGGED;
10517         return 0;
10518  }
10519  
10520 @@ -1645,6 +1649,9 @@ xfs_vget(
10521                                          * in stat(). */
10522  #define MNTOPT_ATTR2   "attr2"         /* do use attr2 attribute format */
10523  #define MNTOPT_NOATTR2 "noattr2"       /* do not use attr2 attribute format */
10524 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
10525 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
10526 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
10527  
10528  STATIC unsigned long
10529  suffix_strtoul(char *s, char **endp, unsigned int base)
10530 @@ -1831,6 +1838,19 @@ xfs_parseargs(
10531                         args->flags |= XFSMNT_ATTR2;
10532                 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
10533                         args->flags &= ~XFSMNT_ATTR2;
10534 +#ifndef CONFIG_TAGGING_NONE
10535 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
10536 +                       args->flags2 |= XFSMNT2_TAGGED;
10537 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
10538 +                       args->flags2 &= ~XFSMNT2_TAGGED;
10539 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
10540 +                       args->flags2 |= XFSMNT2_TAGGED;
10541 +#endif
10542 +#ifdef CONFIG_PROPAGATE
10543 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
10544 +                       /* use value */
10545 +                       args->flags2 |= XFSMNT2_TAGGED;
10546 +#endif
10547                 } else if (!strcmp(this_char, "osyncisdsync")) {
10548                         /* no-op, this is now the default */
10549                         cmn_err(CE_WARN,
10550 diff -Nurp linux-2.6.22.18/fs/xfs/xfs_vnodeops.c linux-2.6.22.18-vs2.3.0.32/fs/xfs/xfs_vnodeops.c
10551 --- linux-2.6.22.18/fs/xfs/xfs_vnodeops.c       2007-07-22 00:00:18.000000000 +0200
10552 +++ linux-2.6.22.18-vs2.3.0.32/fs/xfs/xfs_vnodeops.c    2008-02-11 12:35:35.000000000 +0100
10553 @@ -159,6 +159,7 @@ xfs_getattr(
10554         vap->va_mode = ip->i_d.di_mode;
10555         vap->va_uid = ip->i_d.di_uid;
10556         vap->va_gid = ip->i_d.di_gid;
10557 +       vap->va_tag = ip->i_d.di_tag;
10558         vap->va_projid = ip->i_d.di_projid;
10559  
10560         /*
10561 @@ -259,6 +260,7 @@ xfs_setattr(
10562         uint                    commit_flags=0;
10563         uid_t                   uid=0, iuid=0;
10564         gid_t                   gid=0, igid=0;
10565 +       tag_t                   tag=0, itag=0;
10566         int                     timeflags = 0;
10567         bhv_vnode_t             *vp;
10568         xfs_prid_t              projid=0, iprojid=0;
10569 @@ -315,6 +317,7 @@ xfs_setattr(
10570             (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_PROJID))) {
10571                 uint    qflags = 0;
10572  
10573 +               /* TODO: handle tagging? */
10574                 if ((mask & XFS_AT_UID) && XFS_IS_UQUOTA_ON(mp)) {
10575                         uid = vap->va_uid;
10576                         qflags |= XFS_QMOPT_UQUOTA;
10577 @@ -394,6 +397,8 @@ xfs_setattr(
10578         if (mask &
10579             (XFS_AT_MODE|XFS_AT_XFLAGS|XFS_AT_EXTSIZE|XFS_AT_UID|
10580              XFS_AT_GID|XFS_AT_PROJID)) {
10581 +               /* TODO: handle tagging? */
10582 +
10583                 /*
10584                  * CAP_FOWNER overrides the following restrictions:
10585                  *
10586 @@ -442,7 +447,7 @@ xfs_setattr(
10587          * and can change the group id only to a group of which he
10588          * or she is a member.
10589          */
10590 -       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_PROJID)) {
10591 +       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_TAG|XFS_AT_PROJID)) {
10592                 /*
10593                  * These IDs could have changed since we last looked at them.
10594                  * But, we're assured that if the ownership did change
10595 @@ -450,10 +455,12 @@ xfs_setattr(
10596                  * would have changed also.
10597                  */
10598                 iuid = ip->i_d.di_uid;
10599 -               iprojid = ip->i_d.di_projid;
10600                 igid = ip->i_d.di_gid;
10601 -               gid = (mask & XFS_AT_GID) ? vap->va_gid : igid;
10602 +               itag = ip->i_d.di_tag;
10603 +               iprojid = ip->i_d.di_projid;
10604                 uid = (mask & XFS_AT_UID) ? vap->va_uid : iuid;
10605 +               gid = (mask & XFS_AT_GID) ? vap->va_gid : igid;
10606 +               tag = (mask & XFS_AT_TAG) ? vap->va_tag : itag;
10607                 projid = (mask & XFS_AT_PROJID) ? (xfs_prid_t)vap->va_projid :
10608                          iprojid;
10609  
10610 @@ -481,6 +488,7 @@ xfs_setattr(
10611                 if ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
10612                     (XFS_IS_PQUOTA_ON(mp) && iprojid != projid) ||
10613                     (XFS_IS_GQUOTA_ON(mp) && igid != gid)) {
10614 +                       /* TODO: handle tagging? */
10615                         ASSERT(tp);
10616                         code = XFS_QM_DQVOPCHOWNRESV(mp, tp, ip, udqp, gdqp,
10617                                                 capable(CAP_FOWNER) ?
10618 @@ -706,7 +714,7 @@ xfs_setattr(
10619          * and can change the group id only to a group of which he
10620          * or she is a member.
10621          */
10622 -       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_PROJID)) {
10623 +       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_TAG|XFS_AT_PROJID)) {
10624                 /*
10625                  * CAP_FSETID overrides the following restrictions:
10626                  *
10627 @@ -722,6 +730,9 @@ xfs_setattr(
10628                  * Change the ownerships and register quota modifications
10629                  * in the transaction.
10630                  */
10631 +               if (itag != tag) {
10632 +                       ip->i_d.di_tag = tag;
10633 +               }
10634                 if (iuid != uid) {
10635                         if (XFS_IS_UQUOTA_ON(mp)) {
10636                                 ASSERT(mask & XFS_AT_UID);
10637 @@ -802,6 +813,10 @@ xfs_setattr(
10638                         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
10639                         if (vap->va_xflags & XFS_XFLAG_IMMUTABLE)
10640                                 di_flags |= XFS_DIFLAG_IMMUTABLE;
10641 +                       if (vap->va_xflags & XFS_XFLAG_IUNLINK)
10642 +                               di_flags |= XFS_DIFLAG_IUNLINK;
10643 +                       if (vap->va_xflags & XFS_XFLAG_BARRIER)
10644 +                               di_flags |= XFS_DIFLAG_BARRIER;
10645                         if (vap->va_xflags & XFS_XFLAG_APPEND)
10646                                 di_flags |= XFS_DIFLAG_APPEND;
10647                         if (vap->va_xflags & XFS_XFLAG_SYNC)
10648 diff -Nurp linux-2.6.22.18/include/asm-alpha/socket.h linux-2.6.22.18-vs2.3.0.32/include/asm-alpha/socket.h
10649 --- linux-2.6.22.18/include/asm-alpha/socket.h  2007-07-22 00:00:18.000000000 +0200
10650 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-alpha/socket.h       2008-02-11 12:35:35.000000000 +0100
10651 @@ -55,6 +55,8 @@
10652  #define SO_TIMESTAMPNS         35
10653  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10654  
10655 +#define SO_PEERTAG             36
10656 +
10657  /* Security levels - as per NRL IPv6 - don't actually do anything */
10658  #define SO_SECURITY_AUTHENTICATION             19
10659  #define SO_SECURITY_ENCRYPTION_TRANSPORT       20
10660 diff -Nurp linux-2.6.22.18/include/asm-arm/socket.h linux-2.6.22.18-vs2.3.0.32/include/asm-arm/socket.h
10661 --- linux-2.6.22.18/include/asm-arm/socket.h    2007-07-22 00:00:19.000000000 +0200
10662 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-arm/socket.h 2008-02-11 12:35:35.000000000 +0100
10663 @@ -52,4 +52,6 @@
10664  #define SO_TIMESTAMPNS         35
10665  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10666  
10667 +#define SO_PEERTAG             36
10668 +
10669  #endif /* _ASM_SOCKET_H */
10670 diff -Nurp linux-2.6.22.18/include/asm-arm/tlb.h linux-2.6.22.18-vs2.3.0.32/include/asm-arm/tlb.h
10671 --- linux-2.6.22.18/include/asm-arm/tlb.h       2006-06-18 03:49:35.000000000 +0200
10672 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-arm/tlb.h    2008-02-11 12:35:35.000000000 +0100
10673 @@ -28,6 +28,7 @@
10674  #else /* !CONFIG_MMU */
10675  
10676  #include <asm/pgalloc.h>
10677 +#include <linux/vs_memory.h>
10678  
10679  /*
10680   * TLB handling.  This allows us to remove pages from the page
10681 diff -Nurp linux-2.6.22.18/include/asm-arm26/tlb.h linux-2.6.22.18-vs2.3.0.32/include/asm-arm26/tlb.h
10682 --- linux-2.6.22.18/include/asm-arm26/tlb.h     2006-06-18 03:49:35.000000000 +0200
10683 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-arm26/tlb.h  2008-02-11 12:35:35.000000000 +0100
10684 @@ -3,6 +3,7 @@
10685  
10686  #include <asm/pgalloc.h>
10687  #include <asm/tlbflush.h>
10688 +#include <linux/vs_memory.h>
10689  
10690  /*
10691   * TLB handling.  This allows us to remove pages from the page
10692 diff -Nurp linux-2.6.22.18/include/asm-arm26/unistd.h linux-2.6.22.18-vs2.3.0.32/include/asm-arm26/unistd.h
10693 --- linux-2.6.22.18/include/asm-arm26/unistd.h  2007-05-04 15:58:22.000000000 +0200
10694 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-arm26/unistd.h       2008-02-11 12:35:35.000000000 +0100
10695 @@ -302,6 +302,8 @@
10696  #define __NR_mq_getsetattr             (__NR_SYSCALL_BASE+279)
10697  #define __NR_waitid                    (__NR_SYSCALL_BASE+280)
10698  
10699 +#define __NR_vserver                   (__NR_SYSCALL_BASE+313)
10700 +
10701  /*
10702   * The following SWIs are ARM private. FIXME - make appropriate for arm26
10703   */
10704 diff -Nurp linux-2.6.22.18/include/asm-cris/socket.h linux-2.6.22.18-vs2.3.0.32/include/asm-cris/socket.h
10705 --- linux-2.6.22.18/include/asm-cris/socket.h   2007-07-22 00:00:19.000000000 +0200
10706 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-cris/socket.h        2008-02-11 12:35:35.000000000 +0100
10707 @@ -54,6 +54,8 @@
10708  #define SO_TIMESTAMPNS         35
10709  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10710  
10711 +#define SO_PEERTAG             36
10712 +
10713  #endif /* _ASM_SOCKET_H */
10714  
10715  
10716 diff -Nurp linux-2.6.22.18/include/asm-frv/socket.h linux-2.6.22.18-vs2.3.0.32/include/asm-frv/socket.h
10717 --- linux-2.6.22.18/include/asm-frv/socket.h    2007-07-22 00:00:19.000000000 +0200
10718 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-frv/socket.h 2008-02-11 12:35:35.000000000 +0100
10719 @@ -52,5 +52,7 @@
10720  #define SO_TIMESTAMPNS         35
10721  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10722  
10723 +#define SO_PEERTAG             36
10724 +
10725  #endif /* _ASM_SOCKET_H */
10726  
10727 diff -Nurp linux-2.6.22.18/include/asm-generic/tlb.h linux-2.6.22.18-vs2.3.0.32/include/asm-generic/tlb.h
10728 --- linux-2.6.22.18/include/asm-generic/tlb.h   2007-05-04 15:57:38.000000000 +0200
10729 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-generic/tlb.h        2008-02-11 12:35:35.000000000 +0100
10730 @@ -14,6 +14,7 @@
10731  #define _ASM_GENERIC__TLB_H
10732  
10733  #include <linux/swap.h>
10734 +#include <linux/vs_memory.h>
10735  #include <asm/pgalloc.h>
10736  #include <asm/tlbflush.h>
10737  
10738 diff -Nurp linux-2.6.22.18/include/asm-h8300/socket.h linux-2.6.22.18-vs2.3.0.32/include/asm-h8300/socket.h
10739 --- linux-2.6.22.18/include/asm-h8300/socket.h  2007-07-22 00:00:19.000000000 +0200
10740 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-h8300/socket.h       2008-02-11 12:35:35.000000000 +0100
10741 @@ -52,4 +52,6 @@
10742  #define SO_TIMESTAMPNS         35
10743  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10744  
10745 +#define SO_PEERTAG             36
10746 +
10747  #endif /* _ASM_SOCKET_H */
10748 diff -Nurp linux-2.6.22.18/include/asm-i386/socket.h linux-2.6.22.18-vs2.3.0.32/include/asm-i386/socket.h
10749 --- linux-2.6.22.18/include/asm-i386/socket.h   2007-07-22 00:00:19.000000000 +0200
10750 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-i386/socket.h        2008-02-11 12:35:35.000000000 +0100
10751 @@ -52,4 +52,6 @@
10752  #define SO_TIMESTAMPNS         35
10753  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10754  
10755 +#define SO_PEERTAG             36
10756 +
10757  #endif /* _ASM_SOCKET_H */
10758 diff -Nurp linux-2.6.22.18/include/asm-ia64/socket.h linux-2.6.22.18-vs2.3.0.32/include/asm-ia64/socket.h
10759 --- linux-2.6.22.18/include/asm-ia64/socket.h   2007-07-22 00:00:19.000000000 +0200
10760 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-ia64/socket.h        2008-02-11 12:35:35.000000000 +0100
10761 @@ -61,4 +61,6 @@
10762  #define SO_TIMESTAMPNS         35
10763  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10764  
10765 +#define SO_PEERTAG             36
10766 +
10767  #endif /* _ASM_IA64_SOCKET_H */
10768 diff -Nurp linux-2.6.22.18/include/asm-ia64/tlb.h linux-2.6.22.18-vs2.3.0.32/include/asm-ia64/tlb.h
10769 --- linux-2.6.22.18/include/asm-ia64/tlb.h      2007-05-04 15:55:44.000000000 +0200
10770 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-ia64/tlb.h   2008-02-11 12:35:35.000000000 +0100
10771 @@ -40,6 +40,7 @@
10772  #include <linux/mm.h>
10773  #include <linux/pagemap.h>
10774  #include <linux/swap.h>
10775 +#include <linux/vs_memory.h>
10776  
10777  #include <asm/pgalloc.h>
10778  #include <asm/processor.h>
10779 diff -Nurp linux-2.6.22.18/include/asm-m32r/socket.h linux-2.6.22.18-vs2.3.0.32/include/asm-m32r/socket.h
10780 --- linux-2.6.22.18/include/asm-m32r/socket.h   2007-07-22 00:00:19.000000000 +0200
10781 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-m32r/socket.h        2008-02-11 12:35:35.000000000 +0100
10782 @@ -52,4 +52,6 @@
10783  #define SO_TIMESTAMPNS         35
10784  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10785  
10786 +#define SO_PEERTAG             36
10787 +
10788  #endif /* _ASM_M32R_SOCKET_H */
10789 diff -Nurp linux-2.6.22.18/include/asm-mips/socket.h linux-2.6.22.18-vs2.3.0.32/include/asm-mips/socket.h
10790 --- linux-2.6.22.18/include/asm-mips/socket.h   2007-07-22 00:00:19.000000000 +0200
10791 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-mips/socket.h        2008-02-11 12:35:35.000000000 +0100
10792 @@ -73,6 +73,8 @@ To add: #define SO_REUSEPORT 0x0200   /* A
10793  #define SO_TIMESTAMPNS         35
10794  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10795  
10796 +#define SO_PEERTAG             36
10797 +
10798  #ifdef __KERNEL__
10799  
10800  /** sock_type - Socket types
10801 diff -Nurp linux-2.6.22.18/include/asm-parisc/socket.h linux-2.6.22.18-vs2.3.0.32/include/asm-parisc/socket.h
10802 --- linux-2.6.22.18/include/asm-parisc/socket.h 2007-07-22 00:00:20.000000000 +0200
10803 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-parisc/socket.h      2008-02-11 12:35:35.000000000 +0100
10804 @@ -51,5 +51,6 @@
10805  
10806  #define SO_PEERSEC             0x401d
10807  #define SO_PASSSEC             0x401e
10808 +#define SO_PEERTAG             0x401f
10809  
10810  #endif /* _ASM_SOCKET_H */
10811 diff -Nurp linux-2.6.22.18/include/asm-powerpc/socket.h linux-2.6.22.18-vs2.3.0.32/include/asm-powerpc/socket.h
10812 --- linux-2.6.22.18/include/asm-powerpc/socket.h        2007-07-22 00:00:20.000000000 +0200
10813 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-powerpc/socket.h     2008-02-11 12:35:35.000000000 +0100
10814 @@ -59,4 +59,6 @@
10815  #define SO_TIMESTAMPNS         35
10816  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10817  
10818 +#define SO_PEERTAG             36
10819 +
10820  #endif /* _ASM_POWERPC_SOCKET_H */
10821 diff -Nurp linux-2.6.22.18/include/asm-powerpc/systbl.h linux-2.6.22.18-vs2.3.0.32/include/asm-powerpc/systbl.h
10822 --- linux-2.6.22.18/include/asm-powerpc/systbl.h        2007-07-22 00:00:20.000000000 +0200
10823 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-powerpc/systbl.h     2008-02-11 12:35:35.000000000 +0100
10824 @@ -260,7 +260,7 @@ COMPAT_SYS_SPU(fstatfs64)
10825  SYSX(sys_ni_syscall, ppc_fadvise64_64, ppc_fadvise64_64)
10826  PPC_SYS_SPU(rtas)
10827  OLDSYS(debug_setcontext)
10828 -SYSCALL(ni_syscall)
10829 +SYSX(sys_vserver, sys32_vserver, sys_vserver)
10830  COMPAT_SYS(migrate_pages)
10831  COMPAT_SYS(mbind)
10832  COMPAT_SYS(get_mempolicy)
10833 diff -Nurp linux-2.6.22.18/include/asm-powerpc/unistd.h linux-2.6.22.18-vs2.3.0.32/include/asm-powerpc/unistd.h
10834 --- linux-2.6.22.18/include/asm-powerpc/unistd.h        2007-07-22 00:00:20.000000000 +0200
10835 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-powerpc/unistd.h     2008-02-11 12:35:35.000000000 +0100
10836 @@ -275,7 +275,7 @@
10837  #endif
10838  #define __NR_rtas              255
10839  #define __NR_sys_debug_setcontext 256
10840 -/* Number 257 is reserved for vserver */
10841 +#define __NR_vserver           257
10842  #define __NR_migrate_pages     258
10843  #define __NR_mbind             259
10844  #define __NR_get_mempolicy     260
10845 diff -Nurp linux-2.6.22.18/include/asm-s390/socket.h linux-2.6.22.18-vs2.3.0.32/include/asm-s390/socket.h
10846 --- linux-2.6.22.18/include/asm-s390/socket.h   2007-07-22 00:00:20.000000000 +0200
10847 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-s390/socket.h        2008-02-11 12:35:35.000000000 +0100
10848 @@ -60,4 +60,6 @@
10849  #define SO_TIMESTAMPNS         35
10850  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10851  
10852 +#define SO_PEERTAG             36
10853 +
10854  #endif /* _ASM_SOCKET_H */
10855 diff -Nurp linux-2.6.22.18/include/asm-s390/unistd.h linux-2.6.22.18-vs2.3.0.32/include/asm-s390/unistd.h
10856 --- linux-2.6.22.18/include/asm-s390/unistd.h   2007-07-22 00:00:20.000000000 +0200
10857 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-s390/unistd.h        2008-02-11 12:35:35.000000000 +0100
10858 @@ -202,7 +202,7 @@
10859  #define __NR_clock_gettime     (__NR_timer_create+6)
10860  #define __NR_clock_getres      (__NR_timer_create+7)
10861  #define __NR_clock_nanosleep   (__NR_timer_create+8)
10862 -/* Number 263 is reserved for vserver */
10863 +#define __NR_vserver           263
10864  #define __NR_statfs64          265
10865  #define __NR_fstatfs64         266
10866  #define __NR_remap_file_pages  267
10867 diff -Nurp linux-2.6.22.18/include/asm-sh/socket.h linux-2.6.22.18-vs2.3.0.32/include/asm-sh/socket.h
10868 --- linux-2.6.22.18/include/asm-sh/socket.h     2007-07-22 00:00:20.000000000 +0200
10869 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-sh/socket.h  2008-02-11 12:35:35.000000000 +0100
10870 @@ -52,4 +52,6 @@
10871  #define SO_TIMESTAMPNS         35
10872  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10873  
10874 +#define SO_PEERTAG             36
10875 +
10876  #endif /* __ASM_SH_SOCKET_H */
10877 diff -Nurp linux-2.6.22.18/include/asm-sparc/socket.h linux-2.6.22.18-vs2.3.0.32/include/asm-sparc/socket.h
10878 --- linux-2.6.22.18/include/asm-sparc/socket.h  2007-07-22 00:00:20.000000000 +0200
10879 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-sparc/socket.h       2008-02-11 12:35:35.000000000 +0100
10880 @@ -52,6 +52,8 @@
10881  #define SO_TIMESTAMPNS         0x0021
10882  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10883  
10884 +#define SO_PEERTAG             36
10885 +
10886  /* Security levels - as per NRL IPv6 - don't actually do anything */
10887  #define SO_SECURITY_AUTHENTICATION             0x5001
10888  #define SO_SECURITY_ENCRYPTION_TRANSPORT       0x5002
10889 diff -Nurp linux-2.6.22.18/include/asm-sparc/unistd.h linux-2.6.22.18-vs2.3.0.32/include/asm-sparc/unistd.h
10890 --- linux-2.6.22.18/include/asm-sparc/unistd.h  2007-07-22 00:00:20.000000000 +0200
10891 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-sparc/unistd.h       2008-02-11 12:35:35.000000000 +0100
10892 @@ -283,7 +283,7 @@
10893  #define __NR_timer_getoverrun  264
10894  #define __NR_timer_delete      265
10895  #define __NR_timer_create      266
10896 -/* #define __NR_vserver                267 Reserved for VSERVER */
10897 +#define __NR_vserver           267
10898  #define __NR_io_setup          268
10899  #define __NR_io_destroy                269
10900  #define __NR_io_submit         270
10901 diff -Nurp linux-2.6.22.18/include/asm-sparc64/socket.h linux-2.6.22.18-vs2.3.0.32/include/asm-sparc64/socket.h
10902 --- linux-2.6.22.18/include/asm-sparc64/socket.h        2007-07-22 00:00:20.000000000 +0200
10903 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-sparc64/socket.h     2008-02-11 12:35:35.000000000 +0100
10904 @@ -52,6 +52,8 @@
10905  #define SO_TIMESTAMPNS         0x0021
10906  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10907  
10908 +#define SO_PEERTAG             0x0022
10909 +
10910  /* Security levels - as per NRL IPv6 - don't actually do anything */
10911  #define SO_SECURITY_AUTHENTICATION             0x5001
10912  #define SO_SECURITY_ENCRYPTION_TRANSPORT       0x5002
10913 diff -Nurp linux-2.6.22.18/include/asm-sparc64/tlb.h linux-2.6.22.18-vs2.3.0.32/include/asm-sparc64/tlb.h
10914 --- linux-2.6.22.18/include/asm-sparc64/tlb.h   2007-07-22 00:00:20.000000000 +0200
10915 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-sparc64/tlb.h        2008-02-11 12:35:35.000000000 +0100
10916 @@ -3,6 +3,7 @@
10917  
10918  #include <linux/swap.h>
10919  #include <linux/pagemap.h>
10920 +#include <linux/vs_memory.h>
10921  #include <asm/pgalloc.h>
10922  #include <asm/tlbflush.h>
10923  #include <asm/mmu_context.h>
10924 diff -Nurp linux-2.6.22.18/include/asm-sparc64/unistd.h linux-2.6.22.18-vs2.3.0.32/include/asm-sparc64/unistd.h
10925 --- linux-2.6.22.18/include/asm-sparc64/unistd.h        2007-07-22 00:00:20.000000000 +0200
10926 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-sparc64/unistd.h     2008-02-11 12:35:35.000000000 +0100
10927 @@ -285,7 +285,7 @@
10928  #define __NR_timer_getoverrun  264
10929  #define __NR_timer_delete      265
10930  #define __NR_timer_create      266
10931 -/* #define __NR_vserver                267 Reserved for VSERVER */
10932 +#define __NR_vserver           267
10933  #define __NR_io_setup          268
10934  #define __NR_io_destroy                269
10935  #define __NR_io_submit         270
10936 diff -Nurp linux-2.6.22.18/include/asm-v850/socket.h linux-2.6.22.18-vs2.3.0.32/include/asm-v850/socket.h
10937 --- linux-2.6.22.18/include/asm-v850/socket.h   2007-07-22 00:00:20.000000000 +0200
10938 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-v850/socket.h        2008-02-11 12:35:35.000000000 +0100
10939 @@ -52,4 +52,6 @@
10940  #define SO_TIMESTAMPNS         35
10941  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10942  
10943 +#define SO_PEERTAG             36
10944 +
10945  #endif /* __V850_SOCKET_H__ */
10946 diff -Nurp linux-2.6.22.18/include/asm-x86_64/socket.h linux-2.6.22.18-vs2.3.0.32/include/asm-x86_64/socket.h
10947 --- linux-2.6.22.18/include/asm-x86_64/socket.h 2007-07-22 00:00:20.000000000 +0200
10948 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-x86_64/socket.h      2008-02-11 12:35:35.000000000 +0100
10949 @@ -52,4 +52,6 @@
10950  #define SO_TIMESTAMPNS         35
10951  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10952  
10953 +#define SO_PEERTAG             36
10954 +
10955  #endif /* _ASM_SOCKET_H */
10956 diff -Nurp linux-2.6.22.18/include/asm-x86_64/unistd.h linux-2.6.22.18-vs2.3.0.32/include/asm-x86_64/unistd.h
10957 --- linux-2.6.22.18/include/asm-x86_64/unistd.h 2007-07-22 00:00:20.000000000 +0200
10958 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-x86_64/unistd.h      2008-02-11 12:35:35.000000000 +0100
10959 @@ -532,7 +532,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
10960  #define __NR_utimes            235
10961  __SYSCALL(__NR_utimes, sys_utimes)
10962  #define __NR_vserver           236
10963 -__SYSCALL(__NR_vserver, sys_ni_syscall)
10964 +__SYSCALL(__NR_vserver, sys_vserver)
10965  #define __NR_mbind             237
10966  __SYSCALL(__NR_mbind, sys_mbind)
10967  #define __NR_set_mempolicy     238
10968 diff -Nurp linux-2.6.22.18/include/asm-xtensa/socket.h linux-2.6.22.18-vs2.3.0.32/include/asm-xtensa/socket.h
10969 --- linux-2.6.22.18/include/asm-xtensa/socket.h 2007-07-22 00:00:20.000000000 +0200
10970 +++ linux-2.6.22.18-vs2.3.0.32/include/asm-xtensa/socket.h      2008-02-11 12:35:35.000000000 +0100
10971 @@ -63,4 +63,6 @@
10972  #define SO_TIMESTAMPNS         35
10973  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10974  
10975 +#define SO_PEERTAG             36
10976 +
10977  #endif /* _XTENSA_SOCKET_H */
10978 diff -Nurp linux-2.6.22.18/include/linux/capability.h linux-2.6.22.18-vs2.3.0.32/include/linux/capability.h
10979 --- linux-2.6.22.18/include/linux/capability.h  2007-07-22 00:00:20.000000000 +0200
10980 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/capability.h       2008-02-11 12:35:35.000000000 +0100
10981 @@ -237,6 +237,7 @@ typedef __u32 kernel_cap_t;
10982     arbitrary SCSI commands */
10983  /* Allow setting encryption key on loopback filesystem */
10984  /* Allow setting zone reclaim policy */
10985 +/* Allow the selection of a security context */
10986  
10987  #define CAP_SYS_ADMIN        21
10988  
10989 @@ -290,6 +291,11 @@ typedef __u32 kernel_cap_t;
10990  
10991  #define CAP_AUDIT_CONTROL    30
10992  
10993 +/* Allow context manipulations */
10994 +/* Allow changing context info on files */
10995 +
10996 +#define CAP_CONTEXT         31
10997 +
10998  #ifdef __KERNEL__
10999  /* 
11000   * Bounding set
11001 diff -Nurp linux-2.6.22.18/include/linux/devpts_fs.h linux-2.6.22.18-vs2.3.0.32/include/linux/devpts_fs.h
11002 --- linux-2.6.22.18/include/linux/devpts_fs.h   2006-06-18 03:49:35.000000000 +0200
11003 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/devpts_fs.h        2008-02-11 12:35:35.000000000 +0100
11004 @@ -30,5 +30,4 @@ static inline void devpts_pty_kill(int n
11005  
11006  #endif
11007  
11008 -
11009  #endif /* _LINUX_DEVPTS_FS_H */
11010 diff -Nurp linux-2.6.22.18/include/linux/ext2_fs.h linux-2.6.22.18-vs2.3.0.32/include/linux/ext2_fs.h
11011 --- linux-2.6.22.18/include/linux/ext2_fs.h     2007-05-04 15:57:41.000000000 +0200
11012 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/ext2_fs.h  2008-02-11 12:35:35.000000000 +0100
11013 @@ -188,6 +188,8 @@ struct ext2_group_desc
11014  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
11015  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
11016  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
11017 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
11018 +#define EXT2_IUNLINK_FL                        FS_IUNLINK_FL   /* Immutable unlink */
11019  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
11020  
11021  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
11022 @@ -244,7 +246,7 @@ struct ext2_inode {
11023                 struct {
11024                         __u8    l_i_frag;       /* Fragment number */
11025                         __u8    l_i_fsize;      /* Fragment size */
11026 -                       __u16   i_pad1;
11027 +                       __u16   l_i_tag;        /* Context Tag */
11028                         __le16  l_i_uid_high;   /* these 2 fields    */
11029                         __le16  l_i_gid_high;   /* were reserved2[0] */
11030                         __u32   l_i_reserved2;
11031 @@ -276,6 +278,7 @@ struct ext2_inode {
11032  #define i_gid_low      i_gid
11033  #define i_uid_high     osd2.linux2.l_i_uid_high
11034  #define i_gid_high     osd2.linux2.l_i_gid_high
11035 +#define i_raw_tag      osd2.linux2.l_i_tag
11036  #define i_reserved2    osd2.linux2.l_i_reserved2
11037  #endif
11038  
11039 @@ -317,8 +320,9 @@ struct ext2_inode {
11040  #define EXT2_MOUNT_XATTR_USER          0x004000  /* Extended user attributes */
11041  #define EXT2_MOUNT_POSIX_ACL           0x008000  /* POSIX Access Control Lists */
11042  #define EXT2_MOUNT_XIP                 0x010000  /* Execute in place */
11043 -#define EXT2_MOUNT_USRQUOTA            0x020000 /* user quota */
11044 -#define EXT2_MOUNT_GRPQUOTA            0x040000 /* group quota */
11045 +#define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
11046 +#define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
11047 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
11048  
11049  
11050  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
11051 diff -Nurp linux-2.6.22.18/include/linux/ext3_fs.h linux-2.6.22.18-vs2.3.0.32/include/linux/ext3_fs.h
11052 --- linux-2.6.22.18/include/linux/ext3_fs.h     2007-07-22 00:00:20.000000000 +0200
11053 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/ext3_fs.h  2008-02-11 12:35:35.000000000 +0100
11054 @@ -177,6 +177,8 @@ struct ext3_group_desc
11055  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
11056  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
11057  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
11058 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
11059 +#define EXT3_IUNLINK_FL                        0x08000000 /* Immutable unlink */
11060  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
11061  
11062  #define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
11063 @@ -296,7 +298,7 @@ struct ext3_inode {
11064                 struct {
11065                         __u8    l_i_frag;       /* Fragment number */
11066                         __u8    l_i_fsize;      /* Fragment size */
11067 -                       __u16   i_pad1;
11068 +                       __u16   l_i_tag;        /* Context Tag */
11069                         __le16  l_i_uid_high;   /* these 2 fields    */
11070                         __le16  l_i_gid_high;   /* were reserved2[0] */
11071                         __u32   l_i_reserved2;
11072 @@ -330,6 +332,7 @@ struct ext3_inode {
11073  #define i_gid_low      i_gid
11074  #define i_uid_high     osd2.linux2.l_i_uid_high
11075  #define i_gid_high     osd2.linux2.l_i_gid_high
11076 +#define i_raw_tag      osd2.linux2.l_i_tag
11077  #define i_reserved2    osd2.linux2.l_i_reserved2
11078  
11079  #elif defined(__GNU__)
11080 @@ -384,6 +387,7 @@ struct ext3_inode {
11081  #define EXT3_MOUNT_QUOTA               0x80000 /* Some quota option set */
11082  #define EXT3_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
11083  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
11084 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
11085  
11086  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
11087  #ifndef _LINUX_EXT2_FS_H
11088 @@ -812,6 +816,7 @@ struct buffer_head * ext3_bread (handle_
11089  int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
11090         sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result,
11091         int create, int extend_disksize);
11092 +extern int ext3_sync_flags(struct inode *inode);
11093  
11094  extern void ext3_read_inode (struct inode *);
11095  extern int  ext3_write_inode (struct inode *, int);
11096 diff -Nurp linux-2.6.22.18/include/linux/ext4_fs.h linux-2.6.22.18-vs2.3.0.32/include/linux/ext4_fs.h
11097 --- linux-2.6.22.18/include/linux/ext4_fs.h     2007-07-22 00:00:22.000000000 +0200
11098 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/ext4_fs.h  2008-02-11 12:35:35.000000000 +0100
11099 @@ -189,8 +189,10 @@ struct ext4_group_desc
11100  #define EXT4_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
11101  #define EXT4_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
11102  #define EXT4_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
11103 -#define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
11104  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
11105 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
11106 +#define EXT4_IUNLINK_FL                        0x08000000 /* Immutable unlink */
11107 +#define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
11108  
11109  #define EXT4_FL_USER_VISIBLE           0x000BDFFF /* User visible flags */
11110  #define EXT4_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
11111 @@ -312,7 +314,8 @@ struct ext4_inode {
11112                         __le16  l_i_file_acl_high;
11113                         __le16  l_i_uid_high;   /* these 2 fields */
11114                         __le16  l_i_gid_high;   /* were reserved2[0] */
11115 -                       __u32   l_i_reserved2;
11116 +                       __u16   l_i_tag;        /* Context Tag */
11117 +                       __u16   l_i_reserved2;
11118                 } linux2;
11119                 struct {
11120                         __u8    h_i_frag;       /* Fragment number */
11121 @@ -344,6 +347,7 @@ struct ext4_inode {
11122  #define i_gid_low      i_gid
11123  #define i_uid_high     osd2.linux2.l_i_uid_high
11124  #define i_gid_high     osd2.linux2.l_i_gid_high
11125 +#define i_raw_tag      osd2.linux2.l_i_tag
11126  #define i_reserved2    osd2.linux2.l_i_reserved2
11127  
11128  #elif defined(__GNU__)
11129 @@ -400,6 +404,7 @@ struct ext4_inode {
11130  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
11131  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
11132  #define EXT4_MOUNT_EXTENTS             0x400000 /* Extents support */
11133 +#define EXT4_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
11134  
11135  /* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */
11136  #ifndef _LINUX_EXT2_FS_H
11137 @@ -850,6 +855,7 @@ struct buffer_head * ext4_bread (handle_
11138  int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,
11139         sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result,
11140         int create, int extend_disksize);
11141 +extern int ext4_sync_flags(struct inode *inode);
11142  
11143  extern void ext4_read_inode (struct inode *);
11144  extern int  ext4_write_inode (struct inode *, int);
11145 diff -Nurp linux-2.6.22.18/include/linux/fs.h linux-2.6.22.18-vs2.3.0.32/include/linux/fs.h
11146 --- linux-2.6.22.18/include/linux/fs.h  2007-07-22 00:00:23.000000000 +0200
11147 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/fs.h       2008-02-11 12:35:35.000000000 +0100
11148 @@ -123,6 +123,8 @@ extern int dir_notify_enable;
11149  #define MS_SLAVE       (1<<19) /* change to slave */
11150  #define MS_SHARED      (1<<20) /* change to shared */
11151  #define MS_RELATIME    (1<<21) /* Update atime relative to mtime/ctime. */
11152 +#define MS_TAGGED      (1<<24) /* use generic inode tagging */
11153 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
11154  #define MS_ACTIVE      (1<<30)
11155  #define MS_NOUSER      (1<<31)
11156  
11157 @@ -149,6 +151,8 @@ extern int dir_notify_enable;
11158  #define S_NOCMTIME     128     /* Do not update file c/mtime */
11159  #define S_SWAPFILE     256     /* Do not truncate: swapon got its bmaps */
11160  #define S_PRIVATE      512     /* Inode is fs-internal */
11161 +#define S_BARRIER      1024    /* Barrier for chroot() */
11162 +#define S_IUNLINK      2048    /* Immutable unlink */
11163  
11164  /*
11165   * Note that nosuid etc flags are inode-specific: setting some file-system
11166 @@ -165,24 +169,36 @@ extern int dir_notify_enable;
11167   */
11168  #define __IS_FLG(inode,flg) ((inode)->i_sb->s_flags & (flg))
11169  
11170 -#define IS_RDONLY(inode) ((inode)->i_sb->s_flags & MS_RDONLY)
11171 +#define IS_RDONLY(inode)       __IS_FLG(inode, MS_RDONLY)
11172  #define IS_SYNC(inode)         (__IS_FLG(inode, MS_SYNCHRONOUS) || \
11173                                         ((inode)->i_flags & S_SYNC))
11174  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
11175                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
11176  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
11177 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
11178 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
11179 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
11180  
11181  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
11182  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
11183  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
11184 +#define IS_IUNLINK(inode)      ((inode)->i_flags & S_IUNLINK)
11185 +#define IS_IXORUNLINK(inode)   ((IS_IUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
11186  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
11187  
11188 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_flags & S_BARRIER))
11189  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
11190  #define IS_NOCMTIME(inode)     ((inode)->i_flags & S_NOCMTIME)
11191  #define IS_SWAPFILE(inode)     ((inode)->i_flags & S_SWAPFILE)
11192  #define IS_PRIVATE(inode)      ((inode)->i_flags & S_PRIVATE)
11193  
11194 +#ifdef CONFIG_VSERVER_COWBL
11195 +#  define IS_COW(inode)                (IS_IUNLINK(inode) && IS_IMMUTABLE(inode))
11196 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
11197 +#else
11198 +#  define IS_COW(inode)                (0)
11199 +#  define IS_COW_LINK(inode)   (0)
11200 +#endif
11201 +
11202  /* the read-only stuff doesn't really belong here, but any other place is
11203     probably as bad and I don't want to create yet another include file. */
11204  
11205 @@ -256,12 +272,13 @@ extern int dir_notify_enable;
11206  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
11207  #define FS_EXTENT_FL                   0x00080000 /* Extents */
11208  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
11209 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
11210 +#define FS_IUNLINK_FL                  0x08000000 /* Immutable unlink */
11211  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
11212  
11213  #define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
11214  #define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
11215  
11216 -
11217  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
11218  #define SYNC_FILE_RANGE_WRITE          2
11219  #define SYNC_FILE_RANGE_WAIT_AFTER     4
11220 @@ -327,6 +344,7 @@ typedef void (dio_iodone_t)(struct kiocb
11221  #define ATTR_KILL_SUID 2048
11222  #define ATTR_KILL_SGID 4096
11223  #define ATTR_FILE      8192
11224 +#define ATTR_TAG       16384
11225  
11226  /*
11227   * This is the Inode Attributes structure, used for notify_change().  It
11228 @@ -342,6 +360,7 @@ struct iattr {
11229         umode_t         ia_mode;
11230         uid_t           ia_uid;
11231         gid_t           ia_gid;
11232 +       tag_t           ia_tag;
11233         loff_t          ia_size;
11234         struct timespec ia_atime;
11235         struct timespec ia_mtime;
11236 @@ -355,6 +374,9 @@ struct iattr {
11237         struct file     *ia_file;
11238  };
11239  
11240 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
11241 +#define ATTR_FLAG_IUNLINK      1024    /* Immutable unlink */
11242 +
11243  /*
11244   * Includes for diskquotas.
11245   */
11246 @@ -537,7 +559,9 @@ struct inode {
11247         unsigned int            i_nlink;
11248         uid_t                   i_uid;
11249         gid_t                   i_gid;
11250 +       tag_t                   i_tag;
11251         dev_t                   i_rdev;
11252 +       dev_t                   i_mdev;
11253         unsigned long           i_version;
11254         loff_t                  i_size;
11255  #ifdef __NEED_I_SIZE_ORDERED
11256 @@ -672,12 +696,12 @@ static inline void i_size_write(struct i
11257  
11258  static inline unsigned iminor(const struct inode *inode)
11259  {
11260 -       return MINOR(inode->i_rdev);
11261 +       return MINOR(inode->i_mdev);
11262  }
11263  
11264  static inline unsigned imajor(const struct inode *inode)
11265  {
11266 -       return MAJOR(inode->i_rdev);
11267 +       return MAJOR(inode->i_mdev);
11268  }
11269  
11270  extern struct block_device *I_BDEV(struct inode *inode);
11271 @@ -728,6 +752,7 @@ struct file {
11272         loff_t                  f_pos;
11273         struct fown_struct      f_owner;
11274         unsigned int            f_uid, f_gid;
11275 +       xid_t                   f_xid;
11276         struct file_ra_state    f_ra;
11277  
11278         unsigned long           f_version;
11279 @@ -811,6 +836,7 @@ struct file_lock {
11280         unsigned char fl_type;
11281         loff_t fl_start;
11282         loff_t fl_end;
11283 +       xid_t fl_xid;
11284  
11285         struct fasync_struct *  fl_fasync; /* for lease break notifications */
11286         unsigned long fl_break_time;    /* for nonblocking lease breaks */
11287 @@ -993,12 +1019,12 @@ extern void unlock_super(struct super_bl
11288   */
11289  extern int vfs_permission(struct nameidata *, int);
11290  extern int vfs_create(struct inode *, struct dentry *, int, struct nameidata *);
11291 -extern int vfs_mkdir(struct inode *, struct dentry *, int);
11292 -extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t);
11293 -extern int vfs_symlink(struct inode *, struct dentry *, const char *, int);
11294 -extern int vfs_link(struct dentry *, struct inode *, struct dentry *);
11295 -extern int vfs_rmdir(struct inode *, struct dentry *);
11296 -extern int vfs_unlink(struct inode *, struct dentry *);
11297 +extern int vfs_mkdir(struct inode *, struct dentry *, int, struct nameidata *);
11298 +extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t, struct nameidata *);
11299 +extern int vfs_symlink(struct inode *, struct dentry *, const char *, int, struct nameidata *);
11300 +extern int vfs_link(struct dentry *, struct inode *, struct dentry *, struct nameidata *);
11301 +extern int vfs_rmdir(struct inode *, struct dentry *, struct nameidata *);
11302 +extern int vfs_unlink(struct inode *, struct dentry *, struct nameidata *);
11303  extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
11304  
11305  /*
11306 @@ -1138,6 +1164,7 @@ struct inode_operations {
11307         ssize_t (*listxattr) (struct dentry *, char *, size_t);
11308         int (*removexattr) (struct dentry *, const char *);
11309         void (*truncate_range)(struct inode *, loff_t, loff_t);
11310 +       int (*sync_flags) (struct inode *);
11311  };
11312  
11313  struct seq_file;
11314 @@ -1153,6 +1180,7 @@ extern ssize_t vfs_readv(struct file *, 
11315                 unsigned long, loff_t *);
11316  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
11317                 unsigned long, loff_t *);
11318 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
11319  
11320  /*
11321   * NOTE: write_inode, delete_inode, clear_inode, put_inode can be called
11322 @@ -1898,6 +1926,7 @@ extern int dcache_dir_open(struct inode 
11323  extern int dcache_dir_close(struct inode *, struct file *);
11324  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
11325  extern int dcache_readdir(struct file *, void *, filldir_t);
11326 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
11327  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
11328  extern int simple_statfs(struct dentry *, struct kstatfs *);
11329  extern int simple_link(struct dentry *, struct inode *, struct dentry *);
11330 diff -Nurp linux-2.6.22.18/include/linux/init_task.h linux-2.6.22.18-vs2.3.0.32/include/linux/init_task.h
11331 --- linux-2.6.22.18/include/linux/init_task.h   2007-07-22 00:00:23.000000000 +0200
11332 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/init_task.h        2008-02-11 12:35:35.000000000 +0100
11333 @@ -169,6 +169,10 @@ extern struct group_info init_groups;
11334         },                                                              \
11335         INIT_TRACE_IRQFLAGS                                             \
11336         INIT_LOCKDEP                                                    \
11337 +       .xid            = 0,                                            \
11338 +       .vx_info        = NULL,                                         \
11339 +       .nid            = 0,                                            \
11340 +       .nx_info        = NULL,                                         \
11341  }
11342  
11343  
11344 diff -Nurp linux-2.6.22.18/include/linux/ipc.h linux-2.6.22.18-vs2.3.0.32/include/linux/ipc.h
11345 --- linux-2.6.22.18/include/linux/ipc.h 2007-07-22 00:00:23.000000000 +0200
11346 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/ipc.h      2008-02-11 12:35:35.000000000 +0100
11347 @@ -63,6 +63,7 @@ struct kern_ipc_perm
11348         key_t           key;
11349         uid_t           uid;
11350         gid_t           gid;
11351 +       xid_t           xid;
11352         uid_t           cuid;
11353         gid_t           cgid;
11354         mode_t          mode; 
11355 diff -Nurp linux-2.6.22.18/include/linux/jffs2.h linux-2.6.22.18-vs2.3.0.32/include/linux/jffs2.h
11356 --- linux-2.6.22.18/include/linux/jffs2.h       2007-05-04 15:57:43.000000000 +0200
11357 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/jffs2.h    2008-02-11 12:35:36.000000000 +0100
11358 @@ -82,12 +82,36 @@
11359  //#define JFFS2_NODETYPE_OPTIONS (JFFS2_FEATURE_RWCOMPAT_COPY | JFFS2_NODE_ACCURATE | 4)
11360  
11361  
11362 -#define JFFS2_INO_FLAG_PREREAD   1     /* Do read_inode() for this one at
11363 +#define JFFS2_INO_FLAG_PREREAD   0x01  /* Do read_inode() for this one at
11364                                            mount time, don't wait for it to
11365                                            happen later */
11366 -#define JFFS2_INO_FLAG_USERCOMPR  2    /* User has requested a specific
11367 +#define JFFS2_INO_FLAG_USERCOMPR 0x02  /* User has requested a specific
11368                                            compression type */
11369  
11370 +#define JFFS2_INO_FLAG_IMMUTABLE 0x10  /* immutable node */
11371 +#define JFFS2_INO_FLAG_IUNLINK   0x20  /* immutable unlink */
11372 +#define JFFS2_INO_FLAG_BARRIER   0x40  /* barrier */
11373 +
11374 +#define JFFS2_USER_VISIBLE       0x10
11375 +#define JFFS2_USER_MODIFIABLE    0x10
11376 +
11377 +/*
11378 + * Mount flags
11379 + */
11380 +#define JFFS2_MOUNT_TAGGED     (1<<24)   /* Enable Context Tags */
11381 +
11382 +#define clear_opt(o, opt)      o &= ~JFFS2_MOUNT_##opt
11383 +#define set_opt(o, opt)                o |= JFFS2_MOUNT_##opt
11384 +
11385 +/*
11386 + * Maximal mount counts between two filesystem checks
11387 + */
11388 +#define EXT2_DFL_MAX_MNT_COUNT         20      /* Allow 20 mounts */
11389 +#define EXT2_DFL_CHECKINTERVAL         0       /* Don't use interval check */
11390 +
11391 +/*
11392 + * Behaviour when detecting errors
11393 + */
11394  
11395  /* These can go once we've made sure we've caught all uses without
11396     byteswapping */
11397 @@ -97,7 +121,7 @@ typedef struct {
11398  } __attribute__((packed)) jint32_t;
11399  
11400  typedef struct {
11401 -       uint32_t m;
11402 +       uint16_t m;
11403  } __attribute__((packed)) jmode_t;
11404  
11405  typedef struct {
11406 @@ -145,7 +169,8 @@ struct jffs2_raw_inode
11407         jint32_t hdr_crc;
11408         jint32_t ino;        /* Inode number.  */
11409         jint32_t version;    /* Version number.  */
11410 -       jmode_t mode;       /* The file's type or mode.  */
11411 +       jmode_t mode;        /* The file's type or mode.  */
11412 +       jint16_t tag;        /* context tagging */
11413         jint16_t uid;        /* The file's owner.  */
11414         jint16_t gid;        /* The file's group.  */
11415         jint32_t isize;      /* Total resultant size of this inode (used for truncations)  */
11416 diff -Nurp linux-2.6.22.18/include/linux/Kbuild linux-2.6.22.18-vs2.3.0.32/include/linux/Kbuild
11417 --- linux-2.6.22.18/include/linux/Kbuild        2007-09-29 14:11:49.000000000 +0200
11418 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/Kbuild     2008-02-11 12:35:35.000000000 +0100
11419 @@ -351,3 +351,6 @@ unifdef-y += xattr.h
11420  unifdef-y += xfrm.h
11421  
11422  objhdr-y += version.h
11423 +
11424 +header-y += vserver/
11425 +
11426 diff -Nurp linux-2.6.22.18/include/linux/loop.h linux-2.6.22.18-vs2.3.0.32/include/linux/loop.h
11427 --- linux-2.6.22.18/include/linux/loop.h        2007-07-22 00:00:24.000000000 +0200
11428 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/loop.h     2008-02-11 12:35:36.000000000 +0100
11429 @@ -45,6 +45,7 @@ struct loop_device {
11430         struct loop_func_table *lo_encryption;
11431         __u32           lo_init[2];
11432         uid_t           lo_key_owner;   /* Who set the key */
11433 +       xid_t           lo_xid;
11434         int             (*ioctl)(struct loop_device *, int cmd, 
11435                                  unsigned long arg); 
11436  
11437 diff -Nurp linux-2.6.22.18/include/linux/magic.h linux-2.6.22.18-vs2.3.0.32/include/linux/magic.h
11438 --- linux-2.6.22.18/include/linux/magic.h       2007-07-22 00:00:24.000000000 +0200
11439 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/magic.h    2008-02-11 12:35:36.000000000 +0100
11440 @@ -3,7 +3,7 @@
11441  
11442  #define ADFS_SUPER_MAGIC       0xadf5
11443  #define AFFS_SUPER_MAGIC       0xadff
11444 -#define AFS_SUPER_MAGIC                0x5346414F
11445 +#define AFS_SUPER_MAGIC                0x5346414F
11446  #define AUTOFS_SUPER_MAGIC     0x0187
11447  #define CODA_SUPER_MAGIC       0x73757245
11448  #define EFS_SUPER_MAGIC                0x414A53
11449 @@ -27,6 +27,7 @@
11450  #define NFS_SUPER_MAGIC                0x6969
11451  #define OPENPROM_SUPER_MAGIC   0x9fa1
11452  #define PROC_SUPER_MAGIC       0x9fa0
11453 +#define DEVPTS_SUPER_MAGIC     0x1cd1
11454  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
11455  
11456  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
11457 diff -Nurp linux-2.6.22.18/include/linux/major.h linux-2.6.22.18-vs2.3.0.32/include/linux/major.h
11458 --- linux-2.6.22.18/include/linux/major.h       2007-07-22 00:00:24.000000000 +0200
11459 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/major.h    2008-02-11 12:35:36.000000000 +0100
11460 @@ -15,6 +15,7 @@
11461  #define HD_MAJOR               IDE0_MAJOR
11462  #define PTY_SLAVE_MAJOR                3
11463  #define TTY_MAJOR              4
11464 +#define VROOT_MAJOR            4
11465  #define TTYAUX_MAJOR           5
11466  #define LP_MAJOR               6
11467  #define VCS_MAJOR              7
11468 diff -Nurp linux-2.6.22.18/include/linux/mount.h linux-2.6.22.18-vs2.3.0.32/include/linux/mount.h
11469 --- linux-2.6.22.18/include/linux/mount.h       2007-07-22 00:00:24.000000000 +0200
11470 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/mount.h    2008-02-11 12:35:36.000000000 +0100
11471 @@ -28,6 +28,9 @@ struct mnt_namespace;
11472  #define MNT_NOATIME    0x08
11473  #define MNT_NODIRATIME 0x10
11474  #define MNT_RELATIME   0x20
11475 +#define MNT_RDONLY     0x40
11476 +
11477 +#define MNT_IS_RDONLY(m)       ((m) && ((m)->mnt_flags & MNT_RDONLY))
11478  
11479  #define MNT_SHRINKABLE 0x100
11480  
11481 @@ -35,6 +38,10 @@ struct mnt_namespace;
11482  #define MNT_UNBINDABLE 0x2000  /* if the vfsmount is a unbindable mount */
11483  #define MNT_PNODE_MASK 0x3000  /* propagation flag mask */
11484  
11485 +#define MNT_TAGID      0x10000
11486 +#define MNT_NOTAG      0x20000
11487 +#define MNT_NOTAGCHECK 0x40000
11488 +
11489  struct vfsmount {
11490         struct list_head mnt_hash;
11491         struct vfsmount *mnt_parent;    /* fs we are mounted on */
11492 @@ -61,6 +68,7 @@ struct vfsmount {
11493         atomic_t mnt_count;
11494         int mnt_expiry_mark;            /* true if marked for expiry */
11495         int mnt_pinned;
11496 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
11497  };
11498  
11499  static inline struct vfsmount *mntget(struct vfsmount *mnt)
11500 diff -Nurp linux-2.6.22.18/include/linux/net.h linux-2.6.22.18-vs2.3.0.32/include/linux/net.h
11501 --- linux-2.6.22.18/include/linux/net.h 2007-07-22 00:00:24.000000000 +0200
11502 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/net.h      2008-02-11 12:35:36.000000000 +0100
11503 @@ -63,6 +63,7 @@ typedef enum {
11504  #define SOCK_NOSPACE           2
11505  #define SOCK_PASSCRED          3
11506  #define SOCK_PASSSEC           4
11507 +#define SOCK_USER_SOCKET       5
11508  
11509  #ifndef ARCH_HAS_SOCKET_TYPES
11510  /**
11511 diff -Nurp linux-2.6.22.18/include/linux/nfs_mount.h linux-2.6.22.18-vs2.3.0.32/include/linux/nfs_mount.h
11512 --- linux-2.6.22.18/include/linux/nfs_mount.h   2007-07-22 00:00:24.000000000 +0200
11513 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/nfs_mount.h        2008-02-11 12:35:36.000000000 +0100
11514 @@ -62,6 +62,7 @@ struct nfs_mount_data {
11515  #define NFS_MOUNT_STRICTLOCK   0x1000  /* reserved for NFSv4 */
11516  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
11517  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
11518 +#define NFS_MOUNT_TAGGED       0x8000  /* context tagging */
11519  #define NFS_MOUNT_FLAGMASK     0xFFFF
11520  
11521  #endif
11522 diff -Nurp linux-2.6.22.18/include/linux/nsproxy.h linux-2.6.22.18-vs2.3.0.32/include/linux/nsproxy.h
11523 --- linux-2.6.22.18/include/linux/nsproxy.h     2007-07-22 00:00:24.000000000 +0200
11524 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/nsproxy.h  2008-02-11 12:35:36.000000000 +0100
11525 @@ -3,6 +3,7 @@
11526  
11527  #include <linux/spinlock.h>
11528  #include <linux/sched.h>
11529 +#include <linux/vserver/debug.h>
11530  
11531  struct mnt_namespace;
11532  struct uts_namespace;
11533 @@ -32,26 +33,46 @@ struct nsproxy {
11534  extern struct nsproxy init_nsproxy;
11535  
11536  int copy_namespaces(int flags, struct task_struct *tsk);
11537 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
11538  void get_task_namespaces(struct task_struct *tsk);
11539  void free_nsproxy(struct nsproxy *ns);
11540  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
11541         struct fs_struct *);
11542  
11543 -static inline void put_nsproxy(struct nsproxy *ns)
11544 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
11545 +
11546 +static inline void __get_nsproxy(struct nsproxy *ns,
11547 +       const char *_file, int _line)
11548  {
11549 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
11550 +               ns, atomic_read(&ns->count), _file, _line);
11551 +       atomic_inc(&ns->count);
11552 +}
11553 +
11554 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
11555 +
11556 +static inline void __put_nsproxy(struct nsproxy *ns,
11557 +       const char *_file, int _line)
11558 +{
11559 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
11560 +               ns, atomic_read(&ns->count), _file, _line);
11561         if (atomic_dec_and_test(&ns->count)) {
11562                 free_nsproxy(ns);
11563         }
11564  }
11565  
11566 -static inline void exit_task_namespaces(struct task_struct *p)
11567 +#define        exit_task_namespaces(p) __exit_task_namespaces(p, __FILE__, __LINE__)
11568 +
11569 +static inline void __exit_task_namespaces(struct task_struct *p,
11570 +       const char *_file, int _line)
11571  {
11572         struct nsproxy *ns = p->nsproxy;
11573         if (ns) {
11574                 task_lock(p);
11575                 p->nsproxy = NULL;
11576                 task_unlock(p);
11577 -               put_nsproxy(ns);
11578 +               __put_nsproxy(ns, _file, _line);
11579         }
11580  }
11581 +
11582  #endif
11583 diff -Nurp linux-2.6.22.18/include/linux/pid.h linux-2.6.22.18-vs2.3.0.32/include/linux/pid.h
11584 --- linux-2.6.22.18/include/linux/pid.h 2007-07-22 00:00:24.000000000 +0200
11585 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/pid.h      2008-02-11 12:35:36.000000000 +0100
11586 @@ -8,7 +8,8 @@ enum pid_type
11587         PIDTYPE_PID,
11588         PIDTYPE_PGID,
11589         PIDTYPE_SID,
11590 -       PIDTYPE_MAX
11591 +       PIDTYPE_MAX,
11592 +       PIDTYPE_REALPID
11593  };
11594  
11595  /*
11596 diff -Nurp linux-2.6.22.18/include/linux/proc_fs.h linux-2.6.22.18-vs2.3.0.32/include/linux/proc_fs.h
11597 --- linux-2.6.22.18/include/linux/proc_fs.h     2007-07-22 00:00:24.000000000 +0200
11598 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/proc_fs.h  2008-02-11 12:35:36.000000000 +0100
11599 @@ -54,6 +54,7 @@ struct proc_dir_entry {
11600         nlink_t nlink;
11601         uid_t uid;
11602         gid_t gid;
11603 +       int vx_flags;
11604         loff_t size;
11605         const struct inode_operations *proc_iops;
11606         const struct file_operations *proc_fops;
11607 @@ -246,13 +247,20 @@ static inline void kclist_add(struct kco
11608  extern void kclist_add(struct kcore_list *, void *, size_t);
11609  #endif
11610  
11611 +struct vx_info;
11612 +struct nx_info;
11613 +
11614  union proc_op {
11615         int (*proc_get_link)(struct inode *, struct dentry **, struct vfsmount **);
11616         int (*proc_read)(struct task_struct *task, char *page);
11617 +       int (*proc_vs_read)(char *page);
11618 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
11619 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
11620  };
11621  
11622  struct proc_inode {
11623         struct pid *pid;
11624 +       int vx_flags;
11625         int fd;
11626         union proc_op op;
11627         struct proc_dir_entry *pde;
11628 diff -Nurp linux-2.6.22.18/include/linux/reiserfs_fs.h linux-2.6.22.18-vs2.3.0.32/include/linux/reiserfs_fs.h
11629 --- linux-2.6.22.18/include/linux/reiserfs_fs.h 2007-07-21 23:58:53.000000000 +0200
11630 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/reiserfs_fs.h      2008-02-11 12:35:36.000000000 +0100
11631 @@ -821,6 +821,10 @@ struct stat_data_v1 {
11632  #define REISERFS_COMPR_FL     FS_COMPR_FL
11633  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
11634  
11635 +/* unfortunately reiserfs sdattr is only 16 bit */
11636 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
11637 +#define REISERFS_IUNLINK_FL   (FS_IUNLINK_FL >> 16)
11638 +
11639  /* persistent flags that file inherits from the parent directory */
11640  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
11641                                 REISERFS_SYNC_FL |      \
11642 @@ -830,6 +834,9 @@ struct stat_data_v1 {
11643                                 REISERFS_COMPR_FL |     \
11644                                 REISERFS_NOTAIL_FL )
11645  
11646 +#define REISERFS_FL_USER_VISIBLE       0x80FF
11647 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
11648 +
11649  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
11650     address blocks) */
11651  struct stat_data {
11652 @@ -1901,6 +1908,7 @@ static inline void reiserfs_update_sd(st
11653  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
11654  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
11655  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
11656 +int reiserfs_sync_flags(struct inode *inode);
11657  
11658  /* namei.c */
11659  void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
11660 diff -Nurp linux-2.6.22.18/include/linux/reiserfs_fs_sb.h linux-2.6.22.18-vs2.3.0.32/include/linux/reiserfs_fs_sb.h
11661 --- linux-2.6.22.18/include/linux/reiserfs_fs_sb.h      2007-07-22 00:00:24.000000000 +0200
11662 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/reiserfs_fs_sb.h   2008-02-11 12:35:36.000000000 +0100
11663 @@ -458,6 +458,7 @@ enum reiserfs_mount_options {
11664         REISERFS_POSIXACL,
11665         REISERFS_BARRIER_NONE,
11666         REISERFS_BARRIER_FLUSH,
11667 +       REISERFS_TAGGED,
11668  
11669         /* Actions on error */
11670         REISERFS_ERROR_PANIC,
11671 diff -Nurp linux-2.6.22.18/include/linux/sched.h linux-2.6.22.18-vs2.3.0.32/include/linux/sched.h
11672 --- linux-2.6.22.18/include/linux/sched.h       2007-07-22 00:00:24.000000000 +0200
11673 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/sched.h    2008-02-11 12:35:36.000000000 +0100
11674 @@ -26,6 +26,7 @@
11675  #define CLONE_STOPPED          0x02000000      /* Start in stopped state */
11676  #define CLONE_NEWUTS           0x04000000      /* New utsname group? */
11677  #define CLONE_NEWIPC           0x08000000      /* New ipcs */
11678 +#define CLONE_KTHREAD          0x10000000      /* clone a kernel thread */
11679  
11680  /*
11681   * Scheduling policies
11682 @@ -94,7 +95,7 @@ struct bio;
11683   * List of flags we want to share for kernel threads,
11684   * if only because they are not used by them anyway.
11685   */
11686 -#define CLONE_KERNEL   (CLONE_FS | CLONE_FILES | CLONE_SIGHAND)
11687 +#define CLONE_KERNEL   (CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_KTHREAD)
11688  
11689  /*
11690   * These are the constant used to fake the fixed-point load-average
11691 @@ -146,12 +147,13 @@ extern unsigned long weighted_cpuload(co
11692  #define TASK_UNINTERRUPTIBLE   2
11693  #define TASK_STOPPED           4
11694  #define TASK_TRACED            8
11695 +#define TASK_ONHOLD            16
11696  /* in tsk->exit_state */
11697 -#define EXIT_ZOMBIE            16
11698 -#define EXIT_DEAD              32
11699 +#define EXIT_ZOMBIE            32
11700 +#define EXIT_DEAD              64
11701  /* in tsk->state again */
11702 -#define TASK_NONINTERACTIVE    64
11703 -#define TASK_DEAD              128
11704 +#define TASK_NONINTERACTIVE    128
11705 +#define TASK_DEAD              256
11706  
11707  #define __set_task_state(tsk, state_value)             \
11708         do { (tsk)->state = (state_value); } while (0)
11709 @@ -287,27 +289,30 @@ extern void arch_unmap_area_topdown(stru
11710   * The mm counters are not protected by its page_table_lock,
11711   * so must be incremented atomically.
11712   */
11713 -#define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
11714 -#define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
11715 -#define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
11716 -#define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
11717 -#define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
11718  typedef atomic_long_t mm_counter_t;
11719 +#define __set_mm_counter(mm, member, value) \
11720 +       atomic_long_set(&(mm)->_##member, value)
11721 +#define get_mm_counter(mm, member) \
11722 +       ((unsigned long)atomic_long_read(&(mm)->_##member))
11723  
11724  #else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
11725  /*
11726   * The mm counters are protected by its page_table_lock,
11727   * so can be incremented directly.
11728   */
11729 -#define set_mm_counter(mm, member, value) (mm)->_##member = (value)
11730 -#define get_mm_counter(mm, member) ((mm)->_##member)
11731 -#define add_mm_counter(mm, member, value) (mm)->_##member += (value)
11732 -#define inc_mm_counter(mm, member) (mm)->_##member++
11733 -#define dec_mm_counter(mm, member) (mm)->_##member--
11734  typedef unsigned long mm_counter_t;
11735 +#define __set_mm_counter(mm, member, value) (mm)->_##member = (value)
11736 +#define get_mm_counter(mm, member) ((mm)->_##member)
11737  
11738  #endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
11739  
11740 +#define set_mm_counter(mm, member, value) \
11741 +       vx_ ## member ## pages_sub((mm), (get_mm_counter(mm, member) - value))
11742 +#define add_mm_counter(mm, member, value) \
11743 +       vx_ ## member ## pages_add((mm), (value))
11744 +#define inc_mm_counter(mm, member) vx_ ## member ## pages_inc((mm))
11745 +#define dec_mm_counter(mm, member) vx_ ## member ## pages_dec((mm))
11746 +
11747  #define get_mm_rss(mm)                                 \
11748         (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
11749  #define update_hiwater_rss(mm) do {                    \
11750 @@ -365,6 +370,7 @@ struct mm_struct {
11751  
11752         /* Architecture-specific MM context */
11753         mm_context_t context;
11754 +       struct vx_info *mm_vx_info;
11755  
11756         /* Swap token stuff */
11757         /*
11758 @@ -570,9 +576,10 @@ struct user_struct {
11759         /* Hash table maintenance information */
11760         struct list_head uidhash_list;
11761         uid_t uid;
11762 +       xid_t xid;
11763  };
11764  
11765 -extern struct user_struct *find_user(uid_t);
11766 +extern struct user_struct *find_user(xid_t, uid_t);
11767  
11768  extern struct user_struct root_user;
11769  #define INIT_USER (&root_user)
11770 @@ -969,6 +976,15 @@ struct task_struct {
11771         
11772         void *security;
11773         struct audit_context *audit_context;
11774 +
11775 +/* vserver context data */
11776 +       struct vx_info *vx_info;
11777 +       struct nx_info *nx_info;
11778 +
11779 +       xid_t xid;
11780 +       nid_t nid;
11781 +       tag_t tag;
11782 +
11783         seccomp_t seccomp;
11784  
11785  /* Thread group tracking */
11786 @@ -1290,12 +1306,16 @@ extern struct task_struct init_task;
11787  
11788  extern struct   mm_struct init_mm;
11789  
11790 -#define find_task_by_pid(nr)   find_task_by_pid_type(PIDTYPE_PID, nr)
11791 +#define find_task_by_real_pid(nr) \
11792 +       find_task_by_pid_type(PIDTYPE_REALPID, nr)
11793 +#define find_task_by_pid(nr) \
11794 +       find_task_by_pid_type(PIDTYPE_PID, nr)
11795 +
11796  extern struct task_struct *find_task_by_pid_type(int type, int pid);
11797  extern void __set_special_pids(pid_t session, pid_t pgrp);
11798  
11799  /* per-UID process charging. */
11800 -extern struct user_struct * alloc_uid(uid_t);
11801 +extern struct user_struct * alloc_uid(xid_t, uid_t);
11802  static inline struct user_struct *get_uid(struct user_struct *u)
11803  {
11804         atomic_inc(&u->__count);
11805 diff -Nurp linux-2.6.22.18/include/linux/shmem_fs.h linux-2.6.22.18-vs2.3.0.32/include/linux/shmem_fs.h
11806 --- linux-2.6.22.18/include/linux/shmem_fs.h    2007-05-04 15:57:44.000000000 +0200
11807 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/shmem_fs.h 2008-02-11 12:35:36.000000000 +0100
11808 @@ -8,6 +8,9 @@
11809  
11810  #define SHMEM_NR_DIRECT 16
11811  
11812 +#define TMPFS_SUPER_MAGIC      0x01021994
11813 +
11814 +
11815  struct shmem_inode_info {
11816         spinlock_t              lock;
11817         unsigned long           flags;
11818 diff -Nurp linux-2.6.22.18/include/linux/stat.h linux-2.6.22.18-vs2.3.0.32/include/linux/stat.h
11819 --- linux-2.6.22.18/include/linux/stat.h        2007-07-22 00:00:24.000000000 +0200
11820 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/stat.h     2008-02-11 12:35:36.000000000 +0100
11821 @@ -66,6 +66,7 @@ struct kstat {
11822         unsigned int    nlink;
11823         uid_t           uid;
11824         gid_t           gid;
11825 +       tag_t           tag;
11826         dev_t           rdev;
11827         loff_t          size;
11828         struct timespec  atime;
11829 diff -Nurp linux-2.6.22.18/include/linux/sunrpc/auth.h linux-2.6.22.18-vs2.3.0.32/include/linux/sunrpc/auth.h
11830 --- linux-2.6.22.18/include/linux/sunrpc/auth.h 2007-05-04 15:57:44.000000000 +0200
11831 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/sunrpc/auth.h      2008-02-11 12:35:36.000000000 +0100
11832 @@ -24,6 +24,7 @@
11833  struct auth_cred {
11834         uid_t   uid;
11835         gid_t   gid;
11836 +       tag_t   tag;
11837         struct group_info *group_info;
11838  };
11839  
11840 diff -Nurp linux-2.6.22.18/include/linux/sunrpc/clnt.h linux-2.6.22.18-vs2.3.0.32/include/linux/sunrpc/clnt.h
11841 --- linux-2.6.22.18/include/linux/sunrpc/clnt.h 2007-07-22 00:00:24.000000000 +0200
11842 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/sunrpc/clnt.h      2008-02-11 12:35:36.000000000 +0100
11843 @@ -43,7 +43,8 @@ struct rpc_clnt {
11844                                 cl_discrtry : 1,/* disconnect before retry */
11845                                 cl_autobind : 1,/* use getport() */
11846                                 cl_oneshot  : 1,/* dispose after use */
11847 -                               cl_dead     : 1;/* abandoned */
11848 +                               cl_dead     : 1,/* abandoned */
11849 +                               cl_tag      : 1;/* context tagging */
11850  
11851         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
11852  
11853 diff -Nurp linux-2.6.22.18/include/linux/syscalls.h linux-2.6.22.18-vs2.3.0.32/include/linux/syscalls.h
11854 --- linux-2.6.22.18/include/linux/syscalls.h    2007-07-22 00:00:24.000000000 +0200
11855 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/syscalls.h 2008-02-11 12:35:36.000000000 +0100
11856 @@ -294,6 +294,8 @@ asmlinkage long sys_symlink(const char _
11857  asmlinkage long sys_unlink(const char __user *pathname);
11858  asmlinkage long sys_rename(const char __user *oldname,
11859                                 const char __user *newname);
11860 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
11861 +                               umode_t mode);
11862  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
11863  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
11864  
11865 diff -Nurp linux-2.6.22.18/include/linux/sysctl.h linux-2.6.22.18-vs2.3.0.32/include/linux/sysctl.h
11866 --- linux-2.6.22.18/include/linux/sysctl.h      2007-07-22 00:00:24.000000000 +0200
11867 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/sysctl.h   2008-02-11 12:35:36.000000000 +0100
11868 @@ -106,6 +106,7 @@ enum
11869         KERN_CAP_BSET=14,       /* int: capability bounding set */
11870         KERN_PANIC=15,          /* int: panic timeout */
11871         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
11872 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
11873  
11874         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
11875         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
11876 diff -Nurp linux-2.6.22.18/include/linux/sysfs.h linux-2.6.22.18-vs2.3.0.32/include/linux/sysfs.h
11877 --- linux-2.6.22.18/include/linux/sysfs.h       2007-07-22 00:00:24.000000000 +0200
11878 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/sysfs.h    2008-02-11 12:35:36.000000000 +0100
11879 @@ -15,6 +15,8 @@
11880  #include <linux/list.h>
11881  #include <asm/atomic.h>
11882  
11883 +#define SYSFS_SUPER_MAGIC      0x62656572
11884 +
11885  struct kobject;
11886  struct module;
11887  struct nameidata;
11888 diff -Nurp linux-2.6.22.18/include/linux/time.h linux-2.6.22.18-vs2.3.0.32/include/linux/time.h
11889 --- linux-2.6.22.18/include/linux/time.h        2007-07-22 00:00:24.000000000 +0200
11890 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/time.h     2008-02-11 12:35:36.000000000 +0100
11891 @@ -176,6 +176,9 @@ static inline void timespec_add_ns(struc
11892         }
11893         a->tv_nsec = ns;
11894  }
11895 +
11896 +#include <linux/vs_time.h>
11897 +
11898  #endif /* __KERNEL__ */
11899  
11900  #define NFDBITS                        __NFDBITS
11901 diff -Nurp linux-2.6.22.18/include/linux/types.h linux-2.6.22.18-vs2.3.0.32/include/linux/types.h
11902 --- linux-2.6.22.18/include/linux/types.h       2007-05-04 15:58:24.000000000 +0200
11903 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/types.h    2008-02-11 12:35:36.000000000 +0100
11904 @@ -39,6 +39,9 @@ typedef __kernel_uid32_t      uid_t;
11905  typedef __kernel_gid32_t       gid_t;
11906  typedef __kernel_uid16_t        uid16_t;
11907  typedef __kernel_gid16_t        gid16_t;
11908 +typedef unsigned int           xid_t;
11909 +typedef unsigned int           nid_t;
11910 +typedef unsigned int           tag_t;
11911  
11912  #ifdef CONFIG_UID16
11913  /* This is defined by include/asm-{arch}/posix_types.h */
11914 diff -Nurp linux-2.6.22.18/include/linux/vroot.h linux-2.6.22.18-vs2.3.0.32/include/linux/vroot.h
11915 --- linux-2.6.22.18/include/linux/vroot.h       1970-01-01 01:00:00.000000000 +0100
11916 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vroot.h    2008-02-11 12:35:36.000000000 +0100
11917 @@ -0,0 +1,51 @@
11918 +
11919 +/*
11920 + * include/linux/vroot.h
11921 + *
11922 + * written by Herbert Pötzl, 9/11/2002
11923 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
11924 + *
11925 + * Copyright (C) 2002-2007 by Herbert Pötzl.
11926 + * Redistribution of this file is permitted under the
11927 + * GNU General Public License.
11928 + */
11929 +
11930 +#ifndef _LINUX_VROOT_H
11931 +#define _LINUX_VROOT_H
11932 +
11933 +
11934 +#ifdef __KERNEL__
11935 +
11936 +/* Possible states of device */
11937 +enum {
11938 +       Vr_unbound,
11939 +       Vr_bound,
11940 +};
11941 +
11942 +struct vroot_device {
11943 +       int             vr_number;
11944 +       int             vr_refcnt;
11945 +
11946 +       struct semaphore        vr_ctl_mutex;
11947 +       struct block_device    *vr_device;
11948 +       int                     vr_state;
11949 +};
11950 +
11951 +
11952 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
11953 +
11954 +extern int register_vroot_grb(vroot_grb_func *);
11955 +extern int unregister_vroot_grb(vroot_grb_func *);
11956 +
11957 +#endif /* __KERNEL__ */
11958 +
11959 +#define MAX_VROOT_DEFAULT      8
11960 +
11961 +/*
11962 + * IOCTL commands --- we will commandeer 0x56 ('V')
11963 + */
11964 +
11965 +#define VROOT_SET_DEV          0x5600
11966 +#define VROOT_CLR_DEV          0x5601
11967 +
11968 +#endif /* _LINUX_VROOT_H */
11969 diff -Nurp linux-2.6.22.18/include/linux/vs_base.h linux-2.6.22.18-vs2.3.0.32/include/linux/vs_base.h
11970 --- linux-2.6.22.18/include/linux/vs_base.h     1970-01-01 01:00:00.000000000 +0100
11971 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vs_base.h  2008-02-11 12:35:36.000000000 +0100
11972 @@ -0,0 +1,9 @@
11973 +#ifndef _VS_BASE_H
11974 +#define _VS_BASE_H
11975 +
11976 +#include "vserver/base.h"
11977 +#include "vserver/debug.h"
11978 +
11979 +#else
11980 +#warning duplicate inclusion
11981 +#endif
11982 diff -Nurp linux-2.6.22.18/include/linux/vs_context.h linux-2.6.22.18-vs2.3.0.32/include/linux/vs_context.h
11983 --- linux-2.6.22.18/include/linux/vs_context.h  1970-01-01 01:00:00.000000000 +0100
11984 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vs_context.h       2008-02-11 12:35:36.000000000 +0100
11985 @@ -0,0 +1,224 @@
11986 +#ifndef _VS_CONTEXT_H
11987 +#define _VS_CONTEXT_H
11988 +
11989 +#include "vserver/base.h"
11990 +#include "vserver/context.h"
11991 +#include "vserver/history.h"
11992 +#include "vserver/debug.h"
11993 +
11994 +
11995 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
11996 +
11997 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
11998 +       const char *_file, int _line, void *_here)
11999 +{
12000 +       if (!vxi)
12001 +               return NULL;
12002 +
12003 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
12004 +               vxi, vxi ? vxi->vx_id : 0,
12005 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
12006 +               _file, _line);
12007 +       __vxh_get_vx_info(vxi, _here);
12008 +
12009 +       atomic_inc(&vxi->vx_usecnt);
12010 +       return vxi;
12011 +}
12012 +
12013 +
12014 +extern void free_vx_info(struct vx_info *);
12015 +
12016 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
12017 +
12018 +static inline void __put_vx_info(struct vx_info *vxi,
12019 +       const char *_file, int _line, void *_here)
12020 +{
12021 +       if (!vxi)
12022 +               return;
12023 +
12024 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
12025 +               vxi, vxi ? vxi->vx_id : 0,
12026 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
12027 +               _file, _line);
12028 +       __vxh_put_vx_info(vxi, _here);
12029 +
12030 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
12031 +               free_vx_info(vxi);
12032 +}
12033 +
12034 +
12035 +#define init_vx_info(p, i) \
12036 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
12037 +
12038 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
12039 +       const char *_file, int _line, void *_here)
12040 +{
12041 +       if (vxi) {
12042 +               vxlprintk(VXD_CBIT(xid, 3),
12043 +                       "init_vx_info(%p[#%d.%d])",
12044 +                       vxi, vxi ? vxi->vx_id : 0,
12045 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
12046 +                       _file, _line);
12047 +               __vxh_init_vx_info(vxi, vxp, _here);
12048 +
12049 +               atomic_inc(&vxi->vx_usecnt);
12050 +       }
12051 +       *vxp = vxi;
12052 +}
12053 +
12054 +
12055 +#define set_vx_info(p, i) \
12056 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
12057 +
12058 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
12059 +       const char *_file, int _line, void *_here)
12060 +{
12061 +       struct vx_info *vxo;
12062 +
12063 +       if (!vxi)
12064 +               return;
12065 +
12066 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
12067 +               vxi, vxi ? vxi->vx_id : 0,
12068 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
12069 +               _file, _line);
12070 +       __vxh_set_vx_info(vxi, vxp, _here);
12071 +
12072 +       atomic_inc(&vxi->vx_usecnt);
12073 +       vxo = xchg(vxp, vxi);
12074 +       BUG_ON(vxo);
12075 +}
12076 +
12077 +
12078 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
12079 +
12080 +static inline void __clr_vx_info(struct vx_info **vxp,
12081 +       const char *_file, int _line, void *_here)
12082 +{
12083 +       struct vx_info *vxo;
12084 +
12085 +       vxo = xchg(vxp, NULL);
12086 +       if (!vxo)
12087 +               return;
12088 +
12089 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
12090 +               vxo, vxo ? vxo->vx_id : 0,
12091 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
12092 +               _file, _line);
12093 +       __vxh_clr_vx_info(vxo, vxp, _here);
12094 +
12095 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
12096 +               free_vx_info(vxo);
12097 +}
12098 +
12099 +
12100 +#define claim_vx_info(v, p) \
12101 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
12102 +
12103 +static inline void __claim_vx_info(struct vx_info *vxi,
12104 +       struct task_struct *task,
12105 +       const char *_file, int _line, void *_here)
12106 +{
12107 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
12108 +               vxi, vxi ? vxi->vx_id : 0,
12109 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
12110 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
12111 +               task, _file, _line);
12112 +       __vxh_claim_vx_info(vxi, task, _here);
12113 +
12114 +       atomic_inc(&vxi->vx_tasks);
12115 +}
12116 +
12117 +
12118 +extern void unhash_vx_info(struct vx_info *);
12119 +
12120 +#define release_vx_info(v, p) \
12121 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
12122 +
12123 +static inline void __release_vx_info(struct vx_info *vxi,
12124 +       struct task_struct *task,
12125 +       const char *_file, int _line, void *_here)
12126 +{
12127 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
12128 +               vxi, vxi ? vxi->vx_id : 0,
12129 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
12130 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
12131 +               task, _file, _line);
12132 +       __vxh_release_vx_info(vxi, task, _here);
12133 +
12134 +       might_sleep();
12135 +
12136 +       if (atomic_dec_and_test(&vxi->vx_tasks))
12137 +               unhash_vx_info(vxi);
12138 +}
12139 +
12140 +
12141 +#define task_get_vx_info(p) \
12142 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
12143 +
12144 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
12145 +       const char *_file, int _line, void *_here)
12146 +{
12147 +       struct vx_info *vxi;
12148 +
12149 +       task_lock(p);
12150 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
12151 +               p, _file, _line);
12152 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
12153 +       task_unlock(p);
12154 +       return vxi;
12155 +}
12156 +
12157 +
12158 +static inline void __wakeup_vx_info(struct vx_info *vxi)
12159 +{
12160 +       if (waitqueue_active(&vxi->vx_wait))
12161 +               wake_up_interruptible(&vxi->vx_wait);
12162 +}
12163 +
12164 +
12165 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
12166 +
12167 +static inline void __enter_vx_info(struct vx_info *vxi,
12168 +       struct vx_info_save *vxis, const char *_file, int _line)
12169 +{
12170 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
12171 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
12172 +               current->xid, current->vx_info, _file, _line);
12173 +       vxis->vxi = xchg(&current->vx_info, vxi);
12174 +       vxis->xid = current->xid;
12175 +       current->xid = vxi ? vxi->vx_id : 0;
12176 +}
12177 +
12178 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
12179 +
12180 +static inline void __leave_vx_info(struct vx_info_save *vxis,
12181 +       const char *_file, int _line)
12182 +{
12183 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
12184 +               vxis, vxis->xid, vxis->vxi, current,
12185 +               current->xid, current->vx_info, _file, _line);
12186 +       (void)xchg(&current->vx_info, vxis->vxi);
12187 +       current->xid = vxis->xid;
12188 +}
12189 +
12190 +
12191 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
12192 +{
12193 +       vxis->vxi = xchg(&current->vx_info, NULL);
12194 +       vxis->xid = xchg(&current->xid, (xid_t)0);
12195 +}
12196 +
12197 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
12198 +{
12199 +       (void)xchg(&current->xid, vxis->xid);
12200 +       (void)xchg(&current->vx_info, vxis->vxi);
12201 +}
12202 +
12203 +extern void exit_vx_info(struct task_struct *, int);
12204 +extern void exit_vx_info_early(struct task_struct *, int);
12205 +
12206 +
12207 +#else
12208 +#warning duplicate inclusion
12209 +#endif
12210 diff -Nurp linux-2.6.22.18/include/linux/vs_cowbl.h linux-2.6.22.18-vs2.3.0.32/include/linux/vs_cowbl.h
12211 --- linux-2.6.22.18/include/linux/vs_cowbl.h    1970-01-01 01:00:00.000000000 +0100
12212 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vs_cowbl.h 2008-02-11 12:35:36.000000000 +0100
12213 @@ -0,0 +1,44 @@
12214 +#ifndef _VS_COWBL_H
12215 +#define _VS_COWBL_H
12216 +
12217 +#include <linux/fs.h>
12218 +#include <linux/dcache.h>
12219 +#include <linux/namei.h>
12220 +
12221 +extern struct dentry *cow_break_link(const char *pathname);
12222 +
12223 +static inline int cow_check_and_break(struct nameidata *nd)
12224 +{
12225 +       struct inode *inode = nd->dentry->d_inode;
12226 +       int error = 0;
12227 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(nd->mnt))
12228 +               return -EROFS;
12229 +       if (IS_COW(inode)) {
12230 +               if (IS_COW_LINK(inode)) {
12231 +                       struct dentry *new_dentry, *old_dentry = nd->dentry;
12232 +                       char *path, *buf;
12233 +
12234 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
12235 +                       if (!buf) {
12236 +                               return -ENOMEM;
12237 +                       }
12238 +                       path = d_path(nd->dentry, nd->mnt, buf, PATH_MAX);
12239 +                       new_dentry = cow_break_link(path);
12240 +                       kfree(buf);
12241 +                       if (!IS_ERR(new_dentry)) {
12242 +                               nd->dentry = new_dentry;
12243 +                               dput(old_dentry);
12244 +                       } else
12245 +                               error = PTR_ERR(new_dentry);
12246 +               } else {
12247 +                       inode->i_flags &= ~(S_IUNLINK | S_IMMUTABLE);
12248 +                       inode->i_ctime = CURRENT_TIME;
12249 +                       mark_inode_dirty(inode);
12250 +               }
12251 +       }
12252 +       return error;
12253 +}
12254 +
12255 +#else
12256 +#warning duplicate inclusion
12257 +#endif
12258 diff -Nurp linux-2.6.22.18/include/linux/vs_cvirt.h linux-2.6.22.18-vs2.3.0.32/include/linux/vs_cvirt.h
12259 --- linux-2.6.22.18/include/linux/vs_cvirt.h    1970-01-01 01:00:00.000000000 +0100
12260 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vs_cvirt.h 2008-02-11 12:35:36.000000000 +0100
12261 @@ -0,0 +1,49 @@
12262 +#ifndef _VS_CVIRT_H
12263 +#define _VS_CVIRT_H
12264 +
12265 +#include "vserver/cvirt.h"
12266 +#include "vserver/context.h"
12267 +#include "vserver/base.h"
12268 +#include "vserver/debug.h"
12269 +
12270 +
12271 +static inline void vx_activate_task(struct task_struct *p)
12272 +{
12273 +       struct vx_info *vxi;
12274 +
12275 +       if ((vxi = p->vx_info)) {
12276 +               vx_update_load(vxi);
12277 +               atomic_inc(&vxi->cvirt.nr_running);
12278 +       }
12279 +}
12280 +
12281 +static inline void vx_deactivate_task(struct task_struct *p)
12282 +{
12283 +       struct vx_info *vxi;
12284 +
12285 +       if ((vxi = p->vx_info)) {
12286 +               vx_update_load(vxi);
12287 +               atomic_dec(&vxi->cvirt.nr_running);
12288 +       }
12289 +}
12290 +
12291 +static inline void vx_uninterruptible_inc(struct task_struct *p)
12292 +{
12293 +       struct vx_info *vxi;
12294 +
12295 +       if ((vxi = p->vx_info))
12296 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
12297 +}
12298 +
12299 +static inline void vx_uninterruptible_dec(struct task_struct *p)
12300 +{
12301 +       struct vx_info *vxi;
12302 +
12303 +       if ((vxi = p->vx_info))
12304 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
12305 +}
12306 +
12307 +
12308 +#else
12309 +#warning duplicate inclusion
12310 +#endif
12311 diff -Nurp linux-2.6.22.18/include/linux/vs_device.h linux-2.6.22.18-vs2.3.0.32/include/linux/vs_device.h
12312 --- linux-2.6.22.18/include/linux/vs_device.h   1970-01-01 01:00:00.000000000 +0100
12313 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vs_device.h        2008-02-11 12:35:36.000000000 +0100
12314 @@ -0,0 +1,45 @@
12315 +#ifndef _VS_DEVICE_H
12316 +#define _VS_DEVICE_H
12317 +
12318 +#include "vserver/base.h"
12319 +#include "vserver/device.h"
12320 +#include "vserver/debug.h"
12321 +
12322 +
12323 +#ifdef CONFIG_VSERVER_DEVICE
12324 +
12325 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
12326 +
12327 +#define vs_device_perm(v, d, m, p) \
12328 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
12329 +
12330 +#else
12331 +
12332 +static inline
12333 +int vs_map_device(struct vx_info *vxi,
12334 +       dev_t device, dev_t *target, umode_t mode)
12335 +{
12336 +       if (target)
12337 +               *target = device;
12338 +       return ~0;
12339 +}
12340 +
12341 +#define vs_device_perm(v, d, m, p) ((p) == (p))
12342 +
12343 +#endif
12344 +
12345 +
12346 +#define vs_map_chrdev(d, t, p) \
12347 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
12348 +#define vs_map_blkdev(d, t, p) \
12349 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
12350 +
12351 +#define vs_chrdev_perm(d, p) \
12352 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
12353 +#define vs_blkdev_perm(d, p) \
12354 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
12355 +
12356 +
12357 +#else
12358 +#warning duplicate inclusion
12359 +#endif
12360 diff -Nurp linux-2.6.22.18/include/linux/vs_dlimit.h linux-2.6.22.18-vs2.3.0.32/include/linux/vs_dlimit.h
12361 --- linux-2.6.22.18/include/linux/vs_dlimit.h   1970-01-01 01:00:00.000000000 +0100
12362 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vs_dlimit.h        2008-02-11 12:35:36.000000000 +0100
12363 @@ -0,0 +1,211 @@
12364 +#ifndef _VS_DLIMIT_H
12365 +#define _VS_DLIMIT_H
12366 +
12367 +#include <linux/fs.h>
12368 +
12369 +#include "vserver/dlimit.h"
12370 +#include "vserver/base.h"
12371 +#include "vserver/debug.h"
12372 +
12373 +
12374 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
12375 +
12376 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
12377 +       const char *_file, int _line)
12378 +{
12379 +       if (!dli)
12380 +               return NULL;
12381 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
12382 +               dli, dli ? dli->dl_tag : 0,
12383 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
12384 +               _file, _line);
12385 +       atomic_inc(&dli->dl_usecnt);
12386 +       return dli;
12387 +}
12388 +
12389 +
12390 +#define free_dl_info(i) \
12391 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
12392 +
12393 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
12394 +
12395 +static inline void __put_dl_info(struct dl_info *dli,
12396 +       const char *_file, int _line)
12397 +{
12398 +       if (!dli)
12399 +               return;
12400 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
12401 +               dli, dli ? dli->dl_tag : 0,
12402 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
12403 +               _file, _line);
12404 +       if (atomic_dec_and_test(&dli->dl_usecnt))
12405 +               free_dl_info(dli);
12406 +}
12407 +
12408 +
12409 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
12410 +
12411 +static inline int __dl_alloc_space(struct super_block *sb,
12412 +       tag_t tag, dlsize_t nr, const char *file, int line)
12413 +{
12414 +       struct dl_info *dli = NULL;
12415 +       int ret = 0;
12416 +
12417 +       if (nr == 0)
12418 +               goto out;
12419 +       dli = locate_dl_info(sb, tag);
12420 +       if (!dli)
12421 +               goto out;
12422 +
12423 +       spin_lock(&dli->dl_lock);
12424 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
12425 +       if (!ret)
12426 +               dli->dl_space_used += nr;
12427 +       spin_unlock(&dli->dl_lock);
12428 +       put_dl_info(dli);
12429 +out:
12430 +       vxlprintk(VXD_CBIT(dlim, 1),
12431 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
12432 +               sb, tag, __dlimit_char(dli), (long long)nr,
12433 +               ret, file, line);
12434 +       return ret;
12435 +}
12436 +
12437 +static inline void __dl_free_space(struct super_block *sb,
12438 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
12439 +{
12440 +       struct dl_info *dli = NULL;
12441 +
12442 +       if (nr == 0)
12443 +               goto out;
12444 +       dli = locate_dl_info(sb, tag);
12445 +       if (!dli)
12446 +               goto out;
12447 +
12448 +       spin_lock(&dli->dl_lock);
12449 +       if (dli->dl_space_used > nr)
12450 +               dli->dl_space_used -= nr;
12451 +       else
12452 +               dli->dl_space_used = 0;
12453 +       spin_unlock(&dli->dl_lock);
12454 +       put_dl_info(dli);
12455 +out:
12456 +       vxlprintk(VXD_CBIT(dlim, 1),
12457 +               "FREE  (%p,#%d)%c %lld bytes",
12458 +               sb, tag, __dlimit_char(dli), (long long)nr,
12459 +               _file, _line);
12460 +}
12461 +
12462 +static inline int __dl_alloc_inode(struct super_block *sb,
12463 +       tag_t tag, const char *_file, int _line)
12464 +{
12465 +       struct dl_info *dli;
12466 +       int ret = 0;
12467 +
12468 +       dli = locate_dl_info(sb, tag);
12469 +       if (!dli)
12470 +               goto out;
12471 +
12472 +       spin_lock(&dli->dl_lock);
12473 +       ret = (dli->dl_inodes_used >= dli->dl_inodes_total);
12474 +       if (!ret)
12475 +               dli->dl_inodes_used++;
12476 +       spin_unlock(&dli->dl_lock);
12477 +       put_dl_info(dli);
12478 +out:
12479 +       vxlprintk(VXD_CBIT(dlim, 0),
12480 +               "ALLOC (%p,#%d)%c inode (%d)",
12481 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
12482 +       return ret;
12483 +}
12484 +
12485 +static inline void __dl_free_inode(struct super_block *sb,
12486 +       tag_t tag, const char *_file, int _line)
12487 +{
12488 +       struct dl_info *dli;
12489 +
12490 +       dli = locate_dl_info(sb, tag);
12491 +       if (!dli)
12492 +               goto out;
12493 +
12494 +       spin_lock(&dli->dl_lock);
12495 +       if (dli->dl_inodes_used > 1)
12496 +               dli->dl_inodes_used--;
12497 +       else
12498 +               dli->dl_inodes_used = 0;
12499 +       spin_unlock(&dli->dl_lock);
12500 +       put_dl_info(dli);
12501 +out:
12502 +       vxlprintk(VXD_CBIT(dlim, 0),
12503 +               "FREE  (%p,#%d)%c inode",
12504 +               sb, tag, __dlimit_char(dli), _file, _line);
12505 +}
12506 +
12507 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
12508 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
12509 +       const char *_file, int _line)
12510 +{
12511 +       struct dl_info *dli;
12512 +       uint64_t broot, bfree;
12513 +
12514 +       dli = locate_dl_info(sb, tag);
12515 +       if (!dli)
12516 +               return;
12517 +
12518 +       spin_lock(&dli->dl_lock);
12519 +       broot = (dli->dl_space_total -
12520 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
12521 +               >> sb->s_blocksize_bits;
12522 +       bfree = (dli->dl_space_total - dli->dl_space_used)
12523 +                       >> sb->s_blocksize_bits;
12524 +       spin_unlock(&dli->dl_lock);
12525 +
12526 +       vxlprintk(VXD_CBIT(dlim, 2),
12527 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
12528 +               (long long)bfree, (long long)broot,
12529 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
12530 +               _file, _line);
12531 +       if (free_blocks) {
12532 +               if (*free_blocks > bfree)
12533 +                       *free_blocks = bfree;
12534 +       }
12535 +       if (root_blocks) {
12536 +               if (*root_blocks > broot)
12537 +                       *root_blocks = broot;
12538 +       }
12539 +       put_dl_info(dli);
12540 +}
12541 +
12542 +#define DLIMIT_ALLOC_SPACE(in, bytes) \
12543 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
12544 +               __FILE__, __LINE__ )
12545 +
12546 +#define DLIMIT_FREE_SPACE(in, bytes) \
12547 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
12548 +               __FILE__, __LINE__ )
12549 +
12550 +#define DLIMIT_ALLOC_BLOCK(in, nr) \
12551 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, \
12552 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
12553 +               __FILE__, __LINE__ )
12554 +
12555 +#define DLIMIT_FREE_BLOCK(in, nr) \
12556 +       __dl_free_space((in)->i_sb, (in)->i_tag, \
12557 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
12558 +               __FILE__, __LINE__ )
12559 +
12560 +
12561 +#define DLIMIT_ALLOC_INODE(in) \
12562 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
12563 +
12564 +#define DLIMIT_FREE_INODE(in) \
12565 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
12566 +
12567 +
12568 +#define DLIMIT_ADJUST_BLOCK(sb, tag, fb, rb) \
12569 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
12570 +
12571 +
12572 +#else
12573 +#warning duplicate inclusion
12574 +#endif
12575 diff -Nurp linux-2.6.22.18/include/linux/vserver/base.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/base.h
12576 --- linux-2.6.22.18/include/linux/vserver/base.h        1970-01-01 01:00:00.000000000 +0100
12577 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/base.h     2008-02-11 12:35:36.000000000 +0100
12578 @@ -0,0 +1,218 @@
12579 +#ifndef _VX_BASE_H
12580 +#define _VX_BASE_H
12581 +
12582 +
12583 +/* context state changes */
12584 +
12585 +enum {
12586 +       VSC_STARTUP = 1,
12587 +       VSC_SHUTDOWN,
12588 +
12589 +       VSC_NETUP,
12590 +       VSC_NETDOWN,
12591 +};
12592 +
12593 +
12594 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
12595 +
12596 +/* check conditions */
12597 +
12598 +#define VS_ADMIN       0x0001
12599 +#define VS_WATCH       0x0002
12600 +#define VS_HIDE                0x0004
12601 +#define VS_HOSTID      0x0008
12602 +
12603 +#define VS_IDENT       0x0010
12604 +#define VS_EQUIV       0x0020
12605 +#define VS_PARENT      0x0040
12606 +#define VS_CHILD       0x0080
12607 +
12608 +#define VS_ARG_MASK    0x00F0
12609 +
12610 +#ifdef CONFIG_VSERVER_PRIVACY
12611 +#define VS_ADMIN_P     (0)
12612 +#define VS_WATCH_P     (0)
12613 +#else
12614 +#define VS_ADMIN_P     VS_ADMIN
12615 +#define VS_WATCH_P     VS_WATCH
12616 +#endif
12617 +
12618 +#define VS_HARDIRQ     0x1000
12619 +#define VS_SOFTIRQ     0x2000
12620 +#define VS_IRQ         0x4000
12621 +
12622 +#define VS_IRQ_MASK    0xF000
12623 +
12624 +#include <linux/hardirq.h>
12625 +
12626 +/*
12627 + * check current context for ADMIN/WATCH and
12628 + * optionally against supplied argument
12629 + */
12630 +static inline int __vs_check(int cid, int id, unsigned int mode)
12631 +{
12632 +       if (mode & VS_ARG_MASK) {
12633 +               if ((mode & VS_IDENT) && (id == cid))
12634 +                       return 1;
12635 +       }
12636 +       if (mode & VS_IRQ_MASK) {
12637 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
12638 +                       return 1;
12639 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
12640 +                       return 1;
12641 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
12642 +                       return 1;
12643 +       }
12644 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
12645 +               ((mode & VS_WATCH) && (cid == 1)) ||
12646 +               ((mode & VS_HOSTID) && (id == 0)));
12647 +}
12648 +
12649 +#define vx_task_xid(t) ((t)->xid)
12650 +
12651 +#define vx_current_xid() vx_task_xid(current)
12652 +
12653 +#define current_vx_info() (current->vx_info)
12654 +
12655 +
12656 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
12657 +
12658 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
12659 +
12660 +
12661 +#define nx_task_nid(t) ((t)->nid)
12662 +
12663 +#define nx_current_nid() nx_task_nid(current)
12664 +
12665 +#define current_nx_info() (current->nx_info)
12666 +
12667 +
12668 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
12669 +
12670 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
12671 +
12672 +
12673 +
12674 +/* generic flag merging */
12675 +
12676 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
12677 +
12678 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
12679 +
12680 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
12681 +
12682 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
12683 +
12684 +
12685 +/* context flags */
12686 +
12687 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
12688 +
12689 +#define vx_current_flags()     __vx_flags(current->vx_info)
12690 +
12691 +#define vx_info_flags(v, m, f) \
12692 +       vs_check_flags(__vx_flags(v), m, f)
12693 +
12694 +#define task_vx_flags(t, m, f) \
12695 +       ((t) && vx_info_flags((t)->vx_info, m, f))
12696 +
12697 +#define vx_flags(m, f) vx_info_flags(current->vx_info, m, f)
12698 +
12699 +
12700 +/* context caps */
12701 +
12702 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
12703 +
12704 +#define vx_current_ccaps()     __vx_ccaps(current->vx_info)
12705 +
12706 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
12707 +
12708 +#define vx_ccaps(c)    vx_info_ccaps(current->vx_info, (c))
12709 +
12710 +
12711 +
12712 +/* network flags */
12713 +
12714 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
12715 +
12716 +#define nx_current_flags()     __nx_flags(current->nx_info)
12717 +
12718 +#define nx_info_flags(n, m, f) \
12719 +       vs_check_flags(__nx_flags(n), m, f)
12720 +
12721 +#define task_nx_flags(t, m, f) \
12722 +       ((t) && nx_info_flags((t)->nx_info, m, f))
12723 +
12724 +#define nx_flags(m, f) nx_info_flags(current->nx_info, m, f)
12725 +
12726 +
12727 +/* network caps */
12728 +
12729 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
12730 +
12731 +#define nx_current_ncaps()     __nx_ncaps(current->nx_info)
12732 +
12733 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
12734 +
12735 +#define nx_ncaps(c)    nx_info_ncaps(current->nx_info, c)
12736 +
12737 +
12738 +/* context mask capabilities */
12739 +
12740 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
12741 +
12742 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
12743 +
12744 +#define vx_mcaps(c)    vx_info_mcaps(current->vx_info, c)
12745 +
12746 +
12747 +/* context bcap mask */
12748 +
12749 +#define __vx_bcaps(v)  ((v) ? (v)->vx_bcaps : ~0 )
12750 +
12751 +#define vx_current_bcaps()     __vx_bcaps(current->vx_info)
12752 +
12753 +#define vx_info_bcaps(v, c)    (__vx_bcaps(v) & (c))
12754 +
12755 +#define vx_bcaps(c)    vx_info_bcaps(current->vx_info, c)
12756 +
12757 +
12758 +#define vx_info_cap_bset(v)    ((v) ? (v)->vx_cap_bset : cap_bset)
12759 +
12760 +#define vx_current_cap_bset()  vx_info_cap_bset(current->vx_info)
12761 +
12762 +
12763 +#define __vx_info_mbcap(v, b) \
12764 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
12765 +       vx_info_bcaps(v, b) : (b))
12766 +
12767 +#define vx_info_mbcap(v, b)    __vx_info_mbcap(v, cap_t(b))
12768 +
12769 +#define task_vx_mbcap(t, b) \
12770 +       vx_info_mbcap((t)->vx_info, (t)->b)
12771 +
12772 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
12773 +
12774 +#define vx_cap_raised(v, c, f) (vx_info_mbcap(v, c) & CAP_TO_MASK(f))
12775 +
12776 +#define vx_capable(b, c) (capable(b) || \
12777 +       (cap_raised(current->cap_effective, b) && vx_ccaps(c)))
12778 +
12779 +#define nx_capable(b, c) (capable(b) || \
12780 +       (cap_raised(current->cap_effective, b) && nx_ncaps(c)))
12781 +
12782 +#define vx_current_initpid(n) \
12783 +       (current->vx_info && \
12784 +       (current->vx_info->vx_initpid == (n)))
12785 +
12786 +
12787 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
12788 +
12789 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
12790 +
12791 +
12792 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
12793 +
12794 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
12795 +
12796 +#endif
12797 diff -Nurp linux-2.6.22.18/include/linux/vserver/cacct_cmd.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/cacct_cmd.h
12798 --- linux-2.6.22.18/include/linux/vserver/cacct_cmd.h   1970-01-01 01:00:00.000000000 +0100
12799 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/cacct_cmd.h        2008-02-11 12:35:36.000000000 +0100
12800 @@ -0,0 +1,23 @@
12801 +#ifndef _VX_CACCT_CMD_H
12802 +#define _VX_CACCT_CMD_H
12803 +
12804 +
12805 +/* virtual host info name commands */
12806 +
12807 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
12808 +
12809 +struct vcmd_sock_stat_v0 {
12810 +       uint32_t field;
12811 +       uint32_t count[3];
12812 +       uint64_t total[3];
12813 +};
12814 +
12815 +
12816 +#ifdef __KERNEL__
12817 +
12818 +#include <linux/compiler.h>
12819 +
12820 +extern int vc_sock_stat(struct vx_info *, void __user *);
12821 +
12822 +#endif /* __KERNEL__ */
12823 +#endif /* _VX_CACCT_CMD_H */
12824 diff -Nurp linux-2.6.22.18/include/linux/vserver/cacct_def.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/cacct_def.h
12825 --- linux-2.6.22.18/include/linux/vserver/cacct_def.h   1970-01-01 01:00:00.000000000 +0100
12826 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/cacct_def.h        2008-02-11 12:35:36.000000000 +0100
12827 @@ -0,0 +1,43 @@
12828 +#ifndef _VX_CACCT_DEF_H
12829 +#define _VX_CACCT_DEF_H
12830 +
12831 +#include <asm/atomic.h>
12832 +#include <linux/vserver/cacct.h>
12833 +
12834 +
12835 +struct _vx_sock_acc {
12836 +       atomic_long_t count;
12837 +       atomic_long_t total;
12838 +};
12839 +
12840 +/* context sub struct */
12841 +
12842 +struct _vx_cacct {
12843 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
12844 +       atomic_t slab[8];
12845 +       atomic_t page[6][8];
12846 +};
12847 +
12848 +#ifdef CONFIG_VSERVER_DEBUG
12849 +
12850 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
12851 +{
12852 +       int i, j;
12853 +
12854 +       printk("\t_vx_cacct:");
12855 +       for (i = 0; i < 6; i++) {
12856 +               struct _vx_sock_acc *ptr = cacct->sock[i];
12857 +
12858 +               printk("\t [%d] =", i);
12859 +               for (j = 0; j < 3; j++) {
12860 +                       printk(" [%d] = %8lu, %8lu", j,
12861 +                               atomic_long_read(&ptr[j].count),
12862 +                               atomic_long_read(&ptr[j].total));
12863 +               }
12864 +               printk("\n");
12865 +       }
12866 +}
12867 +
12868 +#endif
12869 +
12870 +#endif /* _VX_CACCT_DEF_H */
12871 diff -Nurp linux-2.6.22.18/include/linux/vserver/cacct.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/cacct.h
12872 --- linux-2.6.22.18/include/linux/vserver/cacct.h       1970-01-01 01:00:00.000000000 +0100
12873 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/cacct.h    2008-02-11 12:35:36.000000000 +0100
12874 @@ -0,0 +1,15 @@
12875 +#ifndef _VX_CACCT_H
12876 +#define _VX_CACCT_H
12877 +
12878 +
12879 +enum sock_acc_field {
12880 +       VXA_SOCK_UNSPEC = 0,
12881 +       VXA_SOCK_UNIX,
12882 +       VXA_SOCK_INET,
12883 +       VXA_SOCK_INET6,
12884 +       VXA_SOCK_PACKET,
12885 +       VXA_SOCK_OTHER,
12886 +       VXA_SOCK_SIZE   /* array size */
12887 +};
12888 +
12889 +#endif /* _VX_CACCT_H */
12890 diff -Nurp linux-2.6.22.18/include/linux/vserver/cacct_int.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/cacct_int.h
12891 --- linux-2.6.22.18/include/linux/vserver/cacct_int.h   1970-01-01 01:00:00.000000000 +0100
12892 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/cacct_int.h        2008-02-11 12:35:36.000000000 +0100
12893 @@ -0,0 +1,21 @@
12894 +#ifndef _VX_CACCT_INT_H
12895 +#define _VX_CACCT_INT_H
12896 +
12897 +
12898 +#ifdef __KERNEL__
12899 +
12900 +static inline
12901 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
12902 +{
12903 +       return atomic_long_read(&cacct->sock[type][pos].count);
12904 +}
12905 +
12906 +
12907 +static inline
12908 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
12909 +{
12910 +       return atomic_long_read(&cacct->sock[type][pos].total);
12911 +}
12912 +
12913 +#endif /* __KERNEL__ */
12914 +#endif /* _VX_CACCT_INT_H */
12915 diff -Nurp linux-2.6.22.18/include/linux/vserver/context_cmd.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/context_cmd.h
12916 --- linux-2.6.22.18/include/linux/vserver/context_cmd.h 1970-01-01 01:00:00.000000000 +0100
12917 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/context_cmd.h      2008-02-11 12:35:36.000000000 +0100
12918 @@ -0,0 +1,128 @@
12919 +#ifndef _VX_CONTEXT_CMD_H
12920 +#define _VX_CONTEXT_CMD_H
12921 +
12922 +
12923 +/* vinfo commands */
12924 +
12925 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
12926 +
12927 +#ifdef __KERNEL__
12928 +extern int vc_task_xid(uint32_t);
12929 +
12930 +#endif /* __KERNEL__ */
12931 +
12932 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
12933 +
12934 +struct vcmd_vx_info_v0 {
12935 +       uint32_t xid;
12936 +       uint32_t initpid;
12937 +       /* more to come */
12938 +};
12939 +
12940 +#ifdef __KERNEL__
12941 +extern int vc_vx_info(struct vx_info *, void __user *);
12942 +
12943 +#endif /* __KERNEL__ */
12944 +
12945 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
12946 +
12947 +struct vcmd_ctx_stat_v0 {
12948 +       uint32_t usecnt;
12949 +       uint32_t tasks;
12950 +       /* more to come */
12951 +};
12952 +
12953 +#ifdef __KERNEL__
12954 +extern int vc_ctx_stat(struct vx_info *, void __user *);
12955 +
12956 +#endif /* __KERNEL__ */
12957 +
12958 +/* context commands */
12959 +
12960 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
12961 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
12962 +
12963 +struct vcmd_ctx_create {
12964 +       uint64_t flagword;
12965 +};
12966 +
12967 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
12968 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
12969 +
12970 +struct vcmd_ctx_migrate {
12971 +       uint64_t flagword;
12972 +};
12973 +
12974 +#ifdef __KERNEL__
12975 +extern int vc_ctx_create(uint32_t, void __user *);
12976 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
12977 +
12978 +#endif /* __KERNEL__ */
12979 +
12980 +
12981 +/* flag commands */
12982 +
12983 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
12984 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
12985 +
12986 +struct vcmd_ctx_flags_v0 {
12987 +       uint64_t flagword;
12988 +       uint64_t mask;
12989 +};
12990 +
12991 +#ifdef __KERNEL__
12992 +extern int vc_get_cflags(struct vx_info *, void __user *);
12993 +extern int vc_set_cflags(struct vx_info *, void __user *);
12994 +
12995 +#endif /* __KERNEL__ */
12996 +
12997 +
12998 +/* context caps commands */
12999 +
13000 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
13001 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
13002 +
13003 +struct vcmd_ctx_caps_v1 {
13004 +       uint64_t ccaps;
13005 +       uint64_t cmask;
13006 +};
13007 +
13008 +#ifdef __KERNEL__
13009 +extern int vc_get_ccaps(struct vx_info *, void __user *);
13010 +extern int vc_set_ccaps(struct vx_info *, void __user *);
13011 +
13012 +#endif /* __KERNEL__ */
13013 +
13014 +
13015 +/* bcaps commands */
13016 +
13017 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
13018 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
13019 +
13020 +struct vcmd_bcaps {
13021 +       uint64_t bcaps;
13022 +       uint64_t bmask;
13023 +};
13024 +
13025 +#ifdef __KERNEL__
13026 +extern int vc_get_bcaps(struct vx_info *, void __user *);
13027 +extern int vc_set_bcaps(struct vx_info *, void __user *);
13028 +
13029 +#endif /* __KERNEL__ */
13030 +
13031 +
13032 +/* OOM badness */
13033 +
13034 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
13035 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
13036 +
13037 +struct vcmd_badness_v0 {
13038 +       int64_t bias;
13039 +};
13040 +
13041 +#ifdef __KERNEL__
13042 +extern int vc_get_badness(struct vx_info *, void __user *);
13043 +extern int vc_set_badness(struct vx_info *, void __user *);
13044 +
13045 +#endif /* __KERNEL__ */
13046 +#endif /* _VX_CONTEXT_CMD_H */
13047 diff -Nurp linux-2.6.22.18/include/linux/vserver/context.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/context.h
13048 --- linux-2.6.22.18/include/linux/vserver/context.h     1970-01-01 01:00:00.000000000 +0100
13049 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/context.h  2008-02-11 12:35:36.000000000 +0100
13050 @@ -0,0 +1,176 @@
13051 +#ifndef _VX_CONTEXT_H
13052 +#define _VX_CONTEXT_H
13053 +
13054 +#include <linux/types.h>
13055 +#include <linux/capability.h>
13056 +
13057 +
13058 +/* context flags */
13059 +
13060 +#define VXF_INFO_SCHED         0x00000002
13061 +#define VXF_INFO_NPROC         0x00000004
13062 +#define VXF_INFO_PRIVATE       0x00000008
13063 +
13064 +#define VXF_INFO_INIT          0x00000010
13065 +#define VXF_INFO_HIDE          0x00000020
13066 +#define VXF_INFO_ULIMIT                0x00000040
13067 +#define VXF_INFO_NSPACE                0x00000080
13068 +
13069 +#define VXF_SCHED_HARD         0x00000100
13070 +#define VXF_SCHED_PRIO         0x00000200
13071 +#define VXF_SCHED_PAUSE                0x00000400
13072 +
13073 +#define VXF_VIRT_MEM           0x00010000
13074 +#define VXF_VIRT_UPTIME                0x00020000
13075 +#define VXF_VIRT_CPU           0x00040000
13076 +#define VXF_VIRT_LOAD          0x00080000
13077 +#define VXF_VIRT_TIME          0x00100000
13078 +
13079 +#define VXF_HIDE_MOUNT         0x01000000
13080 +/* was VXF_HIDE_NETIF          0x02000000 */
13081 +#define VXF_HIDE_VINFO         0x04000000
13082 +
13083 +#define VXF_STATE_SETUP                (1ULL << 32)
13084 +#define VXF_STATE_INIT         (1ULL << 33)
13085 +#define VXF_STATE_ADMIN                (1ULL << 34)
13086 +
13087 +#define VXF_SC_HELPER          (1ULL << 36)
13088 +#define VXF_REBOOT_KILL                (1ULL << 37)
13089 +#define VXF_PERSISTENT         (1ULL << 38)
13090 +
13091 +#define VXF_FORK_RSS           (1ULL << 48)
13092 +#define VXF_PROLIFIC           (1ULL << 49)
13093 +
13094 +#define VXF_IGNEG_NICE         (1ULL << 52)
13095 +
13096 +#define VXF_ONE_TIME           (0x0007ULL << 32)
13097 +
13098 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
13099 +
13100 +
13101 +/* context migration */
13102 +
13103 +#define VXM_SET_INIT           0x00000001
13104 +#define VXM_SET_REAPER         0x00000002
13105 +
13106 +/* context caps */
13107 +
13108 +#define VXC_CAP_MASK           0x00000000
13109 +
13110 +#define VXC_SET_UTSNAME                0x00000001
13111 +#define VXC_SET_RLIMIT         0x00000002
13112 +
13113 +/* was VXC_RAW_ICMP            0x00000100 */
13114 +#define VXC_SYSLOG             0x00001000
13115 +
13116 +#define VXC_SECURE_MOUNT       0x00010000
13117 +#define VXC_SECURE_REMOUNT     0x00020000
13118 +#define VXC_BINARY_MOUNT       0x00040000
13119 +
13120 +#define VXC_QUOTA_CTL          0x00100000
13121 +#define VXC_ADMIN_MAPPER       0x00200000
13122 +#define VXC_ADMIN_CLOOP                0x00400000
13123 +
13124 +#define VXC_KTHREAD            0x01000000
13125 +
13126 +
13127 +#ifdef __KERNEL__
13128 +
13129 +#include <linux/list.h>
13130 +#include <linux/spinlock.h>
13131 +#include <linux/rcupdate.h>
13132 +
13133 +#include "limit_def.h"
13134 +#include "sched_def.h"
13135 +#include "cvirt_def.h"
13136 +#include "cacct_def.h"
13137 +#include "device_def.h"
13138 +
13139 +struct _vx_info_pc {
13140 +       struct _vx_sched_pc sched_pc;
13141 +       struct _vx_cvirt_pc cvirt_pc;
13142 +};
13143 +
13144 +struct vx_info {
13145 +       struct hlist_node vx_hlist;             /* linked list of contexts */
13146 +       xid_t vx_id;                            /* context id */
13147 +       atomic_t vx_usecnt;                     /* usage count */
13148 +       atomic_t vx_tasks;                      /* tasks count */
13149 +       struct vx_info *vx_parent;              /* parent context */
13150 +       int vx_state;                           /* context state */
13151 +
13152 +       unsigned long vx_nsmask;                /* assignment mask */
13153 +       struct nsproxy *vx_nsproxy;             /* private namespace */
13154 +       struct fs_struct *vx_fs;                /* private namespace fs */
13155 +
13156 +       uint64_t vx_flags;                      /* context flags */
13157 +       uint64_t vx_bcaps;                      /* bounding caps (system) */
13158 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
13159 +       kernel_cap_t vx_cap_bset;               /* the guest's bset */
13160 +
13161 +       struct task_struct *vx_reaper;          /* guest reaper process */
13162 +       pid_t vx_initpid;                       /* PID of guest init */
13163 +       int64_t vx_badness_bias;                /* OOM points bias */
13164 +
13165 +       struct _vx_limit limit;                 /* vserver limits */
13166 +       struct _vx_sched sched;                 /* vserver scheduler */
13167 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
13168 +       struct _vx_cacct cacct;                 /* context accounting */
13169 +
13170 +       struct _vx_device dmap;                 /* default device map targets */
13171 +
13172 +#ifndef CONFIG_SMP
13173 +       struct _vx_info_pc info_pc;             /* per cpu data */
13174 +#else
13175 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
13176 +#endif
13177 +
13178 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
13179 +       int reboot_cmd;                         /* last sys_reboot() cmd */
13180 +       int exit_code;                          /* last process exit code */
13181 +
13182 +       char vx_name[65];                       /* vserver name */
13183 +};
13184 +
13185 +#ifndef CONFIG_SMP
13186 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
13187 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
13188 +#else
13189 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
13190 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
13191 +#endif
13192 +
13193 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
13194 +
13195 +
13196 +struct vx_info_save {
13197 +       struct vx_info *vxi;
13198 +       xid_t xid;
13199 +};
13200 +
13201 +
13202 +/* status flags */
13203 +
13204 +#define VXS_HASHED     0x0001
13205 +#define VXS_PAUSED     0x0010
13206 +#define VXS_SHUTDOWN   0x0100
13207 +#define VXS_HELPER     0x1000
13208 +#define VXS_RELEASED   0x8000
13209 +
13210 +
13211 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
13212 +extern void release_vx_info(struct vx_info *, struct task_struct *);
13213 +
13214 +extern struct vx_info *lookup_vx_info(int);
13215 +extern struct vx_info *lookup_or_create_vx_info(int);
13216 +
13217 +extern int get_xid_list(int, unsigned int *, int);
13218 +extern int xid_is_hashed(xid_t);
13219 +
13220 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
13221 +
13222 +extern long vs_state_change(struct vx_info *, unsigned int);
13223 +
13224 +
13225 +#endif /* __KERNEL__ */
13226 +#endif /* _VX_CONTEXT_H */
13227 diff -Nurp linux-2.6.22.18/include/linux/vserver/cvirt_cmd.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/cvirt_cmd.h
13228 --- linux-2.6.22.18/include/linux/vserver/cvirt_cmd.h   1970-01-01 01:00:00.000000000 +0100
13229 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/cvirt_cmd.h        2008-02-11 12:35:36.000000000 +0100
13230 @@ -0,0 +1,53 @@
13231 +#ifndef _VX_CVIRT_CMD_H
13232 +#define _VX_CVIRT_CMD_H
13233 +
13234 +
13235 +/* virtual host info name commands */
13236 +
13237 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
13238 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
13239 +
13240 +struct vcmd_vhi_name_v0 {
13241 +       uint32_t field;
13242 +       char name[65];
13243 +};
13244 +
13245 +
13246 +enum vhi_name_field {
13247 +       VHIN_CONTEXT = 0,
13248 +       VHIN_SYSNAME,
13249 +       VHIN_NODENAME,
13250 +       VHIN_RELEASE,
13251 +       VHIN_VERSION,
13252 +       VHIN_MACHINE,
13253 +       VHIN_DOMAINNAME,
13254 +};
13255 +
13256 +
13257 +#ifdef __KERNEL__
13258 +
13259 +#include <linux/compiler.h>
13260 +
13261 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
13262 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
13263 +
13264 +#endif /* __KERNEL__ */
13265 +
13266 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
13267 +
13268 +struct vcmd_virt_stat_v0 {
13269 +       uint64_t offset;
13270 +       uint64_t uptime;
13271 +       uint32_t nr_threads;
13272 +       uint32_t nr_running;
13273 +       uint32_t nr_uninterruptible;
13274 +       uint32_t nr_onhold;
13275 +       uint32_t nr_forks;
13276 +       uint32_t load[3];
13277 +};
13278 +
13279 +#ifdef __KERNEL__
13280 +extern int vc_virt_stat(struct vx_info *, void __user *);
13281 +
13282 +#endif /* __KERNEL__ */
13283 +#endif /* _VX_CVIRT_CMD_H */
13284 diff -Nurp linux-2.6.22.18/include/linux/vserver/cvirt_def.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/cvirt_def.h
13285 --- linux-2.6.22.18/include/linux/vserver/cvirt_def.h   1970-01-01 01:00:00.000000000 +0100
13286 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/cvirt_def.h        2008-02-11 12:35:36.000000000 +0100
13287 @@ -0,0 +1,81 @@
13288 +#ifndef _VX_CVIRT_DEF_H
13289 +#define _VX_CVIRT_DEF_H
13290 +
13291 +#include <linux/jiffies.h>
13292 +#include <linux/spinlock.h>
13293 +#include <linux/wait.h>
13294 +#include <linux/time.h>
13295 +#include <linux/utsname.h>
13296 +#include <asm/atomic.h>
13297 +
13298 +
13299 +struct _vx_usage_stat {
13300 +       uint64_t user;
13301 +       uint64_t nice;
13302 +       uint64_t system;
13303 +       uint64_t softirq;
13304 +       uint64_t irq;
13305 +       uint64_t idle;
13306 +       uint64_t iowait;
13307 +};
13308 +
13309 +struct _vx_syslog {
13310 +       wait_queue_head_t log_wait;
13311 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
13312 +
13313 +       unsigned long log_start;        /* next char to be read by syslog() */
13314 +       unsigned long con_start;        /* next char to be sent to consoles */
13315 +       unsigned long log_end;  /* most-recently-written-char + 1 */
13316 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
13317 +
13318 +       char log_buf[1024];
13319 +};
13320 +
13321 +
13322 +/* context sub struct */
13323 +
13324 +struct _vx_cvirt {
13325 +       atomic_t nr_threads;            /* number of current threads */
13326 +       atomic_t nr_running;            /* number of running threads */
13327 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
13328 +
13329 +       atomic_t nr_onhold;             /* processes on hold */
13330 +       uint32_t onhold_last;           /* jiffies when put on hold */
13331 +
13332 +       struct timeval bias_tv;         /* time offset to the host */
13333 +       struct timespec bias_idle;
13334 +       struct timespec bias_uptime;    /* context creation point */
13335 +       uint64_t bias_clock;            /* offset in clock_t */
13336 +
13337 +       spinlock_t load_lock;           /* lock for the load averages */
13338 +       atomic_t load_updates;          /* nr of load updates done so far */
13339 +       uint32_t load_last;             /* last time load was calculated */
13340 +       uint32_t load[3];               /* load averages 1,5,15 */
13341 +
13342 +       atomic_t total_forks;           /* number of forks so far */
13343 +
13344 +       struct _vx_syslog syslog;
13345 +};
13346 +
13347 +struct _vx_cvirt_pc {
13348 +       struct _vx_usage_stat cpustat;
13349 +};
13350 +
13351 +
13352 +#ifdef CONFIG_VSERVER_DEBUG
13353 +
13354 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
13355 +{
13356 +       printk("\t_vx_cvirt:\n");
13357 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
13358 +               atomic_read(&cvirt->nr_threads),
13359 +               atomic_read(&cvirt->nr_running),
13360 +               atomic_read(&cvirt->nr_uninterruptible),
13361 +               atomic_read(&cvirt->nr_onhold));
13362 +       /* add rest here */
13363 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
13364 +}
13365 +
13366 +#endif
13367 +
13368 +#endif /* _VX_CVIRT_DEF_H */
13369 diff -Nurp linux-2.6.22.18/include/linux/vserver/cvirt.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/cvirt.h
13370 --- linux-2.6.22.18/include/linux/vserver/cvirt.h       1970-01-01 01:00:00.000000000 +0100
13371 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/cvirt.h    2008-02-11 12:35:36.000000000 +0100
13372 @@ -0,0 +1,20 @@
13373 +#ifndef _VX_CVIRT_H
13374 +#define _VX_CVIRT_H
13375 +
13376 +
13377 +#ifdef __KERNEL__
13378 +
13379 +struct timespec;
13380 +
13381 +void vx_vsi_uptime(struct timespec *, struct timespec *);
13382 +
13383 +
13384 +struct vx_info;
13385 +
13386 +void vx_update_load(struct vx_info *);
13387 +
13388 +
13389 +int vx_do_syslog(int, char __user *, int);
13390 +
13391 +#endif /* __KERNEL__ */
13392 +#endif /* _VX_CVIRT_H */
13393 diff -Nurp linux-2.6.22.18/include/linux/vserver/debug_cmd.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/debug_cmd.h
13394 --- linux-2.6.22.18/include/linux/vserver/debug_cmd.h   1970-01-01 01:00:00.000000000 +0100
13395 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/debug_cmd.h        2008-02-11 12:35:36.000000000 +0100
13396 @@ -0,0 +1,58 @@
13397 +#ifndef _VX_DEBUG_CMD_H
13398 +#define _VX_DEBUG_CMD_H
13399 +
13400 +
13401 +/* debug commands */
13402 +
13403 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
13404 +
13405 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
13406 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
13407 +
13408 +struct  vcmd_read_history_v0 {
13409 +       uint32_t index;
13410 +       uint32_t count;
13411 +       char __user *data;
13412 +};
13413 +
13414 +struct  vcmd_read_monitor_v0 {
13415 +       uint32_t index;
13416 +       uint32_t count;
13417 +       char __user *data;
13418 +};
13419 +
13420 +
13421 +#ifdef __KERNEL__
13422 +
13423 +#ifdef CONFIG_COMPAT
13424 +
13425 +#include <asm/compat.h>
13426 +
13427 +struct vcmd_read_history_v0_x32 {
13428 +       uint32_t index;
13429 +       uint32_t count;
13430 +       compat_uptr_t data_ptr;
13431 +};
13432 +
13433 +struct vcmd_read_monitor_v0_x32 {
13434 +       uint32_t index;
13435 +       uint32_t count;
13436 +       compat_uptr_t data_ptr;
13437 +};
13438 +
13439 +#endif  /* CONFIG_COMPAT */
13440 +
13441 +extern int vc_dump_history(uint32_t);
13442 +
13443 +extern int vc_read_history(uint32_t, void __user *);
13444 +extern int vc_read_monitor(uint32_t, void __user *);
13445 +
13446 +#ifdef CONFIG_COMPAT
13447 +
13448 +extern int vc_read_history_x32(uint32_t, void __user *);
13449 +extern int vc_read_monitor_x32(uint32_t, void __user *);
13450 +
13451 +#endif  /* CONFIG_COMPAT */
13452 +
13453 +#endif /* __KERNEL__ */
13454 +#endif /* _VX_DEBUG_CMD_H */
13455 diff -Nurp linux-2.6.22.18/include/linux/vserver/debug.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/debug.h
13456 --- linux-2.6.22.18/include/linux/vserver/debug.h       1970-01-01 01:00:00.000000000 +0100
13457 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/debug.h    2008-02-11 12:35:36.000000000 +0100
13458 @@ -0,0 +1,130 @@
13459 +#ifndef _VX_DEBUG_H
13460 +#define _VX_DEBUG_H
13461 +
13462 +
13463 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
13464 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
13465 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
13466 +
13467 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
13468 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
13469 +#define VXF_DEV                "%p[%lu,%d:%d]"
13470 +
13471 +
13472 +#define __FUNC__       __func__
13473 +
13474 +
13475 +#define vxd_path(d, m)                                         \
13476 +       ({ static char _buffer[PATH_MAX];                       \
13477 +          d_path(d, m, _buffer, sizeof(_buffer)); })
13478 +
13479 +#define vxd_cond_path(n)                                       \
13480 +       ((n) ? vxd_path((n)->dentry, (n)->mnt) : "<null>" )
13481 +
13482 +
13483 +#ifdef CONFIG_VSERVER_DEBUG
13484 +
13485 +extern unsigned int vx_debug_switch;
13486 +extern unsigned int vx_debug_xid;
13487 +extern unsigned int vx_debug_nid;
13488 +extern unsigned int vx_debug_tag;
13489 +extern unsigned int vx_debug_net;
13490 +extern unsigned int vx_debug_limit;
13491 +extern unsigned int vx_debug_cres;
13492 +extern unsigned int vx_debug_dlim;
13493 +extern unsigned int vx_debug_quota;
13494 +extern unsigned int vx_debug_cvirt;
13495 +extern unsigned int vx_debug_space;
13496 +extern unsigned int vx_debug_misc;
13497 +
13498 +
13499 +#define VX_LOGLEVEL    "vxD: "
13500 +#define VX_PROC_FMT    "%p: "
13501 +#define VX_PROCESS     current
13502 +
13503 +#define vxdprintk(c, f, x...)                                  \
13504 +       do {                                                    \
13505 +               if (c)                                          \
13506 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
13507 +                               VX_PROCESS , ##x);              \
13508 +       } while (0)
13509 +
13510 +#define vxlprintk(c, f, x...)                                  \
13511 +       do {                                                    \
13512 +               if (c)                                          \
13513 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
13514 +       } while (0)
13515 +
13516 +#define vxfprintk(c, f, x...)                                  \
13517 +       do {                                                    \
13518 +               if (c)                                          \
13519 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
13520 +       } while (0)
13521 +
13522 +
13523 +struct vx_info;
13524 +
13525 +void dump_vx_info(struct vx_info *, int);
13526 +void dump_vx_info_inactive(int);
13527 +
13528 +#else  /* CONFIG_VSERVER_DEBUG */
13529 +
13530 +#define vx_debug_switch 0
13531 +#define vx_debug_xid   0
13532 +#define vx_debug_nid   0
13533 +#define vx_debug_tag   0
13534 +#define vx_debug_net   0
13535 +#define vx_debug_limit 0
13536 +#define vx_debug_cres  0
13537 +#define vx_debug_dlim  0
13538 +#define vx_debug_cvirt 0
13539 +
13540 +#define vxdprintk(x...) do { } while (0)
13541 +#define vxlprintk(x...) do { } while (0)
13542 +#define vxfprintk(x...) do { } while (0)
13543 +
13544 +#endif /* CONFIG_VSERVER_DEBUG */
13545 +
13546 +
13547 +#ifdef CONFIG_VSERVER_WARN
13548 +
13549 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
13550 +#define VX_WARN_TASK   "[»%s«,%u:#%u|%u|%u] "
13551 +#define VX_WARN_XID    "[xid #%u] "
13552 +#define VX_WARN_NID    "[nid #%u] "
13553 +#define VX_WARN_TAG    "[tag #%u] "
13554 +
13555 +#define vxwprintk(c, f, x...)                                  \
13556 +       do {                                                    \
13557 +               if (c)                                          \
13558 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
13559 +       } while (0)
13560 +
13561 +#else  /* CONFIG_VSERVER_WARN */
13562 +
13563 +#define vxwprintk(x...) do { } while (0)
13564 +
13565 +#endif /* CONFIG_VSERVER_WARN */
13566 +
13567 +#define vxwprintk_task(c, f, x...)                             \
13568 +       vxwprintk(c, VX_WARN_TASK f,                            \
13569 +               current->comm, current->pid,                    \
13570 +               current->xid, current->nid, current->tag, ##x)
13571 +#define vxwprintk_xid(c, f, x...)                              \
13572 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
13573 +#define vxwprintk_nid(c, f, x...)                              \
13574 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
13575 +#define vxwprintk_tag(c, f, x...)                              \
13576 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
13577 +
13578 +#ifdef CONFIG_VSERVER_DEBUG
13579 +#define vxd_assert_lock(l)     assert_spin_locked(l)
13580 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
13581 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
13582 +#else
13583 +#define vxd_assert_lock(l)     do { } while (0)
13584 +#define vxd_assert(c, f, x...) do { } while (0)
13585 +#endif
13586 +
13587 +
13588 +#endif /* _VX_DEBUG_H */
13589 diff -Nurp linux-2.6.22.18/include/linux/vserver/device_cmd.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/device_cmd.h
13590 --- linux-2.6.22.18/include/linux/vserver/device_cmd.h  1970-01-01 01:00:00.000000000 +0100
13591 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/device_cmd.h       2008-02-11 12:35:36.000000000 +0100
13592 @@ -0,0 +1,44 @@
13593 +#ifndef _VX_DEVICE_CMD_H
13594 +#define _VX_DEVICE_CMD_H
13595 +
13596 +
13597 +/*  device vserver commands */
13598 +
13599 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
13600 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
13601 +
13602 +struct vcmd_set_mapping_v0 {
13603 +       const char __user *device;
13604 +       const char __user *target;
13605 +       uint32_t flags;
13606 +};
13607 +
13608 +
13609 +#ifdef __KERNEL__
13610 +
13611 +#ifdef CONFIG_COMPAT
13612 +
13613 +#include <asm/compat.h>
13614 +
13615 +struct vcmd_set_mapping_v0_x32 {
13616 +       compat_uptr_t device_ptr;
13617 +       compat_uptr_t target_ptr;
13618 +       uint32_t flags;
13619 +};
13620 +
13621 +#endif /* CONFIG_COMPAT */
13622 +
13623 +#include <linux/compiler.h>
13624 +
13625 +extern int vc_set_mapping(struct vx_info *, void __user *);
13626 +extern int vc_unset_mapping(struct vx_info *, void __user *);
13627 +
13628 +#ifdef CONFIG_COMPAT
13629 +
13630 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
13631 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
13632 +
13633 +#endif /* CONFIG_COMPAT */
13634 +
13635 +#endif /* __KERNEL__ */
13636 +#endif /* _VX_DEVICE_CMD_H */
13637 diff -Nurp linux-2.6.22.18/include/linux/vserver/device_def.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/device_def.h
13638 --- linux-2.6.22.18/include/linux/vserver/device_def.h  1970-01-01 01:00:00.000000000 +0100
13639 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/device_def.h       2008-02-11 12:35:36.000000000 +0100
13640 @@ -0,0 +1,17 @@
13641 +#ifndef _VX_DEVICE_DEF_H
13642 +#define _VX_DEVICE_DEF_H
13643 +
13644 +#include <linux/types.h>
13645 +
13646 +struct vx_dmap_target {
13647 +       dev_t target;
13648 +       uint32_t flags;
13649 +};
13650 +
13651 +struct _vx_device {
13652 +#ifdef CONFIG_VSERVER_DEVICE
13653 +       struct vx_dmap_target targets[2];
13654 +#endif
13655 +};
13656 +
13657 +#endif /* _VX_DEVICE_DEF_H */
13658 diff -Nurp linux-2.6.22.18/include/linux/vserver/device.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/device.h
13659 --- linux-2.6.22.18/include/linux/vserver/device.h      1970-01-01 01:00:00.000000000 +0100
13660 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/device.h   2008-02-11 12:35:36.000000000 +0100
13661 @@ -0,0 +1,15 @@
13662 +#ifndef _VX_DEVICE_H
13663 +#define _VX_DEVICE_H
13664 +
13665 +
13666 +#define DATTR_CREATE   0x00000001
13667 +#define DATTR_OPEN     0x00000002
13668 +
13669 +#define DATTR_REMAP    0x00000010
13670 +
13671 +#define DATTR_MASK     0x00000013
13672 +
13673 +
13674 +#else  /* _VX_DEVICE_H */
13675 +#warning duplicate inclusion
13676 +#endif /* _VX_DEVICE_H */
13677 diff -Nurp linux-2.6.22.18/include/linux/vserver/dlimit_cmd.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/dlimit_cmd.h
13678 --- linux-2.6.22.18/include/linux/vserver/dlimit_cmd.h  1970-01-01 01:00:00.000000000 +0100
13679 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/dlimit_cmd.h       2008-02-11 12:35:36.000000000 +0100
13680 @@ -0,0 +1,74 @@
13681 +#ifndef _VX_DLIMIT_CMD_H
13682 +#define _VX_DLIMIT_CMD_H
13683 +
13684 +
13685 +/*  dlimit vserver commands */
13686 +
13687 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
13688 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
13689 +
13690 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
13691 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
13692 +
13693 +struct vcmd_ctx_dlimit_base_v0 {
13694 +       const char __user *name;
13695 +       uint32_t flags;
13696 +};
13697 +
13698 +struct vcmd_ctx_dlimit_v0 {
13699 +       const char __user *name;
13700 +       uint32_t space_used;                    /* used space in kbytes */
13701 +       uint32_t space_total;                   /* maximum space in kbytes */
13702 +       uint32_t inodes_used;                   /* used inodes */
13703 +       uint32_t inodes_total;                  /* maximum inodes */
13704 +       uint32_t reserved;                      /* reserved for root in % */
13705 +       uint32_t flags;
13706 +};
13707 +
13708 +#define CDLIM_UNSET            ((uint32_t)0UL)
13709 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
13710 +#define CDLIM_KEEP             ((uint32_t)~1UL)
13711 +
13712 +#ifdef __KERNEL__
13713 +
13714 +#ifdef CONFIG_COMPAT
13715 +
13716 +#include <asm/compat.h>
13717 +
13718 +struct vcmd_ctx_dlimit_base_v0_x32 {
13719 +       compat_uptr_t name_ptr;
13720 +       uint32_t flags;
13721 +};
13722 +
13723 +struct vcmd_ctx_dlimit_v0_x32 {
13724 +       compat_uptr_t name_ptr;
13725 +       uint32_t space_used;                    /* used space in kbytes */
13726 +       uint32_t space_total;                   /* maximum space in kbytes */
13727 +       uint32_t inodes_used;                   /* used inodes */
13728 +       uint32_t inodes_total;                  /* maximum inodes */
13729 +       uint32_t reserved;                      /* reserved for root in % */
13730 +       uint32_t flags;
13731 +};
13732 +
13733 +#endif /* CONFIG_COMPAT */
13734 +
13735 +#include <linux/compiler.h>
13736 +
13737 +extern int vc_add_dlimit(uint32_t, void __user *);
13738 +extern int vc_rem_dlimit(uint32_t, void __user *);
13739 +
13740 +extern int vc_set_dlimit(uint32_t, void __user *);
13741 +extern int vc_get_dlimit(uint32_t, void __user *);
13742 +
13743 +#ifdef CONFIG_COMPAT
13744 +
13745 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
13746 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
13747 +
13748 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
13749 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
13750 +
13751 +#endif /* CONFIG_COMPAT */
13752 +
13753 +#endif /* __KERNEL__ */
13754 +#endif /* _VX_DLIMIT_CMD_H */
13755 diff -Nurp linux-2.6.22.18/include/linux/vserver/dlimit.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/dlimit.h
13756 --- linux-2.6.22.18/include/linux/vserver/dlimit.h      1970-01-01 01:00:00.000000000 +0100
13757 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/dlimit.h   2008-02-11 12:35:36.000000000 +0100
13758 @@ -0,0 +1,54 @@
13759 +#ifndef _VX_DLIMIT_H
13760 +#define _VX_DLIMIT_H
13761 +
13762 +#include "switch.h"
13763 +
13764 +
13765 +#ifdef __KERNEL__
13766 +
13767 +/*      keep in sync with CDLIM_INFINITY       */
13768 +
13769 +#define DLIM_INFINITY          (~0ULL)
13770 +
13771 +#include <linux/spinlock.h>
13772 +#include <linux/rcupdate.h>
13773 +
13774 +struct super_block;
13775 +
13776 +struct dl_info {
13777 +       struct hlist_node dl_hlist;             /* linked list of contexts */
13778 +       struct rcu_head dl_rcu;                 /* the rcu head */
13779 +       tag_t dl_tag;                           /* context tag */
13780 +       atomic_t dl_usecnt;                     /* usage count */
13781 +       atomic_t dl_refcnt;                     /* reference count */
13782 +
13783 +       struct super_block *dl_sb;              /* associated superblock */
13784 +
13785 +       spinlock_t dl_lock;                     /* protect the values */
13786 +
13787 +       unsigned long long dl_space_used;       /* used space in bytes */
13788 +       unsigned long long dl_space_total;      /* maximum space in bytes */
13789 +       unsigned long dl_inodes_used;           /* used inodes */
13790 +       unsigned long dl_inodes_total;          /* maximum inodes */
13791 +
13792 +       unsigned int dl_nrlmult;                /* non root limit mult */
13793 +};
13794 +
13795 +struct rcu_head;
13796 +
13797 +extern void rcu_free_dl_info(struct rcu_head *);
13798 +extern void unhash_dl_info(struct dl_info *);
13799 +
13800 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
13801 +
13802 +
13803 +struct kstatfs;
13804 +
13805 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
13806 +
13807 +typedef uint64_t dlsize_t;
13808 +
13809 +#endif /* __KERNEL__ */
13810 +#else  /* _VX_DLIMIT_H */
13811 +#warning duplicate inclusion
13812 +#endif /* _VX_DLIMIT_H */
13813 diff -Nurp linux-2.6.22.18/include/linux/vserver/global.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/global.h
13814 --- linux-2.6.22.18/include/linux/vserver/global.h      1970-01-01 01:00:00.000000000 +0100
13815 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/global.h   2008-02-11 12:35:36.000000000 +0100
13816 @@ -0,0 +1,18 @@
13817 +#ifndef _VX_GLOBAL_H
13818 +#define _VX_GLOBAL_H
13819 +
13820 +
13821 +extern atomic_t vx_global_ctotal;
13822 +extern atomic_t vx_global_cactive;
13823 +
13824 +extern atomic_t nx_global_ctotal;
13825 +extern atomic_t nx_global_cactive;
13826 +
13827 +extern atomic_t vs_global_nsproxy;
13828 +extern atomic_t vs_global_fs;
13829 +extern atomic_t vs_global_mnt_ns;
13830 +extern atomic_t vs_global_uts_ns;
13831 +extern atomic_t vs_global_ipc_ns;
13832 +
13833 +
13834 +#endif /* _VX_GLOBAL_H */
13835 diff -Nurp linux-2.6.22.18/include/linux/vserver/history.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/history.h
13836 --- linux-2.6.22.18/include/linux/vserver/history.h     1970-01-01 01:00:00.000000000 +0100
13837 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/history.h  2008-02-11 12:35:36.000000000 +0100
13838 @@ -0,0 +1,197 @@
13839 +#ifndef _VX_HISTORY_H
13840 +#define _VX_HISTORY_H
13841 +
13842 +
13843 +enum {
13844 +       VXH_UNUSED = 0,
13845 +       VXH_THROW_OOPS = 1,
13846 +
13847 +       VXH_GET_VX_INFO,
13848 +       VXH_PUT_VX_INFO,
13849 +       VXH_INIT_VX_INFO,
13850 +       VXH_SET_VX_INFO,
13851 +       VXH_CLR_VX_INFO,
13852 +       VXH_CLAIM_VX_INFO,
13853 +       VXH_RELEASE_VX_INFO,
13854 +       VXH_ALLOC_VX_INFO,
13855 +       VXH_DEALLOC_VX_INFO,
13856 +       VXH_HASH_VX_INFO,
13857 +       VXH_UNHASH_VX_INFO,
13858 +       VXH_LOC_VX_INFO,
13859 +       VXH_LOOKUP_VX_INFO,
13860 +       VXH_CREATE_VX_INFO,
13861 +};
13862 +
13863 +struct _vxhe_vxi {
13864 +       struct vx_info *ptr;
13865 +       unsigned xid;
13866 +       unsigned usecnt;
13867 +       unsigned tasks;
13868 +};
13869 +
13870 +struct _vxhe_set_clr {
13871 +       void *data;
13872 +};
13873 +
13874 +struct _vxhe_loc_lookup {
13875 +       unsigned arg;
13876 +};
13877 +
13878 +struct _vx_hist_entry {
13879 +       void *loc;
13880 +       unsigned short seq;
13881 +       unsigned short type;
13882 +       struct _vxhe_vxi vxi;
13883 +       union {
13884 +               struct _vxhe_set_clr sc;
13885 +               struct _vxhe_loc_lookup ll;
13886 +       };
13887 +};
13888 +
13889 +#ifdef CONFIG_VSERVER_HISTORY
13890 +
13891 +extern unsigned volatile int vxh_active;
13892 +
13893 +struct _vx_hist_entry *vxh_advance(void *loc);
13894 +
13895 +
13896 +static inline
13897 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
13898 +{
13899 +       entry->vxi.ptr = vxi;
13900 +       if (vxi) {
13901 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
13902 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
13903 +               entry->vxi.xid = vxi->vx_id;
13904 +       }
13905 +}
13906 +
13907 +
13908 +#define        __HERE__ current_text_addr()
13909 +
13910 +#define __VXH_BODY(__type, __data, __here)     \
13911 +       struct _vx_hist_entry *entry;           \
13912 +                                               \
13913 +       preempt_disable();                      \
13914 +       entry = vxh_advance(__here);            \
13915 +       __data;                                 \
13916 +       entry->type = __type;                   \
13917 +       preempt_enable();
13918 +
13919 +
13920 +       /* pass vxi only */
13921 +
13922 +#define __VXH_SMPL                             \
13923 +       __vxh_copy_vxi(entry, vxi)
13924 +
13925 +static inline
13926 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
13927 +{
13928 +       __VXH_BODY(__type, __VXH_SMPL, __here)
13929 +}
13930 +
13931 +       /* pass vxi and data (void *) */
13932 +
13933 +#define __VXH_DATA                             \
13934 +       __vxh_copy_vxi(entry, vxi);             \
13935 +       entry->sc.data = data
13936 +
13937 +static inline
13938 +void   __vxh_data(struct vx_info *vxi, void *data,
13939 +                       int __type, void *__here)
13940 +{
13941 +       __VXH_BODY(__type, __VXH_DATA, __here)
13942 +}
13943 +
13944 +       /* pass vxi and arg (long) */
13945 +
13946 +#define __VXH_LONG                             \
13947 +       __vxh_copy_vxi(entry, vxi);             \
13948 +       entry->ll.arg = arg
13949 +
13950 +static inline
13951 +void   __vxh_long(struct vx_info *vxi, long arg,
13952 +                       int __type, void *__here)
13953 +{
13954 +       __VXH_BODY(__type, __VXH_LONG, __here)
13955 +}
13956 +
13957 +
13958 +static inline
13959 +void   __vxh_throw_oops(void *__here)
13960 +{
13961 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
13962 +       /* prevent further acquisition */
13963 +       vxh_active = 0;
13964 +}
13965 +
13966 +
13967 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
13968 +
13969 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
13970 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
13971 +
13972 +#define __vxh_init_vx_info(v, d, h) \
13973 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
13974 +#define __vxh_set_vx_info(v, d, h) \
13975 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
13976 +#define __vxh_clr_vx_info(v, d, h) \
13977 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
13978 +
13979 +#define __vxh_claim_vx_info(v, d, h) \
13980 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
13981 +#define __vxh_release_vx_info(v, d, h) \
13982 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
13983 +
13984 +#define vxh_alloc_vx_info(v) \
13985 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
13986 +#define vxh_dealloc_vx_info(v) \
13987 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
13988 +
13989 +#define vxh_hash_vx_info(v) \
13990 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
13991 +#define vxh_unhash_vx_info(v) \
13992 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
13993 +
13994 +#define vxh_loc_vx_info(v, l) \
13995 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
13996 +#define vxh_lookup_vx_info(v, l) \
13997 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
13998 +#define vxh_create_vx_info(v, l) \
13999 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
14000 +
14001 +extern void vxh_dump_history(void);
14002 +
14003 +
14004 +#else  /* CONFIG_VSERVER_HISTORY */
14005 +
14006 +#define        __HERE__        0
14007 +
14008 +#define vxh_throw_oops()               do { } while (0)
14009 +
14010 +#define __vxh_get_vx_info(v, h)                do { } while (0)
14011 +#define __vxh_put_vx_info(v, h)                do { } while (0)
14012 +
14013 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
14014 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
14015 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
14016 +
14017 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
14018 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
14019 +
14020 +#define vxh_alloc_vx_info(v)           do { } while (0)
14021 +#define vxh_dealloc_vx_info(v)         do { } while (0)
14022 +
14023 +#define vxh_hash_vx_info(v)            do { } while (0)
14024 +#define vxh_unhash_vx_info(v)          do { } while (0)
14025 +
14026 +#define vxh_loc_vx_info(v, l)          do { } while (0)
14027 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
14028 +#define vxh_create_vx_info(v, l)       do { } while (0)
14029 +
14030 +#define vxh_dump_history()             do { } while (0)
14031 +
14032 +
14033 +#endif /* CONFIG_VSERVER_HISTORY */
14034 +
14035 +#endif /* _VX_HISTORY_H */
14036 diff -Nurp linux-2.6.22.18/include/linux/vserver/inode_cmd.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/inode_cmd.h
14037 --- linux-2.6.22.18/include/linux/vserver/inode_cmd.h   1970-01-01 01:00:00.000000000 +0100
14038 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/inode_cmd.h        2008-02-11 12:35:36.000000000 +0100
14039 @@ -0,0 +1,59 @@
14040 +#ifndef _VX_INODE_CMD_H
14041 +#define _VX_INODE_CMD_H
14042 +
14043 +
14044 +/*  inode vserver commands */
14045 +
14046 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
14047 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
14048 +
14049 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
14050 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
14051 +
14052 +struct vcmd_ctx_iattr_v1 {
14053 +       const char __user *name;
14054 +       uint32_t tag;
14055 +       uint32_t flags;
14056 +       uint32_t mask;
14057 +};
14058 +
14059 +struct vcmd_ctx_fiattr_v0 {
14060 +       uint32_t tag;
14061 +       uint32_t flags;
14062 +       uint32_t mask;
14063 +};
14064 +
14065 +
14066 +#ifdef __KERNEL__
14067 +
14068 +
14069 +#ifdef CONFIG_COMPAT
14070 +
14071 +#include <asm/compat.h>
14072 +
14073 +struct vcmd_ctx_iattr_v1_x32 {
14074 +       compat_uptr_t name_ptr;
14075 +       uint32_t tag;
14076 +       uint32_t flags;
14077 +       uint32_t mask;
14078 +};
14079 +
14080 +#endif /* CONFIG_COMPAT */
14081 +
14082 +#include <linux/compiler.h>
14083 +
14084 +extern int vc_get_iattr(void __user *);
14085 +extern int vc_set_iattr(void __user *);
14086 +
14087 +extern int vc_fget_iattr(uint32_t, void __user *);
14088 +extern int vc_fset_iattr(uint32_t, void __user *);
14089 +
14090 +#ifdef CONFIG_COMPAT
14091 +
14092 +extern int vc_get_iattr_x32(void __user *);
14093 +extern int vc_set_iattr_x32(void __user *);
14094 +
14095 +#endif /* CONFIG_COMPAT */
14096 +
14097 +#endif /* __KERNEL__ */
14098 +#endif /* _VX_INODE_CMD_H */
14099 diff -Nurp linux-2.6.22.18/include/linux/vserver/inode.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/inode.h
14100 --- linux-2.6.22.18/include/linux/vserver/inode.h       1970-01-01 01:00:00.000000000 +0100
14101 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/inode.h    2008-02-11 12:35:36.000000000 +0100
14102 @@ -0,0 +1,38 @@
14103 +#ifndef _VX_INODE_H
14104 +#define _VX_INODE_H
14105 +
14106 +
14107 +#define IATTR_TAG      0x01000000
14108 +
14109 +#define IATTR_ADMIN    0x00000001
14110 +#define IATTR_WATCH    0x00000002
14111 +#define IATTR_HIDE     0x00000004
14112 +#define IATTR_FLAGS    0x00000007
14113 +
14114 +#define IATTR_BARRIER  0x00010000
14115 +#define IATTR_IUNLINK  0x00020000
14116 +#define IATTR_IMMUTABLE 0x00040000
14117 +
14118 +#ifdef __KERNEL__
14119 +
14120 +
14121 +#ifdef CONFIG_VSERVER_PROC_SECURE
14122 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
14123 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
14124 +#else
14125 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
14126 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
14127 +#endif
14128 +
14129 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
14130 +
14131 +#endif /* __KERNEL__ */
14132 +
14133 +/* inode ioctls */
14134 +
14135 +#define FIOC_GETXFLG   _IOR('x', 5, long)
14136 +#define FIOC_SETXFLG   _IOW('x', 6, long)
14137 +
14138 +#else  /* _VX_INODE_H */
14139 +#warning duplicate inclusion
14140 +#endif /* _VX_INODE_H */
14141 diff -Nurp linux-2.6.22.18/include/linux/vserver/Kbuild linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/Kbuild
14142 --- linux-2.6.22.18/include/linux/vserver/Kbuild        1970-01-01 01:00:00.000000000 +0100
14143 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/Kbuild     2008-02-11 12:35:36.000000000 +0100
14144 @@ -0,0 +1,8 @@
14145 +
14146 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
14147 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
14148 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
14149 +       debug_cmd.h device_cmd.h
14150 +
14151 +unifdef-y += switch.h network.h monitor.h inode.h device.h
14152 +
14153 diff -Nurp linux-2.6.22.18/include/linux/vserver/limit_cmd.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/limit_cmd.h
14154 --- linux-2.6.22.18/include/linux/vserver/limit_cmd.h   1970-01-01 01:00:00.000000000 +0100
14155 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/limit_cmd.h        2008-02-11 12:35:36.000000000 +0100
14156 @@ -0,0 +1,69 @@
14157 +#ifndef _VX_LIMIT_CMD_H
14158 +#define _VX_LIMIT_CMD_H
14159 +
14160 +
14161 +/*  rlimit vserver commands */
14162 +
14163 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
14164 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
14165 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
14166 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
14167 +
14168 +struct vcmd_ctx_rlimit_v0 {
14169 +       uint32_t id;
14170 +       uint64_t minimum;
14171 +       uint64_t softlimit;
14172 +       uint64_t maximum;
14173 +};
14174 +
14175 +struct vcmd_ctx_rlimit_mask_v0 {
14176 +       uint32_t minimum;
14177 +       uint32_t softlimit;
14178 +       uint32_t maximum;
14179 +};
14180 +
14181 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
14182 +
14183 +struct vcmd_rlimit_stat_v0 {
14184 +       uint32_t id;
14185 +       uint32_t hits;
14186 +       uint64_t value;
14187 +       uint64_t minimum;
14188 +       uint64_t maximum;
14189 +};
14190 +
14191 +#define CRLIM_UNSET            (0ULL)
14192 +#define CRLIM_INFINITY         (~0ULL)
14193 +#define CRLIM_KEEP             (~1ULL)
14194 +
14195 +#ifdef __KERNEL__
14196 +
14197 +#ifdef CONFIG_IA32_EMULATION
14198 +
14199 +struct vcmd_ctx_rlimit_v0_x32 {
14200 +       uint32_t id;
14201 +       uint64_t minimum;
14202 +       uint64_t softlimit;
14203 +       uint64_t maximum;
14204 +} __attribute__ ((aligned (4)));
14205 +
14206 +#endif /* CONFIG_IA32_EMULATION */
14207 +
14208 +#include <linux/compiler.h>
14209 +
14210 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
14211 +extern int vc_get_rlimit(struct vx_info *, void __user *);
14212 +extern int vc_set_rlimit(struct vx_info *, void __user *);
14213 +extern int vc_reset_minmax(struct vx_info *, void __user *);
14214 +
14215 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
14216 +
14217 +#ifdef CONFIG_IA32_EMULATION
14218 +
14219 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
14220 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
14221 +
14222 +#endif /* CONFIG_IA32_EMULATION */
14223 +
14224 +#endif /* __KERNEL__ */
14225 +#endif /* _VX_LIMIT_CMD_H */
14226 diff -Nurp linux-2.6.22.18/include/linux/vserver/limit_def.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/limit_def.h
14227 --- linux-2.6.22.18/include/linux/vserver/limit_def.h   1970-01-01 01:00:00.000000000 +0100
14228 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/limit_def.h        2008-02-11 12:35:36.000000000 +0100
14229 @@ -0,0 +1,47 @@
14230 +#ifndef _VX_LIMIT_DEF_H
14231 +#define _VX_LIMIT_DEF_H
14232 +
14233 +#include <asm/atomic.h>
14234 +#include <asm/resource.h>
14235 +
14236 +#include "limit.h"
14237 +
14238 +
14239 +struct _vx_res_limit {
14240 +       rlim_t soft;            /* Context soft limit */
14241 +       rlim_t hard;            /* Context hard limit */
14242 +
14243 +       rlim_atomic_t rcur;     /* Current value */
14244 +       rlim_t rmin;            /* Context minimum */
14245 +       rlim_t rmax;            /* Context maximum */
14246 +
14247 +       atomic_t lhit;          /* Limit hits */
14248 +};
14249 +
14250 +/* context sub struct */
14251 +
14252 +struct _vx_limit {
14253 +       struct _vx_res_limit res[NUM_LIMITS];
14254 +};
14255 +
14256 +#ifdef CONFIG_VSERVER_DEBUG
14257 +
14258 +static inline void __dump_vx_limit(struct _vx_limit *limit)
14259 +{
14260 +       int i;
14261 +
14262 +       printk("\t_vx_limit:");
14263 +       for (i = 0; i < NUM_LIMITS; i++) {
14264 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
14265 +                       i, (unsigned long)__rlim_get(limit, i),
14266 +                       (unsigned long)__rlim_rmin(limit, i),
14267 +                       (unsigned long)__rlim_rmax(limit, i),
14268 +                       (long)__rlim_soft(limit, i),
14269 +                       (long)__rlim_hard(limit, i),
14270 +                       atomic_read(&__rlim_lhit(limit, i)));
14271 +       }
14272 +}
14273 +
14274 +#endif
14275 +
14276 +#endif /* _VX_LIMIT_DEF_H */
14277 diff -Nurp linux-2.6.22.18/include/linux/vserver/limit.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/limit.h
14278 --- linux-2.6.22.18/include/linux/vserver/limit.h       1970-01-01 01:00:00.000000000 +0100
14279 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/limit.h    2008-02-11 12:35:36.000000000 +0100
14280 @@ -0,0 +1,70 @@
14281 +#ifndef _VX_LIMIT_H
14282 +#define _VX_LIMIT_H
14283 +
14284 +#define VLIMIT_NSOCK   16
14285 +#define VLIMIT_OPENFD  17
14286 +#define VLIMIT_ANON    18
14287 +#define VLIMIT_SHMEM   19
14288 +#define VLIMIT_SEMARY  20
14289 +#define VLIMIT_NSEMS   21
14290 +#define VLIMIT_DENTRY  22
14291 +#define VLIMIT_MAPPED  23
14292 +
14293 +
14294 +#ifdef __KERNEL__
14295 +
14296 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
14297 +
14298 +/*     keep in sync with CRLIM_INFINITY */
14299 +
14300 +#define        VLIM_INFINITY   (~0ULL)
14301 +
14302 +#include <asm/atomic.h>
14303 +#include <asm/resource.h>
14304 +
14305 +#ifndef RLIM_INFINITY
14306 +#warning RLIM_INFINITY is undefined
14307 +#endif
14308 +
14309 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
14310 +
14311 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
14312 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
14313 +
14314 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
14315 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
14316 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
14317 +
14318 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
14319 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
14320 +
14321 +typedef atomic_long_t rlim_atomic_t;
14322 +typedef unsigned long rlim_t;
14323 +
14324 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
14325 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
14326 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
14327 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
14328 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
14329 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
14330 +
14331 +
14332 +#if    (RLIM_INFINITY == VLIM_INFINITY)
14333 +#define        VX_VLIM(r) ((long long)(long)(r))
14334 +#define        VX_RLIM(v) ((rlim_t)(v))
14335 +#else
14336 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
14337 +               ? VLIM_INFINITY : (long long)(r))
14338 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
14339 +               ? RLIM_INFINITY : (rlim_t)(v))
14340 +#endif
14341 +
14342 +struct sysinfo;
14343 +
14344 +void vx_vsi_meminfo(struct sysinfo *);
14345 +void vx_vsi_swapinfo(struct sysinfo *);
14346 +
14347 +#define NUM_LIMITS     24
14348 +
14349 +#endif /* __KERNEL__ */
14350 +#endif /* _VX_LIMIT_H */
14351 diff -Nurp linux-2.6.22.18/include/linux/vserver/limit_int.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/limit_int.h
14352 --- linux-2.6.22.18/include/linux/vserver/limit_int.h   1970-01-01 01:00:00.000000000 +0100
14353 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/limit_int.h        2008-02-11 12:35:36.000000000 +0100
14354 @@ -0,0 +1,198 @@
14355 +#ifndef _VX_LIMIT_INT_H
14356 +#define _VX_LIMIT_INT_H
14357 +
14358 +#include "context.h"
14359 +
14360 +#ifdef __KERNEL__
14361 +
14362 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
14363 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
14364 +
14365 +extern const char *vlimit_name[NUM_LIMITS];
14366 +
14367 +static inline void __vx_acc_cres(struct vx_info *vxi,
14368 +       int res, int dir, void *_data, char *_file, int _line)
14369 +{
14370 +       if (VXD_RCRES_COND(res))
14371 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
14372 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
14373 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
14374 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
14375 +       if (!vxi)
14376 +               return;
14377 +
14378 +       if (dir > 0)
14379 +               __rlim_inc(&vxi->limit, res);
14380 +       else
14381 +               __rlim_dec(&vxi->limit, res);
14382 +}
14383 +
14384 +static inline void __vx_add_cres(struct vx_info *vxi,
14385 +       int res, int amount, void *_data, char *_file, int _line)
14386 +{
14387 +       if (VXD_RCRES_COND(res))
14388 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
14389 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
14390 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
14391 +                       amount, _data, _file, _line);
14392 +       if (amount == 0)
14393 +               return;
14394 +       if (!vxi)
14395 +               return;
14396 +       __rlim_add(&vxi->limit, res, amount);
14397 +}
14398 +
14399 +static inline
14400 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
14401 +{
14402 +       int cond = (value > __rlim_rmax(limit, res));
14403 +
14404 +       if (cond)
14405 +               __rlim_rmax(limit, res) = value;
14406 +       return cond;
14407 +}
14408 +
14409 +static inline
14410 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
14411 +{
14412 +       int cond = (value < __rlim_rmin(limit, res));
14413 +
14414 +       if (cond)
14415 +               __rlim_rmin(limit, res) = value;
14416 +       return cond;
14417 +}
14418 +
14419 +static inline
14420 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
14421 +{
14422 +       if (!__vx_cres_adjust_max(limit, res, value))
14423 +               __vx_cres_adjust_min(limit, res, value);
14424 +}
14425 +
14426 +
14427 +/*     return values:
14428 +        +1 ... no limit hit
14429 +        -1 ... over soft limit
14430 +         0 ... over hard limit         */
14431 +
14432 +static inline int __vx_cres_avail(struct vx_info *vxi,
14433 +       int res, int num, char *_file, int _line)
14434 +{
14435 +       struct _vx_limit *limit;
14436 +       rlim_t value;
14437 +
14438 +       if (VXD_RLIMIT_COND(res))
14439 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
14440 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
14441 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
14442 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
14443 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
14444 +                       num, _file, _line);
14445 +       if (!vxi)
14446 +               return 1;
14447 +
14448 +       limit = &vxi->limit;
14449 +       value = __rlim_get(limit, res);
14450 +
14451 +       if (!__vx_cres_adjust_max(limit, res, value))
14452 +               __vx_cres_adjust_min(limit, res, value);
14453 +
14454 +       if (num == 0)
14455 +               return 1;
14456 +
14457 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
14458 +               return -1;
14459 +       if (value + num <= __rlim_soft(limit, res))
14460 +               return -1;
14461 +
14462 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
14463 +               return 1;
14464 +       if (value + num <= __rlim_hard(limit, res))
14465 +               return 1;
14466 +
14467 +       __rlim_hit(limit, res);
14468 +       return 0;
14469 +}
14470 +
14471 +
14472 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
14473 +
14474 +static inline
14475 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
14476 +{
14477 +       rlim_t value, sum = 0;
14478 +       int res;
14479 +
14480 +       while ((res = *array++)) {
14481 +               value = __rlim_get(limit, res);
14482 +               __vx_cres_fixup(limit, res, value);
14483 +               sum += value;
14484 +       }
14485 +       return sum;
14486 +}
14487 +
14488 +static inline
14489 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
14490 +{
14491 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
14492 +       int res = *array;
14493 +
14494 +       if (value == __rlim_get(limit, res))
14495 +               return value;
14496 +
14497 +       __rlim_set(limit, res, value);
14498 +       /* now adjust min/max */
14499 +       if (!__vx_cres_adjust_max(limit, res, value))
14500 +               __vx_cres_adjust_min(limit, res, value);
14501 +
14502 +       return value;
14503 +}
14504 +
14505 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
14506 +       const int *array, int num, char *_file, int _line)
14507 +{
14508 +       struct _vx_limit *limit;
14509 +       rlim_t value = 0;
14510 +       int res;
14511 +
14512 +       if (num == 0)
14513 +               return 1;
14514 +       if (!vxi)
14515 +               return 1;
14516 +
14517 +       limit = &vxi->limit;
14518 +       res = *array;
14519 +       value = __vx_cres_array_sum(limit, array + 1);
14520 +
14521 +       __rlim_set(limit, res, value);
14522 +       __vx_cres_fixup(limit, res, value);
14523 +
14524 +       return __vx_cres_avail(vxi, res, num, _file, _line);
14525 +}
14526 +
14527 +
14528 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
14529 +{
14530 +       rlim_t value;
14531 +       int res;
14532 +
14533 +       /* complex resources first */
14534 +       if ((id < 0) || (id == RLIMIT_RSS))
14535 +               __vx_cres_array_fixup(limit, VLA_RSS);
14536 +
14537 +       for (res = 0; res < NUM_LIMITS; res++) {
14538 +               if ((id > 0) && (res != id))
14539 +                       continue;
14540 +
14541 +               value = __rlim_get(limit, res);
14542 +               __vx_cres_fixup(limit, res, value);
14543 +
14544 +               /* not supposed to happen, maybe warn? */
14545 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
14546 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
14547 +       }
14548 +}
14549 +
14550 +
14551 +#endif /* __KERNEL__ */
14552 +#endif /* _VX_LIMIT_INT_H */
14553 diff -Nurp linux-2.6.22.18/include/linux/vserver/monitor.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/monitor.h
14554 --- linux-2.6.22.18/include/linux/vserver/monitor.h     1970-01-01 01:00:00.000000000 +0100
14555 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/monitor.h  2008-02-11 12:35:36.000000000 +0100
14556 @@ -0,0 +1,96 @@
14557 +#ifndef _VX_MONITOR_H
14558 +#define _VX_MONITOR_H
14559 +
14560 +#include <linux/types.h>
14561 +
14562 +enum {
14563 +       VXM_UNUSED = 0,
14564 +
14565 +       VXM_SYNC = 0x10,
14566 +
14567 +       VXM_UPDATE = 0x20,
14568 +       VXM_UPDATE_1,
14569 +       VXM_UPDATE_2,
14570 +
14571 +       VXM_RQINFO_1 = 0x24,
14572 +       VXM_RQINFO_2,
14573 +
14574 +       VXM_ACTIVATE = 0x40,
14575 +       VXM_DEACTIVATE,
14576 +       VXM_IDLE,
14577 +
14578 +       VXM_HOLD = 0x44,
14579 +       VXM_UNHOLD,
14580 +
14581 +       VXM_MIGRATE = 0x48,
14582 +       VXM_RESCHED,
14583 +
14584 +       /* all other bits are flags */
14585 +       VXM_SCHED = 0x80,
14586 +};
14587 +
14588 +struct _vxm_update_1 {
14589 +       uint32_t tokens_max;
14590 +       uint32_t fill_rate;
14591 +       uint32_t interval;
14592 +};
14593 +
14594 +struct _vxm_update_2 {
14595 +       uint32_t tokens_min;
14596 +       uint32_t fill_rate;
14597 +       uint32_t interval;
14598 +};
14599 +
14600 +struct _vxm_rqinfo_1 {
14601 +       uint16_t running;
14602 +       uint16_t onhold;
14603 +       uint16_t iowait;
14604 +       uint16_t uintr;
14605 +       uint32_t idle_tokens;
14606 +};
14607 +
14608 +struct _vxm_rqinfo_2 {
14609 +       uint32_t norm_time;
14610 +       uint32_t idle_time;
14611 +       uint32_t idle_skip;
14612 +};
14613 +
14614 +struct _vxm_sched {
14615 +       uint32_t tokens;
14616 +       uint32_t norm_time;
14617 +       uint32_t idle_time;
14618 +};
14619 +
14620 +struct _vxm_task {
14621 +       uint16_t pid;
14622 +       uint16_t state;
14623 +};
14624 +
14625 +struct _vxm_event {
14626 +       uint32_t jif;
14627 +       union {
14628 +               uint32_t seq;
14629 +               uint32_t sec;
14630 +       };
14631 +       union {
14632 +               uint32_t tokens;
14633 +               uint32_t nsec;
14634 +               struct _vxm_task tsk;
14635 +       };
14636 +};
14637 +
14638 +struct _vx_mon_entry {
14639 +       uint16_t type;
14640 +       uint16_t xid;
14641 +       union {
14642 +               struct _vxm_event ev;
14643 +               struct _vxm_sched sd;
14644 +               struct _vxm_update_1 u1;
14645 +               struct _vxm_update_2 u2;
14646 +               struct _vxm_rqinfo_1 q1;
14647 +               struct _vxm_rqinfo_2 q2;
14648 +       };
14649 +};
14650 +
14651 +
14652 +#endif /* _VX_MONITOR_H */
14653 diff -Nurp linux-2.6.22.18/include/linux/vserver/network_cmd.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/network_cmd.h
14654 --- linux-2.6.22.18/include/linux/vserver/network_cmd.h 1970-01-01 01:00:00.000000000 +0100
14655 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/network_cmd.h      2008-02-11 12:35:36.000000000 +0100
14656 @@ -0,0 +1,150 @@
14657 +#ifndef _VX_NETWORK_CMD_H
14658 +#define _VX_NETWORK_CMD_H
14659 +
14660 +
14661 +/* vinfo commands */
14662 +
14663 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
14664 +
14665 +#ifdef __KERNEL__
14666 +extern int vc_task_nid(uint32_t);
14667 +
14668 +#endif /* __KERNEL__ */
14669 +
14670 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
14671 +
14672 +struct vcmd_nx_info_v0 {
14673 +       uint32_t nid;
14674 +       /* more to come */
14675 +};
14676 +
14677 +#ifdef __KERNEL__
14678 +extern int vc_nx_info(struct nx_info *, void __user *);
14679 +
14680 +#endif /* __KERNEL__ */
14681 +
14682 +#include <linux/in.h>
14683 +#include <linux/in6.h>
14684 +
14685 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
14686 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
14687 +
14688 +struct  vcmd_net_create {
14689 +       uint64_t flagword;
14690 +};
14691 +
14692 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
14693 +
14694 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
14695 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
14696 +
14697 +struct vcmd_net_addr_v0 {
14698 +       uint16_t type;
14699 +       uint16_t count;
14700 +       struct in_addr ip[4];
14701 +       struct in_addr mask[4];
14702 +};
14703 +
14704 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
14705 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
14706 +
14707 +struct vcmd_net_addr_ipv4_v1 {
14708 +       uint16_t type;
14709 +       uint16_t flags;
14710 +       struct in_addr ip;
14711 +       struct in_addr mask;
14712 +};
14713 +
14714 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
14715 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
14716 +
14717 +struct vcmd_net_addr_ipv6_v1 {
14718 +       uint16_t type;
14719 +       uint16_t flags;
14720 +       uint32_t prefix;
14721 +       struct in6_addr ip;
14722 +       struct in6_addr mask;
14723 +};
14724 +
14725 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
14726 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
14727 +
14728 +struct vcmd_match_ipv4_v0 {
14729 +       uint16_t type;
14730 +       uint16_t flags;
14731 +       uint16_t parent;
14732 +       uint16_t prefix;
14733 +       struct in_addr ip;
14734 +       struct in_addr ip2;
14735 +       struct in_addr mask;
14736 +};
14737 +
14738 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
14739 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
14740 +
14741 +struct vcmd_match_ipv6_v0 {
14742 +       uint16_t type;
14743 +       uint16_t flags;
14744 +       uint16_t parent;
14745 +       uint16_t prefix;
14746 +       struct in6_addr ip;
14747 +       struct in6_addr ip2;
14748 +       struct in6_addr mask;
14749 +};
14750 +
14751 +
14752 +#ifdef __KERNEL__
14753 +extern int vc_net_create(uint32_t, void __user *);
14754 +extern int vc_net_migrate(struct nx_info *, void __user *);
14755 +
14756 +extern int vc_net_add(struct nx_info *, void __user *);
14757 +extern int vc_net_remove(struct nx_info *, void __user *);
14758 +
14759 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
14760 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
14761 +
14762 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
14763 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
14764 +
14765 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
14766 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
14767 +
14768 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
14769 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
14770 +
14771 +#endif /* __KERNEL__ */
14772 +
14773 +
14774 +/* flag commands */
14775 +
14776 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
14777 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
14778 +
14779 +struct vcmd_net_flags_v0 {
14780 +       uint64_t flagword;
14781 +       uint64_t mask;
14782 +};
14783 +
14784 +#ifdef __KERNEL__
14785 +extern int vc_get_nflags(struct nx_info *, void __user *);
14786 +extern int vc_set_nflags(struct nx_info *, void __user *);
14787 +
14788 +#endif /* __KERNEL__ */
14789 +
14790 +
14791 +/* network caps commands */
14792 +
14793 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
14794 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
14795 +
14796 +struct vcmd_net_caps_v0 {
14797 +       uint64_t ncaps;
14798 +       uint64_t cmask;
14799 +};
14800 +
14801 +#ifdef __KERNEL__
14802 +extern int vc_get_ncaps(struct nx_info *, void __user *);
14803 +extern int vc_set_ncaps(struct nx_info *, void __user *);
14804 +
14805 +#endif /* __KERNEL__ */
14806 +#endif /* _VX_CONTEXT_CMD_H */
14807 diff -Nurp linux-2.6.22.18/include/linux/vserver/network.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/network.h
14808 --- linux-2.6.22.18/include/linux/vserver/network.h     1970-01-01 01:00:00.000000000 +0100
14809 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/network.h  2008-02-11 12:35:36.000000000 +0100
14810 @@ -0,0 +1,143 @@
14811 +#ifndef _VX_NETWORK_H
14812 +#define _VX_NETWORK_H
14813 +
14814 +#include <linux/types.h>
14815 +
14816 +
14817 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
14818 +
14819 +
14820 +/* network flags */
14821 +
14822 +#define NXF_INFO_PRIVATE       0x00000008
14823 +
14824 +#define NXF_SINGLE_IP          0x00000100
14825 +#define NXF_LBACK_REMAP                0x00000200
14826 +
14827 +#define NXF_HIDE_NETIF         0x02000000
14828 +#define NXF_HIDE_LBACK         0x04000000
14829 +
14830 +#define NXF_STATE_SETUP                (1ULL << 32)
14831 +#define NXF_STATE_ADMIN                (1ULL << 34)
14832 +
14833 +#define NXF_SC_HELPER          (1ULL << 36)
14834 +#define NXF_PERSISTENT         (1ULL << 38)
14835 +
14836 +#define NXF_ONE_TIME           (0x0005ULL << 32)
14837 +
14838 +
14839 +#define        NXF_INIT_SET            (__nxf_init_set())
14840 +
14841 +static inline uint64_t __nxf_init_set(void) {
14842 +       return    NXF_STATE_ADMIN
14843 +#ifdef CONFIG_VSERVER_AUTO_LBACK
14844 +               | NXF_LBACK_REMAP
14845 +               | NXF_HIDE_LBACK
14846 +#endif
14847 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
14848 +               | NXF_SINGLE_IP
14849 +#endif
14850 +               | NXF_HIDE_NETIF;
14851 +}
14852 +
14853 +
14854 +/* network caps */
14855 +
14856 +#define NXC_RAW_ICMP           0x00000100
14857 +
14858 +
14859 +/* address types */
14860 +
14861 +#define NXA_TYPE_IPV4          0x0001
14862 +#define NXA_TYPE_IPV6          0x0002
14863 +
14864 +#define NXA_TYPE_NONE          0x0000
14865 +#define NXA_TYPE_ANY           0x00FF
14866 +
14867 +#define NXA_TYPE_ADDR          0x0010
14868 +#define NXA_TYPE_MASK          0x0020
14869 +#define NXA_TYPE_RANGE         0x0040
14870 +
14871 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
14872 +
14873 +#define NXA_MOD_BCAST          0x0100
14874 +#define NXA_MOD_LBACK          0x0200
14875 +
14876 +#define NXA_LOOPBACK           0x1000
14877 +
14878 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
14879 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
14880 +
14881 +#ifdef __KERNEL__
14882 +
14883 +#include <linux/list.h>
14884 +#include <linux/spinlock.h>
14885 +#include <linux/rcupdate.h>
14886 +#include <linux/in.h>
14887 +#include <linux/in6.h>
14888 +#include <asm/atomic.h>
14889 +
14890 +struct nx_addr_v4 {
14891 +       struct nx_addr_v4 *next;
14892 +       struct in_addr ip[2];
14893 +       struct in_addr mask;
14894 +       uint16_t type;
14895 +       uint16_t flags;
14896 +};
14897 +
14898 +struct nx_addr_v6 {
14899 +       struct nx_addr_v6 *next;
14900 +       struct in6_addr ip;
14901 +       struct in6_addr mask;
14902 +       uint32_t prefix;
14903 +       uint16_t type;
14904 +       uint16_t flags;
14905 +};
14906 +
14907 +struct nx_info {
14908 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
14909 +       nid_t nx_id;                    /* vnet id */
14910 +       atomic_t nx_usecnt;             /* usage count */
14911 +       atomic_t nx_tasks;              /* tasks count */
14912 +       int nx_state;                   /* context state */
14913 +
14914 +       uint64_t nx_flags;              /* network flag word */
14915 +       uint64_t nx_ncaps;              /* network capabilities */
14916 +
14917 +       struct in_addr v4_lback;        /* Loopback address */
14918 +       struct in_addr v4_bcast;        /* Broadcast address */
14919 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
14920 +#ifdef CONFIG_IPV6
14921 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
14922 +#endif
14923 +       char nx_name[65];               /* network context name */
14924 +};
14925 +
14926 +
14927 +/* status flags */
14928 +
14929 +#define NXS_HASHED      0x0001
14930 +#define NXS_SHUTDOWN    0x0100
14931 +#define NXS_RELEASED    0x8000
14932 +
14933 +extern struct nx_info *lookup_nx_info(int);
14934 +
14935 +extern int get_nid_list(int, unsigned int *, int);
14936 +extern int nid_is_hashed(nid_t);
14937 +
14938 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
14939 +
14940 +extern long vs_net_change(struct nx_info *, unsigned int);
14941 +
14942 +struct sock;
14943 +
14944 +
14945 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
14946 +#ifdef  CONFIG_IPV6
14947 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
14948 +#else
14949 +#define NX_IPV6(n)     (0)
14950 +#endif
14951 +
14952 +#endif /* __KERNEL__ */
14953 +#endif /* _VX_NETWORK_H */
14954 diff -Nurp linux-2.6.22.18/include/linux/vserver/percpu.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/percpu.h
14955 --- linux-2.6.22.18/include/linux/vserver/percpu.h      1970-01-01 01:00:00.000000000 +0100
14956 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/percpu.h   2008-02-11 12:35:36.000000000 +0100
14957 @@ -0,0 +1,14 @@
14958 +#ifndef _VX_PERCPU_H
14959 +#define _VX_PERCPU_H
14960 +
14961 +#include "cvirt_def.h"
14962 +#include "sched_def.h"
14963 +
14964 +struct _vx_percpu {
14965 +       struct _vx_cvirt_pc cvirt;
14966 +       struct _vx_sched_pc sched;
14967 +};
14968 +
14969 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
14970 +
14971 +#endif /* _VX_PERCPU_H */
14972 diff -Nurp linux-2.6.22.18/include/linux/vserver/sched_cmd.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/sched_cmd.h
14973 --- linux-2.6.22.18/include/linux/vserver/sched_cmd.h   1970-01-01 01:00:00.000000000 +0100
14974 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/sched_cmd.h        2008-02-11 12:35:36.000000000 +0100
14975 @@ -0,0 +1,108 @@
14976 +#ifndef _VX_SCHED_CMD_H
14977 +#define _VX_SCHED_CMD_H
14978 +
14979 +
14980 +/*  sched vserver commands */
14981 +
14982 +#define VCMD_set_sched_v2      VC_CMD(SCHED, 1, 2)
14983 +#define VCMD_set_sched_v3      VC_CMD(SCHED, 1, 3)
14984 +#define VCMD_set_sched_v4      VC_CMD(SCHED, 1, 4)
14985 +
14986 +struct vcmd_set_sched_v2 {
14987 +       int32_t fill_rate;
14988 +       int32_t interval;
14989 +       int32_t tokens;
14990 +       int32_t tokens_min;
14991 +       int32_t tokens_max;
14992 +       uint64_t cpu_mask;
14993 +};
14994 +
14995 +struct vcmd_set_sched_v3 {
14996 +       uint32_t set_mask;
14997 +       int32_t fill_rate;
14998 +       int32_t interval;
14999 +       int32_t tokens;
15000 +       int32_t tokens_min;
15001 +       int32_t tokens_max;
15002 +       int32_t priority_bias;
15003 +};
15004 +
15005 +struct vcmd_set_sched_v4 {
15006 +       uint32_t set_mask;
15007 +       int32_t fill_rate;
15008 +       int32_t interval;
15009 +       int32_t tokens;
15010 +       int32_t tokens_min;
15011 +       int32_t tokens_max;
15012 +       int32_t prio_bias;
15013 +       int32_t cpu_id;
15014 +       int32_t bucket_id;
15015 +};
15016 +
15017 +#define VCMD_set_sched         VC_CMD(SCHED, 1, 5)
15018 +#define VCMD_get_sched         VC_CMD(SCHED, 2, 5)
15019 +
15020 +struct vcmd_sched_v5 {
15021 +       uint32_t mask;
15022 +       int32_t cpu_id;
15023 +       int32_t bucket_id;
15024 +       int32_t fill_rate[2];
15025 +       int32_t interval[2];
15026 +       int32_t tokens;
15027 +       int32_t tokens_min;
15028 +       int32_t tokens_max;
15029 +       int32_t prio_bias;
15030 +};
15031 +
15032 +#define VXSM_FILL_RATE         0x0001
15033 +#define VXSM_INTERVAL          0x0002
15034 +#define VXSM_FILL_RATE2                0x0004
15035 +#define VXSM_INTERVAL2         0x0008
15036 +#define VXSM_TOKENS            0x0010
15037 +#define VXSM_TOKENS_MIN                0x0020
15038 +#define VXSM_TOKENS_MAX                0x0040
15039 +#define VXSM_PRIO_BIAS         0x0100
15040 +
15041 +#define VXSM_IDLE_TIME         0x0200
15042 +#define VXSM_FORCE             0x0400
15043 +
15044 +#define        VXSM_V3_MASK            0x0173
15045 +#define        VXSM_SET_MASK           0x01FF
15046 +
15047 +#define VXSM_CPU_ID            0x1000
15048 +#define VXSM_BUCKET_ID         0x2000
15049 +
15050 +#define VXSM_MSEC              0x4000
15051 +
15052 +#define SCHED_KEEP             (-2)    /* only for v2 */
15053 +
15054 +#ifdef __KERNEL__
15055 +
15056 +#include <linux/compiler.h>
15057 +
15058 +extern int vc_set_sched_v2(struct vx_info *, void __user *);
15059 +extern int vc_set_sched_v3(struct vx_info *, void __user *);
15060 +extern int vc_set_sched_v4(struct vx_info *, void __user *);
15061 +extern int vc_set_sched(struct vx_info *, void __user *);
15062 +extern int vc_get_sched(struct vx_info *, void __user *);
15063 +
15064 +#endif /* __KERNEL__ */
15065 +
15066 +#define VCMD_sched_info                VC_CMD(SCHED, 3, 0)
15067 +
15068 +struct vcmd_sched_info {
15069 +       int32_t cpu_id;
15070 +       int32_t bucket_id;
15071 +       uint64_t user_msec;
15072 +       uint64_t sys_msec;
15073 +       uint64_t hold_msec;
15074 +       uint32_t token_usec;
15075 +       int32_t vavavoom;
15076 +};
15077 +
15078 +#ifdef __KERNEL__
15079 +
15080 +extern int vc_sched_info(struct vx_info *, void __user *);
15081 +
15082 +#endif /* __KERNEL__ */
15083 +#endif /* _VX_SCHED_CMD_H */
15084 diff -Nurp linux-2.6.22.18/include/linux/vserver/sched_def.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/sched_def.h
15085 --- linux-2.6.22.18/include/linux/vserver/sched_def.h   1970-01-01 01:00:00.000000000 +0100
15086 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/sched_def.h        2008-02-11 12:35:36.000000000 +0100
15087 @@ -0,0 +1,68 @@
15088 +#ifndef _VX_SCHED_DEF_H
15089 +#define _VX_SCHED_DEF_H
15090 +
15091 +#include <linux/spinlock.h>
15092 +#include <linux/jiffies.h>
15093 +#include <linux/cpumask.h>
15094 +#include <asm/atomic.h>
15095 +#include <asm/param.h>
15096 +
15097 +
15098 +/* context sub struct */
15099 +
15100 +struct _vx_sched {
15101 +       spinlock_t tokens_lock;         /* lock for token bucket */
15102 +
15103 +       int tokens;                     /* number of CPU tokens */
15104 +       int fill_rate[2];               /* Fill rate: add X tokens... */
15105 +       int interval[2];                /* Divisor:   per Y jiffies   */
15106 +       int tokens_min;                 /* Limit:     minimum for unhold */
15107 +       int tokens_max;                 /* Limit:     no more than N tokens */
15108 +
15109 +       int prio_bias;                  /* bias offset for priority */
15110 +
15111 +       unsigned update_mask;           /* which features should be updated */
15112 +       cpumask_t update;               /* CPUs which should update */
15113 +};
15114 +
15115 +struct _vx_sched_pc {
15116 +       int tokens;                     /* number of CPU tokens */
15117 +       int flags;                      /* bucket flags */
15118 +
15119 +       int fill_rate[2];               /* Fill rate: add X tokens... */
15120 +       int interval[2];                /* Divisor:   per Y jiffies   */
15121 +       int tokens_min;                 /* Limit:     minimum for unhold */
15122 +       int tokens_max;                 /* Limit:     no more than N tokens */
15123 +
15124 +       int prio_bias;                  /* bias offset for priority */
15125 +       int vavavoom;                   /* last calculated vavavoom */
15126 +
15127 +       unsigned long norm_time;        /* last time accounted */
15128 +       unsigned long idle_time;        /* non linear time for fair sched */
15129 +       unsigned long token_time;       /* token time for accounting */
15130 +       unsigned long onhold;           /* jiffies when put on hold */
15131 +
15132 +       uint64_t user_ticks;            /* token tick events */
15133 +       uint64_t sys_ticks;             /* token tick events */
15134 +       uint64_t hold_ticks;            /* token ticks paused */
15135 +};
15136 +
15137 +
15138 +#define VXSF_ONHOLD    0x0001
15139 +#define VXSF_IDLE_TIME 0x0100
15140 +
15141 +#ifdef CONFIG_VSERVER_DEBUG
15142 +
15143 +static inline void __dump_vx_sched(struct _vx_sched *sched)
15144 +{
15145 +       printk("\t_vx_sched:\n");
15146 +       printk("\t tokens: %4d/%4d, %4d/%4d, %4d, %4d\n",
15147 +               sched->fill_rate[0], sched->interval[0],
15148 +               sched->fill_rate[1], sched->interval[1],
15149 +               sched->tokens_min, sched->tokens_max);
15150 +       printk("\t priority = %4d\n", sched->prio_bias);
15151 +}
15152 +
15153 +#endif
15154 +
15155 +#endif /* _VX_SCHED_DEF_H */
15156 diff -Nurp linux-2.6.22.18/include/linux/vserver/sched.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/sched.h
15157 --- linux-2.6.22.18/include/linux/vserver/sched.h       1970-01-01 01:00:00.000000000 +0100
15158 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/sched.h    2008-02-11 12:35:36.000000000 +0100
15159 @@ -0,0 +1,26 @@
15160 +#ifndef _VX_SCHED_H
15161 +#define _VX_SCHED_H
15162 +
15163 +
15164 +#ifdef __KERNEL__
15165 +
15166 +struct timespec;
15167 +
15168 +void vx_vsi_uptime(struct timespec *, struct timespec *);
15169 +
15170 +
15171 +struct vx_info;
15172 +
15173 +void vx_update_load(struct vx_info *);
15174 +
15175 +
15176 +int vx_tokens_recalc(struct _vx_sched_pc *,
15177 +       unsigned long *, unsigned long *, int [2]);
15178 +
15179 +void vx_update_sched_param(struct _vx_sched *sched,
15180 +       struct _vx_sched_pc *sched_pc);
15181 +
15182 +#endif /* __KERNEL__ */
15183 +#else  /* _VX_SCHED_H */
15184 +#warning duplicate inclusion
15185 +#endif /* _VX_SCHED_H */
15186 diff -Nurp linux-2.6.22.18/include/linux/vserver/signal_cmd.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/signal_cmd.h
15187 --- linux-2.6.22.18/include/linux/vserver/signal_cmd.h  1970-01-01 01:00:00.000000000 +0100
15188 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/signal_cmd.h       2008-02-11 12:35:36.000000000 +0100
15189 @@ -0,0 +1,43 @@
15190 +#ifndef _VX_SIGNAL_CMD_H
15191 +#define _VX_SIGNAL_CMD_H
15192 +
15193 +
15194 +/*  signalling vserver commands */
15195 +
15196 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
15197 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
15198 +
15199 +struct vcmd_ctx_kill_v0 {
15200 +       int32_t pid;
15201 +       int32_t sig;
15202 +};
15203 +
15204 +struct vcmd_wait_exit_v0 {
15205 +       int32_t reboot_cmd;
15206 +       int32_t exit_code;
15207 +};
15208 +
15209 +#ifdef __KERNEL__
15210 +
15211 +extern int vc_ctx_kill(struct vx_info *, void __user *);
15212 +extern int vc_wait_exit(struct vx_info *, void __user *);
15213 +
15214 +#endif /* __KERNEL__ */
15215 +
15216 +/*  process alteration commands */
15217 +
15218 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
15219 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
15220 +
15221 +struct vcmd_pflags_v0 {
15222 +       uint32_t flagword;
15223 +       uint32_t mask;
15224 +};
15225 +
15226 +#ifdef __KERNEL__
15227 +
15228 +extern int vc_get_pflags(uint32_t pid, void __user *);
15229 +extern int vc_set_pflags(uint32_t pid, void __user *);
15230 +
15231 +#endif /* __KERNEL__ */
15232 +#endif /* _VX_SIGNAL_CMD_H */
15233 diff -Nurp linux-2.6.22.18/include/linux/vserver/signal.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/signal.h
15234 --- linux-2.6.22.18/include/linux/vserver/signal.h      1970-01-01 01:00:00.000000000 +0100
15235 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/signal.h   2008-02-11 12:35:36.000000000 +0100
15236 @@ -0,0 +1,14 @@
15237 +#ifndef _VX_SIGNAL_H
15238 +#define _VX_SIGNAL_H
15239 +
15240 +
15241 +#ifdef __KERNEL__
15242 +
15243 +struct vx_info;
15244 +
15245 +int vx_info_kill(struct vx_info *, int, int);
15246 +
15247 +#endif /* __KERNEL__ */
15248 +#else  /* _VX_SIGNAL_H */
15249 +#warning duplicate inclusion
15250 +#endif /* _VX_SIGNAL_H */
15251 diff -Nurp linux-2.6.22.18/include/linux/vserver/space_cmd.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/space_cmd.h
15252 --- linux-2.6.22.18/include/linux/vserver/space_cmd.h   1970-01-01 01:00:00.000000000 +0100
15253 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/space_cmd.h        2008-02-11 12:35:36.000000000 +0100
15254 @@ -0,0 +1,26 @@
15255 +#ifndef _VX_SPACE_CMD_H
15256 +#define _VX_SPACE_CMD_H
15257 +
15258 +
15259 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
15260 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 1)
15261 +
15262 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
15263 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 1)
15264 +
15265 +#define VCMD_get_space_mask    VC_CMD(PROCALT, 4, 0)
15266 +
15267 +
15268 +struct vcmd_space_mask {
15269 +       uint64_t mask;
15270 +};
15271 +
15272 +
15273 +#ifdef __KERNEL__
15274 +
15275 +extern int vc_enter_space(struct vx_info *, void __user *);
15276 +extern int vc_set_space(struct vx_info *, void __user *);
15277 +extern int vc_get_space_mask(struct vx_info *, void __user *);
15278 +
15279 +#endif /* __KERNEL__ */
15280 +#endif /* _VX_SPACE_CMD_H */
15281 diff -Nurp linux-2.6.22.18/include/linux/vserver/space.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/space.h
15282 --- linux-2.6.22.18/include/linux/vserver/space.h       1970-01-01 01:00:00.000000000 +0100
15283 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/space.h    2008-02-11 12:35:36.000000000 +0100
15284 @@ -0,0 +1,13 @@
15285 +#ifndef _VX_SPACE_H
15286 +#define _VX_SPACE_H
15287 +
15288 +
15289 +#include <linux/types.h>
15290 +
15291 +struct vx_info;
15292 +
15293 +int vx_set_space(struct vx_info *vxi, unsigned long mask);
15294 +
15295 +#else  /* _VX_SPACE_H */
15296 +#warning duplicate inclusion
15297 +#endif /* _VX_SPACE_H */
15298 diff -Nurp linux-2.6.22.18/include/linux/vserver/switch.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/switch.h
15299 --- linux-2.6.22.18/include/linux/vserver/switch.h      1970-01-01 01:00:00.000000000 +0100
15300 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/switch.h   2008-02-11 12:35:36.000000000 +0100
15301 @@ -0,0 +1,99 @@
15302 +#ifndef _VX_SWITCH_H
15303 +#define _VX_SWITCH_H
15304 +
15305 +#include <linux/types.h>
15306 +
15307 +
15308 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
15309 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
15310 +#define VC_VERSION(c)          ((c) & 0xFFF)
15311 +
15312 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
15313 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
15314 +
15315 +/*
15316 +
15317 +  Syscall Matrix V2.8
15318 +
15319 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
15320 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
15321 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
15322 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15323 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
15324 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
15325 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15326 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
15327 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
15328 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15329 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
15330 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
15331 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15332 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
15333 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
15334 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15335 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
15336 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
15337 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15338 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
15339 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
15340 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
15341 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |       |       |
15342 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
15343 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15344 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
15345 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
15346 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15347 +
15348 +*/
15349 +
15350 +#define VC_CAT_VERSION         0
15351 +
15352 +#define VC_CAT_VSETUP          1
15353 +#define VC_CAT_VHOST           2
15354 +
15355 +#define VC_CAT_DEVICE          6
15356 +
15357 +#define VC_CAT_VPROC           9
15358 +#define VC_CAT_PROCALT         10
15359 +#define VC_CAT_PROCMIG         11
15360 +#define VC_CAT_PROCTRL         12
15361 +
15362 +#define VC_CAT_SCHED           14
15363 +#define VC_CAT_MEMCTRL         20
15364 +
15365 +#define VC_CAT_VNET            25
15366 +#define VC_CAT_NETALT          26
15367 +#define VC_CAT_NETMIG          27
15368 +#define VC_CAT_NETCTRL         28
15369 +
15370 +#define VC_CAT_TAGMIG          35
15371 +#define VC_CAT_DLIMIT          36
15372 +#define VC_CAT_INODE           38
15373 +
15374 +#define VC_CAT_VSTAT           40
15375 +#define VC_CAT_VINFO           46
15376 +#define VC_CAT_EVENT           48
15377 +
15378 +#define VC_CAT_FLAGS           52
15379 +#define VC_CAT_DEBUG           56
15380 +#define VC_CAT_RLIMIT          60
15381 +
15382 +#define VC_CAT_SYSTEST         61
15383 +#define VC_CAT_COMPAT          63
15384 +
15385 +/*  query version */
15386 +
15387 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
15388 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
15389 +
15390 +
15391 +#ifdef __KERNEL__
15392 +
15393 +#include <linux/errno.h>
15394 +
15395 +
15396 +#else  /* __KERNEL__ */
15397 +#define __user
15398 +#endif /* __KERNEL__ */
15399 +
15400 +#endif /* _VX_SWITCH_H */
15401 diff -Nurp linux-2.6.22.18/include/linux/vserver/tag_cmd.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/tag_cmd.h
15402 --- linux-2.6.22.18/include/linux/vserver/tag_cmd.h     1970-01-01 01:00:00.000000000 +0100
15403 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/tag_cmd.h  2008-02-11 12:35:36.000000000 +0100
15404 @@ -0,0 +1,22 @@
15405 +#ifndef _VX_TAG_CMD_H
15406 +#define _VX_TAG_CMD_H
15407 +
15408 +
15409 +/* vinfo commands */
15410 +
15411 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
15412 +
15413 +#ifdef __KERNEL__
15414 +extern int vc_task_tag(uint32_t);
15415 +
15416 +#endif /* __KERNEL__ */
15417 +
15418 +/* context commands */
15419 +
15420 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
15421 +
15422 +#ifdef __KERNEL__
15423 +extern int vc_tag_migrate(uint32_t);
15424 +
15425 +#endif /* __KERNEL__ */
15426 +#endif /* _VX_TAG_CMD_H */
15427 diff -Nurp linux-2.6.22.18/include/linux/vserver/tag.h linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/tag.h
15428 --- linux-2.6.22.18/include/linux/vserver/tag.h 1970-01-01 01:00:00.000000000 +0100
15429 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vserver/tag.h      2008-02-11 12:35:36.000000000 +0100
15430 @@ -0,0 +1,143 @@
15431 +#ifndef _DX_TAG_H
15432 +#define _DX_TAG_H
15433 +
15434 +#include <linux/types.h>
15435 +
15436 +
15437 +#define DX_TAG(in)     (IS_TAGGED(in))
15438 +
15439 +
15440 +#ifdef CONFIG_DX_TAG_NFSD
15441 +#define DX_TAG_NFSD    1
15442 +#else
15443 +#define DX_TAG_NFSD    0
15444 +#endif
15445 +
15446 +
15447 +#ifdef CONFIG_TAGGING_NONE
15448 +
15449 +#define MAX_UID                0xFFFFFFFF
15450 +#define MAX_GID                0xFFFFFFFF
15451 +
15452 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
15453 +
15454 +#define TAGINO_UID(cond, uid, tag)     (uid)
15455 +#define TAGINO_GID(cond, gid, tag)     (gid)
15456 +
15457 +#endif
15458 +
15459 +
15460 +#ifdef CONFIG_TAGGING_GID16
15461 +
15462 +#define MAX_UID                0xFFFFFFFF
15463 +#define MAX_GID                0x0000FFFF
15464 +
15465 +#define INOTAG_TAG(cond, uid, gid, tag)        \
15466 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
15467 +
15468 +#define TAGINO_UID(cond, uid, tag)     (uid)
15469 +#define TAGINO_GID(cond, gid, tag)     \
15470 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
15471 +
15472 +#endif
15473 +
15474 +
15475 +#ifdef CONFIG_TAGGING_ID24
15476 +
15477 +#define MAX_UID                0x00FFFFFF
15478 +#define MAX_GID                0x00FFFFFF
15479 +
15480 +#define INOTAG_TAG(cond, uid, gid, tag)        \
15481 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
15482 +
15483 +#define TAGINO_UID(cond, uid, tag)     \
15484 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
15485 +#define TAGINO_GID(cond, gid, tag)     \
15486 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
15487 +
15488 +#endif
15489 +
15490 +
15491 +#ifdef CONFIG_TAGGING_UID16
15492 +
15493 +#define MAX_UID                0x0000FFFF
15494 +#define MAX_GID                0xFFFFFFFF
15495 +
15496 +#define INOTAG_TAG(cond, uid, gid, tag)        \
15497 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
15498 +
15499 +#define TAGINO_UID(cond, uid, tag)     \
15500 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
15501 +#define TAGINO_GID(cond, gid, tag)     (gid)
15502 +
15503 +#endif
15504 +
15505 +
15506 +#ifdef CONFIG_TAGGING_INTERN
15507 +
15508 +#define MAX_UID                0xFFFFFFFF
15509 +#define MAX_GID                0xFFFFFFFF
15510 +
15511 +#define INOTAG_TAG(cond, uid, gid, tag)        \
15512 +       ((cond) ? (tag) : 0)
15513 +
15514 +#define TAGINO_UID(cond, uid, tag)     (uid)
15515 +#define TAGINO_GID(cond, gid, tag)     (gid)
15516 +
15517 +#endif
15518 +
15519 +
15520 +#ifndef CONFIG_TAGGING_NONE
15521 +#define dx_current_fstag(sb)   \
15522 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
15523 +#else
15524 +#define dx_current_fstag(sb)   (0)
15525 +#endif
15526 +
15527 +#ifndef CONFIG_TAGGING_INTERN
15528 +#define TAGINO_TAG(cond, tag)  (0)
15529 +#else
15530 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
15531 +#endif
15532 +
15533 +#define INOTAG_UID(cond, uid, gid)     \
15534 +       ((cond) ? ((uid) & MAX_UID) : (uid))
15535 +#define INOTAG_GID(cond, uid, gid)     \
15536 +       ((cond) ? ((gid) & MAX_GID) : (gid))
15537 +
15538 +
15539 +static inline uid_t dx_map_uid(uid_t uid)
15540 +{
15541 +       if ((uid > MAX_UID) && (uid != -1))
15542 +               uid = -2;
15543 +       return (uid & MAX_UID);
15544 +}
15545 +
15546 +static inline gid_t dx_map_gid(gid_t gid)
15547 +{
15548 +       if ((gid > MAX_GID) && (gid != -1))
15549 +               gid = -2;
15550 +       return (gid & MAX_GID);
15551 +}
15552 +
15553 +struct peer_tag {
15554 +       int32_t xid;
15555 +       int32_t nid;
15556 +};
15557 +
15558 +#define dx_notagcheck(nd) \
15559 +       ((nd) && (nd)->mnt && ((nd)->mnt->mnt_flags & MNT_NOTAGCHECK))
15560 +
15561 +int dx_parse_tag(char *string, tag_t *tag, int remove);
15562 +
15563 +#ifdef CONFIG_PROPAGATE
15564 +
15565 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
15566 +
15567 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
15568 +
15569 +#else
15570 +#define dx_propagate_tag(n, i) do { } while (0)
15571 +#endif
15572 +
15573 +#endif /* _DX_TAG_H */
15574 diff -Nurp linux-2.6.22.18/include/linux/vs_inet6.h linux-2.6.22.18-vs2.3.0.32/include/linux/vs_inet6.h
15575 --- linux-2.6.22.18/include/linux/vs_inet6.h    1970-01-01 01:00:00.000000000 +0100
15576 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vs_inet6.h 2008-02-11 12:35:36.000000000 +0100
15577 @@ -0,0 +1,228 @@
15578 +#ifndef _VS_INET6_H
15579 +#define _VS_INET6_H
15580 +
15581 +#include <net/ipv6.h>
15582 +#include "vserver/base.h"
15583 +#include "vserver/network.h"
15584 +#include "vserver/debug.h"
15585 +
15586 +#define NXAV6(a)       NIP6((a)->ip), NIP6((a)->mask), (a)->prefix, (a)->type
15587 +#define NXAV6_FMT      "[" NIP6_FMT "/" NIP6_FMT "/%d:%04x]"
15588 +
15589 +
15590 +#ifdef CONFIG_IPV6
15591 +
15592 +static inline
15593 +int v6_addr_match(struct nx_addr_v6 *nxa,
15594 +       const struct in6_addr *addr, uint16_t mask)
15595 +{
15596 +       switch (nxa->type & mask) {
15597 +       case NXA_TYPE_MASK:
15598 +               return ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
15599 +       case NXA_TYPE_ADDR:
15600 +               return ipv6_addr_equal(&nxa->ip, addr);
15601 +       case NXA_TYPE_ANY:
15602 +               return 1;
15603 +       default:
15604 +               return 0;
15605 +       }
15606 +}
15607 +
15608 +static inline
15609 +int v6_addr_in_nx_info(struct nx_info *nxi,
15610 +       const struct in6_addr *addr, uint16_t mask)
15611 +{
15612 +       struct nx_addr_v6 *nxa;
15613 +
15614 +       if (!nxi)
15615 +               return 1;
15616 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
15617 +               if (v6_addr_match(nxa, addr, mask))
15618 +                       return 1;
15619 +       return 0;
15620 +}
15621 +
15622 +static inline
15623 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
15624 +{
15625 +       /* FIXME: needs full range checks */
15626 +       return v6_addr_match(nxa, &addr->ip, mask);
15627 +}
15628 +
15629 +static inline
15630 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
15631 +{
15632 +       struct nx_addr_v6 *ptr;
15633 +
15634 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
15635 +               if (v6_nx_addr_match(ptr, nxa, mask))
15636 +                       return 1;
15637 +       return 0;
15638 +}
15639 +
15640 +
15641 +/*
15642 + *     Check if a given address matches for a socket
15643 + *
15644 + *     nxi:            the socket's nx_info if any
15645 + *     addr:           to be verified address
15646 + */
15647 +static inline
15648 +int v6_sock_addr_match (
15649 +       struct nx_info *nxi,
15650 +       struct inet_sock *inet,
15651 +       struct in6_addr *addr)
15652 +{
15653 +       struct sock *sk = &inet->sk;
15654 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
15655 +
15656 +       if (!ipv6_addr_any(addr) &&
15657 +               ipv6_addr_equal(saddr, addr))
15658 +               return 1;
15659 +       if (ipv6_addr_any(saddr))
15660 +               return v6_addr_in_nx_info(nxi, addr, -1);
15661 +       return 0;
15662 +}
15663 +
15664 +/*
15665 + *     check if address is covered by socket
15666 + *
15667 + *     sk:     the socket to check against
15668 + *     addr:   the address in question (must be != 0)
15669 + */
15670 +
15671 +static inline
15672 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
15673 +{
15674 +       struct nx_info *nxi = sk->sk_nx_info;
15675 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
15676 +
15677 +       vxdprintk(VXD_CBIT(net, 5),
15678 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:" NIP6_FMT " %p;%lx",
15679 +               sk, NXAV6(nxa), nxi, NIP6(*saddr), sk->sk_socket,
15680 +               (sk->sk_socket?sk->sk_socket->flags:0));
15681 +
15682 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
15683 +               return v6_addr_match(nxa, saddr, -1);
15684 +       } else if (nxi) {               /* match against nx_info */
15685 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
15686 +       } else {                        /* unrestricted any socket */
15687 +               return 1;
15688 +       }
15689 +}
15690 +
15691 +
15692 +/* inet related checks and helpers */
15693 +
15694 +
15695 +struct in_ifaddr;
15696 +struct net_device;
15697 +struct sock;
15698 +
15699 +
15700 +#include <linux/netdevice.h>
15701 +#include <linux/inetdevice.h>
15702 +#include <net/inet_timewait_sock.h>
15703 +
15704 +
15705 +int dev_in_nx_info(struct net_device *, struct nx_info *);
15706 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
15707 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
15708 +
15709 +
15710 +
15711 +static inline
15712 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
15713 +{
15714 +       if (!nxi)
15715 +               return 1;
15716 +       if (!ifa)
15717 +               return 0;
15718 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
15719 +}
15720 +
15721 +static inline
15722 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
15723 +{
15724 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
15725 +               return 1;
15726 +       if (v6_ifa_in_nx_info(ifa, nxi))
15727 +               return 1;
15728 +       return 0;
15729 +}
15730 +
15731 +
15732 +struct nx_v6_sock_addr {
15733 +       struct in6_addr saddr;  /* Address used for validation */
15734 +       struct in6_addr baddr;  /* Address used for socket bind */
15735 +};
15736 +
15737 +static inline
15738 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
15739 +       struct nx_v6_sock_addr *nsa)
15740 +{
15741 +       // struct sock *sk = &inet->sk;
15742 +       // struct nx_info *nxi = sk->sk_nx_info;
15743 +       struct in6_addr saddr = addr->sin6_addr;
15744 +       struct in6_addr baddr = saddr;
15745 +
15746 +       nsa->saddr = saddr;
15747 +       nsa->baddr = baddr;
15748 +       return 0;
15749 +}
15750 +
15751 +static inline
15752 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
15753 +{
15754 +       // struct sock *sk = &inet->sk;
15755 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
15756 +
15757 +       // *saddr = nsa->baddr;
15758 +       // inet->saddr = nsa->baddr;
15759 +}
15760 +
15761 +static inline
15762 +int nx_info_has_v6(struct nx_info *nxi)
15763 +{
15764 +       if (!nxi)
15765 +               return 1;
15766 +       if (NX_IPV6(nxi))
15767 +               return 1;
15768 +       return 0;
15769 +}
15770 +
15771 +#else /* CONFIG_IPV6 */
15772 +
15773 +static inline
15774 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
15775 +{
15776 +       return 1;
15777 +}
15778 +
15779 +
15780 +static inline
15781 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
15782 +{
15783 +       return 1;
15784 +}
15785 +
15786 +static inline
15787 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
15788 +{
15789 +       return 1;
15790 +}
15791 +
15792 +static inline
15793 +int nx_info_has_v6(struct nx_info *nxi)
15794 +{
15795 +       return 0;
15796 +}
15797 +
15798 +#endif /* CONFIG_IPV6 */
15799 +
15800 +#define current_nx_info_has_v6() \
15801 +       nx_info_has_v6(current_nx_info())
15802 +
15803 +#else
15804 +#warning duplicate inclusion
15805 +#endif
15806 diff -Nurp linux-2.6.22.18/include/linux/vs_inet.h linux-2.6.22.18-vs2.3.0.32/include/linux/vs_inet.h
15807 --- linux-2.6.22.18/include/linux/vs_inet.h     1970-01-01 01:00:00.000000000 +0100
15808 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vs_inet.h  2008-02-11 12:35:36.000000000 +0100
15809 @@ -0,0 +1,341 @@
15810 +#ifndef _VS_INET_H
15811 +#define _VS_INET_H
15812 +
15813 +#include "vserver/base.h"
15814 +#include "vserver/network.h"
15815 +#include "vserver/debug.h"
15816 +
15817 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
15818 +
15819 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
15820 +                       NIPQUAD((a)->mask), (a)->type
15821 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
15822 +
15823 +
15824 +static inline
15825 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
15826 +{
15827 +       __be32 ip = nxa->ip[0].s_addr;
15828 +       __be32 mask = nxa->mask.s_addr;
15829 +       __be32 bcast = ip | ~mask;
15830 +       int ret = 0;
15831 +
15832 +       switch (nxa->type & tmask) {
15833 +       case NXA_TYPE_MASK:
15834 +               ret = (ip == (addr & mask));
15835 +               break;
15836 +       case NXA_TYPE_ADDR:
15837 +               ret = 3;
15838 +               if (addr == ip)
15839 +                       break;
15840 +               /* fall through to broadcast */
15841 +       case NXA_MOD_BCAST:
15842 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
15843 +               break;
15844 +       case NXA_TYPE_RANGE:
15845 +               ret = ((nxa->ip[0].s_addr <= addr) &&
15846 +                       (nxa->ip[1].s_addr > addr));
15847 +               break;
15848 +       case NXA_TYPE_ANY:
15849 +               ret = 2;
15850 +               break;
15851 +       }
15852 +
15853 +       vxdprintk(VXD_CBIT(net, 0),
15854 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
15855 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
15856 +       return ret;
15857 +}
15858 +
15859 +static inline
15860 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
15861 +{
15862 +       struct nx_addr_v4 *nxa;
15863 +       int ret = 1;
15864 +
15865 +       if (!nxi)
15866 +               goto out;
15867 +
15868 +       ret = 2;
15869 +       /* allow 127.0.0.1 when remapping lback */
15870 +       if ((tmask & NXA_LOOPBACK) &&
15871 +               (addr == IPI_LOOPBACK) &&
15872 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
15873 +               goto out;
15874 +       ret = 3;
15875 +       /* check for lback address */
15876 +       if ((tmask & NXA_MOD_LBACK) &&
15877 +               (nxi->v4_lback.s_addr == addr))
15878 +               goto out;
15879 +       ret = 4;
15880 +       /* check for broadcast address */
15881 +       if ((tmask & NXA_MOD_BCAST) &&
15882 +               (nxi->v4_bcast.s_addr == addr))
15883 +               goto out;
15884 +       ret = 5;
15885 +       /* check for v4 addresses */
15886 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
15887 +               if (v4_addr_match(nxa, addr, tmask))
15888 +                       goto out;
15889 +       ret = 0;
15890 +out:
15891 +       vxdprintk(VXD_CBIT(net, 0),
15892 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
15893 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
15894 +       return ret;
15895 +}
15896 +
15897 +static inline
15898 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
15899 +{
15900 +       /* FIXME: needs full range checks */
15901 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
15902 +}
15903 +
15904 +static inline
15905 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
15906 +{
15907 +       struct nx_addr_v4 *ptr;
15908 +
15909 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
15910 +               if (v4_nx_addr_match(ptr, nxa, mask))
15911 +                       return 1;
15912 +       return 0;
15913 +}
15914 +
15915 +#include <net/inet_sock.h>
15916 +
15917 +/*
15918 + *     Check if a given address matches for a socket
15919 + *
15920 + *     nxi:            the socket's nx_info if any
15921 + *     addr:           to be verified address
15922 + */
15923 +static inline
15924 +int v4_sock_addr_match (
15925 +       struct nx_info *nxi,
15926 +       struct inet_sock *inet,
15927 +       __be32 addr)
15928 +{
15929 +       __be32 saddr = inet->rcv_saddr;
15930 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
15931 +
15932 +       if (addr && (saddr == addr || bcast == addr))
15933 +               return 1;
15934 +       if (!saddr)
15935 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
15936 +       return 0;
15937 +}
15938 +
15939 +
15940 +/* inet related checks and helpers */
15941 +
15942 +
15943 +struct in_ifaddr;
15944 +struct net_device;
15945 +struct sock;
15946 +
15947 +#ifdef CONFIG_INET
15948 +
15949 +#include <linux/netdevice.h>
15950 +#include <linux/inetdevice.h>
15951 +#include <net/inet_timewait_sock.h>
15952 +
15953 +
15954 +int dev_in_nx_info(struct net_device *, struct nx_info *);
15955 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
15956 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
15957 +
15958 +
15959 +/*
15960 + *     check if address is covered by socket
15961 + *
15962 + *     sk:     the socket to check against
15963 + *     addr:   the address in question (must be != 0)
15964 + */
15965 +
15966 +static inline
15967 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
15968 +{
15969 +       struct nx_info *nxi = sk->sk_nx_info;
15970 +       __be32 saddr = inet_rcv_saddr(sk);
15971 +
15972 +       vxdprintk(VXD_CBIT(net, 5),
15973 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
15974 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
15975 +               (sk->sk_socket?sk->sk_socket->flags:0));
15976 +
15977 +       if (saddr) {            /* direct address match */
15978 +               return v4_addr_match(nxa, saddr, -1);
15979 +       } else if (nxi) {       /* match against nx_info */
15980 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
15981 +       } else {                /* unrestricted any socket */
15982 +               return 1;
15983 +       }
15984 +}
15985 +
15986 +
15987 +
15988 +static inline
15989 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
15990 +{
15991 +       vxdprintk(VXD_CBIT(net, 1), "nx_dev_visible(%p[#%u],%p Â»%s«) %d",
15992 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
15993 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
15994 +
15995 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
15996 +               return 1;
15997 +       if (dev_in_nx_info(dev, nxi))
15998 +               return 1;
15999 +       return 0;
16000 +}
16001 +
16002 +
16003 +static inline
16004 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
16005 +{
16006 +       if (!nxi)
16007 +               return 1;
16008 +       if (!ifa)
16009 +               return 0;
16010 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
16011 +}
16012 +
16013 +static inline
16014 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
16015 +{
16016 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
16017 +               nxi, nxi ? nxi->nx_id : 0, ifa,
16018 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
16019 +
16020 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
16021 +               return 1;
16022 +       if (v4_ifa_in_nx_info(ifa, nxi))
16023 +               return 1;
16024 +       return 0;
16025 +}
16026 +
16027 +
16028 +struct nx_v4_sock_addr {
16029 +       __be32 saddr;   /* Address used for validation */
16030 +       __be32 baddr;   /* Address used for socket bind */
16031 +};
16032 +
16033 +static inline
16034 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
16035 +       struct nx_v4_sock_addr *nsa)
16036 +{
16037 +       struct sock *sk = &inet->sk;
16038 +       struct nx_info *nxi = sk->sk_nx_info;
16039 +       __be32 saddr = addr->sin_addr.s_addr;
16040 +       __be32 baddr = saddr;
16041 +
16042 +       vxdprintk(VXD_CBIT(net, 3),
16043 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
16044 +               sk, sk->sk_nx_info, sk->sk_socket,
16045 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
16046 +               NIPQUAD(saddr));
16047 +
16048 +       if (nxi) {
16049 +               if (saddr == INADDR_ANY) {
16050 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
16051 +                               baddr = nxi->v4.ip[0].s_addr;
16052 +               } else if (saddr == IPI_LOOPBACK) {
16053 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
16054 +                               baddr = nxi->v4_lback.s_addr;
16055 +               } else {        /* normal address bind */
16056 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
16057 +                               return -EADDRNOTAVAIL;
16058 +               }
16059 +       }
16060 +
16061 +       vxdprintk(VXD_CBIT(net, 3),
16062 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
16063 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
16064 +
16065 +       nsa->saddr = saddr;
16066 +       nsa->baddr = baddr;
16067 +       return 0;
16068 +}
16069 +
16070 +static inline
16071 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
16072 +{
16073 +       inet->saddr = nsa->baddr;
16074 +       inet->rcv_saddr = nsa->baddr;
16075 +}
16076 +
16077 +
16078 +/*
16079 + *      helper to simplify inet_lookup_listener
16080 + *
16081 + *      nxi:   the socket's nx_info if any
16082 + *      addr:  to be verified address
16083 + *      saddr: socket address
16084 + */
16085 +static inline int v4_inet_addr_match (
16086 +       struct nx_info *nxi,
16087 +       __be32 addr,
16088 +       __be32 saddr)
16089 +{
16090 +       if (addr && (saddr == addr))
16091 +               return 1;
16092 +       if (!saddr)
16093 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
16094 +       return 0;
16095 +}
16096 +
16097 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
16098 +{
16099 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
16100 +               (addr == nxi->v4_lback.s_addr))
16101 +               return IPI_LOOPBACK;
16102 +       return addr;
16103 +}
16104 +
16105 +static inline
16106 +int nx_info_has_v4(struct nx_info *nxi)
16107 +{
16108 +       if (!nxi)
16109 +               return 1;
16110 +       if (NX_IPV4(nxi))
16111 +               return 1;
16112 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
16113 +               return 1;
16114 +       return 0;
16115 +}
16116 +
16117 +#else /* CONFIG_INET */
16118 +
16119 +static inline
16120 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
16121 +{
16122 +       return 1;
16123 +}
16124 +
16125 +static inline
16126 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
16127 +{
16128 +       return 1;
16129 +}
16130 +
16131 +static inline
16132 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
16133 +{
16134 +       return 1;
16135 +}
16136 +
16137 +static inline
16138 +int nx_info_has_v4(struct nx_info *nxi)
16139 +{
16140 +       return 0;
16141 +}
16142 +
16143 +#endif /* CONFIG_INET */
16144 +
16145 +#define current_nx_info_has_v4() \
16146 +       nx_info_has_v4(current_nx_info())
16147 +
16148 +#else
16149 +#warning duplicate inclusion
16150 +#endif
16151 diff -Nurp linux-2.6.22.18/include/linux/vs_limit.h linux-2.6.22.18-vs2.3.0.32/include/linux/vs_limit.h
16152 --- linux-2.6.22.18/include/linux/vs_limit.h    1970-01-01 01:00:00.000000000 +0100
16153 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vs_limit.h 2008-02-11 12:35:36.000000000 +0100
16154 @@ -0,0 +1,140 @@
16155 +#ifndef _VS_LIMIT_H
16156 +#define _VS_LIMIT_H
16157 +
16158 +#include "vserver/limit.h"
16159 +#include "vserver/base.h"
16160 +#include "vserver/context.h"
16161 +#include "vserver/debug.h"
16162 +#include "vserver/context.h"
16163 +#include "vserver/limit_int.h"
16164 +
16165 +
16166 +#define vx_acc_cres(v, d, p, r) \
16167 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
16168 +
16169 +#define vx_acc_cres_cond(x, d, p, r) \
16170 +       __vx_acc_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
16171 +       r, d, p, __FILE__, __LINE__)
16172 +
16173 +
16174 +#define vx_add_cres(v, a, p, r) \
16175 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
16176 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
16177 +
16178 +#define vx_add_cres_cond(x, a, p, r) \
16179 +       __vx_add_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
16180 +       r, a, p, __FILE__, __LINE__)
16181 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
16182 +
16183 +
16184 +/* process and file limits */
16185 +
16186 +#define vx_nproc_inc(p) \
16187 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
16188 +
16189 +#define vx_nproc_dec(p) \
16190 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
16191 +
16192 +#define vx_files_inc(f) \
16193 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
16194 +
16195 +#define vx_files_dec(f) \
16196 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
16197 +
16198 +#define vx_locks_inc(l) \
16199 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
16200 +
16201 +#define vx_locks_dec(l) \
16202 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
16203 +
16204 +#define vx_openfd_inc(f) \
16205 +       vx_acc_cres(current->vx_info, 1, (void *)(long)(f), VLIMIT_OPENFD)
16206 +
16207 +#define vx_openfd_dec(f) \
16208 +       vx_acc_cres(current->vx_info,-1, (void *)(long)(f), VLIMIT_OPENFD)
16209 +
16210 +
16211 +#define vx_cres_avail(v, n, r) \
16212 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
16213 +
16214 +
16215 +#define vx_nproc_avail(n) \
16216 +       vx_cres_avail(current->vx_info, n, RLIMIT_NPROC)
16217 +
16218 +#define vx_files_avail(n) \
16219 +       vx_cres_avail(current->vx_info, n, RLIMIT_NOFILE)
16220 +
16221 +#define vx_locks_avail(n) \
16222 +       vx_cres_avail(current->vx_info, n, RLIMIT_LOCKS)
16223 +
16224 +#define vx_openfd_avail(n) \
16225 +       vx_cres_avail(current->vx_info, n, VLIMIT_OPENFD)
16226 +
16227 +
16228 +/* dentry limits */
16229 +
16230 +#define vx_dentry_inc(d) do {                                          \
16231 +       if (atomic_read(&d->d_count) == 1)                              \
16232 +               vx_acc_cres(current->vx_info, 1, d, VLIMIT_DENTRY);     \
16233 +       } while (0)
16234 +
16235 +#define vx_dentry_dec(d) do {                                          \
16236 +       if (atomic_read(&d->d_count) == 0)                              \
16237 +               vx_acc_cres(current->vx_info,-1, d, VLIMIT_DENTRY);     \
16238 +       } while (0)
16239 +
16240 +#define vx_dentry_avail(n) \
16241 +       vx_cres_avail(current->vx_info, n, VLIMIT_DENTRY)
16242 +
16243 +
16244 +/* socket limits */
16245 +
16246 +#define vx_sock_inc(s) \
16247 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
16248 +
16249 +#define vx_sock_dec(s) \
16250 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
16251 +
16252 +#define vx_sock_avail(n) \
16253 +       vx_cres_avail(current->vx_info, n, VLIMIT_NSOCK)
16254 +
16255 +
16256 +/* ipc resource limits */
16257 +
16258 +#define vx_ipcmsg_add(v, u, a) \
16259 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
16260 +
16261 +#define vx_ipcmsg_sub(v, u, a) \
16262 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
16263 +
16264 +#define vx_ipcmsg_avail(v, a) \
16265 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
16266 +
16267 +
16268 +#define vx_ipcshm_add(v, k, a) \
16269 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
16270 +
16271 +#define vx_ipcshm_sub(v, k, a) \
16272 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
16273 +
16274 +#define vx_ipcshm_avail(v, a) \
16275 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
16276 +
16277 +
16278 +#define vx_semary_inc(a) \
16279 +       vx_acc_cres(current->vx_info, 1, a, VLIMIT_SEMARY)
16280 +
16281 +#define vx_semary_dec(a) \
16282 +       vx_acc_cres(current->vx_info, -1, a, VLIMIT_SEMARY)
16283 +
16284 +
16285 +#define vx_nsems_add(a,n) \
16286 +       vx_add_cres(current->vx_info, n, a, VLIMIT_NSEMS)
16287 +
16288 +#define vx_nsems_sub(a,n) \
16289 +       vx_sub_cres(current->vx_info, n, a, VLIMIT_NSEMS)
16290 +
16291 +
16292 +#else
16293 +#warning duplicate inclusion
16294 +#endif
16295 diff -Nurp linux-2.6.22.18/include/linux/vs_memory.h linux-2.6.22.18-vs2.3.0.32/include/linux/vs_memory.h
16296 --- linux-2.6.22.18/include/linux/vs_memory.h   1970-01-01 01:00:00.000000000 +0100
16297 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vs_memory.h        2008-02-11 12:35:36.000000000 +0100
16298 @@ -0,0 +1,159 @@
16299 +#ifndef _VS_MEMORY_H
16300 +#define _VS_MEMORY_H
16301 +
16302 +#include "vserver/limit.h"
16303 +#include "vserver/base.h"
16304 +#include "vserver/context.h"
16305 +#include "vserver/debug.h"
16306 +#include "vserver/context.h"
16307 +#include "vserver/limit_int.h"
16308 +
16309 +
16310 +#define __acc_add_long(a, v)   (*(v) += (a))
16311 +#define __acc_inc_long(v)      (++*(v))
16312 +#define __acc_dec_long(v)      (--*(v))
16313 +
16314 +#if    NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
16315 +#define __acc_add_atomic(a, v) atomic_long_add(a, v)
16316 +#define __acc_inc_atomic(v)    atomic_long_inc(v)
16317 +#define __acc_dec_atomic(v)    atomic_long_dec(v)
16318 +#else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
16319 +#define __acc_add_atomic(a, v) __acc_add_long(a, v)
16320 +#define __acc_inc_atomic(v)    __acc_inc_long(v)
16321 +#define __acc_dec_atomic(v)    __acc_dec_long(v)
16322 +#endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
16323 +
16324 +
16325 +#define vx_acc_page(m, d, v, r) do {                                   \
16326 +       if ((d) > 0)                                                    \
16327 +               __acc_inc_long(&(m)->v);                                \
16328 +       else                                                            \
16329 +               __acc_dec_long(&(m)->v);                                \
16330 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
16331 +} while (0)
16332 +
16333 +#define vx_acc_page_atomic(m, d, v, r) do {                            \
16334 +       if ((d) > 0)                                                    \
16335 +               __acc_inc_atomic(&(m)->v);                              \
16336 +       else                                                            \
16337 +               __acc_dec_atomic(&(m)->v);                              \
16338 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
16339 +} while (0)
16340 +
16341 +
16342 +#define vx_acc_pages(m, p, v, r) do {                                  \
16343 +       unsigned long __p = (p);                                        \
16344 +       __acc_add_long(__p, &(m)->v);                                   \
16345 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
16346 +} while (0)
16347 +
16348 +#define vx_acc_pages_atomic(m, p, v, r) do {                           \
16349 +       unsigned long __p = (p);                                        \
16350 +       __acc_add_atomic(__p, &(m)->v);                                 \
16351 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
16352 +} while (0)
16353 +
16354 +
16355 +
16356 +#define vx_acc_vmpage(m, d) \
16357 +       vx_acc_page(m, d, total_vm,  RLIMIT_AS)
16358 +#define vx_acc_vmlpage(m, d) \
16359 +       vx_acc_page(m, d, locked_vm, RLIMIT_MEMLOCK)
16360 +#define vx_acc_file_rsspage(m, d) \
16361 +       vx_acc_page_atomic(m, d, _file_rss, VLIMIT_MAPPED)
16362 +#define vx_acc_anon_rsspage(m, d) \
16363 +       vx_acc_page_atomic(m, d, _anon_rss, VLIMIT_ANON)
16364 +
16365 +#define vx_acc_vmpages(m, p) \
16366 +       vx_acc_pages(m, p, total_vm,  RLIMIT_AS)
16367 +#define vx_acc_vmlpages(m, p) \
16368 +       vx_acc_pages(m, p, locked_vm, RLIMIT_MEMLOCK)
16369 +#define vx_acc_file_rsspages(m, p) \
16370 +       vx_acc_pages_atomic(m, p, _file_rss, VLIMIT_MAPPED)
16371 +#define vx_acc_anon_rsspages(m, p) \
16372 +       vx_acc_pages_atomic(m, p, _anon_rss, VLIMIT_ANON)
16373 +
16374 +#define vx_pages_add(s, r, p)  __vx_add_cres(s, r, p, 0, __FILE__, __LINE__)
16375 +#define vx_pages_sub(s, r, p)  vx_pages_add(s, r, -(p))
16376 +
16377 +#define vx_vmpages_inc(m)              vx_acc_vmpage(m, 1)
16378 +#define vx_vmpages_dec(m)              vx_acc_vmpage(m, -1)
16379 +#define vx_vmpages_add(m, p)           vx_acc_vmpages(m, p)
16380 +#define vx_vmpages_sub(m, p)           vx_acc_vmpages(m, -(p))
16381 +
16382 +#define vx_vmlocked_inc(m)             vx_acc_vmlpage(m, 1)
16383 +#define vx_vmlocked_dec(m)             vx_acc_vmlpage(m, -1)
16384 +#define vx_vmlocked_add(m, p)          vx_acc_vmlpages(m, p)
16385 +#define vx_vmlocked_sub(m, p)          vx_acc_vmlpages(m, -(p))
16386 +
16387 +#define vx_file_rsspages_inc(m)                vx_acc_file_rsspage(m, 1)
16388 +#define vx_file_rsspages_dec(m)                vx_acc_file_rsspage(m, -1)
16389 +#define vx_file_rsspages_add(m, p)     vx_acc_file_rsspages(m, p)
16390 +#define vx_file_rsspages_sub(m, p)     vx_acc_file_rsspages(m, -(p))
16391 +
16392 +#define vx_anon_rsspages_inc(m)                vx_acc_anon_rsspage(m, 1)
16393 +#define vx_anon_rsspages_dec(m)                vx_acc_anon_rsspage(m, -1)
16394 +#define vx_anon_rsspages_add(m, p)     vx_acc_anon_rsspages(m, p)
16395 +#define vx_anon_rsspages_sub(m, p)     vx_acc_anon_rsspages(m, -(p))
16396 +
16397 +
16398 +#define vx_pages_avail(m, p, r) \
16399 +       __vx_cres_avail((m)->mm_vx_info, r, p, __FILE__, __LINE__)
16400 +
16401 +#define vx_vmpages_avail(m, p) vx_pages_avail(m, p, RLIMIT_AS)
16402 +#define vx_vmlocked_avail(m, p)        vx_pages_avail(m, p, RLIMIT_MEMLOCK)
16403 +#define vx_anon_avail(m, p)    vx_pages_avail(m, p, VLIMIT_ANON)
16404 +#define vx_mapped_avail(m, p)  vx_pages_avail(m, p, VLIMIT_MAPPED)
16405 +
16406 +#define vx_rss_avail(m, p) \
16407 +       __vx_cres_array_avail((m)->mm_vx_info, VLA_RSS, p, __FILE__, __LINE__)
16408 +
16409 +
16410 +enum {
16411 +       VXPT_UNKNOWN = 0,
16412 +       VXPT_ANON,
16413 +       VXPT_NONE,
16414 +       VXPT_FILE,
16415 +       VXPT_SWAP,
16416 +       VXPT_WRITE
16417 +};
16418 +
16419 +#if 0
16420 +#define        vx_page_fault(mm, vma, type, ret)
16421 +#else
16422 +
16423 +static inline
16424 +void __vx_page_fault(struct mm_struct *mm,
16425 +       struct vm_area_struct *vma, int type, int ret)
16426 +{
16427 +       struct vx_info *vxi = mm->mm_vx_info;
16428 +       int what;
16429 +/*
16430 +       static char *page_type[6] =
16431 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
16432 +       static char *page_what[4] =
16433 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
16434 +*/
16435 +
16436 +       if (!vxi)
16437 +               return;
16438 +
16439 +       what = (ret & 0x3);
16440 +
16441 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
16442 +               type, what, ret, page_type[type], page_what[what]);
16443 +*/
16444 +       if (ret & VM_FAULT_WRITE)
16445 +               what |= 0x4;
16446 +       atomic_inc(&vxi->cacct.page[type][what]);
16447 +}
16448 +
16449 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
16450 +#endif
16451 +
16452 +
16453 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
16454 +
16455 +#else
16456 +#warning duplicate inclusion
16457 +#endif
16458 diff -Nurp linux-2.6.22.18/include/linux/vs_network.h linux-2.6.22.18-vs2.3.0.32/include/linux/vs_network.h
16459 --- linux-2.6.22.18/include/linux/vs_network.h  1970-01-01 01:00:00.000000000 +0100
16460 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vs_network.h       2008-02-11 12:35:36.000000000 +0100
16461 @@ -0,0 +1,166 @@
16462 +#ifndef _NX_VS_NETWORK_H
16463 +#define _NX_VS_NETWORK_H
16464 +
16465 +#include "vserver/context.h"
16466 +#include "vserver/network.h"
16467 +#include "vserver/base.h"
16468 +#include "vserver/debug.h"
16469 +
16470 +
16471 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
16472 +
16473 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
16474 +       const char *_file, int _line)
16475 +{
16476 +       if (!nxi)
16477 +               return NULL;
16478 +
16479 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
16480 +               nxi, nxi ? nxi->nx_id : 0,
16481 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
16482 +               _file, _line);
16483 +
16484 +       atomic_inc(&nxi->nx_usecnt);
16485 +       return nxi;
16486 +}
16487 +
16488 +
16489 +extern void free_nx_info(struct nx_info *);
16490 +
16491 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
16492 +
16493 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
16494 +{
16495 +       if (!nxi)
16496 +               return;
16497 +
16498 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
16499 +               nxi, nxi ? nxi->nx_id : 0,
16500 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
16501 +               _file, _line);
16502 +
16503 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
16504 +               free_nx_info(nxi);
16505 +}
16506 +
16507 +
16508 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
16509 +
16510 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
16511 +               const char *_file, int _line)
16512 +{
16513 +       if (nxi) {
16514 +               vxlprintk(VXD_CBIT(nid, 3),
16515 +                       "init_nx_info(%p[#%d.%d])",
16516 +                       nxi, nxi ? nxi->nx_id : 0,
16517 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
16518 +                       _file, _line);
16519 +
16520 +               atomic_inc(&nxi->nx_usecnt);
16521 +       }
16522 +       *nxp = nxi;
16523 +}
16524 +
16525 +
16526 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
16527 +
16528 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
16529 +       const char *_file, int _line)
16530 +{
16531 +       struct nx_info *nxo;
16532 +
16533 +       if (!nxi)
16534 +               return;
16535 +
16536 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
16537 +               nxi, nxi ? nxi->nx_id : 0,
16538 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
16539 +               _file, _line);
16540 +
16541 +       atomic_inc(&nxi->nx_usecnt);
16542 +       nxo = xchg(nxp, nxi);
16543 +       BUG_ON(nxo);
16544 +}
16545 +
16546 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
16547 +
16548 +static inline void __clr_nx_info(struct nx_info **nxp,
16549 +       const char *_file, int _line)
16550 +{
16551 +       struct nx_info *nxo;
16552 +
16553 +       nxo = xchg(nxp, NULL);
16554 +       if (!nxo)
16555 +               return;
16556 +
16557 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
16558 +               nxo, nxo ? nxo->nx_id : 0,
16559 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
16560 +               _file, _line);
16561 +
16562 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
16563 +               free_nx_info(nxo);
16564 +}
16565 +
16566 +
16567 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
16568 +
16569 +static inline void __claim_nx_info(struct nx_info *nxi,
16570 +       struct task_struct *task, const char *_file, int _line)
16571 +{
16572 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
16573 +               nxi, nxi ? nxi->nx_id : 0,
16574 +               nxi?atomic_read(&nxi->nx_usecnt):0,
16575 +               nxi?atomic_read(&nxi->nx_tasks):0,
16576 +               task, _file, _line);
16577 +
16578 +       atomic_inc(&nxi->nx_tasks);
16579 +}
16580 +
16581 +
16582 +extern void unhash_nx_info(struct nx_info *);
16583 +
16584 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
16585 +
16586 +static inline void __release_nx_info(struct nx_info *nxi,
16587 +       struct task_struct *task, const char *_file, int _line)
16588 +{
16589 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
16590 +               nxi, nxi ? nxi->nx_id : 0,
16591 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
16592 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
16593 +               task, _file, _line);
16594 +
16595 +       might_sleep();
16596 +
16597 +       if (atomic_dec_and_test(&nxi->nx_tasks))
16598 +               unhash_nx_info(nxi);
16599 +}
16600 +
16601 +
16602 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
16603 +
16604 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
16605 +       const char *_file, int _line)
16606 +{
16607 +       struct nx_info *nxi;
16608 +
16609 +       task_lock(p);
16610 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
16611 +               p, _file, _line);
16612 +       nxi = __get_nx_info(p->nx_info, _file, _line);
16613 +       task_unlock(p);
16614 +       return nxi;
16615 +}
16616 +
16617 +
16618 +static inline void exit_nx_info(struct task_struct *p)
16619 +{
16620 +       if (p->nx_info)
16621 +               release_nx_info(p->nx_info, p);
16622 +}
16623 +
16624 +
16625 +#else
16626 +#warning duplicate inclusion
16627 +#endif
16628 diff -Nurp linux-2.6.22.18/include/linux/vs_pid.h linux-2.6.22.18-vs2.3.0.32/include/linux/vs_pid.h
16629 --- linux-2.6.22.18/include/linux/vs_pid.h      1970-01-01 01:00:00.000000000 +0100
16630 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vs_pid.h   2008-02-11 12:35:36.000000000 +0100
16631 @@ -0,0 +1,133 @@
16632 +#ifndef _VS_PID_H
16633 +#define _VS_PID_H
16634 +
16635 +#include "vserver/base.h"
16636 +#include "vserver/context.h"
16637 +#include "vserver/debug.h"
16638 +#include <linux/pid_namespace.h>
16639 +
16640 +
16641 +/* pid faking stuff */
16642 +
16643 +
16644 +#define vx_info_map_pid(v, p) \
16645 +       __vx_info_map_pid((v), (p), __FUNC__, __FILE__, __LINE__)
16646 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
16647 +#define vx_map_pid(p) vx_info_map_pid(current->vx_info, p)
16648 +#define vx_map_tgid(p) vx_map_pid(p)
16649 +
16650 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
16651 +       const char *func, const char *file, int line)
16652 +{
16653 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
16654 +               vxfprintk(VXD_CBIT(cvirt, 2),
16655 +                       "vx_map_tgid: %p/%llx: %d -> %d",
16656 +                       vxi, (long long)vxi->vx_flags, pid,
16657 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
16658 +                       func, file, line);
16659 +               if (pid == 0)
16660 +                       return 0;
16661 +               if (pid == vxi->vx_initpid)
16662 +                       return 1;
16663 +       }
16664 +       return pid;
16665 +}
16666 +
16667 +#define vx_info_rmap_pid(v, p) \
16668 +       __vx_info_rmap_pid((v), (p), __FUNC__, __FILE__, __LINE__)
16669 +#define vx_rmap_pid(p) vx_info_rmap_pid(current->vx_info, p)
16670 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
16671 +
16672 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
16673 +       const char *func, const char *file, int line)
16674 +{
16675 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
16676 +               vxfprintk(VXD_CBIT(cvirt, 2),
16677 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
16678 +                       vxi, (long long)vxi->vx_flags, pid,
16679 +                       (pid == 1) ? vxi->vx_initpid : pid,
16680 +                       func, file, line);
16681 +               if ((pid == 1) && vxi->vx_initpid)
16682 +                       return vxi->vx_initpid;
16683 +               if (pid == vxi->vx_initpid)
16684 +                       return ~0U;
16685 +       }
16686 +       return pid;
16687 +}
16688 +
16689 +
16690 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
16691 +
16692 +static inline
16693 +int vx_proc_task_visible(struct task_struct *task)
16694 +{
16695 +       if ((task->pid == 1) &&
16696 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
16697 +               /* show a blend through init */
16698 +               goto visible;
16699 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
16700 +               goto visible;
16701 +       return 0;
16702 +visible:
16703 +       return 1;
16704 +}
16705 +
16706 +static inline
16707 +struct task_struct *vx_find_proc_task_by_pid(int pid)
16708 +{
16709 +       struct task_struct *task = find_task_by_pid(pid);
16710 +
16711 +       if (task && !vx_proc_task_visible(task)) {
16712 +               vxdprintk(VXD_CBIT(misc, 6),
16713 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
16714 +                       task, task->xid, task->pid,
16715 +                       current, current->xid, current->pid);
16716 +               task = NULL;
16717 +       }
16718 +       return task;
16719 +}
16720 +
16721 +static inline
16722 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
16723 +{
16724 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
16725 +
16726 +       if (task && !vx_proc_task_visible(task)) {
16727 +               vxdprintk(VXD_CBIT(misc, 6),
16728 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
16729 +                       task, task->xid, task->pid,
16730 +                       current, current->xid, current->pid);
16731 +               put_task_struct(task);
16732 +               task = NULL;
16733 +       }
16734 +       return task;
16735 +}
16736 +
16737 +
16738 +static inline
16739 +struct task_struct *vx_child_reaper(struct task_struct *p)
16740 +{
16741 +       struct vx_info *vxi = p->vx_info;
16742 +       struct task_struct *reaper = child_reaper(p);
16743 +
16744 +       if (!vxi)
16745 +               goto out;
16746 +
16747 +       BUG_ON(!p->vx_info->vx_reaper);
16748 +
16749 +       /* child reaper for the guest reaper */
16750 +       if (vxi->vx_reaper == p)
16751 +               goto out;
16752 +
16753 +       reaper = vxi->vx_reaper;
16754 +out:
16755 +       vxdprintk(VXD_CBIT(xid, 7),
16756 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
16757 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
16758 +       return reaper;
16759 +}
16760 +
16761 +
16762 +#else
16763 +#warning duplicate inclusion
16764 +#endif
16765 diff -Nurp linux-2.6.22.18/include/linux/vs_sched.h linux-2.6.22.18-vs2.3.0.32/include/linux/vs_sched.h
16766 --- linux-2.6.22.18/include/linux/vs_sched.h    1970-01-01 01:00:00.000000000 +0100
16767 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vs_sched.h 2008-02-11 12:35:36.000000000 +0100
16768 @@ -0,0 +1,110 @@
16769 +#ifndef _VS_SCHED_H
16770 +#define _VS_SCHED_H
16771 +
16772 +#include "vserver/base.h"
16773 +#include "vserver/context.h"
16774 +#include "vserver/sched.h"
16775 +
16776 +
16777 +#define VAVAVOOM_RATIO          50
16778 +
16779 +#define MAX_PRIO_BIAS           20
16780 +#define MIN_PRIO_BIAS          -20
16781 +
16782 +
16783 +#ifdef CONFIG_VSERVER_HARDCPU
16784 +
16785 +/*
16786 + * effective_prio - return the priority that is based on the static
16787 + * priority but is modified by bonuses/penalties.
16788 + *
16789 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
16790 + * into a -4 ... 0 ... +4 bonus/penalty range.
16791 + *
16792 + * Additionally, we scale another amount based on the number of
16793 + * CPU tokens currently held by the context, if the process is
16794 + * part of a context (and the appropriate SCHED flag is set).
16795 + * This ranges from -5 ... 0 ... +15, quadratically.
16796 + *
16797 + * So, the total bonus is -9 .. 0 .. +19
16798 + * We use ~50% of the full 0...39 priority range so that:
16799 + *
16800 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
16801 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
16802 + *    unless that context is far exceeding its CPU allocation.
16803 + *
16804 + * Both properties are important to certain workloads.
16805 + */
16806 +static inline
16807 +int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
16808 +{
16809 +       int vavavoom, max;
16810 +
16811 +       /* lots of tokens = lots of vavavoom
16812 +        *      no tokens = no vavavoom      */
16813 +       if ((vavavoom = sched_pc->tokens) >= 0) {
16814 +               max = sched_pc->tokens_max;
16815 +               vavavoom = max - vavavoom;
16816 +               max = max * max;
16817 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
16818 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
16819 +               return vavavoom;
16820 +       }
16821 +       return 0;
16822 +}
16823 +
16824 +
16825 +static inline
16826 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
16827 +{
16828 +       struct vx_info *vxi = p->vx_info;
16829 +       struct _vx_sched_pc *sched_pc;
16830 +
16831 +       if (!vxi)
16832 +               return prio;
16833 +
16834 +       sched_pc = &vx_cpu(vxi, sched_pc);
16835 +       if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
16836 +               int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
16837 +
16838 +               sched_pc->vavavoom = vavavoom;
16839 +               prio += vavavoom;
16840 +       }
16841 +       prio += sched_pc->prio_bias;
16842 +       return prio;
16843 +}
16844 +
16845 +#else /* !CONFIG_VSERVER_HARDCPU */
16846 +
16847 +static inline
16848 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
16849 +{
16850 +       struct vx_info *vxi = p->vx_info;
16851 +
16852 +       if (vxi)
16853 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
16854 +       return prio;
16855 +}
16856 +
16857 +#endif /* CONFIG_VSERVER_HARDCPU */
16858 +
16859 +
16860 +static inline void vx_account_user(struct vx_info *vxi,
16861 +       cputime_t cputime, int nice)
16862 +{
16863 +       if (!vxi)
16864 +               return;
16865 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
16866 +}
16867 +
16868 +static inline void vx_account_system(struct vx_info *vxi,
16869 +       cputime_t cputime, int idle)
16870 +{
16871 +       if (!vxi)
16872 +               return;
16873 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
16874 +}
16875 +
16876 +#else
16877 +#warning duplicate inclusion
16878 +#endif
16879 diff -Nurp linux-2.6.22.18/include/linux/vs_socket.h linux-2.6.22.18-vs2.3.0.32/include/linux/vs_socket.h
16880 --- linux-2.6.22.18/include/linux/vs_socket.h   1970-01-01 01:00:00.000000000 +0100
16881 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vs_socket.h        2008-02-11 12:35:36.000000000 +0100
16882 @@ -0,0 +1,80 @@
16883 +#ifndef _VS_SOCKET_H
16884 +#define _VS_SOCKET_H
16885 +
16886 +#include "vserver/debug.h"
16887 +#include "vserver/base.h"
16888 +#include "vserver/cacct.h"
16889 +#include "vserver/context.h"
16890 +#include "vserver/tag.h"
16891 +
16892 +
16893 +/* socket accounting */
16894 +
16895 +#include <linux/socket.h>
16896 +
16897 +static inline int vx_sock_type(int family)
16898 +{
16899 +       switch (family) {
16900 +       case PF_UNSPEC:
16901 +               return VXA_SOCK_UNSPEC;
16902 +       case PF_UNIX:
16903 +               return VXA_SOCK_UNIX;
16904 +       case PF_INET:
16905 +               return VXA_SOCK_INET;
16906 +       case PF_INET6:
16907 +               return VXA_SOCK_INET6;
16908 +       case PF_PACKET:
16909 +               return VXA_SOCK_PACKET;
16910 +       default:
16911 +               return VXA_SOCK_OTHER;
16912 +       }
16913 +}
16914 +
16915 +#define vx_acc_sock(v, f, p, s) \
16916 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
16917 +
16918 +static inline void __vx_acc_sock(struct vx_info *vxi,
16919 +       int family, int pos, int size, char *file, int line)
16920 +{
16921 +       if (vxi) {
16922 +               int type = vx_sock_type(family);
16923 +
16924 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
16925 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
16926 +       }
16927 +}
16928 +
16929 +#define vx_sock_recv(sk, s) \
16930 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
16931 +#define vx_sock_send(sk, s) \
16932 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
16933 +#define vx_sock_fail(sk, s) \
16934 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
16935 +
16936 +
16937 +#define sock_vx_init(s) do {           \
16938 +       (s)->sk_xid = 0;                \
16939 +       (s)->sk_vx_info = NULL;         \
16940 +       } while (0)
16941 +
16942 +#define sock_nx_init(s) do {           \
16943 +       (s)->sk_nid = 0;                \
16944 +       (s)->sk_nx_info = NULL;         \
16945 +       } while (0)
16946 +
16947 +static inline
16948 +int vx_socket_peer_tag(struct socket *sock, int level,
16949 +       char __user *optval, int __user *optlen, int len)
16950 +{
16951 +       struct peer_tag tag;
16952 +
16953 +       tag.xid = sock->sk->sk_xid;
16954 +       tag.nid = sock->sk->sk_nid;
16955 +       if (copy_to_user(optval, &tag, sizeof(tag)))
16956 +               return -EFAULT;
16957 +       return 0;
16958 +}
16959 +
16960 +#else
16961 +#warning duplicate inclusion
16962 +#endif
16963 diff -Nurp linux-2.6.22.18/include/linux/vs_tag.h linux-2.6.22.18-vs2.3.0.32/include/linux/vs_tag.h
16964 --- linux-2.6.22.18/include/linux/vs_tag.h      1970-01-01 01:00:00.000000000 +0100
16965 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vs_tag.h   2008-02-11 12:35:36.000000000 +0100
16966 @@ -0,0 +1,43 @@
16967 +#ifndef _VS_TAG_H
16968 +#define _VS_TAG_H
16969 +
16970 +#include <linux/vserver/tag.h>
16971 +
16972 +/* check conditions */
16973 +
16974 +#define DX_ADMIN       0x0001
16975 +#define DX_WATCH       0x0002
16976 +#define DX_HOSTID      0x0008
16977 +
16978 +#define DX_IDENT       0x0010
16979 +
16980 +#define DX_ARG_MASK    0x0010
16981 +
16982 +
16983 +#define dx_task_tag(t) ((t)->tag)
16984 +
16985 +#define dx_current_tag() dx_task_tag(current)
16986 +
16987 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
16988 +
16989 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
16990 +
16991 +
16992 +/*
16993 + * check current context for ADMIN/WATCH and
16994 + * optionally against supplied argument
16995 + */
16996 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
16997 +{
16998 +       if (mode & DX_ARG_MASK) {
16999 +               if ((mode & DX_IDENT) && (id == cid))
17000 +                       return 1;
17001 +       }
17002 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
17003 +               ((mode & DX_WATCH) && (cid == 1)) ||
17004 +               ((mode & DX_HOSTID) && (id == 0)));
17005 +}
17006 +
17007 +#else
17008 +#warning duplicate inclusion
17009 +#endif
17010 diff -Nurp linux-2.6.22.18/include/linux/vs_time.h linux-2.6.22.18-vs2.3.0.32/include/linux/vs_time.h
17011 --- linux-2.6.22.18/include/linux/vs_time.h     1970-01-01 01:00:00.000000000 +0100
17012 +++ linux-2.6.22.18-vs2.3.0.32/include/linux/vs_time.h  2008-02-11 12:35:36.000000000 +0100
17013 @@ -0,0 +1,19 @@
17014 +#ifndef _VS_TIME_H
17015 +#define _VS_TIME_H
17016 +
17017 +
17018 +/* time faking stuff */
17019 +
17020 +#ifdef CONFIG_VSERVER_VTIME
17021 +
17022 +extern void vx_gettimeofday(struct timeval *tv);
17023 +extern int vx_settimeofday(struct timespec *ts);
17024 +
17025 +#else
17026 +#define        vx_gettimeofday(t)      do_gettimeofday(t)
17027 +#define        vx_settimeofday(t)      do_settimeofday(t)
17028 +#endif
17029 +
17030 +#else
17031 +#warning duplicate inclusion
17032 +#endif
17033 diff -Nurp linux-2.6.22.18/include/net/addrconf.h linux-2.6.22.18-vs2.3.0.32/include/net/addrconf.h
17034 --- linux-2.6.22.18/include/net/addrconf.h      2007-07-22 00:00:24.000000000 +0200
17035 +++ linux-2.6.22.18-vs2.3.0.32/include/net/addrconf.h   2008-02-11 12:35:36.000000000 +0100
17036 @@ -69,10 +69,12 @@ extern struct inet6_ifaddr *        ipv6_get_if
17037                                                 int strict);
17038  extern int                     ipv6_get_saddr(struct dst_entry *dst, 
17039                                                struct in6_addr *daddr,
17040 -                                              struct in6_addr *saddr);
17041 +                                              struct in6_addr *saddr,
17042 +                                              struct nx_info *nxi);
17043  extern int                     ipv6_dev_get_saddr(struct net_device *dev, 
17044                                                struct in6_addr *daddr,
17045 -                                              struct in6_addr *saddr);
17046 +                                              struct in6_addr *saddr,
17047 +                                              struct nx_info *nxi);
17048  extern int                     ipv6_get_lladdr(struct net_device *dev,
17049                                                 struct in6_addr *addr,
17050                                                 unsigned char banned_flags);
17051 diff -Nurp linux-2.6.22.18/include/net/af_unix.h linux-2.6.22.18-vs2.3.0.32/include/net/af_unix.h
17052 --- linux-2.6.22.18/include/net/af_unix.h       2007-07-22 00:00:24.000000000 +0200
17053 +++ linux-2.6.22.18-vs2.3.0.32/include/net/af_unix.h    2008-02-11 12:35:36.000000000 +0100
17054 @@ -4,6 +4,7 @@
17055  #include <linux/socket.h>
17056  #include <linux/un.h>
17057  #include <linux/mutex.h>
17058 +#include <linux/vs_base.h>
17059  #include <net/sock.h>
17060  
17061  extern void unix_inflight(struct file *fp);
17062 @@ -17,9 +18,9 @@ extern spinlock_t unix_table_lock;
17063  
17064  extern atomic_t unix_tot_inflight;
17065  
17066 -static inline struct sock *first_unix_socket(int *i)
17067 +static inline struct sock *next_unix_socket_table(int *i)
17068  {
17069 -       for (*i = 0; *i <= UNIX_HASH_SIZE; (*i)++) {
17070 +       for ((*i)++; *i <= UNIX_HASH_SIZE; (*i)++) {
17071                 if (!hlist_empty(&unix_socket_table[*i]))
17072                         return __sk_head(&unix_socket_table[*i]);
17073         }
17074 @@ -28,16 +29,19 @@ static inline struct sock *first_unix_so
17075  
17076  static inline struct sock *next_unix_socket(int *i, struct sock *s)
17077  {
17078 -       struct sock *next = sk_next(s);
17079 -       /* More in this chain? */
17080 -       if (next)
17081 -               return next;
17082 -       /* Look for next non-empty chain. */
17083 -       for ((*i)++; *i <= UNIX_HASH_SIZE; (*i)++) {
17084 -               if (!hlist_empty(&unix_socket_table[*i]))
17085 -                       return __sk_head(&unix_socket_table[*i]);
17086 -       }
17087 -       return NULL;
17088 +       do {
17089 +               if (s)
17090 +                       s = sk_next(s);
17091 +               if (!s)
17092 +                       s = next_unix_socket_table(i);
17093 +       } while (s && !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT));
17094 +       return s;
17095 +}
17096 +
17097 +static inline struct sock *first_unix_socket(int *i)
17098 +{
17099 +       *i = 0;
17100 +       return next_unix_socket(i, NULL);
17101  }
17102  
17103  #define forall_unix_sockets(i, s) \
17104 diff -Nurp linux-2.6.22.18/include/net/inet_timewait_sock.h linux-2.6.22.18-vs2.3.0.32/include/net/inet_timewait_sock.h
17105 --- linux-2.6.22.18/include/net/inet_timewait_sock.h    2007-07-21 23:58:53.000000000 +0200
17106 +++ linux-2.6.22.18-vs2.3.0.32/include/net/inet_timewait_sock.h 2008-02-11 12:35:36.000000000 +0100
17107 @@ -115,6 +115,10 @@ struct inet_timewait_sock {
17108  #define tw_refcnt              __tw_common.skc_refcnt
17109  #define tw_hash                        __tw_common.skc_hash
17110  #define tw_prot                        __tw_common.skc_prot
17111 +#define tw_xid         __tw_common.skc_xid
17112 +#define tw_vx_info             __tw_common.skc_vx_info
17113 +#define tw_nid         __tw_common.skc_nid
17114 +#define tw_nx_info             __tw_common.skc_nx_info
17115         volatile unsigned char  tw_substate;
17116         /* 3 bits hole, try to pack */
17117         unsigned char           tw_rcv_wscale;
17118 diff -Nurp linux-2.6.22.18/include/net/route.h linux-2.6.22.18-vs2.3.0.32/include/net/route.h
17119 --- linux-2.6.22.18/include/net/route.h 2007-07-21 23:58:53.000000000 +0200
17120 +++ linux-2.6.22.18-vs2.3.0.32/include/net/route.h      2008-02-11 12:35:36.000000000 +0100
17121 @@ -27,12 +27,16 @@
17122  #include <net/dst.h>
17123  #include <net/inetpeer.h>
17124  #include <net/flow.h>
17125 +#include <net/inet_sock.h>
17126  #include <linux/in_route.h>
17127  #include <linux/rtnetlink.h>
17128  #include <linux/route.h>
17129  #include <linux/ip.h>
17130  #include <linux/cache.h>
17131  #include <linux/security.h>
17132 +#include <linux/vs_base.h>
17133 +#include <linux/vs_inet.h>
17134 +#include <linux/in.h>
17135  
17136  #ifndef __KERNEL__
17137  #warning This file is not supposed to be used outside of kernel.
17138 @@ -143,6 +147,8 @@ static inline char rt_tos2priority(u8 to
17139         return ip_tos2prio[IPTOS_TOS(tos)>>1];
17140  }
17141  
17142 +extern int ip_v4_find_src(struct nx_info *, struct rtable **, struct flowi *);
17143 +
17144  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
17145                                    __be32 src, u32 tos, int oif, u8 protocol,
17146                                    __be16 sport, __be16 dport, struct sock *sk,
17147 @@ -158,7 +164,21 @@ static inline int ip_route_connect(struc
17148                                          .dport = dport } } };
17149  
17150         int err;
17151 -       if (!dst || !src) {
17152 +       struct nx_info *nx_info = current->nx_info;
17153 +
17154 +       if (sk)
17155 +               nx_info = sk->sk_nx_info;
17156 +
17157 +       vxdprintk(VXD_CBIT(net, 4),
17158 +               "ip_route_connect(%p) %p,%p;%lx",
17159 +               sk, nx_info, sk->sk_socket,
17160 +               (sk->sk_socket?sk->sk_socket->flags:0));
17161 +
17162 +       err = ip_v4_find_src(nx_info, rp, &fl);
17163 +       if (err)
17164 +               return err;
17165 +
17166 +       if (!fl.fl4_dst || !fl.fl4_src) {
17167                 err = __ip_route_output_key(rp, &fl);
17168                 if (err)
17169                         return err;
17170 diff -Nurp linux-2.6.22.18/include/net/sock.h linux-2.6.22.18-vs2.3.0.32/include/net/sock.h
17171 --- linux-2.6.22.18/include/net/sock.h  2007-07-22 00:00:24.000000000 +0200
17172 +++ linux-2.6.22.18-vs2.3.0.32/include/net/sock.h       2008-02-11 12:35:36.000000000 +0100
17173 @@ -119,6 +119,10 @@ struct sock_common {
17174         atomic_t                skc_refcnt;
17175         unsigned int            skc_hash;
17176         struct proto            *skc_prot;
17177 +       xid_t                   skc_xid;
17178 +       struct vx_info          *skc_vx_info;
17179 +       nid_t                   skc_nid;
17180 +       struct nx_info          *skc_nx_info;
17181  };
17182  
17183  /**
17184 @@ -195,6 +199,10 @@ struct sock {
17185  #define sk_refcnt              __sk_common.skc_refcnt
17186  #define sk_hash                        __sk_common.skc_hash
17187  #define sk_prot                        __sk_common.skc_prot
17188 +#define sk_xid                 __sk_common.skc_xid
17189 +#define sk_vx_info             __sk_common.skc_vx_info
17190 +#define sk_nid                 __sk_common.skc_nid
17191 +#define sk_nx_info             __sk_common.skc_nx_info
17192         unsigned char           sk_shutdown : 2,
17193                                 sk_no_check : 2,
17194                                 sk_userlocks : 4;
17195 diff -Nurp linux-2.6.22.18/init/main.c linux-2.6.22.18-vs2.3.0.32/init/main.c
17196 --- linux-2.6.22.18/init/main.c 2007-07-22 00:00:24.000000000 +0200
17197 +++ linux-2.6.22.18-vs2.3.0.32/init/main.c      2008-02-11 12:35:36.000000000 +0100
17198 @@ -55,6 +55,7 @@
17199  #include <linux/pid_namespace.h>
17200  #include <linux/device.h>
17201  #include <linux/kthread.h>
17202 +#include <linux/vserver/percpu.h>
17203  
17204  #include <asm/io.h>
17205  #include <asm/bugs.h>
17206 @@ -364,12 +365,14 @@ EXPORT_SYMBOL(__per_cpu_offset);
17207  
17208  static void __init setup_per_cpu_areas(void)
17209  {
17210 -       unsigned long size, i;
17211 +       unsigned long size, vspc, i;
17212         char *ptr;
17213         unsigned long nr_possible_cpus = num_possible_cpus();
17214  
17215 +       vspc = PERCPU_PERCTX * CONFIG_VSERVER_CONTEXTS;
17216 +
17217         /* Copy section for each CPU (we discard the original) */
17218 -       size = ALIGN(PERCPU_ENOUGH_ROOM, PAGE_SIZE);
17219 +       size = ALIGN(PERCPU_ENOUGH_ROOM + vspc, PAGE_SIZE);
17220         ptr = alloc_bootmem_pages(size * nr_possible_cpus);
17221  
17222         for_each_possible_cpu(i) {
17223 diff -Nurp linux-2.6.22.18/ipc/mqueue.c linux-2.6.22.18-vs2.3.0.32/ipc/mqueue.c
17224 --- linux-2.6.22.18/ipc/mqueue.c        2007-12-09 12:43:53.000000000 +0100
17225 +++ linux-2.6.22.18-vs2.3.0.32/ipc/mqueue.c     2008-02-11 12:35:36.000000000 +0100
17226 @@ -29,6 +29,8 @@
17227  #include <linux/audit.h>
17228  #include <linux/signal.h>
17229  #include <linux/mutex.h>
17230 +#include <linux/vs_context.h>
17231 +#include <linux/vs_limit.h>
17232  
17233  #include <net/sock.h>
17234  #include "util.h"
17235 @@ -151,17 +153,20 @@ static struct inode *mqueue_get_inode(st
17236                         spin_lock(&mq_lock);
17237                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
17238                             u->mq_bytes + mq_bytes >
17239 -                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur) {
17240 +                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur ||
17241 +                           !vx_ipcmsg_avail(p->vx_info, mq_bytes)) {
17242                                 spin_unlock(&mq_lock);
17243                                 goto out_inode;
17244                         }
17245                         u->mq_bytes += mq_bytes;
17246 +                       vx_ipcmsg_add(p->vx_info, u, mq_bytes);
17247                         spin_unlock(&mq_lock);
17248  
17249                         info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
17250                         if (!info->messages) {
17251                                 spin_lock(&mq_lock);
17252                                 u->mq_bytes -= mq_bytes;
17253 +                               vx_ipcmsg_sub(p->vx_info, u, mq_bytes);
17254                                 spin_unlock(&mq_lock);
17255                                 goto out_inode;
17256                         }
17257 @@ -257,10 +262,14 @@ static void mqueue_delete_inode(struct i
17258                    (info->attr.mq_maxmsg * info->attr.mq_msgsize));
17259         user = info->user;
17260         if (user) {
17261 +               struct vx_info *vxi = lookup_vx_info(user->xid);
17262 +
17263                 spin_lock(&mq_lock);
17264                 user->mq_bytes -= mq_bytes;
17265 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
17266                 queues_count--;
17267                 spin_unlock(&mq_lock);
17268 +               put_vx_info(vxi);
17269                 free_uid(user);
17270         }
17271  }
17272 @@ -748,7 +757,7 @@ asmlinkage long sys_mq_unlink(const char
17273         if (inode)
17274                 atomic_inc(&inode->i_count);
17275  
17276 -       err = vfs_unlink(dentry->d_parent->d_inode, dentry);
17277 +       err = vfs_unlink(dentry->d_parent->d_inode, dentry, NULL);
17278  out_err:
17279         dput(dentry);
17280  
17281 diff -Nurp linux-2.6.22.18/ipc/msg.c linux-2.6.22.18-vs2.3.0.32/ipc/msg.c
17282 --- linux-2.6.22.18/ipc/msg.c   2007-05-04 15:58:24.000000000 +0200
17283 +++ linux-2.6.22.18-vs2.3.0.32/ipc/msg.c        2008-02-11 12:35:36.000000000 +0100
17284 @@ -36,6 +36,7 @@
17285  #include <linux/seq_file.h>
17286  #include <linux/mutex.h>
17287  #include <linux/nsproxy.h>
17288 +#include <linux/vs_base.h>
17289  
17290  #include <asm/current.h>
17291  #include <asm/uaccess.h>
17292 @@ -149,6 +150,7 @@ static int newque (struct ipc_namespace 
17293  
17294         msq->q_perm.mode = msgflg & S_IRWXUGO;
17295         msq->q_perm.key = key;
17296 +       msq->q_perm.xid = vx_current_xid();
17297  
17298         msq->q_perm.security = NULL;
17299         retval = security_msg_queue_alloc(msq);
17300 diff -Nurp linux-2.6.22.18/ipc/sem.c linux-2.6.22.18-vs2.3.0.32/ipc/sem.c
17301 --- linux-2.6.22.18/ipc/sem.c   2007-07-22 00:00:24.000000000 +0200
17302 +++ linux-2.6.22.18-vs2.3.0.32/ipc/sem.c        2008-02-11 12:35:36.000000000 +0100
17303 @@ -82,6 +82,8 @@
17304  #include <linux/seq_file.h>
17305  #include <linux/mutex.h>
17306  #include <linux/nsproxy.h>
17307 +#include <linux/vs_base.h>
17308 +#include <linux/vs_limit.h>
17309  
17310  #include <asm/uaccess.h>
17311  #include "util.h"
17312 @@ -229,6 +231,7 @@ static int newary (struct ipc_namespace 
17313  
17314         sma->sem_perm.mode = (semflg & S_IRWXUGO);
17315         sma->sem_perm.key = key;
17316 +       sma->sem_perm.xid = vx_current_xid();
17317  
17318         sma->sem_perm.security = NULL;
17319         retval = security_sem_alloc(sma);
17320 @@ -244,6 +247,9 @@ static int newary (struct ipc_namespace 
17321                 return -ENOSPC;
17322         }
17323         ns->used_sems += nsems;
17324 +       /* FIXME: obsoleted? */
17325 +       vx_semary_inc(sma);
17326 +       vx_nsems_add(sma, nsems);
17327  
17328         sma->sem_id = sem_buildid(ns, id, sma->sem_perm.seq);
17329         sma->sem_base = (struct sem *) &sma[1];
17330 @@ -525,6 +531,9 @@ static void freeary (struct ipc_namespac
17331         sem_unlock(sma);
17332  
17333         ns->used_sems -= sma->sem_nsems;
17334 +       /* FIXME: obsoleted? */
17335 +       vx_nsems_sub(sma, sma->sem_nsems);
17336 +       vx_semary_dec(sma);
17337         size = sizeof (*sma) + sma->sem_nsems * sizeof (struct sem);
17338         security_sem_free(sma);
17339         ipc_rcu_putref(sma);
17340 diff -Nurp linux-2.6.22.18/ipc/shm.c linux-2.6.22.18-vs2.3.0.32/ipc/shm.c
17341 --- linux-2.6.22.18/ipc/shm.c   2007-08-12 03:54:37.000000000 +0200
17342 +++ linux-2.6.22.18-vs2.3.0.32/ipc/shm.c        2008-02-11 12:35:36.000000000 +0100
17343 @@ -38,6 +38,8 @@
17344  #include <linux/mutex.h>
17345  #include <linux/nsproxy.h>
17346  #include <linux/mount.h>
17347 +#include <linux/vs_context.h>
17348 +#include <linux/vs_limit.h>
17349  
17350  #include <asm/uaccess.h>
17351  
17352 @@ -185,7 +187,12 @@ static void shm_open(struct vm_area_stru
17353   */
17354  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
17355  {
17356 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
17357 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
17358 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
17359 +
17360 +       vx_ipcshm_sub(vxi, shp, numpages);
17361 +       ns->shm_tot -= numpages;
17362 +
17363         shm_rmid(ns, shp->id);
17364         shm_unlock(shp);
17365         if (!is_file_hugepages(shp->shm_file))
17366 @@ -195,6 +202,7 @@ static void shm_destroy(struct ipc_names
17367                                                 shp->mlock_user);
17368         fput (shp->shm_file);
17369         security_shm_free(shp);
17370 +       put_vx_info(vxi);
17371         ipc_rcu_putref(shp);
17372  }
17373  
17374 @@ -351,11 +359,15 @@ static int newseg (struct ipc_namespace 
17375         if (ns->shm_tot + numpages > ns->shm_ctlall)
17376                 return -ENOSPC;
17377  
17378 +       if (!vx_ipcshm_avail(current->vx_info, numpages))
17379 +               return -ENOSPC;
17380 +
17381         shp = ipc_rcu_alloc(sizeof(*shp));
17382         if (!shp)
17383                 return -ENOMEM;
17384  
17385         shp->shm_perm.key = key;
17386 +       shp->shm_perm.xid = vx_current_xid();
17387         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
17388         shp->mlock_user = NULL;
17389  
17390 @@ -406,6 +418,7 @@ static int newseg (struct ipc_namespace 
17391         file->f_dentry->d_inode->i_ino = shp->id;
17392  
17393         ns->shm_tot += numpages;
17394 +       vx_ipcshm_add(current->vx_info, key, numpages);
17395         shm_unlock(shp);
17396         return shp->id;
17397  
17398 diff -Nurp linux-2.6.22.18/ipc/util.c linux-2.6.22.18-vs2.3.0.32/ipc/util.c
17399 --- linux-2.6.22.18/ipc/util.c  2007-07-22 00:00:24.000000000 +0200
17400 +++ linux-2.6.22.18-vs2.3.0.32/ipc/util.c       2008-02-11 12:35:36.000000000 +0100
17401 @@ -32,6 +32,8 @@
17402  #include <linux/proc_fs.h>
17403  #include <linux/audit.h>
17404  #include <linux/nsproxy.h>
17405 +#include <linux/vs_base.h>
17406 +#include <linux/vserver/global.h>
17407  
17408  #include <asm/unistd.h>
17409  
17410 @@ -72,6 +74,7 @@ static struct ipc_namespace *clone_ipc_n
17411                 goto err_shm;
17412  
17413         kref_init(&ns->kref);
17414 +       atomic_inc(&vs_global_ipc_ns);
17415         return ns;
17416  
17417  err_shm:
17418 @@ -108,6 +111,7 @@ void free_ipc_ns(struct kref *kref)
17419         sem_exit_ns(ns);
17420         msg_exit_ns(ns);
17421         shm_exit_ns(ns);
17422 +       atomic_dec(&vs_global_ipc_ns);
17423         kfree(ns);
17424  }
17425  #else
17426 diff -Nurp linux-2.6.22.18/kernel/capability.c linux-2.6.22.18-vs2.3.0.32/kernel/capability.c
17427 --- linux-2.6.22.18/kernel/capability.c 2007-07-21 23:58:53.000000000 +0200
17428 +++ linux-2.6.22.18-vs2.3.0.32/kernel/capability.c      2008-02-11 12:35:36.000000000 +0100
17429 @@ -12,6 +12,7 @@
17430  #include <linux/module.h>
17431  #include <linux/security.h>
17432  #include <linux/syscalls.h>
17433 +#include <linux/vs_context.h>
17434  #include <asm/uaccess.h>
17435  
17436  unsigned securebits = SECUREBITS_DEFAULT; /* systemwide security settings */
17437 @@ -103,6 +104,8 @@ static inline int cap_set_pg(int pgrp_nr
17438  
17439         pgrp = find_pid(pgrp_nr);
17440         do_each_pid_task(pgrp, PIDTYPE_PGID, g) {
17441 +               if (!vx_check(g->xid, VS_ADMIN_P | VS_IDENT))
17442 +                       continue;
17443                 target = g;
17444                 while_each_thread(g, target) {
17445                         if (!security_capset_check(target, effective,
17446 @@ -246,8 +249,12 @@ int __capable(struct task_struct *t, int
17447  }
17448  EXPORT_SYMBOL(__capable);
17449  
17450 +#include <linux/vserver/base.h>
17451  int capable(int cap)
17452  {
17453 +       /* here for now so we don't require task locking */
17454 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
17455 +               return 0;
17456         return __capable(current, cap);
17457  }
17458  EXPORT_SYMBOL(capable);
17459 diff -Nurp linux-2.6.22.18/kernel/compat.c linux-2.6.22.18-vs2.3.0.32/kernel/compat.c
17460 --- linux-2.6.22.18/kernel/compat.c     2007-07-22 00:00:24.000000000 +0200
17461 +++ linux-2.6.22.18-vs2.3.0.32/kernel/compat.c  2008-02-11 12:35:36.000000000 +0100
17462 @@ -846,7 +846,7 @@ asmlinkage long compat_sys_time(compat_t
17463         compat_time_t i;
17464         struct timeval tv;
17465  
17466 -       do_gettimeofday(&tv);
17467 +       vx_gettimeofday(&tv);
17468         i = tv.tv_sec;
17469  
17470         if (tloc) {
17471 @@ -870,7 +870,7 @@ asmlinkage long compat_sys_stime(compat_
17472         if (err)
17473                 return err;
17474  
17475 -       do_settimeofday(&tv);
17476 +       vx_settimeofday(&tv);
17477         return 0;
17478  }
17479  
17480 diff -Nurp linux-2.6.22.18/kernel/exit.c linux-2.6.22.18-vs2.3.0.32/kernel/exit.c
17481 --- linux-2.6.22.18/kernel/exit.c       2008-01-15 16:00:35.000000000 +0100
17482 +++ linux-2.6.22.18-vs2.3.0.32/kernel/exit.c    2008-02-11 12:35:36.000000000 +0100
17483 @@ -44,6 +44,11 @@
17484  #include <linux/resource.h>
17485  #include <linux/blkdev.h>
17486  #include <linux/task_io_accounting_ops.h>
17487 +#include <linux/vs_limit.h>
17488 +#include <linux/vs_context.h>
17489 +#include <linux/vs_network.h>
17490 +#include <linux/vs_pid.h>
17491 +#include <linux/vserver/global.h>
17492  
17493  #include <asm/uaccess.h>
17494  #include <asm/unistd.h>
17495 @@ -443,9 +448,11 @@ static void close_files(struct files_str
17496                                         filp_close(file, files);
17497                                         cond_resched();
17498                                 }
17499 +                               vx_openfd_dec(i);
17500                         }
17501                         i++;
17502                         set >>= 1;
17503 +                       cond_resched();
17504                 }
17505         }
17506  }
17507 @@ -525,6 +532,7 @@ static inline void __put_fs_struct(struc
17508                         dput(fs->altroot);
17509                         mntput(fs->altrootmnt);
17510                 }
17511 +               atomic_dec(&vs_global_fs);
17512                 kmem_cache_free(fs_cachep, fs);
17513         }
17514  }
17515 @@ -596,6 +604,14 @@ static void exit_mm(struct task_struct *
17516  static inline void
17517  choose_new_parent(struct task_struct *p, struct task_struct *reaper)
17518  {
17519 +       /* check for reaper context */
17520 +       vxwprintk((p->xid != reaper->xid) && (reaper != child_reaper(p)),
17521 +               "rogue reaper: %p[%d,#%u] <> %p[%d,#%u]",
17522 +               p, p->pid, p->xid, reaper, reaper->pid, reaper->xid);
17523 +
17524 +       if (p == reaper)
17525 +               reaper = vx_child_reaper(p);
17526 +
17527         /*
17528          * Make sure we're not reparenting to ourselves and that
17529          * the parent is not a zombie.
17530 @@ -687,7 +703,7 @@ forget_original_parent(struct task_struc
17531         do {
17532                 reaper = next_thread(reaper);
17533                 if (reaper == father) {
17534 -                       reaper = child_reaper(father);
17535 +                       reaper = vx_child_reaper(father);
17536                         break;
17537                 }
17538         } while (reaper->exit_state);
17539 @@ -964,6 +980,8 @@ fastcall NORET_TYPE void do_exit(long co
17540         tsk->exit_code = code;
17541         proc_exit_connector(tsk);
17542         exit_task_namespaces(tsk);
17543 +       /* needs to stay before exit_notify() */
17544 +       exit_vx_info_early(tsk, code);
17545         exit_notify(tsk);
17546  #ifdef CONFIG_NUMA
17547         mpol_free(tsk->mempolicy);
17548 @@ -994,6 +1012,10 @@ fastcall NORET_TYPE void do_exit(long co
17549         if (tsk->splice_pipe)
17550                 __free_pipe_info(tsk->splice_pipe);
17551  
17552 +       /* needs to stay after exit_notify() */
17553 +       exit_vx_info(tsk, code);
17554 +       exit_nx_info(tsk);
17555 +
17556         preempt_disable();
17557         /* causes final put_task_struct in finish_task_switch(). */
17558         tsk->state = TASK_DEAD;
17559 diff -Nurp linux-2.6.22.18/kernel/fork.c linux-2.6.22.18-vs2.3.0.32/kernel/fork.c
17560 --- linux-2.6.22.18/kernel/fork.c       2007-07-22 00:00:24.000000000 +0200
17561 +++ linux-2.6.22.18-vs2.3.0.32/kernel/fork.c    2008-02-11 12:35:36.000000000 +0100
17562 @@ -49,6 +49,11 @@
17563  #include <linux/delayacct.h>
17564  #include <linux/taskstats_kern.h>
17565  #include <linux/random.h>
17566 +#include <linux/vs_context.h>
17567 +#include <linux/vs_network.h>
17568 +#include <linux/vs_limit.h>
17569 +#include <linux/vs_memory.h>
17570 +#include <linux/vserver/global.h>
17571  
17572  #include <asm/pgtable.h>
17573  #include <asm/pgalloc.h>
17574 @@ -108,6 +113,8 @@ void free_task(struct task_struct *tsk)
17575  {
17576         free_thread_info(tsk->stack);
17577         rt_mutex_debug_task_free(tsk);
17578 +       clr_vx_info(&tsk->vx_info);
17579 +       clr_nx_info(&tsk->nx_info);
17580         free_task_struct(tsk);
17581  }
17582  EXPORT_SYMBOL(free_task);
17583 @@ -215,6 +222,8 @@ static inline int dup_mmap(struct mm_str
17584         mm->free_area_cache = oldmm->mmap_base;
17585         mm->cached_hole_size = ~0UL;
17586         mm->map_count = 0;
17587 +       __set_mm_counter(mm, file_rss, 0);
17588 +       __set_mm_counter(mm, anon_rss, 0);
17589         cpus_clear(mm->cpu_vm_mask);
17590         mm->mm_rb = RB_ROOT;
17591         rb_link = &mm->mm_rb.rb_node;
17592 @@ -226,7 +235,7 @@ static inline int dup_mmap(struct mm_str
17593  
17594                 if (mpnt->vm_flags & VM_DONTCOPY) {
17595                         long pages = vma_pages(mpnt);
17596 -                       mm->total_vm -= pages;
17597 +                       vx_vmpages_sub(mm, pages);
17598                         vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
17599                                                                 -pages);
17600                         continue;
17601 @@ -327,7 +336,7 @@ static inline void mm_free_pgd(struct mm
17602  
17603  #include <linux/init_task.h>
17604  
17605 -static struct mm_struct * mm_init(struct mm_struct * mm)
17606 +static struct mm_struct * mm_init(struct mm_struct * mm, struct vx_info *vxi)
17607  {
17608         atomic_set(&mm->mm_users, 1);
17609         atomic_set(&mm->mm_count, 1);
17610 @@ -335,8 +344,8 @@ static struct mm_struct * mm_init(struct
17611         INIT_LIST_HEAD(&mm->mmlist);
17612         mm->core_waiters = 0;
17613         mm->nr_ptes = 0;
17614 -       set_mm_counter(mm, file_rss, 0);
17615 -       set_mm_counter(mm, anon_rss, 0);
17616 +       __set_mm_counter(mm, file_rss, 0);
17617 +       __set_mm_counter(mm, anon_rss, 0);
17618         spin_lock_init(&mm->page_table_lock);
17619         rwlock_init(&mm->ioctx_list_lock);
17620         mm->ioctx_list = NULL;
17621 @@ -345,6 +354,7 @@ static struct mm_struct * mm_init(struct
17622  
17623         if (likely(!mm_alloc_pgd(mm))) {
17624                 mm->def_flags = 0;
17625 +               set_vx_info(&mm->mm_vx_info, vxi);
17626                 return mm;
17627         }
17628         free_mm(mm);
17629 @@ -361,7 +371,7 @@ struct mm_struct * mm_alloc(void)
17630         mm = allocate_mm();
17631         if (mm) {
17632                 memset(mm, 0, sizeof(*mm));
17633 -               mm = mm_init(mm);
17634 +               mm = mm_init(mm, current->vx_info);
17635         }
17636         return mm;
17637  }
17638 @@ -376,6 +386,7 @@ void fastcall __mmdrop(struct mm_struct 
17639         BUG_ON(mm == &init_mm);
17640         mm_free_pgd(mm);
17641         destroy_context(mm);
17642 +       clr_vx_info(&mm->mm_vx_info);
17643         free_mm(mm);
17644  }
17645  
17646 @@ -490,12 +501,13 @@ static struct mm_struct *dup_mm(struct t
17647                 goto fail_nomem;
17648  
17649         memcpy(mm, oldmm, sizeof(*mm));
17650 +       mm->mm_vx_info = NULL;
17651  
17652         /* Initializing for Swap token stuff */
17653         mm->token_priority = 0;
17654         mm->last_interval = 0;
17655  
17656 -       if (!mm_init(mm))
17657 +       if (!mm_init(mm, oldmm->mm_vx_info))
17658                 goto fail_nomem;
17659  
17660         if (init_new_context(tsk, mm))
17661 @@ -521,6 +533,7 @@ fail_nocontext:
17662          * If init_new_context() failed, we cannot use mmput() to free the mm
17663          * because it calls destroy_context()
17664          */
17665 +       clr_vx_info(&mm->mm_vx_info);
17666         mm_free_pgd(mm);
17667         free_mm(mm);
17668         return NULL;
17669 @@ -591,6 +604,7 @@ static inline struct fs_struct *__copy_f
17670                         fs->altroot = NULL;
17671                 }
17672                 read_unlock(&old->lock);
17673 +               atomic_inc(&vs_global_fs);
17674         }
17675         return fs;
17676  }
17677 @@ -709,6 +723,8 @@ static struct files_struct *dup_fd(struc
17678                 struct file *f = *old_fds++;
17679                 if (f) {
17680                         get_file(f);
17681 +                       /* TODO: sum it first for check and performance */
17682 +                       vx_openfd_inc(open_files - i);
17683                 } else {
17684                         /*
17685                          * The fd may be claimed in the fd bitmap but not yet
17686 @@ -961,6 +977,8 @@ static struct task_struct *copy_process(
17687  {
17688         int retval;
17689         struct task_struct *p = NULL;
17690 +       struct vx_info *vxi;
17691 +       struct nx_info *nxi;
17692  
17693         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
17694                 return ERR_PTR(-EINVAL);
17695 @@ -995,12 +1013,30 @@ static struct task_struct *copy_process(
17696         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
17697         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
17698  #endif
17699 +       init_vx_info(&p->vx_info, current->vx_info);
17700 +       init_nx_info(&p->nx_info, current->nx_info);
17701 +
17702 +       /* check vserver memory */
17703 +       if (p->mm && !(clone_flags & CLONE_VM)) {
17704 +               if (vx_vmpages_avail(p->mm, p->mm->total_vm))
17705 +                       vx_pages_add(p->vx_info, RLIMIT_AS, p->mm->total_vm);
17706 +               else
17707 +                       goto bad_fork_free;
17708 +       }
17709 +       if (p->mm && vx_flags(VXF_FORK_RSS, 0)) {
17710 +               if (!vx_rss_avail(p->mm, get_mm_counter(p->mm, file_rss)))
17711 +                       goto bad_fork_cleanup_vm;
17712 +       }
17713 +
17714         retval = -EAGAIN;
17715 +       if (!vx_nproc_avail(1))
17716 +               goto bad_fork_cleanup_vm;
17717 +
17718         if (atomic_read(&p->user->processes) >=
17719                         p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
17720                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
17721                                 p->user != &root_user)
17722 -                       goto bad_fork_free;
17723 +                       goto bad_fork_cleanup_vm;
17724         }
17725  
17726         atomic_inc(&p->user->__count);
17727 @@ -1265,6 +1301,18 @@ static struct task_struct *copy_process(
17728  
17729         total_forks++;
17730         spin_unlock(&current->sighand->siglock);
17731 +
17732 +       /* p is copy of current */
17733 +       vxi = p->vx_info;
17734 +       if (vxi) {
17735 +               claim_vx_info(vxi, p);
17736 +               atomic_inc(&vxi->cvirt.nr_threads);
17737 +               atomic_inc(&vxi->cvirt.total_forks);
17738 +               vx_nproc_inc(p);
17739 +       }
17740 +       nxi = p->nx_info;
17741 +       if (nxi)
17742 +               claim_nx_info(nxi, p);
17743         write_unlock_irq(&tasklist_lock);
17744         proc_fork_connector(p);
17745         return p;
17746 @@ -1306,6 +1354,9 @@ bad_fork_cleanup_count:
17747         put_group_info(p->group_info);
17748         atomic_dec(&p->user->processes);
17749         free_uid(p->user);
17750 +bad_fork_cleanup_vm:
17751 +       if (p->mm && !(clone_flags & CLONE_VM))
17752 +               vx_pages_sub(p->vx_info, RLIMIT_AS, p->mm->total_vm);
17753  bad_fork_free:
17754         free_task(p);
17755  fork_out:
17756 @@ -1367,6 +1418,15 @@ long do_fork(unsigned long clone_flags,
17757  
17758         if (!pid)
17759                 return -EAGAIN;
17760 +
17761 +       /* kernel threads are host only */
17762 +       if ((clone_flags & CLONE_KTHREAD) &&
17763 +               !vx_capable(CAP_SYS_ADMIN, VXC_KTHREAD)) {
17764 +               vxwprintk_task(1, "tried to spawn a kernel thread.");
17765 +               free_pid(pid);
17766 +               return -EPERM;
17767 +       }
17768 +
17769         nr = pid->nr;
17770         if (unlikely(current->ptrace)) {
17771                 trace = fork_traceflag (clone_flags);
17772 diff -Nurp linux-2.6.22.18/kernel/kthread.c linux-2.6.22.18-vs2.3.0.32/kernel/kthread.c
17773 --- linux-2.6.22.18/kernel/kthread.c    2007-07-22 00:00:24.000000000 +0200
17774 +++ linux-2.6.22.18-vs2.3.0.32/kernel/kthread.c 2008-02-11 12:35:36.000000000 +0100
17775 @@ -96,7 +96,7 @@ static void create_kthread(struct kthrea
17776         } else {
17777                 wait_for_completion(&create->started);
17778                 read_lock(&tasklist_lock);
17779 -               create->result = find_task_by_pid(pid);
17780 +               create->result = find_task_by_real_pid(pid);
17781                 read_unlock(&tasklist_lock);
17782         }
17783         complete(&create->done);
17784 diff -Nurp linux-2.6.22.18/kernel/Makefile linux-2.6.22.18-vs2.3.0.32/kernel/Makefile
17785 --- linux-2.6.22.18/kernel/Makefile     2007-07-22 00:00:24.000000000 +0200
17786 +++ linux-2.6.22.18-vs2.3.0.32/kernel/Makefile  2008-02-11 12:35:36.000000000 +0100
17787 @@ -10,6 +10,8 @@ obj-y     = sched.o fork.o exec_domain.o
17788             kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \
17789             hrtimer.o rwsem.o latency.o nsproxy.o srcu.o die_notifier.o
17790  
17791 +obj-y    += vserver/
17792 +
17793  obj-$(CONFIG_STACKTRACE) += stacktrace.o
17794  obj-y += time/
17795  obj-$(CONFIG_DEBUG_MUTEXES) += mutex-debug.o
17796 diff -Nurp linux-2.6.22.18/kernel/nsproxy.c linux-2.6.22.18-vs2.3.0.32/kernel/nsproxy.c
17797 --- linux-2.6.22.18/kernel/nsproxy.c    2007-07-22 00:00:25.000000000 +0200
17798 +++ linux-2.6.22.18-vs2.3.0.32/kernel/nsproxy.c 2008-02-11 12:35:36.000000000 +0100
17799 @@ -20,14 +20,11 @@
17800  #include <linux/mnt_namespace.h>
17801  #include <linux/utsname.h>
17802  #include <linux/pid_namespace.h>
17803 +#include <linux/vserver/global.h>
17804 +#include <linux/vserver/debug.h>
17805  
17806  struct nsproxy init_nsproxy = INIT_NSPROXY(init_nsproxy);
17807  
17808 -static inline void get_nsproxy(struct nsproxy *ns)
17809 -{
17810 -       atomic_inc(&ns->count);
17811 -}
17812 -
17813  void get_task_namespaces(struct task_struct *tsk)
17814  {
17815         struct nsproxy *ns = tsk->nsproxy;
17816 @@ -46,6 +43,9 @@ static inline struct nsproxy *clone_nspr
17817         ns = kmemdup(orig, sizeof(struct nsproxy), GFP_KERNEL);
17818         if (ns)
17819                 atomic_set(&ns->count, 1);
17820 +       vxdprintk(VXD_CBIT(space, 2), "clone_nsproxy(%p[%u] = %p[1]",
17821 +               orig, atomic_read(&orig->count), ns);
17822 +       atomic_inc(&vs_global_nsproxy);
17823         return ns;
17824  }
17825  
17826 @@ -54,28 +54,32 @@ static inline struct nsproxy *clone_nspr
17827   * Return the newly created nsproxy.  Do not attach this to the task,
17828   * leave it to the caller to do proper locking and attach it to task.
17829   */
17830 -static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
17831 +static struct nsproxy *unshare_namespaces(int flags, struct nsproxy *orig,
17832                         struct fs_struct *new_fs)
17833  {
17834         struct nsproxy *new_nsp;
17835  
17836 -       new_nsp = clone_nsproxy(tsk->nsproxy);
17837 +       vxdprintk(VXD_CBIT(space, 4),
17838 +               "unshare_namespaces(0x%08x,%p,%p)",
17839 +               flags, orig, new_fs);
17840 +
17841 +       new_nsp = clone_nsproxy(orig);
17842         if (!new_nsp)
17843                 return ERR_PTR(-ENOMEM);
17844  
17845 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
17846 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
17847         if (IS_ERR(new_nsp->mnt_ns))
17848                 goto out_ns;
17849  
17850 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
17851 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
17852         if (IS_ERR(new_nsp->uts_ns))
17853                 goto out_uts;
17854  
17855 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
17856 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
17857         if (IS_ERR(new_nsp->ipc_ns))
17858                 goto out_ipc;
17859  
17860 -       new_nsp->pid_ns = copy_pid_ns(flags, tsk->nsproxy->pid_ns);
17861 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
17862         if (IS_ERR(new_nsp->pid_ns))
17863                 goto out_pid;
17864  
17865 @@ -95,6 +99,33 @@ out_ns:
17866         return ERR_PTR(-ENOMEM);
17867  }
17868  
17869 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
17870 +                       struct fs_struct *new_fs)
17871 +{
17872 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
17873 +}
17874 +
17875 +/*
17876 + * copies the nsproxy, setting refcount to 1, and grabbing a
17877 + * reference to all contained namespaces.
17878 + */
17879 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
17880 +{
17881 +       struct nsproxy *ns = clone_nsproxy(orig);
17882 +
17883 +       if (ns) {
17884 +               if (ns->mnt_ns)
17885 +                       get_mnt_ns(ns->mnt_ns);
17886 +               if (ns->uts_ns)
17887 +                       get_uts_ns(ns->uts_ns);
17888 +               if (ns->ipc_ns)
17889 +                       get_ipc_ns(ns->ipc_ns);
17890 +               if (ns->pid_ns)
17891 +                       get_pid_ns(ns->pid_ns);
17892 +       }
17893 +       return ns;
17894 +}
17895 +
17896  /*
17897   * called from clone.  This now handles copy for nsproxy and all
17898   * namespaces therein.
17899 @@ -102,9 +133,12 @@ out_ns:
17900  int copy_namespaces(int flags, struct task_struct *tsk)
17901  {
17902         struct nsproxy *old_ns = tsk->nsproxy;
17903 -       struct nsproxy *new_ns;
17904 +       struct nsproxy *new_ns = NULL;
17905         int err = 0;
17906  
17907 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08x,%p[%p])",
17908 +               flags, tsk, old_ns);
17909 +
17910         if (!old_ns)
17911                 return 0;
17912  
17913 @@ -127,6 +161,9 @@ int copy_namespaces(int flags, struct ta
17914         tsk->nsproxy = new_ns;
17915  out:
17916         put_nsproxy(old_ns);
17917 +       vxdprintk(VXD_CBIT(space, 3),
17918 +               "copy_namespaces(0x%08x,%p[%p]) = %d [%p]",
17919 +               flags, tsk, old_ns, err, new_ns);
17920         return err;
17921  }
17922  
17923 @@ -140,6 +177,7 @@ void free_nsproxy(struct nsproxy *ns)
17924                 put_ipc_ns(ns->ipc_ns);
17925         if (ns->pid_ns)
17926                 put_pid_ns(ns->pid_ns);
17927 +       atomic_dec(&vs_global_nsproxy);
17928         kfree(ns);
17929  }
17930  
17931 @@ -152,6 +190,10 @@ int unshare_nsproxy_namespaces(unsigned 
17932  {
17933         int err = 0;
17934  
17935 +       vxdprintk(VXD_CBIT(space, 4),
17936 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
17937 +               unshare_flags, current->nsproxy);
17938 +
17939         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC)))
17940                 return 0;
17941  
17942 diff -Nurp linux-2.6.22.18/kernel/pid.c linux-2.6.22.18-vs2.3.0.32/kernel/pid.c
17943 --- linux-2.6.22.18/kernel/pid.c        2007-07-22 00:00:25.000000000 +0200
17944 +++ linux-2.6.22.18-vs2.3.0.32/kernel/pid.c     2008-02-11 12:35:36.000000000 +0100
17945 @@ -28,6 +28,7 @@
17946  #include <linux/hash.h>
17947  #include <linux/pid_namespace.h>
17948  #include <linux/init_task.h>
17949 +#include <linux/vs_pid.h>
17950  
17951  #define pid_hashfn(nr) hash_long((unsigned long)nr, pidhash_shift)
17952  static struct hlist_head *pid_hash;
17953 @@ -295,6 +296,9 @@ void fastcall transfer_pid(struct task_s
17954  struct task_struct * fastcall pid_task(struct pid *pid, enum pid_type type)
17955  {
17956         struct task_struct *result = NULL;
17957 +
17958 +       if (type == PIDTYPE_REALPID)
17959 +               type = PIDTYPE_PID;
17960         if (pid) {
17961                 struct hlist_node *first;
17962                 first = rcu_dereference(pid->tasks[type].first);
17963 @@ -309,7 +313,17 @@ struct task_struct * fastcall pid_task(s
17964   */
17965  struct task_struct *find_task_by_pid_type(int type, int nr)
17966  {
17967 -       return pid_task(find_pid(nr), type);
17968 +       struct task_struct *task;
17969 +
17970 +       if (type == PIDTYPE_PID)
17971 +               nr = vx_rmap_pid(nr);
17972 +
17973 +       task = pid_task(find_pid(nr), type);
17974 +       if (task && (type != PIDTYPE_REALPID) &&
17975 +               /* maybe VS_WATCH_P in the future? */
17976 +               !vx_check(task->xid, VS_WATCH|VS_IDENT))
17977 +               return NULL;
17978 +       return task;
17979  }
17980  
17981  EXPORT_SYMBOL(find_task_by_pid_type);
17982 diff -Nurp linux-2.6.22.18/kernel/posix-timers.c linux-2.6.22.18-vs2.3.0.32/kernel/posix-timers.c
17983 --- linux-2.6.22.18/kernel/posix-timers.c       2007-07-22 00:00:25.000000000 +0200
17984 +++ linux-2.6.22.18-vs2.3.0.32/kernel/posix-timers.c    2008-02-11 12:35:36.000000000 +0100
17985 @@ -47,6 +47,7 @@
17986  #include <linux/wait.h>
17987  #include <linux/workqueue.h>
17988  #include <linux/module.h>
17989 +#include <linux/vs_context.h>
17990  
17991  /*
17992   * Management arrays for POSIX timers.  Timers are kept in slab memory
17993 @@ -297,6 +298,12 @@ void do_schedule_next_timer(struct sigin
17994  
17995  int posix_timer_event(struct k_itimer *timr,int si_private)
17996  {
17997 +       struct vx_info_save vxis;
17998 +       struct vx_info *vxi;
17999 +       int ret;
18000 +
18001 +       vxi = task_get_vx_info(timr->it_process);
18002 +       enter_vx_info(vxi, &vxis);
18003         memset(&timr->sigq->info, 0, sizeof(siginfo_t));
18004         timr->sigq->info.si_sys_private = si_private;
18005         /* Send signal to the process that owns this timer.*/
18006 @@ -309,11 +316,11 @@ int posix_timer_event(struct k_itimer *t
18007  
18008         if (timr->it_sigev_notify & SIGEV_THREAD_ID) {
18009                 struct task_struct *leader;
18010 -               int ret = send_sigqueue(timr->it_sigev_signo, timr->sigq,
18011 -                                       timr->it_process);
18012  
18013 +               ret = send_sigqueue(timr->it_sigev_signo, timr->sigq,
18014 +                                   timr->it_process);
18015                 if (likely(ret >= 0))
18016 -                       return ret;
18017 +                       goto out;
18018  
18019                 timr->it_sigev_notify = SIGEV_SIGNAL;
18020                 leader = timr->it_process->group_leader;
18021 @@ -321,8 +328,12 @@ int posix_timer_event(struct k_itimer *t
18022                 timr->it_process = leader;
18023         }
18024  
18025 -       return send_group_sigqueue(timr->it_sigev_signo, timr->sigq,
18026 +       ret = send_group_sigqueue(timr->it_sigev_signo, timr->sigq,
18027                                    timr->it_process);
18028 +out:
18029 +       leave_vx_info(&vxis);
18030 +       put_vx_info(vxi);
18031 +       return ret;
18032  }
18033  EXPORT_SYMBOL_GPL(posix_timer_event);
18034  
18035 @@ -402,7 +413,7 @@ static struct task_struct * good_sigeven
18036         struct task_struct *rtn = current->group_leader;
18037  
18038         if ((event->sigev_notify & SIGEV_THREAD_ID ) &&
18039 -               (!(rtn = find_task_by_pid(event->sigev_notify_thread_id)) ||
18040 +               (!(rtn = find_task_by_real_pid(event->sigev_notify_thread_id)) ||
18041                  rtn->tgid != current->tgid ||
18042                  (event->sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_SIGNAL))
18043                 return NULL;
18044 diff -Nurp linux-2.6.22.18/kernel/printk.c linux-2.6.22.18-vs2.3.0.32/kernel/printk.c
18045 --- linux-2.6.22.18/kernel/printk.c     2007-07-22 00:00:25.000000000 +0200
18046 +++ linux-2.6.22.18-vs2.3.0.32/kernel/printk.c  2008-02-11 12:35:36.000000000 +0100
18047 @@ -31,6 +31,7 @@
18048  #include <linux/bootmem.h>
18049  #include <linux/syscalls.h>
18050  #include <linux/jiffies.h>
18051 +#include <linux/vs_cvirt.h>
18052  
18053  #include <asm/uaccess.h>
18054  
18055 @@ -182,18 +183,13 @@ int do_syslog(int type, char __user *buf
18056         unsigned long i, j, limit, count;
18057         int do_clear = 0;
18058         char c;
18059 -       int error = 0;
18060 +       int error;
18061  
18062         error = security_syslog(type);
18063         if (error)
18064                 return error;
18065  
18066 -       switch (type) {
18067 -       case 0:         /* Close log */
18068 -               break;
18069 -       case 1:         /* Open log */
18070 -               break;
18071 -       case 2:         /* Read from log */
18072 +       if ((type >= 2) && (type <= 4)) {
18073                 error = -EINVAL;
18074                 if (!buf || len < 0)
18075                         goto out;
18076 @@ -204,6 +200,16 @@ int do_syslog(int type, char __user *buf
18077                         error = -EFAULT;
18078                         goto out;
18079                 }
18080 +       }
18081 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
18082 +               return vx_do_syslog(type, buf, len);
18083 +
18084 +       switch (type) {
18085 +       case 0:         /* Close log */
18086 +               break;
18087 +       case 1:         /* Open log */
18088 +               break;
18089 +       case 2:         /* Read from log */
18090                 error = wait_event_interruptible(log_wait,
18091                                                         (log_start - log_end));
18092                 if (error)
18093 @@ -228,16 +234,6 @@ int do_syslog(int type, char __user *buf
18094                 do_clear = 1;
18095                 /* FALL THRU */
18096         case 3:         /* Read last kernel messages */
18097 -               error = -EINVAL;
18098 -               if (!buf || len < 0)
18099 -                       goto out;
18100 -               error = 0;
18101 -               if (!len)
18102 -                       goto out;
18103 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
18104 -                       error = -EFAULT;
18105 -                       goto out;
18106 -               }
18107                 count = len;
18108                 if (count > log_buf_len)
18109                         count = log_buf_len;
18110 diff -Nurp linux-2.6.22.18/kernel/ptrace.c linux-2.6.22.18-vs2.3.0.32/kernel/ptrace.c
18111 --- linux-2.6.22.18/kernel/ptrace.c     2007-07-22 00:00:25.000000000 +0200
18112 +++ linux-2.6.22.18-vs2.3.0.32/kernel/ptrace.c  2008-02-11 12:35:36.000000000 +0100
18113 @@ -19,6 +19,7 @@
18114  #include <linux/security.h>
18115  #include <linux/signal.h>
18116  #include <linux/audit.h>
18117 +#include <linux/vs_context.h>
18118  
18119  #include <asm/pgtable.h>
18120  #include <asm/uaccess.h>
18121 @@ -145,6 +146,11 @@ static int may_attach(struct task_struct
18122                 dumpable = task->mm->dumpable;
18123         if (!dumpable && !capable(CAP_SYS_PTRACE))
18124                 return -EPERM;
18125 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
18126 +               return -EPERM;
18127 +       if (!vx_check(task->xid, VS_IDENT) &&
18128 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
18129 +               return -EACCES;
18130  
18131         return security_ptrace(current, task);
18132  }
18133 @@ -471,6 +477,10 @@ asmlinkage long sys_ptrace(long request,
18134                 goto out;
18135         }
18136  
18137 +       ret = -EPERM;
18138 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
18139 +               goto out_put_task_struct;
18140 +
18141         if (request == PTRACE_ATTACH) {
18142                 ret = ptrace_attach(child);
18143                 goto out_put_task_struct;
18144 diff -Nurp linux-2.6.22.18/kernel/sched.c linux-2.6.22.18-vs2.3.0.32/kernel/sched.c
18145 --- linux-2.6.22.18/kernel/sched.c      2007-07-22 00:00:25.000000000 +0200
18146 +++ linux-2.6.22.18-vs2.3.0.32/kernel/sched.c   2008-02-11 12:35:36.000000000 +0100
18147 @@ -56,6 +56,8 @@
18148  
18149  #include <asm/tlb.h>
18150  #include <asm/unistd.h>
18151 +#include <linux/vs_sched.h>
18152 +#include <linux/vs_cvirt.h>
18153  
18154  /*
18155   * Scheduler clock - returns current time in nanosec units.
18156 @@ -281,6 +283,16 @@ struct rq {
18157         struct task_struct *migration_thread;
18158         struct list_head migration_queue;
18159  #endif
18160 +       unsigned long norm_time;
18161 +       unsigned long idle_time;
18162 +#ifdef CONFIG_VSERVER_IDLETIME
18163 +       int idle_skip;
18164 +#endif
18165 +#ifdef CONFIG_VSERVER_HARDCPU
18166 +       struct list_head hold_queue;
18167 +       unsigned long nr_onhold;
18168 +       int idle_tokens;
18169 +#endif
18170  
18171  #ifdef CONFIG_SCHEDSTATS
18172         /* latency stats */
18173 @@ -714,6 +726,7 @@ sched_info_switch(struct task_struct *pr
18174   */
18175  static void dequeue_task(struct task_struct *p, struct prio_array *array)
18176  {
18177 +       BUG_ON(p->state & TASK_ONHOLD);
18178         array->nr_active--;
18179         list_del(&p->run_list);
18180         if (list_empty(array->queue + p->prio))
18181 @@ -722,6 +735,7 @@ static void dequeue_task(struct task_str
18182  
18183  static void enqueue_task(struct task_struct *p, struct prio_array *array)
18184  {
18185 +       BUG_ON(p->state & TASK_ONHOLD);
18186         sched_info_queued(p);
18187         list_add_tail(&p->run_list, array->queue + p->prio);
18188         __set_bit(p->prio, array->bitmap);
18189 @@ -735,12 +749,14 @@ static void enqueue_task(struct task_str
18190   */
18191  static void requeue_task(struct task_struct *p, struct prio_array *array)
18192  {
18193 +       BUG_ON(p->state & TASK_ONHOLD);
18194         list_move_tail(&p->run_list, array->queue + p->prio);
18195  }
18196  
18197  static inline void
18198  enqueue_task_head(struct task_struct *p, struct prio_array *array)
18199  {
18200 +       BUG_ON(p->state & TASK_ONHOLD);
18201         list_add(&p->run_list, array->queue + p->prio);
18202         __set_bit(p->prio, array->bitmap);
18203         array->nr_active++;
18204 @@ -769,6 +785,10 @@ static inline int __normal_prio(struct t
18205         bonus = CURRENT_BONUS(p) - MAX_BONUS / 2;
18206  
18207         prio = p->static_prio - bonus;
18208 +
18209 +       /* adjust effective priority */
18210 +       prio = vx_adjust_prio(p, prio, MAX_USER_PRIO);
18211 +
18212         if (prio < MAX_RT_PRIO)
18213                 prio = MAX_RT_PRIO;
18214         if (prio > MAX_PRIO-1)
18215 @@ -878,6 +898,9 @@ static int effective_prio(struct task_st
18216         return p->prio;
18217  }
18218  
18219 +#include "sched_mon.h"
18220 +
18221 +
18222  /*
18223   * __activate_task - move a task to the runqueue.
18224   */
18225 @@ -887,6 +910,7 @@ static void __activate_task(struct task_
18226  
18227         if (batch_task(p))
18228                 target = rq->expired;
18229 +       vxm_activate_task(p, rq);
18230         enqueue_task(p, target);
18231         inc_nr_running(p, rq);
18232  }
18233 @@ -896,6 +920,7 @@ static void __activate_task(struct task_
18234   */
18235  static inline void __activate_idle_task(struct task_struct *p, struct rq *rq)
18236  {
18237 +       vxm_activate_idle(p, rq);
18238         enqueue_task_head(p, rq->active);
18239         inc_nr_running(p, rq);
18240  }
18241 @@ -1030,19 +1055,30 @@ static void activate_task(struct task_st
18242         }
18243         p->timestamp = now;
18244  out:
18245 +       vx_activate_task(p);
18246         __activate_task(p, rq);
18247  }
18248  
18249  /*
18250 - * deactivate_task - remove a task from the runqueue.
18251 + * __deactivate_task - remove a task from the runqueue.
18252   */
18253 -static void deactivate_task(struct task_struct *p, struct rq *rq)
18254 +static void __deactivate_task(struct task_struct *p, struct rq *rq)
18255  {
18256         dec_nr_running(p, rq);
18257         dequeue_task(p, p->array);
18258 +       vxm_deactivate_task(p, rq);
18259         p->array = NULL;
18260  }
18261  
18262 +static inline
18263 +void deactivate_task(struct task_struct *p, struct rq *rq)
18264 +{
18265 +       vx_deactivate_task(p);
18266 +       __deactivate_task(p, rq);
18267 +}
18268 +
18269 +#include "sched_hard.h"
18270 +
18271  /*
18272   * resched_task - mark a task 'to be rescheduled now'.
18273   *
18274 @@ -1129,6 +1165,7 @@ migrate_task(struct task_struct *p, int 
18275  {
18276         struct rq *rq = task_rq(p);
18277  
18278 +       vxm_migrate_task(p, rq, dest_cpu);
18279         /*
18280          * If the task is not on a runqueue (and not running), then
18281          * it is sufficient to simply update the task's cpu field.
18282 @@ -1518,6 +1555,12 @@ static int try_to_wake_up(struct task_st
18283  
18284         rq = task_rq_lock(p, &flags);
18285         old_state = p->state;
18286 +
18287 +       /* we need to unhold suspended tasks */
18288 +       if (old_state & TASK_ONHOLD) {
18289 +               vx_unhold_task(p, rq);
18290 +               old_state = p->state;
18291 +       }
18292         if (!(old_state & state))
18293                 goto out;
18294  
18295 @@ -1625,6 +1668,7 @@ out_activate:
18296  #endif /* CONFIG_SMP */
18297         if (old_state == TASK_UNINTERRUPTIBLE) {
18298                 rq->nr_uninterruptible--;
18299 +               vx_uninterruptible_dec(p);
18300                 /*
18301                  * Tasks on involuntary sleep don't earn
18302                  * sleep_avg beyond just interactive state.
18303 @@ -1676,7 +1720,7 @@ int fastcall wake_up_state(struct task_s
18304         return try_to_wake_up(p, state, 0);
18305  }
18306  
18307 -static void task_running_tick(struct rq *rq, struct task_struct *p);
18308 +static void task_running_tick(struct rq *rq, struct task_struct *p, int cpu);
18309  /*
18310   * Perform scheduler related setup for a newly forked process p.
18311   * p is forked by current.
18312 @@ -1737,7 +1781,7 @@ void fastcall sched_fork(struct task_str
18313                  * runqueue lock is not a problem.
18314                  */
18315                 current->time_slice = 1;
18316 -               task_running_tick(cpu_rq(cpu), current);
18317 +               task_running_tick(cpu_rq(cpu), current, cpu);
18318         }
18319         local_irq_enable();
18320         put_cpu();
18321 @@ -1772,6 +1816,7 @@ void fastcall wake_up_new_task(struct ta
18322  
18323         p->prio = effective_prio(p);
18324  
18325 +       vx_activate_task(p);
18326         if (likely(cpu == this_cpu)) {
18327                 if (!(clone_flags & CLONE_VM)) {
18328                         /*
18329 @@ -1783,6 +1828,7 @@ void fastcall wake_up_new_task(struct ta
18330                                 __activate_task(p, rq);
18331                         else {
18332                                 p->prio = current->prio;
18333 +                               BUG_ON(p->state & TASK_ONHOLD);
18334                                 p->normal_prio = current->normal_prio;
18335                                 list_add_tail(&p->run_list, &current->run_list);
18336                                 p->array = current->array;
18337 @@ -3351,13 +3397,16 @@ static inline int expired_starving(struc
18338  void account_user_time(struct task_struct *p, cputime_t cputime)
18339  {
18340         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
18341 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
18342         cputime64_t tmp;
18343 +       int nice = (TASK_NICE(p) > 0);
18344  
18345         p->utime = cputime_add(p->utime, cputime);
18346 +       vx_account_user(vxi, cputime, nice);
18347  
18348         /* Add user time to cpustat. */
18349         tmp = cputime_to_cputime64(cputime);
18350 -       if (TASK_NICE(p) > 0)
18351 +       if (nice)
18352                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
18353         else
18354                 cpustat->user = cputime64_add(cpustat->user, tmp);
18355 @@ -3373,10 +3422,12 @@ void account_system_time(struct task_str
18356                          cputime_t cputime)
18357  {
18358         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
18359 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
18360         struct rq *rq = this_rq();
18361         cputime64_t tmp;
18362  
18363         p->stime = cputime_add(p->stime, cputime);
18364 +       vx_account_system(vxi, cputime, (p == rq->idle));
18365  
18366         /* Add system time to cpustat. */
18367         tmp = cputime_to_cputime64(cputime);
18368 @@ -3415,7 +3466,7 @@ void account_steal_time(struct task_stru
18369                 cpustat->steal = cputime64_add(cpustat->steal, tmp);
18370  }
18371  
18372 -static void task_running_tick(struct rq *rq, struct task_struct *p)
18373 +static void task_running_tick(struct rq *rq, struct task_struct *p, int cpu)
18374  {
18375         if (p->array != rq->active) {
18376                 /* Task has expired but was not scheduled yet */
18377 @@ -3445,7 +3496,7 @@ static void task_running_tick(struct rq 
18378                 }
18379                 goto out_unlock;
18380         }
18381 -       if (!--p->time_slice) {
18382 +       if (vx_need_resched(p, --p->time_slice, cpu)) {
18383                 dequeue_task(p, rq->active);
18384                 set_tsk_need_resched(p);
18385                 p->prio = effective_prio(p);
18386 @@ -3506,9 +3557,12 @@ void scheduler_tick(void)
18387         struct rq *rq = cpu_rq(cpu);
18388  
18389         update_cpu_clock(p, rq, now);
18390 +       vxm_sync(now, cpu);
18391  
18392 -       if (!idle_at_tick)
18393 -               task_running_tick(rq, p);
18394 +       if (idle_at_tick)
18395 +               vx_idle_resched(rq);
18396 +       else
18397 +               task_running_tick(rq, p, cpu);
18398  #ifdef CONFIG_SMP
18399         update_load(rq);
18400         rq->idle_at_tick = idle_at_tick;
18401 @@ -3630,14 +3684,25 @@ need_resched_nonpreemptible:
18402                                 unlikely(signal_pending(prev))))
18403                         prev->state = TASK_RUNNING;
18404                 else {
18405 -                       if (prev->state == TASK_UNINTERRUPTIBLE)
18406 +                       if (prev->state == TASK_UNINTERRUPTIBLE) {
18407                                 rq->nr_uninterruptible++;
18408 +                               vx_uninterruptible_inc(prev);
18409 +                       }
18410                         deactivate_task(prev, rq);
18411                 }
18412         }
18413  
18414         cpu = smp_processor_id();
18415 +       vx_set_rq_time(rq, jiffies);
18416 +try_unhold:
18417 +       vx_try_unhold(rq, cpu);
18418 +pick_next:
18419 +
18420         if (unlikely(!rq->nr_running)) {
18421 +               /* can we skip idle time? */
18422 +               if (vx_try_skip(rq, cpu))
18423 +                       goto try_unhold;
18424 +
18425                 idle_balance(cpu, rq);
18426                 if (!rq->nr_running) {
18427                         next = rq->idle;
18428 @@ -3663,6 +3728,10 @@ need_resched_nonpreemptible:
18429         queue = array->queue + idx;
18430         next = list_entry(queue->next, struct task_struct, run_list);
18431  
18432 +       /* check before we schedule this context */
18433 +       if (!vx_schedule(next, rq, cpu))
18434 +               goto pick_next;
18435 +
18436         if (!rt_task(next) && interactive_sleep(next->sleep_type)) {
18437                 unsigned long long delta = now - next->timestamp;
18438                 if (unlikely((long long)(now - next->timestamp) < 0))
18439 @@ -4263,7 +4332,7 @@ asmlinkage long sys_nice(int increment)
18440                 nice = 19;
18441  
18442         if (increment < 0 && !can_nice(current, nice))
18443 -               return -EPERM;
18444 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
18445  
18446         retval = security_task_setnice(current, nice);
18447         if (retval)
18448 @@ -4435,6 +4504,7 @@ recheck:
18449         oldprio = p->prio;
18450         __setscheduler(p, policy, param->sched_priority);
18451         if (array) {
18452 +               vx_activate_task(p);
18453                 __activate_task(p, rq);
18454                 /*
18455                  * Reschedule if we are currently running on this runqueue and
18456 @@ -5188,6 +5258,7 @@ static int __migrate_task(struct task_st
18457                 p->timestamp = p->timestamp - rq_src->most_recent_timestamp
18458                                 + rq_dest->most_recent_timestamp;
18459                 deactivate_task(p, rq_src);
18460 +               vx_activate_task(p);
18461                 __activate_task(p, rq_dest);
18462                 if (TASK_PREEMPTS_CURR(p, rq_dest))
18463                         resched_task(rq_dest->curr);
18464 @@ -7058,7 +7129,10 @@ void __init sched_init(void)
18465                 INIT_LIST_HEAD(&rq->migration_queue);
18466  #endif
18467                 atomic_set(&rq->nr_iowait, 0);
18468 -
18469 +#ifdef CONFIG_VSERVER_HARDCPU
18470 +               INIT_LIST_HEAD(&rq->hold_queue);
18471 +               rq->nr_onhold = 0;
18472 +#endif
18473                 for (j = 0; j < 2; j++) {
18474                         array = rq->arrays + j;
18475                         for (k = 0; k < MAX_PRIO; k++) {
18476 @@ -7144,6 +7218,7 @@ void normalize_rt_tasks(void)
18477                         deactivate_task(p, task_rq(p));
18478                 __setscheduler(p, SCHED_NORMAL, 0);
18479                 if (array) {
18480 +                       vx_activate_task(p);
18481                         __activate_task(p, task_rq(p));
18482                         resched_task(rq->curr);
18483                 }
18484 diff -Nurp linux-2.6.22.18/kernel/sched_hard.h linux-2.6.22.18-vs2.3.0.32/kernel/sched_hard.h
18485 --- linux-2.6.22.18/kernel/sched_hard.h 1970-01-01 01:00:00.000000000 +0100
18486 +++ linux-2.6.22.18-vs2.3.0.32/kernel/sched_hard.h      2008-02-11 12:35:36.000000000 +0100
18487 @@ -0,0 +1,324 @@
18488 +
18489 +#ifdef CONFIG_VSERVER_IDLELIMIT
18490 +
18491 +/*
18492 + * vx_idle_resched - reschedule after maxidle
18493 + */
18494 +static inline
18495 +void vx_idle_resched(struct rq *rq)
18496 +{
18497 +       /* maybe have a better criterion for paused */
18498 +       if (!--rq->idle_tokens && !list_empty(&rq->hold_queue))
18499 +               set_need_resched();
18500 +}
18501 +
18502 +#else /* !CONFIG_VSERVER_IDLELIMIT */
18503 +
18504 +#define vx_idle_resched(rq)
18505 +
18506 +#endif /* CONFIG_VSERVER_IDLELIMIT */
18507 +
18508 +
18509 +
18510 +#ifdef CONFIG_VSERVER_IDLETIME
18511 +
18512 +#define vx_set_rq_min_skip(rq, min)            \
18513 +       (rq)->idle_skip = (min)
18514 +
18515 +#define vx_save_min_skip(ret, min, val)                \
18516 +       __vx_save_min_skip(ret, min, val)
18517 +
18518 +static inline
18519 +void __vx_save_min_skip(int ret, int *min, int val)
18520 +{
18521 +       if (ret > -2)
18522 +               return;
18523 +       if ((*min > val) || !*min)
18524 +               *min = val;
18525 +}
18526 +
18527 +static inline
18528 +int vx_try_skip(struct rq *rq, int cpu)
18529 +{
18530 +       /* artificially advance time */
18531 +       if (rq->idle_skip > 0) {
18532 +               vxdprintk(list_empty(&rq->hold_queue),
18533 +                       "hold queue empty on cpu %d", cpu);
18534 +               rq->idle_time += rq->idle_skip;
18535 +               vxm_idle_skip(rq, cpu);
18536 +               return 1;
18537 +       }
18538 +       return 0;
18539 +}
18540 +
18541 +#else /* !CONFIG_VSERVER_IDLETIME */
18542 +
18543 +#define vx_set_rq_min_skip(rq, min)            \
18544 +       ({ int dummy = (min); dummy; })
18545 +
18546 +#define vx_save_min_skip(ret, min, val)
18547 +
18548 +static inline
18549 +int vx_try_skip(struct rq *rq, int cpu)
18550 +{
18551 +       return 0;
18552 +}
18553 +
18554 +#endif /* CONFIG_VSERVER_IDLETIME */
18555 +
18556 +
18557 +
18558 +#ifdef CONFIG_VSERVER_HARDCPU
18559 +
18560 +#define vx_set_rq_max_idle(rq, max)            \
18561 +       (rq)->idle_tokens = (max)
18562 +
18563 +#define vx_save_max_idle(ret, min, val)                \
18564 +       __vx_save_max_idle(ret, min, val)
18565 +
18566 +static inline
18567 +void __vx_save_max_idle(int ret, int *min, int val)
18568 +{
18569 +       if (*min > val)
18570 +               *min = val;
18571 +}
18572 +
18573 +
18574 +/*
18575 + * vx_hold_task - put a task on the hold queue
18576 + */
18577 +static inline
18578 +void vx_hold_task(struct task_struct *p, struct rq *rq)
18579 +{
18580 +       __deactivate_task(p, rq);
18581 +       p->state |= TASK_ONHOLD;
18582 +       /* a new one on hold */
18583 +       rq->nr_onhold++;
18584 +       vxm_hold_task(p, rq);
18585 +       list_add_tail(&p->run_list, &rq->hold_queue);
18586 +}
18587 +
18588 +/*
18589 + * vx_unhold_task - put a task back to the runqueue
18590 + */
18591 +static inline
18592 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
18593 +{
18594 +       list_del(&p->run_list);
18595 +       /* one less waiting */
18596 +       rq->nr_onhold--;
18597 +       p->state &= ~TASK_ONHOLD;
18598 +       enqueue_task(p, rq->expired);
18599 +       inc_nr_running(p, rq);
18600 +       vxm_unhold_task(p, rq);
18601 +
18602 +       if (p->static_prio < rq->best_expired_prio)
18603 +               rq->best_expired_prio = p->static_prio;
18604 +}
18605 +
18606 +unsigned long nr_onhold(void)
18607 +{
18608 +       unsigned long i, sum = 0;
18609 +
18610 +       for_each_online_cpu(i)
18611 +               sum += cpu_rq(i)->nr_onhold;
18612 +
18613 +       return sum;
18614 +}
18615 +
18616 +
18617 +
18618 +static inline
18619 +int __vx_tokens_avail(struct _vx_sched_pc *sched_pc)
18620 +{
18621 +       return sched_pc->tokens;
18622 +}
18623 +
18624 +static inline
18625 +void __vx_consume_token(struct _vx_sched_pc *sched_pc)
18626 +{
18627 +       sched_pc->tokens--;
18628 +}
18629 +
18630 +static inline
18631 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
18632 +{
18633 +       struct vx_info *vxi = p->vx_info;
18634 +
18635 +       if (vx_info_flags(vxi, VXF_SCHED_HARD|VXF_SCHED_PRIO, 0)) {
18636 +               struct _vx_sched_pc *sched_pc =
18637 +                       &vx_per_cpu(vxi, sched_pc, cpu);
18638 +               int tokens;
18639 +
18640 +               /* maybe we can simplify that to decrement
18641 +                  the token counter unconditional? */
18642 +
18643 +               if ((tokens = __vx_tokens_avail(sched_pc)) > 0)
18644 +                       __vx_consume_token(sched_pc);
18645 +
18646 +               /* for tokens > 0, one token was consumed */
18647 +               if (tokens < 2)
18648 +                       slice = 0;
18649 +       }
18650 +       vxm_need_resched(p, slice, cpu);
18651 +       return (slice == 0);
18652 +}
18653 +
18654 +
18655 +#define vx_set_rq_time(rq, time) do {  \
18656 +       rq->norm_time = time;           \
18657 +} while (0)
18658 +
18659 +
18660 +static inline
18661 +void vx_try_unhold(struct rq *rq, int cpu)
18662 +{
18663 +       struct vx_info *vxi = NULL;
18664 +       struct list_head *l, *n;
18665 +       int maxidle = HZ;
18666 +       int minskip = 0;
18667 +
18668 +       /* nothing to do? what about pause? */
18669 +       if (list_empty(&rq->hold_queue))
18670 +               return;
18671 +
18672 +       list_for_each_safe(l, n, &rq->hold_queue) {
18673 +               int ret, delta_min[2];
18674 +               struct _vx_sched_pc *sched_pc;
18675 +               struct task_struct *p;
18676 +
18677 +               p = list_entry(l, struct task_struct, run_list);
18678 +               /* don't bother with same context */
18679 +               if (vxi == p->vx_info)
18680 +                       continue;
18681 +
18682 +               vxi = p->vx_info;
18683 +               /* ignore paused contexts */
18684 +               if (vx_info_flags(vxi, VXF_SCHED_PAUSE, 0))
18685 +                       continue;
18686 +
18687 +               sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
18688 +
18689 +               /* recalc tokens */
18690 +               vxm_sched_info(sched_pc, vxi, cpu);
18691 +               ret = vx_tokens_recalc(sched_pc,
18692 +                       &rq->norm_time, &rq->idle_time, delta_min);
18693 +               vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
18694 +
18695 +               if (ret > 0) {
18696 +                       /* we found a runable context */
18697 +                       vx_unhold_task(p, rq);
18698 +                       break;
18699 +               }
18700 +               vx_save_max_idle(ret, &maxidle, delta_min[0]);
18701 +               vx_save_min_skip(ret, &minskip, delta_min[1]);
18702 +       }
18703 +       vx_set_rq_max_idle(rq, maxidle);
18704 +       vx_set_rq_min_skip(rq, minskip);
18705 +       vxm_rq_max_min(rq, cpu);
18706 +}
18707 +
18708 +
18709 +static inline
18710 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
18711 +{
18712 +       struct vx_info *vxi = next->vx_info;
18713 +       struct _vx_sched_pc *sched_pc;
18714 +       int delta_min[2];
18715 +       int flags, ret;
18716 +
18717 +       if (!vxi)
18718 +               return 1;
18719 +
18720 +       flags = vxi->vx_flags;
18721 +
18722 +       if (unlikely(vs_check_flags(flags, VXF_SCHED_PAUSE, 0)))
18723 +               goto put_on_hold;
18724 +       if (!vs_check_flags(flags, VXF_SCHED_HARD | VXF_SCHED_PRIO, 0))
18725 +               return 1;
18726 +
18727 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
18728 +#ifdef CONFIG_SMP
18729 +       /* update scheduler params */
18730 +       if (cpu_isset(cpu, vxi->sched.update)) {
18731 +               vx_update_sched_param(&vxi->sched, sched_pc);
18732 +               vxm_update_sched(sched_pc, vxi, cpu);
18733 +               cpu_clear(cpu, vxi->sched.update);
18734 +       }
18735 +#endif
18736 +       vxm_sched_info(sched_pc, vxi, cpu);
18737 +       ret  = vx_tokens_recalc(sched_pc,
18738 +               &rq->norm_time, &rq->idle_time, delta_min);
18739 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
18740 +
18741 +       if (!vs_check_flags(flags, VXF_SCHED_HARD, 0))
18742 +               return 1;
18743 +
18744 +       if (unlikely(ret < 0)) {
18745 +               vx_save_max_idle(ret, &rq->idle_tokens, delta_min[0]);
18746 +               vx_save_min_skip(ret, &rq->idle_skip, delta_min[1]);
18747 +               vxm_rq_max_min(rq, cpu);
18748 +       put_on_hold:
18749 +               vx_hold_task(next, rq);
18750 +               return 0;
18751 +       }
18752 +       return 1;
18753 +}
18754 +
18755 +
18756 +#else /* CONFIG_VSERVER_HARDCPU */
18757 +
18758 +static inline
18759 +void vx_hold_task(struct task_struct *p, struct rq *rq)
18760 +{
18761 +       return;
18762 +}
18763 +
18764 +static inline
18765 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
18766 +{
18767 +       return;
18768 +}
18769 +
18770 +unsigned long nr_onhold(void)
18771 +{
18772 +       return 0;
18773 +}
18774 +
18775 +
18776 +static inline
18777 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
18778 +{
18779 +       return (slice == 0);
18780 +}
18781 +
18782 +
18783 +#define vx_set_rq_time(rq, time)
18784 +
18785 +static inline
18786 +void vx_try_unhold(struct rq *rq, int cpu)
18787 +{
18788 +       return;
18789 +}
18790 +
18791 +static inline
18792 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
18793 +{
18794 +       struct vx_info *vxi = next->vx_info;
18795 +       struct _vx_sched_pc *sched_pc;
18796 +       int delta_min[2];
18797 +       int ret;
18798 +
18799 +       if (!vx_info_flags(vxi, VXF_SCHED_PRIO, 0))
18800 +               return 1;
18801 +
18802 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
18803 +       vxm_sched_info(sched_pc, vxi, cpu);
18804 +       ret  = vx_tokens_recalc(sched_pc,
18805 +               &rq->norm_time, &rq->idle_time, delta_min);
18806 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
18807 +       return 1;
18808 +}
18809 +
18810 +#endif /* CONFIG_VSERVER_HARDCPU */
18811 +
18812 diff -Nurp linux-2.6.22.18/kernel/sched_mon.h linux-2.6.22.18-vs2.3.0.32/kernel/sched_mon.h
18813 --- linux-2.6.22.18/kernel/sched_mon.h  1970-01-01 01:00:00.000000000 +0100
18814 +++ linux-2.6.22.18-vs2.3.0.32/kernel/sched_mon.h       2008-02-11 12:35:36.000000000 +0100
18815 @@ -0,0 +1,200 @@
18816 +
18817 +#include <linux/vserver/monitor.h>
18818 +
18819 +#ifdef  CONFIG_VSERVER_MONITOR
18820 +
18821 +#ifdef CONFIG_VSERVER_HARDCPU
18822 +#define HARDCPU(x) (x)
18823 +#else
18824 +#define HARDCPU(x) (0)
18825 +#endif
18826 +
18827 +#ifdef CONFIG_VSERVER_IDLETIME
18828 +#define IDLETIME(x) (x)
18829 +#else
18830 +#define IDLETIME(x) (0)
18831 +#endif
18832 +
18833 +struct _vx_mon_entry *vxm_advance(int cpu);
18834 +
18835 +
18836 +static inline
18837 +void   __vxm_basic(struct _vx_mon_entry *entry, xid_t xid, int type)
18838 +{
18839 +       entry->type = type;
18840 +       entry->xid = xid;
18841 +}
18842 +
18843 +static inline
18844 +void   __vxm_sync(int cpu)
18845 +{
18846 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18847 +
18848 +       __vxm_basic(entry, 0, VXM_SYNC);
18849 +       entry->ev.sec = xtime.tv_sec;
18850 +       entry->ev.nsec = xtime.tv_nsec;
18851 +}
18852 +
18853 +static inline
18854 +void   __vxm_task(struct task_struct *p, int type)
18855 +{
18856 +       struct _vx_mon_entry *entry = vxm_advance(task_cpu(p));
18857 +
18858 +       __vxm_basic(entry, p->xid, type);
18859 +       entry->ev.tsk.pid = p->pid;
18860 +       entry->ev.tsk.state = p->state;
18861 +}
18862 +
18863 +static inline
18864 +void   __vxm_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
18865 +{
18866 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18867 +
18868 +       __vxm_basic(entry, vxi->vx_id, (VXM_SCHED | s->flags));
18869 +       entry->sd.tokens = s->tokens;
18870 +       entry->sd.norm_time = s->norm_time;
18871 +       entry->sd.idle_time = s->idle_time;
18872 +}
18873 +
18874 +static inline
18875 +void   __vxm_rqinfo1(struct rq *q, int cpu)
18876 +{
18877 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18878 +
18879 +       entry->type = VXM_RQINFO_1;
18880 +       entry->xid = ((unsigned long)q >> 16) & 0xffff;
18881 +       entry->q1.running = q->nr_running;
18882 +       entry->q1.onhold = HARDCPU(q->nr_onhold);
18883 +       entry->q1.iowait = atomic_read(&q->nr_iowait);
18884 +       entry->q1.uintr = q->nr_uninterruptible;
18885 +       entry->q1.idle_tokens = IDLETIME(q->idle_tokens);
18886 +}
18887 +
18888 +static inline
18889 +void   __vxm_rqinfo2(struct rq *q, int cpu)
18890 +{
18891 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18892 +
18893 +       entry->type = VXM_RQINFO_2;
18894 +       entry->xid = (unsigned long)q & 0xffff;
18895 +       entry->q2.norm_time = q->norm_time;
18896 +       entry->q2.idle_time = q->idle_time;
18897 +       entry->q2.idle_skip = IDLETIME(q->idle_skip);
18898 +}
18899 +
18900 +static inline
18901 +void   __vxm_update(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
18902 +{
18903 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18904 +
18905 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE);
18906 +       entry->ev.tokens = s->tokens;
18907 +}
18908 +
18909 +static inline
18910 +void   __vxm_update1(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
18911 +{
18912 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18913 +
18914 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_1);
18915 +       entry->u1.tokens_max = s->tokens_max;
18916 +       entry->u1.fill_rate = s->fill_rate[0];
18917 +       entry->u1.interval = s->interval[0];
18918 +}
18919 +
18920 +static inline
18921 +void   __vxm_update2(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
18922 +{
18923 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18924 +
18925 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_2);
18926 +       entry->u2.tokens_min = s->tokens_min;
18927 +       entry->u2.fill_rate = s->fill_rate[1];
18928 +       entry->u2.interval = s->interval[1];
18929 +}
18930 +
18931 +
18932 +#define        vxm_activate_task(p,q)          __vxm_task(p, VXM_ACTIVATE)
18933 +#define        vxm_activate_idle(p,q)          __vxm_task(p, VXM_IDLE)
18934 +#define        vxm_deactivate_task(p,q)        __vxm_task(p, VXM_DEACTIVATE)
18935 +#define        vxm_hold_task(p,q)              __vxm_task(p, VXM_HOLD)
18936 +#define        vxm_unhold_task(p,q)            __vxm_task(p, VXM_UNHOLD)
18937 +
18938 +static inline
18939 +void   vxm_migrate_task(struct task_struct *p, struct rq *rq, int dest)
18940 +{
18941 +       __vxm_task(p, VXM_MIGRATE);
18942 +       __vxm_rqinfo1(rq, task_cpu(p));
18943 +       __vxm_rqinfo2(rq, task_cpu(p));
18944 +}
18945 +
18946 +static inline
18947 +void   vxm_idle_skip(struct rq *rq, int cpu)
18948 +{
18949 +       __vxm_rqinfo1(rq, cpu);
18950 +       __vxm_rqinfo2(rq, cpu);
18951 +}
18952 +
18953 +static inline
18954 +void   vxm_need_resched(struct task_struct *p, int slice, int cpu)
18955 +{
18956 +       if (slice)
18957 +               return;
18958 +
18959 +       __vxm_task(p, VXM_RESCHED);
18960 +}
18961 +
18962 +static inline
18963 +void   vxm_sync(unsigned long now, int cpu)
18964 +{
18965 +       if (!CONFIG_VSERVER_MONITOR_SYNC ||
18966 +               (now % CONFIG_VSERVER_MONITOR_SYNC))
18967 +               return;
18968 +
18969 +       __vxm_sync(cpu);
18970 +}
18971 +
18972 +#define        vxm_sched_info(s,v,c)           __vxm_sched(s,v,c)
18973 +
18974 +static inline
18975 +void   vxm_tokens_recalc(struct _vx_sched_pc *s, struct rq *rq,
18976 +       struct vx_info *vxi, int cpu)
18977 +{
18978 +       __vxm_sched(s, vxi, cpu);
18979 +       __vxm_rqinfo2(rq, cpu);
18980 +}
18981 +
18982 +static inline
18983 +void   vxm_update_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
18984 +{
18985 +       __vxm_sched(s, vxi, cpu);
18986 +       __vxm_update(s, vxi, cpu);
18987 +       __vxm_update1(s, vxi, cpu);
18988 +       __vxm_update2(s, vxi, cpu);
18989 +}
18990 +
18991 +static inline
18992 +void   vxm_rq_max_min(struct rq *rq, int cpu)
18993 +{
18994 +       __vxm_rqinfo1(rq, cpu);
18995 +       __vxm_rqinfo2(rq, cpu);
18996 +}
18997 +
18998 +#else  /* CONFIG_VSERVER_MONITOR */
18999 +
19000 +#define        vxm_activate_task(t,q)          do { } while (0)
19001 +#define        vxm_activate_idle(t,q)          do { } while (0)
19002 +#define        vxm_deactivate_task(t,q)        do { } while (0)
19003 +#define        vxm_hold_task(t,q)              do { } while (0)
19004 +#define        vxm_unhold_task(t,q)            do { } while (0)
19005 +#define        vxm_migrate_task(t,q,d)         do { } while (0)
19006 +#define        vxm_idle_skip(q,c)              do { } while (0)
19007 +#define        vxm_need_resched(t,s,c)         do { } while (0)
19008 +#define        vxm_sync(s,c)                   do { } while (0)
19009 +#define        vxm_sched_info(s,v,c)           do { } while (0)
19010 +#define        vxm_tokens_recalc(s,q,v,c)      do { } while (0)
19011 +#define        vxm_update_sched(s,v,c)         do { } while (0)
19012 +#define        vxm_rq_max_min(q,c)             do { } while (0)
19013 +
19014 +#endif /* CONFIG_VSERVER_MONITOR */
19015 +
19016 diff -Nurp linux-2.6.22.18/kernel/signal.c linux-2.6.22.18-vs2.3.0.32/kernel/signal.c
19017 --- linux-2.6.22.18/kernel/signal.c     2007-09-29 14:11:49.000000000 +0200
19018 +++ linux-2.6.22.18-vs2.3.0.32/kernel/signal.c  2008-02-11 12:35:36.000000000 +0100
19019 @@ -26,6 +26,8 @@
19020  #include <linux/freezer.h>
19021  #include <linux/pid_namespace.h>
19022  #include <linux/nsproxy.h>
19023 +#include <linux/vs_context.h>
19024 +#include <linux/vs_pid.h>
19025  
19026  #include <asm/param.h>
19027  #include <asm/uaccess.h>
19028 @@ -523,19 +525,34 @@ static int check_kill_permission(int sig
19029         if (!valid_signal(sig))
19030                 return error;
19031  
19032 +       if ((info != SEND_SIG_NOINFO) &&
19033 +               (is_si_special(info) || !SI_FROMUSER(info)))
19034 +               goto skip;
19035 +
19036 +       vxdprintk(VXD_CBIT(misc, 7),
19037 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
19038 +               sig, info, t, vx_task_xid(t), t->pid);
19039 +
19040         error = audit_signal_info(sig, t); /* Let audit system see the signal */
19041         if (error)
19042                 return error;
19043  
19044         error = -EPERM;
19045 -       if ((info == SEND_SIG_NOINFO || (!is_si_special(info) && SI_FROMUSER(info)))
19046 -           && ((sig != SIGCONT) ||
19047 +       if (((sig != SIGCONT) ||
19048                 (process_session(current) != process_session(t)))
19049             && (current->euid ^ t->suid) && (current->euid ^ t->uid)
19050             && (current->uid ^ t->suid) && (current->uid ^ t->uid)
19051             && !capable(CAP_KILL))
19052                 return error;
19053  
19054 +       error = -ESRCH;
19055 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
19056 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
19057 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
19058 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
19059 +               return error;
19060 +       }
19061 +skip:
19062         return security_task_kill(t, info, sig, 0);
19063  }
19064  
19065 @@ -1043,7 +1060,7 @@ int kill_pid_info(int sig, struct siginf
19066  
19067         p = pid_task(pid, PIDTYPE_PID);
19068         error = -ESRCH;
19069 -       if (p)
19070 +       if (p && vx_check(vx_task_xid(p), VS_IDENT))
19071                 error = group_send_sig_info(sig, info, p);
19072  
19073         if (unlikely(sig_needs_tasklist(sig)))
19074 @@ -1057,7 +1074,7 @@ kill_proc_info(int sig, struct siginfo *
19075  {
19076         int error;
19077         rcu_read_lock();
19078 -       error = kill_pid_info(sig, info, find_pid(pid));
19079 +       error = kill_pid_info(sig, info, find_pid(vx_rmap_pid(pid)));
19080         rcu_read_unlock();
19081         return error;
19082  }
19083 @@ -1118,7 +1135,9 @@ static int kill_something_info(int sig, 
19084  
19085                 read_lock(&tasklist_lock);
19086                 for_each_process(p) {
19087 -                       if (p->pid > 1 && p->tgid != current->tgid) {
19088 +                       if (vx_check(vx_task_xid(p), VS_ADMIN_P|VS_IDENT) &&
19089 +                               p->pid > 1 && p->tgid != current->tgid &&
19090 +                               !vx_current_initpid(p->pid)) {
19091                                 int err = group_send_sig_info(sig, info, p);
19092                                 ++count;
19093                                 if (err != -EPERM)
19094 @@ -1128,9 +1147,9 @@ static int kill_something_info(int sig, 
19095                 read_unlock(&tasklist_lock);
19096                 ret = count ? retval : -ESRCH;
19097         } else if (pid < 0) {
19098 -               ret = kill_pgrp_info(sig, info, find_pid(-pid));
19099 +               ret = kill_pgrp_info(sig, info, find_pid(vx_rmap_pid(-pid)));
19100         } else {
19101 -               ret = kill_pid_info(sig, info, find_pid(pid));
19102 +               ret = kill_pid_info(sig, info, find_pid(vx_rmap_pid(pid)));
19103         }
19104         rcu_read_unlock();
19105         return ret;
19106 @@ -1814,6 +1833,11 @@ relock:
19107                 if (current == child_reaper(current))
19108                         continue;
19109  
19110 +               /* virtual init is protected against user signals */
19111 +               if ((info->si_code == SI_USER) &&
19112 +                       vx_current_initpid(current->pid))
19113 +                       continue;
19114 +
19115                 if (sig_kernel_stop(signr)) {
19116                         /*
19117                          * The default action is to stop all threads in
19118 diff -Nurp linux-2.6.22.18/kernel/softirq.c linux-2.6.22.18-vs2.3.0.32/kernel/softirq.c
19119 --- linux-2.6.22.18/kernel/softirq.c    2007-07-22 00:00:25.000000000 +0200
19120 +++ linux-2.6.22.18-vs2.3.0.32/kernel/softirq.c 2008-02-11 12:35:36.000000000 +0100
19121 @@ -18,6 +18,7 @@
19122  #include <linux/rcupdate.h>
19123  #include <linux/smp.h>
19124  #include <linux/tick.h>
19125 +#include <linux/vs_context.h>
19126  
19127  #include <asm/irq.h>
19128  /*
19129 diff -Nurp linux-2.6.22.18/kernel/sys.c linux-2.6.22.18-vs2.3.0.32/kernel/sys.c
19130 --- linux-2.6.22.18/kernel/sys.c        2008-01-15 16:00:35.000000000 +0100
19131 +++ linux-2.6.22.18-vs2.3.0.32/kernel/sys.c     2008-02-11 12:35:37.000000000 +0100
19132 @@ -35,6 +35,7 @@
19133  #include <linux/compat.h>
19134  #include <linux/syscalls.h>
19135  #include <linux/kprobes.h>
19136 +#include <linux/vs_pid.h>
19137  
19138  #include <asm/uaccess.h>
19139  #include <asm/io.h>
19140 @@ -638,7 +639,10 @@ static int set_one_prio(struct task_stru
19141                 goto out;
19142         }
19143         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
19144 -               error = -EACCES;
19145 +               if (vx_flags(VXF_IGNEG_NICE, 0))
19146 +                       error = 0;
19147 +               else
19148 +                       error = -EACCES;
19149                 goto out;
19150         }
19151         no_nice = security_task_setnice(p, niceval);
19152 @@ -686,6 +690,8 @@ asmlinkage long sys_setpriority(int whic
19153                         else
19154                                 pgrp = task_pgrp(current);
19155                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
19156 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
19157 +                                       continue;
19158                                 error = set_one_prio(p, niceval, error);
19159                         } while_each_pid_task(pgrp, PIDTYPE_PGID, p);
19160                         break;
19161 @@ -694,7 +700,8 @@ asmlinkage long sys_setpriority(int whic
19162                         if (!who)
19163                                 who = current->uid;
19164                         else
19165 -                               if ((who != current->uid) && !(user = find_user(who)))
19166 +                               if ((who != current->uid) &&
19167 +                                       !(user = find_user(vx_current_xid(), who)))
19168                                         goto out_unlock;        /* No processes for this user */
19169  
19170                         do_each_thread(g, p)
19171 @@ -746,6 +753,8 @@ asmlinkage long sys_getpriority(int whic
19172                         else
19173                                 pgrp = task_pgrp(current);
19174                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
19175 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
19176 +                                       continue;
19177                                 niceval = 20 - task_nice(p);
19178                                 if (niceval > retval)
19179                                         retval = niceval;
19180 @@ -756,7 +765,8 @@ asmlinkage long sys_getpriority(int whic
19181                         if (!who)
19182                                 who = current->uid;
19183                         else
19184 -                               if ((who != current->uid) && !(user = find_user(who)))
19185 +                               if ((who != current->uid) &&
19186 +                                       !(user = find_user(vx_current_xid(), who)))
19187                                         goto out_unlock;        /* No processes for this user */
19188  
19189                         do_each_thread(g, p)
19190 @@ -869,6 +879,9 @@ void kernel_power_off(void)
19191         machine_power_off();
19192  }
19193  EXPORT_SYMBOL_GPL(kernel_power_off);
19194 +
19195 +long vs_reboot(unsigned int, void __user *);
19196 +
19197  /*
19198   * Reboot system call: for obvious reasons only root may call it,
19199   * and even root needs to set up some magic numbers in the registers
19200 @@ -899,6 +912,9 @@ asmlinkage long sys_reboot(int magic1, i
19201         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
19202                 cmd = LINUX_REBOOT_CMD_HALT;
19203  
19204 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
19205 +               return vs_reboot(cmd, arg);
19206 +
19207         lock_kernel();
19208         switch (cmd) {
19209         case LINUX_REBOOT_CMD_RESTART:
19210 @@ -1078,7 +1094,7 @@ static int set_user(uid_t new_ruid, int 
19211  {
19212         struct user_struct *new_user;
19213  
19214 -       new_user = alloc_uid(new_ruid);
19215 +       new_user = alloc_uid(vx_current_xid(), new_ruid);
19216         if (!new_user)
19217                 return -EAGAIN;
19218  
19219 @@ -1432,15 +1448,18 @@ asmlinkage long sys_setpgid(pid_t pid, p
19220  {
19221         struct task_struct *p;
19222         struct task_struct *group_leader = current->group_leader;
19223 +       pid_t rpgid;
19224         int err = -EINVAL;
19225  
19226         if (!pid)
19227 -               pid = group_leader->pid;
19228 +               pid = vx_map_pid(group_leader->pid);
19229         if (!pgid)
19230                 pgid = pid;
19231         if (pgid < 0)
19232                 return -EINVAL;
19233  
19234 +       rpgid = vx_rmap_pid(pgid);
19235 +
19236         /* From this point forward we keep holding onto the tasklist lock
19237          * so that our parent does not change from under us. -DaveM
19238          */
19239 @@ -1474,20 +1493,20 @@ asmlinkage long sys_setpgid(pid_t pid, p
19240  
19241         if (pgid != pid) {
19242                 struct task_struct *g =
19243 -                       find_task_by_pid_type(PIDTYPE_PGID, pgid);
19244 +                       find_task_by_pid_type(PIDTYPE_PGID, rpgid);
19245  
19246                 if (!g || task_session(g) != task_session(group_leader))
19247                         goto out;
19248         }
19249  
19250 -       err = security_task_setpgid(p, pgid);
19251 +       err = security_task_setpgid(p, rpgid);
19252         if (err)
19253                 goto out;
19254  
19255 -       if (process_group(p) != pgid) {
19256 +       if (process_group(p) != rpgid) {
19257                 detach_pid(p, PIDTYPE_PGID);
19258 -               p->signal->pgrp = pgid;
19259 -               attach_pid(p, PIDTYPE_PGID, find_pid(pgid));
19260 +               p->signal->pgrp = rpgid;
19261 +               attach_pid(p, PIDTYPE_PGID, find_pid(rpgid));
19262         }
19263  
19264         err = 0;
19265 @@ -1500,7 +1519,7 @@ out:
19266  asmlinkage long sys_getpgid(pid_t pid)
19267  {
19268         if (!pid)
19269 -               return process_group(current);
19270 +               return vx_rmap_pid(process_group(current));
19271         else {
19272                 int retval;
19273                 struct task_struct *p;
19274 @@ -1512,7 +1531,7 @@ asmlinkage long sys_getpgid(pid_t pid)
19275                 if (p) {
19276                         retval = security_task_getpgid(p);
19277                         if (!retval)
19278 -                               retval = process_group(p);
19279 +                               retval = vx_rmap_pid(process_group(p));
19280                 }
19281                 read_unlock(&tasklist_lock);
19282                 return retval;
19283 @@ -1863,7 +1882,7 @@ asmlinkage long sys_sethostname(char __u
19284         int errno;
19285         char tmp[__NEW_UTS_LEN];
19286  
19287 -       if (!capable(CAP_SYS_ADMIN))
19288 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
19289                 return -EPERM;
19290         if (len < 0 || len > __NEW_UTS_LEN)
19291                 return -EINVAL;
19292 @@ -1908,7 +1927,7 @@ asmlinkage long sys_setdomainname(char _
19293         int errno;
19294         char tmp[__NEW_UTS_LEN];
19295  
19296 -       if (!capable(CAP_SYS_ADMIN))
19297 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
19298                 return -EPERM;
19299         if (len < 0 || len > __NEW_UTS_LEN)
19300                 return -EINVAL;
19301 @@ -1975,7 +1994,7 @@ asmlinkage long sys_setrlimit(unsigned i
19302                 return -EINVAL;
19303         old_rlim = current->signal->rlim + resource;
19304         if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
19305 -           !capable(CAP_SYS_RESOURCE))
19306 +           !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
19307                 return -EPERM;
19308         if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > NR_OPEN)
19309                 return -EPERM;
19310 diff -Nurp linux-2.6.22.18/kernel/sysctl.c linux-2.6.22.18-vs2.3.0.32/kernel/sysctl.c
19311 --- linux-2.6.22.18/kernel/sysctl.c     2007-07-22 00:00:25.000000000 +0200
19312 +++ linux-2.6.22.18-vs2.3.0.32/kernel/sysctl.c  2008-02-11 12:35:38.000000000 +0100
19313 @@ -89,6 +89,7 @@ static int ngroups_max = NGROUPS_MAX;
19314  #ifdef CONFIG_KMOD
19315  extern char modprobe_path[];
19316  #endif
19317 +extern char vshelper_path[];
19318  #ifdef CONFIG_CHR_DEV_SG
19319  extern int sg_big_buff;
19320  #endif
19321 @@ -343,6 +344,15 @@ static ctl_table kern_table[] = {
19322                 .strategy       = &sysctl_string,
19323         },
19324  #endif
19325 +       {
19326 +               .ctl_name       = KERN_VSHELPER,
19327 +               .procname       = "vshelper",
19328 +               .data           = &vshelper_path,
19329 +               .maxlen         = 256,
19330 +               .mode           = 0644,
19331 +               .proc_handler   = &proc_dostring,
19332 +               .strategy       = &sysctl_string,
19333 +       },
19334  #ifdef CONFIG_CHR_DEV_SG
19335         {
19336                 .ctl_name       = KERN_SG_BIG_BUFF,
19337 diff -Nurp linux-2.6.22.18/kernel/time.c linux-2.6.22.18-vs2.3.0.32/kernel/time.c
19338 --- linux-2.6.22.18/kernel/time.c       2007-07-22 00:00:25.000000000 +0200
19339 +++ linux-2.6.22.18-vs2.3.0.32/kernel/time.c    2008-02-11 12:35:38.000000000 +0100
19340 @@ -60,7 +60,7 @@ asmlinkage long sys_time(time_t __user *
19341         time_t i;
19342         struct timeval tv;
19343  
19344 -       do_gettimeofday(&tv);
19345 +       vx_gettimeofday(&tv);
19346         i = tv.tv_sec;
19347  
19348         if (tloc) {
19349 @@ -91,7 +91,7 @@ asmlinkage long sys_stime(time_t __user 
19350         if (err)
19351                 return err;
19352  
19353 -       do_settimeofday(&tv);
19354 +       vx_settimeofday(&tv);
19355         return 0;
19356  }
19357  
19358 @@ -101,7 +101,7 @@ asmlinkage long sys_gettimeofday(struct 
19359  {
19360         if (likely(tv != NULL)) {
19361                 struct timeval ktv;
19362 -               do_gettimeofday(&ktv);
19363 +               vx_gettimeofday(&ktv);
19364                 if (copy_to_user(tv, &ktv, sizeof(ktv)))
19365                         return -EFAULT;
19366         }
19367 @@ -175,7 +175,7 @@ int do_sys_settimeofday(struct timespec 
19368                 /* SMP safe, again the code in arch/foo/time.c should
19369                  * globally block out interrupts when it runs.
19370                  */
19371 -               return do_settimeofday(tv);
19372 +               return vx_settimeofday(tv);
19373         }
19374         return 0;
19375  }
19376 @@ -388,7 +388,7 @@ void getnstimeofday(struct timespec *tv)
19377  {
19378         struct timeval x;
19379  
19380 -       do_gettimeofday(&x);
19381 +       vx_gettimeofday(&x);
19382         tv->tv_sec = x.tv_sec;
19383         tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
19384  }
19385 diff -Nurp linux-2.6.22.18/kernel/timer.c linux-2.6.22.18-vs2.3.0.32/kernel/timer.c
19386 --- linux-2.6.22.18/kernel/timer.c      2007-07-22 00:00:25.000000000 +0200
19387 +++ linux-2.6.22.18-vs2.3.0.32/kernel/timer.c   2008-02-11 12:35:38.000000000 +0100
19388 @@ -36,6 +36,10 @@
19389  #include <linux/delay.h>
19390  #include <linux/tick.h>
19391  #include <linux/kallsyms.h>
19392 +#include <linux/vs_base.h>
19393 +#include <linux/vs_cvirt.h>
19394 +#include <linux/vs_pid.h>
19395 +#include <linux/vserver/sched.h>
19396  
19397  #include <asm/uaccess.h>
19398  #include <asm/unistd.h>
19399 @@ -921,12 +925,6 @@ asmlinkage unsigned long sys_alarm(unsig
19400  
19401  #endif
19402  
19403 -#ifndef __alpha__
19404 -
19405 -/*
19406 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
19407 - * should be moved into arch/i386 instead?
19408 - */
19409  
19410  /**
19411   * sys_getpid - return the thread group id of the current process
19412 @@ -939,7 +937,7 @@ asmlinkage unsigned long sys_alarm(unsig
19413   */
19414  asmlinkage long sys_getpid(void)
19415  {
19416 -       return current->tgid;
19417 +       return vx_map_tgid(current->tgid);
19418  }
19419  
19420  /*
19421 @@ -955,10 +953,23 @@ asmlinkage long sys_getppid(void)
19422         rcu_read_lock();
19423         pid = rcu_dereference(current->real_parent)->tgid;
19424         rcu_read_unlock();
19425 +       return vx_map_pid(pid);
19426 +}
19427 +
19428 +#ifdef __alpha__
19429  
19430 -       return pid;
19431 +/*
19432 + * The Alpha uses getxpid, getxuid, and getxgid instead.
19433 + */
19434 +
19435 +asmlinkage long do_getxpid(long *ppid)
19436 +{
19437 +       *ppid = sys_getppid();
19438 +       return sys_getpid();
19439  }
19440  
19441 +#else /* _alpha_ */
19442 +
19443  asmlinkage long sys_getuid(void)
19444  {
19445         /* Only we change this so SMP safe */
19446 @@ -1118,6 +1129,8 @@ int do_sysinfo(struct sysinfo *info)
19447                         tp.tv_nsec = tp.tv_nsec - NSEC_PER_SEC;
19448                         tp.tv_sec++;
19449                 }
19450 +               if (vx_flags(VXF_VIRT_UPTIME, 0))
19451 +                       vx_vsi_uptime(&tp, NULL);
19452                 info->uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0);
19453  
19454                 info->loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
19455 diff -Nurp linux-2.6.22.18/kernel/user.c linux-2.6.22.18-vs2.3.0.32/kernel/user.c
19456 --- linux-2.6.22.18/kernel/user.c       2007-05-04 15:58:24.000000000 +0200
19457 +++ linux-2.6.22.18-vs2.3.0.32/kernel/user.c    2008-02-11 12:35:38.000000000 +0100
19458 @@ -23,8 +23,8 @@
19459  #define UIDHASH_BITS (CONFIG_BASE_SMALL ? 3 : 8)
19460  #define UIDHASH_SZ             (1 << UIDHASH_BITS)
19461  #define UIDHASH_MASK           (UIDHASH_SZ - 1)
19462 -#define __uidhashfn(uid)       (((uid >> UIDHASH_BITS) + uid) & UIDHASH_MASK)
19463 -#define uidhashentry(uid)      (uidhash_table + __uidhashfn((uid)))
19464 +#define __uidhashfn(xid,uid)   ((((uid) >> UIDHASH_BITS) + ((uid)^(xid))) & UIDHASH_MASK)
19465 +#define uidhashentry(xid,uid)  (uidhash_table + __uidhashfn((xid),(uid)))
19466  
19467  static struct kmem_cache *uid_cachep;
19468  static struct list_head uidhash_table[UIDHASH_SZ];
19469 @@ -66,7 +66,7 @@ static inline void uid_hash_remove(struc
19470         list_del(&up->uidhash_list);
19471  }
19472  
19473 -static inline struct user_struct *uid_hash_find(uid_t uid, struct list_head *hashent)
19474 +static inline struct user_struct *uid_hash_find(xid_t xid, uid_t uid, struct list_head *hashent)
19475  {
19476         struct list_head *up;
19477  
19478 @@ -75,7 +75,7 @@ static inline struct user_struct *uid_ha
19479  
19480                 user = list_entry(up, struct user_struct, uidhash_list);
19481  
19482 -               if(user->uid == uid) {
19483 +               if(user->uid == uid && user->xid == xid) {
19484                         atomic_inc(&user->__count);
19485                         return user;
19486                 }
19487 @@ -90,13 +90,13 @@ static inline struct user_struct *uid_ha
19488   *
19489   * If the user_struct could not be found, return NULL.
19490   */
19491 -struct user_struct *find_user(uid_t uid)
19492 +struct user_struct *find_user(xid_t xid, uid_t uid)
19493  {
19494         struct user_struct *ret;
19495         unsigned long flags;
19496  
19497         spin_lock_irqsave(&uidhash_lock, flags);
19498 -       ret = uid_hash_find(uid, uidhashentry(uid));
19499 +       ret = uid_hash_find(xid, uid, uidhashentry(xid, uid));
19500         spin_unlock_irqrestore(&uidhash_lock, flags);
19501         return ret;
19502  }
19503 @@ -120,13 +120,13 @@ void free_uid(struct user_struct *up)
19504         }
19505  }
19506  
19507 -struct user_struct * alloc_uid(uid_t uid)
19508 +struct user_struct * alloc_uid(xid_t xid, uid_t uid)
19509  {
19510 -       struct list_head *hashent = uidhashentry(uid);
19511 +       struct list_head *hashent = uidhashentry(xid, uid);
19512         struct user_struct *up;
19513  
19514         spin_lock_irq(&uidhash_lock);
19515 -       up = uid_hash_find(uid, hashent);
19516 +       up = uid_hash_find(xid, uid, hashent);
19517         spin_unlock_irq(&uidhash_lock);
19518  
19519         if (!up) {
19520 @@ -136,6 +136,7 @@ struct user_struct * alloc_uid(uid_t uid
19521                 if (!new)
19522                         return NULL;
19523                 new->uid = uid;
19524 +               new->xid = xid;
19525                 atomic_set(&new->__count, 1);
19526                 atomic_set(&new->processes, 0);
19527                 atomic_set(&new->files, 0);
19528 @@ -158,7 +159,7 @@ struct user_struct * alloc_uid(uid_t uid
19529                  * on adding the same user already..
19530                  */
19531                 spin_lock_irq(&uidhash_lock);
19532 -               up = uid_hash_find(uid, hashent);
19533 +               up = uid_hash_find(xid, uid, hashent);
19534                 if (up) {
19535                         key_put(new->uid_keyring);
19536                         key_put(new->session_keyring);
19537 @@ -215,7 +216,7 @@ static int __init uid_cache_init(void)
19538  
19539         /* Insert the root user immediately (init already runs as root) */
19540         spin_lock_irq(&uidhash_lock);
19541 -       uid_hash_insert(&root_user, uidhashentry(0));
19542 +       uid_hash_insert(&root_user, uidhashentry(0,0));
19543         spin_unlock_irq(&uidhash_lock);
19544  
19545         return 0;
19546 diff -Nurp linux-2.6.22.18/kernel/utsname.c linux-2.6.22.18-vs2.3.0.32/kernel/utsname.c
19547 --- linux-2.6.22.18/kernel/utsname.c    2007-07-22 00:00:25.000000000 +0200
19548 +++ linux-2.6.22.18-vs2.3.0.32/kernel/utsname.c 2008-02-11 12:35:38.000000000 +0100
19549 @@ -13,6 +13,7 @@
19550  #include <linux/uts.h>
19551  #include <linux/utsname.h>
19552  #include <linux/version.h>
19553 +#include <linux/vserver/global.h>
19554  
19555  /*
19556   * Clone a new ns copying an original utsname, setting refcount to 1
19557 @@ -27,6 +28,7 @@ static struct uts_namespace *clone_uts_n
19558         if (ns) {
19559                 memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
19560                 kref_init(&ns->kref);
19561 +               atomic_inc(&vs_global_uts_ns);
19562         }
19563         return ns;
19564  }
19565 @@ -58,5 +60,6 @@ void free_uts_ns(struct kref *kref)
19566         struct uts_namespace *ns;
19567  
19568         ns = container_of(kref, struct uts_namespace, kref);
19569 +       atomic_dec(&vs_global_uts_ns);
19570         kfree(ns);
19571  }
19572 diff -Nurp linux-2.6.22.18/kernel/vserver/cacct.c linux-2.6.22.18-vs2.3.0.32/kernel/vserver/cacct.c
19573 --- linux-2.6.22.18/kernel/vserver/cacct.c      1970-01-01 01:00:00.000000000 +0100
19574 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/cacct.c   2008-02-11 12:35:38.000000000 +0100
19575 @@ -0,0 +1,42 @@
19576 +/*
19577 + *  linux/kernel/vserver/cacct.c
19578 + *
19579 + *  Virtual Server: Context Accounting
19580 + *
19581 + *  Copyright (C) 2006-2007 Herbert Pötzl
19582 + *
19583 + *  V0.01  added accounting stats
19584 + *
19585 + */
19586 +
19587 +#include <linux/types.h>
19588 +#include <linux/vs_context.h>
19589 +#include <linux/vserver/cacct_cmd.h>
19590 +#include <linux/vserver/cacct_int.h>
19591 +
19592 +#include <asm/errno.h>
19593 +#include <asm/uaccess.h>
19594 +
19595 +
19596 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
19597 +{
19598 +       struct vcmd_sock_stat_v0 vc_data;
19599 +       int j, field;
19600 +
19601 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19602 +               return -EFAULT;
19603 +
19604 +       field = vc_data.field;
19605 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
19606 +               return -EINVAL;
19607 +
19608 +       for (j = 0; j < 3; j++) {
19609 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
19610 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
19611 +       }
19612 +
19613 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19614 +               return -EFAULT;
19615 +       return 0;
19616 +}
19617 +
19618 diff -Nurp linux-2.6.22.18/kernel/vserver/cacct_init.h linux-2.6.22.18-vs2.3.0.32/kernel/vserver/cacct_init.h
19619 --- linux-2.6.22.18/kernel/vserver/cacct_init.h 1970-01-01 01:00:00.000000000 +0100
19620 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/cacct_init.h      2008-02-11 12:35:38.000000000 +0100
19621 @@ -0,0 +1,25 @@
19622 +
19623 +
19624 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
19625 +{
19626 +       int i, j;
19627 +
19628 +
19629 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
19630 +               for (j = 0; j < 3; j++) {
19631 +                       atomic_set(&cacct->sock[i][j].count, 0);
19632 +                       atomic_set(&cacct->sock[i][j].total, 0);
19633 +               }
19634 +       }
19635 +       for (i = 0; i < 8; i++)
19636 +               atomic_set(&cacct->slab[i], 0);
19637 +       for (i = 0; i < 5; i++)
19638 +               for (j = 0; j < 4; j++)
19639 +                       atomic_set(&cacct->page[i][j], 0);
19640 +}
19641 +
19642 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
19643 +{
19644 +       return;
19645 +}
19646 +
19647 diff -Nurp linux-2.6.22.18/kernel/vserver/cacct_proc.h linux-2.6.22.18-vs2.3.0.32/kernel/vserver/cacct_proc.h
19648 --- linux-2.6.22.18/kernel/vserver/cacct_proc.h 1970-01-01 01:00:00.000000000 +0100
19649 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/cacct_proc.h      2008-02-11 12:35:38.000000000 +0100
19650 @@ -0,0 +1,53 @@
19651 +#ifndef _VX_CACCT_PROC_H
19652 +#define _VX_CACCT_PROC_H
19653 +
19654 +#include <linux/vserver/cacct_int.h>
19655 +
19656 +
19657 +#define VX_SOCKA_TOP   \
19658 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
19659 +
19660 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
19661 +{
19662 +       int i, j, length = 0;
19663 +       static char *type[VXA_SOCK_SIZE] = {
19664 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
19665 +       };
19666 +
19667 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
19668 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
19669 +               length += sprintf(buffer + length, "%s:", type[i]);
19670 +               for (j = 0; j < 3; j++) {
19671 +                       length += sprintf(buffer + length,
19672 +                               "\t%10lu/%-10lu",
19673 +                               vx_sock_count(cacct, i, j),
19674 +                               vx_sock_total(cacct, i, j));
19675 +               }
19676 +               buffer[length++] = '\n';
19677 +       }
19678 +
19679 +       length += sprintf(buffer + length, "\n");
19680 +       length += sprintf(buffer + length,
19681 +               "slab:\t %8u %8u %8u %8u\n",
19682 +               atomic_read(&cacct->slab[1]),
19683 +               atomic_read(&cacct->slab[4]),
19684 +               atomic_read(&cacct->slab[0]),
19685 +               atomic_read(&cacct->slab[2]));
19686 +
19687 +       length += sprintf(buffer + length, "\n");
19688 +       for (i = 0; i < 5; i++) {
19689 +               length += sprintf(buffer + length,
19690 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
19691 +                       atomic_read(&cacct->page[i][0]),
19692 +                       atomic_read(&cacct->page[i][1]),
19693 +                       atomic_read(&cacct->page[i][2]),
19694 +                       atomic_read(&cacct->page[i][3]),
19695 +                       atomic_read(&cacct->page[i][4]),
19696 +                       atomic_read(&cacct->page[i][5]),
19697 +                       atomic_read(&cacct->page[i][6]),
19698 +                       atomic_read(&cacct->page[i][7]));
19699 +       }
19700 +       return length;
19701 +}
19702 +
19703 +#endif /* _VX_CACCT_PROC_H */
19704 diff -Nurp linux-2.6.22.18/kernel/vserver/context.c linux-2.6.22.18-vs2.3.0.32/kernel/vserver/context.c
19705 --- linux-2.6.22.18/kernel/vserver/context.c    1970-01-01 01:00:00.000000000 +0100
19706 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/context.c 2008-02-11 12:35:38.000000000 +0100
19707 @@ -0,0 +1,964 @@
19708 +/*
19709 + *  linux/kernel/vserver/context.c
19710 + *
19711 + *  Virtual Server: Context Support
19712 + *
19713 + *  Copyright (C) 2003-2007  Herbert Pötzl
19714 + *
19715 + *  V0.01  context helper
19716 + *  V0.02  vx_ctx_kill syscall command
19717 + *  V0.03  replaced context_info calls
19718 + *  V0.04  redesign of struct (de)alloc
19719 + *  V0.05  rlimit basic implementation
19720 + *  V0.06  task_xid and info commands
19721 + *  V0.07  context flags and caps
19722 + *  V0.08  switch to RCU based hash
19723 + *  V0.09  revert to non RCU for now
19724 + *  V0.10  and back to working RCU hash
19725 + *  V0.11  and back to locking again
19726 + *  V0.12  referenced context store
19727 + *  V0.13  separate per cpu data
19728 + *  V0.14  changed vcmds to vxi arg
19729 + *  V0.15  added context stat
19730 + *  V0.16  have __create claim() the vxi
19731 + *  V0.17  removed older and legacy stuff
19732 + *
19733 + */
19734 +
19735 +#include <linux/slab.h>
19736 +#include <linux/types.h>
19737 +#include <linux/pid_namespace.h>
19738 +
19739 +#include <linux/vserver/context.h>
19740 +#include <linux/vserver/network.h>
19741 +#include <linux/vserver/debug.h>
19742 +#include <linux/vserver/limit.h>
19743 +#include <linux/vserver/limit_int.h>
19744 +#include <linux/vserver/space.h>
19745 +
19746 +#include <linux/vs_context.h>
19747 +#include <linux/vs_limit.h>
19748 +#include <linux/vserver/context_cmd.h>
19749 +
19750 +#include "cvirt_init.h"
19751 +#include "cacct_init.h"
19752 +#include "limit_init.h"
19753 +#include "sched_init.h"
19754 +
19755 +
19756 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
19757 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
19758 +
19759 +
19760 +/*     now inactive context structures */
19761 +
19762 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
19763 +
19764 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
19765 +
19766 +
19767 +/*     __alloc_vx_info()
19768 +
19769 +       * allocate an initialized vx_info struct
19770 +       * doesn't make it visible (hash)                        */
19771 +
19772 +static struct vx_info *__alloc_vx_info(xid_t xid)
19773 +{
19774 +       struct vx_info *new = NULL;
19775 +       int cpu;
19776 +
19777 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
19778 +
19779 +       /* would this benefit from a slab cache? */
19780 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
19781 +       if (!new)
19782 +               return 0;
19783 +
19784 +       memset(new, 0, sizeof(struct vx_info));
19785 +#ifdef CONFIG_SMP
19786 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
19787 +       if (!new->ptr_pc)
19788 +               goto error;
19789 +#endif
19790 +       new->vx_id = xid;
19791 +       INIT_HLIST_NODE(&new->vx_hlist);
19792 +       atomic_set(&new->vx_usecnt, 0);
19793 +       atomic_set(&new->vx_tasks, 0);
19794 +       new->vx_parent = NULL;
19795 +       new->vx_state = 0;
19796 +       init_waitqueue_head(&new->vx_wait);
19797 +
19798 +       /* prepare reaper */
19799 +       get_task_struct(init_pid_ns.child_reaper);
19800 +       new->vx_reaper = init_pid_ns.child_reaper;
19801 +       new->vx_badness_bias = 0;
19802 +
19803 +       /* rest of init goes here */
19804 +       vx_info_init_limit(&new->limit);
19805 +       vx_info_init_sched(&new->sched);
19806 +       vx_info_init_cvirt(&new->cvirt);
19807 +       vx_info_init_cacct(&new->cacct);
19808 +
19809 +       /* per cpu data structures */
19810 +       for_each_possible_cpu(cpu) {
19811 +               vx_info_init_sched_pc(
19812 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
19813 +               vx_info_init_cvirt_pc(
19814 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
19815 +       }
19816 +
19817 +       new->vx_flags = VXF_INIT_SET;
19818 +       new->vx_bcaps = CAP_INIT_EFF_SET;
19819 +       new->vx_ccaps = 0;
19820 +       new->vx_cap_bset = cap_bset;
19821 +
19822 +       new->reboot_cmd = 0;
19823 +       new->exit_code = 0;
19824 +
19825 +       vxdprintk(VXD_CBIT(xid, 0),
19826 +               "alloc_vx_info(%d) = %p", xid, new);
19827 +       vxh_alloc_vx_info(new);
19828 +       atomic_inc(&vx_global_ctotal);
19829 +       return new;
19830 +#ifdef CONFIG_SMP
19831 +error:
19832 +       kfree(new);
19833 +       return 0;
19834 +#endif
19835 +}
19836 +
19837 +/*     __dealloc_vx_info()
19838 +
19839 +       * final disposal of vx_info                             */
19840 +
19841 +static void __dealloc_vx_info(struct vx_info *vxi)
19842 +{
19843 +       int cpu;
19844 +
19845 +       vxdprintk(VXD_CBIT(xid, 0),
19846 +               "dealloc_vx_info(%p)", vxi);
19847 +       vxh_dealloc_vx_info(vxi);
19848 +
19849 +       vxi->vx_id = -1;
19850 +
19851 +       vx_info_exit_limit(&vxi->limit);
19852 +       vx_info_exit_sched(&vxi->sched);
19853 +       vx_info_exit_cvirt(&vxi->cvirt);
19854 +       vx_info_exit_cacct(&vxi->cacct);
19855 +
19856 +       for_each_possible_cpu(cpu) {
19857 +               vx_info_exit_sched_pc(
19858 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
19859 +               vx_info_exit_cvirt_pc(
19860 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
19861 +       }
19862 +
19863 +       vxi->vx_state |= VXS_RELEASED;
19864 +
19865 +#ifdef CONFIG_SMP
19866 +       free_percpu(vxi->ptr_pc);
19867 +#endif
19868 +       kfree(vxi);
19869 +       atomic_dec(&vx_global_ctotal);
19870 +}
19871 +
19872 +static void __shutdown_vx_info(struct vx_info *vxi)
19873 +{
19874 +       struct nsproxy *nsproxy;
19875 +       struct fs_struct *fs;
19876 +
19877 +       might_sleep();
19878 +
19879 +       vxi->vx_state |= VXS_SHUTDOWN;
19880 +       vs_state_change(vxi, VSC_SHUTDOWN);
19881 +
19882 +       nsproxy = xchg(&vxi->vx_nsproxy, NULL);
19883 +       fs = xchg(&vxi->vx_fs, NULL);
19884 +
19885 +       if (nsproxy)
19886 +               put_nsproxy(nsproxy);
19887 +       if (fs)
19888 +               put_fs_struct(fs);
19889 +}
19890 +
19891 +/* exported stuff */
19892 +
19893 +void free_vx_info(struct vx_info *vxi)
19894 +{
19895 +       unsigned long flags;
19896 +
19897 +       /* check for reference counts first */
19898 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
19899 +       BUG_ON(atomic_read(&vxi->vx_tasks));
19900 +
19901 +       /* context must not be hashed */
19902 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
19903 +
19904 +       /* context shutdown is mandatory */
19905 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
19906 +
19907 +       BUG_ON(vxi->vx_nsproxy);
19908 +       BUG_ON(vxi->vx_fs);
19909 +
19910 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
19911 +       hlist_del(&vxi->vx_hlist);
19912 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
19913 +
19914 +       __dealloc_vx_info(vxi);
19915 +}
19916 +
19917 +
19918 +/*     hash table for vx_info hash */
19919 +
19920 +#define VX_HASH_SIZE   13
19921 +
19922 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
19923 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
19924 +
19925 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
19926 +
19927 +
19928 +static inline unsigned int __hashval(xid_t xid)
19929 +{
19930 +       return (xid % VX_HASH_SIZE);
19931 +}
19932 +
19933 +
19934 +
19935 +/*     __hash_vx_info()
19936 +
19937 +       * add the vxi to the global hash table
19938 +       * requires the hash_lock to be held                     */
19939 +
19940 +static inline void __hash_vx_info(struct vx_info *vxi)
19941 +{
19942 +       struct hlist_head *head;
19943 +
19944 +       vxd_assert_lock(&vx_info_hash_lock);
19945 +       vxdprintk(VXD_CBIT(xid, 4),
19946 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
19947 +       vxh_hash_vx_info(vxi);
19948 +
19949 +       /* context must not be hashed */
19950 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
19951 +
19952 +       vxi->vx_state |= VXS_HASHED;
19953 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
19954 +       hlist_add_head(&vxi->vx_hlist, head);
19955 +       atomic_inc(&vx_global_cactive);
19956 +}
19957 +
19958 +/*     __unhash_vx_info()
19959 +
19960 +       * remove the vxi from the global hash table
19961 +       * requires the hash_lock to be held                     */
19962 +
19963 +static inline void __unhash_vx_info(struct vx_info *vxi)
19964 +{
19965 +       unsigned long flags;
19966 +
19967 +       vxd_assert_lock(&vx_info_hash_lock);
19968 +       vxdprintk(VXD_CBIT(xid, 4),
19969 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
19970 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
19971 +       vxh_unhash_vx_info(vxi);
19972 +
19973 +       /* context must be hashed */
19974 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
19975 +       /* but without tasks */
19976 +       BUG_ON(atomic_read(&vxi->vx_tasks));
19977 +
19978 +       vxi->vx_state &= ~VXS_HASHED;
19979 +       hlist_del_init(&vxi->vx_hlist);
19980 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
19981 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
19982 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
19983 +       atomic_dec(&vx_global_cactive);
19984 +}
19985 +
19986 +
19987 +/*     __lookup_vx_info()
19988 +
19989 +       * requires the hash_lock to be held
19990 +       * doesn't increment the vx_refcnt                       */
19991 +
19992 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
19993 +{
19994 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
19995 +       struct hlist_node *pos;
19996 +       struct vx_info *vxi;
19997 +
19998 +       vxd_assert_lock(&vx_info_hash_lock);
19999 +       hlist_for_each(pos, head) {
20000 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
20001 +
20002 +               if (vxi->vx_id == xid)
20003 +                       goto found;
20004 +       }
20005 +       vxi = NULL;
20006 +found:
20007 +       vxdprintk(VXD_CBIT(xid, 0),
20008 +               "__lookup_vx_info(#%u): %p[#%u]",
20009 +               xid, vxi, vxi ? vxi->vx_id : 0);
20010 +       vxh_lookup_vx_info(vxi, xid);
20011 +       return vxi;
20012 +}
20013 +
20014 +
20015 +/*     __create_vx_info()
20016 +
20017 +       * create the requested context
20018 +       * get(), claim() and hash it                            */
20019 +
20020 +static struct vx_info *__create_vx_info(int id)
20021 +{
20022 +       struct vx_info *new, *vxi = NULL;
20023 +
20024 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
20025 +
20026 +       if (!(new = __alloc_vx_info(id)))
20027 +               return ERR_PTR(-ENOMEM);
20028 +
20029 +       /* required to make dynamic xids unique */
20030 +       spin_lock(&vx_info_hash_lock);
20031 +
20032 +       /* static context requested */
20033 +       if ((vxi = __lookup_vx_info(id))) {
20034 +               vxdprintk(VXD_CBIT(xid, 0),
20035 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
20036 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
20037 +                       vxi = ERR_PTR(-EBUSY);
20038 +               else
20039 +                       vxi = ERR_PTR(-EEXIST);
20040 +               goto out_unlock;
20041 +       }
20042 +       /* new context */
20043 +       vxdprintk(VXD_CBIT(xid, 0),
20044 +               "create_vx_info(%d) = %p (new)", id, new);
20045 +       claim_vx_info(new, NULL);
20046 +       __hash_vx_info(get_vx_info(new));
20047 +       vxi = new, new = NULL;
20048 +
20049 +out_unlock:
20050 +       spin_unlock(&vx_info_hash_lock);
20051 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
20052 +       if (new)
20053 +               __dealloc_vx_info(new);
20054 +       return vxi;
20055 +}
20056 +
20057 +
20058 +/*     exported stuff                                          */
20059 +
20060 +
20061 +void unhash_vx_info(struct vx_info *vxi)
20062 +{
20063 +       __shutdown_vx_info(vxi);
20064 +       spin_lock(&vx_info_hash_lock);
20065 +       __unhash_vx_info(vxi);
20066 +       spin_unlock(&vx_info_hash_lock);
20067 +       __wakeup_vx_info(vxi);
20068 +}
20069 +
20070 +
20071 +/*     lookup_vx_info()
20072 +
20073 +       * search for a vx_info and get() it
20074 +       * negative id means current                             */
20075 +
20076 +struct vx_info *lookup_vx_info(int id)
20077 +{
20078 +       struct vx_info *vxi = NULL;
20079 +
20080 +       if (id < 0) {
20081 +               vxi = get_vx_info(current->vx_info);
20082 +       } else if (id > 1) {
20083 +               spin_lock(&vx_info_hash_lock);
20084 +               vxi = get_vx_info(__lookup_vx_info(id));
20085 +               spin_unlock(&vx_info_hash_lock);
20086 +       }
20087 +       return vxi;
20088 +}
20089 +
20090 +/*     xid_is_hashed()
20091 +
20092 +       * verify that xid is still hashed                       */
20093 +
20094 +int xid_is_hashed(xid_t xid)
20095 +{
20096 +       int hashed;
20097 +
20098 +       spin_lock(&vx_info_hash_lock);
20099 +       hashed = (__lookup_vx_info(xid) != NULL);
20100 +       spin_unlock(&vx_info_hash_lock);
20101 +       return hashed;
20102 +}
20103 +
20104 +#ifdef CONFIG_PROC_FS
20105 +
20106 +/*     get_xid_list()
20107 +
20108 +       * get a subset of hashed xids for proc
20109 +       * assumes size is at least one                          */
20110 +
20111 +int get_xid_list(int index, unsigned int *xids, int size)
20112 +{
20113 +       int hindex, nr_xids = 0;
20114 +
20115 +       /* only show current and children */
20116 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
20117 +               if (index > 0)
20118 +                       return 0;
20119 +               xids[nr_xids] = vx_current_xid();
20120 +               return 1;
20121 +       }
20122 +
20123 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
20124 +               struct hlist_head *head = &vx_info_hash[hindex];
20125 +               struct hlist_node *pos;
20126 +
20127 +               spin_lock(&vx_info_hash_lock);
20128 +               hlist_for_each(pos, head) {
20129 +                       struct vx_info *vxi;
20130 +
20131 +                       if (--index > 0)
20132 +                               continue;
20133 +
20134 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
20135 +                       xids[nr_xids] = vxi->vx_id;
20136 +                       if (++nr_xids >= size) {
20137 +                               spin_unlock(&vx_info_hash_lock);
20138 +                               goto out;
20139 +                       }
20140 +               }
20141 +               /* keep the lock time short */
20142 +               spin_unlock(&vx_info_hash_lock);
20143 +       }
20144 +out:
20145 +       return nr_xids;
20146 +}
20147 +#endif
20148 +
20149 +#ifdef CONFIG_VSERVER_DEBUG
20150 +
20151 +void   dump_vx_info_inactive(int level)
20152 +{
20153 +       struct hlist_node *entry, *next;
20154 +
20155 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
20156 +               struct vx_info *vxi =
20157 +                       list_entry(entry, struct vx_info, vx_hlist);
20158 +
20159 +               dump_vx_info(vxi, level);
20160 +       }
20161 +}
20162 +
20163 +#endif
20164 +
20165 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
20166 +{
20167 +       struct user_struct *new_user, *old_user;
20168 +
20169 +       if (!p || !vxi)
20170 +               BUG();
20171 +
20172 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
20173 +               return -EACCES;
20174 +
20175 +       new_user = alloc_uid(vxi->vx_id, p->uid);
20176 +       if (!new_user)
20177 +               return -ENOMEM;
20178 +
20179 +       old_user = p->user;
20180 +       if (new_user != old_user) {
20181 +               atomic_inc(&new_user->processes);
20182 +               atomic_dec(&old_user->processes);
20183 +               p->user = new_user;
20184 +       }
20185 +       free_uid(old_user);
20186 +       return 0;
20187 +}
20188 +
20189 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
20190 +{
20191 +       p->cap_effective &= vxi->vx_cap_bset;
20192 +       p->cap_inheritable &= vxi->vx_cap_bset;
20193 +       p->cap_permitted &= vxi->vx_cap_bset;
20194 +}
20195 +
20196 +
20197 +#include <linux/file.h>
20198 +
20199 +static int vx_openfd_task(struct task_struct *tsk)
20200 +{
20201 +       struct files_struct *files = tsk->files;
20202 +       struct fdtable *fdt;
20203 +       const unsigned long *bptr;
20204 +       int count, total;
20205 +
20206 +       /* no rcu_read_lock() because of spin_lock() */
20207 +       spin_lock(&files->file_lock);
20208 +       fdt = files_fdtable(files);
20209 +       bptr = fdt->open_fds->fds_bits;
20210 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
20211 +       for (total = 0; count > 0; count--) {
20212 +               if (*bptr)
20213 +                       total += hweight_long(*bptr);
20214 +               bptr++;
20215 +       }
20216 +       spin_unlock(&files->file_lock);
20217 +       return total;
20218 +}
20219 +
20220 +
20221 +/*     for *space compatibility */
20222 +
20223 +asmlinkage long sys_unshare(unsigned long);
20224 +
20225 +/*
20226 + *     migrate task to new context
20227 + *     gets vxi, puts old_vxi on change
20228 + *     optionally unshares namespaces (hack)
20229 + */
20230 +
20231 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
20232 +{
20233 +       struct vx_info *old_vxi;
20234 +       int ret = 0;
20235 +
20236 +       if (!p || !vxi)
20237 +               BUG();
20238 +
20239 +       vxdprintk(VXD_CBIT(xid, 5),
20240 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
20241 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
20242 +
20243 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
20244 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
20245 +               return -EACCES;
20246 +
20247 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
20248 +               return -EFAULT;
20249 +
20250 +       old_vxi = task_get_vx_info(p);
20251 +       if (old_vxi == vxi)
20252 +               goto out;
20253 +
20254 +       if (!(ret = vx_migrate_user(p, vxi))) {
20255 +               int openfd;
20256 +
20257 +               task_lock(p);
20258 +               openfd = vx_openfd_task(p);
20259 +
20260 +               if (old_vxi) {
20261 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
20262 +                       atomic_dec(&old_vxi->cvirt.nr_running);
20263 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
20264 +                       /* FIXME: what about the struct files here? */
20265 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
20266 +                       /* account for the executable */
20267 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
20268 +               }
20269 +               atomic_inc(&vxi->cvirt.nr_threads);
20270 +               atomic_inc(&vxi->cvirt.nr_running);
20271 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
20272 +               /* FIXME: what about the struct files here? */
20273 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
20274 +               /* account for the executable */
20275 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
20276 +
20277 +               if (old_vxi) {
20278 +                       release_vx_info(old_vxi, p);
20279 +                       clr_vx_info(&p->vx_info);
20280 +               }
20281 +               claim_vx_info(vxi, p);
20282 +               set_vx_info(&p->vx_info, vxi);
20283 +               p->xid = vxi->vx_id;
20284 +
20285 +               vxdprintk(VXD_CBIT(xid, 5),
20286 +                       "moved task %p into vxi:%p[#%d]",
20287 +                       p, vxi, vxi->vx_id);
20288 +
20289 +               vx_mask_cap_bset(vxi, p);
20290 +               task_unlock(p);
20291 +
20292 +               /* hack for *spaces to provide compatibility */
20293 +               if (unshare) {
20294 +                       struct nsproxy *old_nsp, *new_nsp;
20295 +
20296 +                       ret = unshare_nsproxy_namespaces(
20297 +                               CLONE_NEWUTS | CLONE_NEWIPC,
20298 +                               &new_nsp, NULL);
20299 +                       if (ret)
20300 +                               goto out;
20301 +
20302 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
20303 +                       vx_set_space(vxi, CLONE_NEWUTS | CLONE_NEWIPC);
20304 +                       put_nsproxy(old_nsp);
20305 +               }
20306 +       }
20307 +out:
20308 +       put_vx_info(old_vxi);
20309 +       return ret;
20310 +}
20311 +
20312 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
20313 +{
20314 +       struct task_struct *old_reaper;
20315 +
20316 +       if (!vxi)
20317 +               return -EINVAL;
20318 +
20319 +       vxdprintk(VXD_CBIT(xid, 6),
20320 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
20321 +               vxi, vxi->vx_id, p, p->xid, p->pid);
20322 +
20323 +       old_reaper = vxi->vx_reaper;
20324 +       if (old_reaper == p)
20325 +               return 0;
20326 +
20327 +       /* set new child reaper */
20328 +       get_task_struct(p);
20329 +       vxi->vx_reaper = p;
20330 +       put_task_struct(old_reaper);
20331 +       return 0;
20332 +}
20333 +
20334 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
20335 +{
20336 +       if (!vxi)
20337 +               return -EINVAL;
20338 +
20339 +       vxdprintk(VXD_CBIT(xid, 6),
20340 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
20341 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
20342 +
20343 +       vxi->vx_flags &= ~VXF_STATE_INIT;
20344 +       vxi->vx_initpid = p->tgid;
20345 +       return 0;
20346 +}
20347 +
20348 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
20349 +{
20350 +       vxdprintk(VXD_CBIT(xid, 6),
20351 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
20352 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
20353 +
20354 +       vxi->exit_code = code;
20355 +       vxi->vx_initpid = 0;
20356 +}
20357 +
20358 +
20359 +void vx_set_persistent(struct vx_info *vxi)
20360 +{
20361 +       vxdprintk(VXD_CBIT(xid, 6),
20362 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
20363 +
20364 +       get_vx_info(vxi);
20365 +       claim_vx_info(vxi, NULL);
20366 +}
20367 +
20368 +void vx_clear_persistent(struct vx_info *vxi)
20369 +{
20370 +       vxdprintk(VXD_CBIT(xid, 6),
20371 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
20372 +
20373 +       release_vx_info(vxi, NULL);
20374 +       put_vx_info(vxi);
20375 +}
20376 +
20377 +void vx_update_persistent(struct vx_info *vxi)
20378 +{
20379 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
20380 +               vx_set_persistent(vxi);
20381 +       else
20382 +               vx_clear_persistent(vxi);
20383 +}
20384 +
20385 +
20386 +/*     task must be current or locked          */
20387 +
20388 +void   exit_vx_info(struct task_struct *p, int code)
20389 +{
20390 +       struct vx_info *vxi = p->vx_info;
20391 +
20392 +       if (vxi) {
20393 +               atomic_dec(&vxi->cvirt.nr_threads);
20394 +               vx_nproc_dec(p);
20395 +
20396 +               vxi->exit_code = code;
20397 +               release_vx_info(vxi, p);
20398 +       }
20399 +}
20400 +
20401 +void   exit_vx_info_early(struct task_struct *p, int code)
20402 +{
20403 +       struct vx_info *vxi = p->vx_info;
20404 +
20405 +       if (vxi) {
20406 +               if (vxi->vx_initpid == p->tgid)
20407 +                       vx_exit_init(vxi, p, code);
20408 +               if (vxi->vx_reaper == p)
20409 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
20410 +       }
20411 +}
20412 +
20413 +
20414 +/* vserver syscall commands below here */
20415 +
20416 +/* taks xid and vx_info functions */
20417 +
20418 +#include <asm/uaccess.h>
20419 +
20420 +
20421 +int vc_task_xid(uint32_t id)
20422 +{
20423 +       xid_t xid;
20424 +
20425 +       if (id) {
20426 +               struct task_struct *tsk;
20427 +
20428 +               read_lock(&tasklist_lock);
20429 +               tsk = find_task_by_real_pid(id);
20430 +               xid = (tsk) ? tsk->xid : -ESRCH;
20431 +               read_unlock(&tasklist_lock);
20432 +       } else
20433 +               xid = vx_current_xid();
20434 +       return xid;
20435 +}
20436 +
20437 +
20438 +int vc_vx_info(struct vx_info *vxi, void __user *data)
20439 +{
20440 +       struct vcmd_vx_info_v0 vc_data;
20441 +
20442 +       vc_data.xid = vxi->vx_id;
20443 +       vc_data.initpid = vxi->vx_initpid;
20444 +
20445 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20446 +               return -EFAULT;
20447 +       return 0;
20448 +}
20449 +
20450 +
20451 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
20452 +{
20453 +       struct vcmd_ctx_stat_v0 vc_data;
20454 +
20455 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
20456 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
20457 +
20458 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20459 +               return -EFAULT;
20460 +       return 0;
20461 +}
20462 +
20463 +
20464 +/* context functions */
20465 +
20466 +int vc_ctx_create(uint32_t xid, void __user *data)
20467 +{
20468 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
20469 +       struct vx_info *new_vxi;
20470 +       int ret;
20471 +
20472 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20473 +               return -EFAULT;
20474 +
20475 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
20476 +               return -EINVAL;
20477 +
20478 +       new_vxi = __create_vx_info(xid);
20479 +       if (IS_ERR(new_vxi))
20480 +               return PTR_ERR(new_vxi);
20481 +
20482 +       /* initial flags */
20483 +       new_vxi->vx_flags = vc_data.flagword;
20484 +
20485 +       ret = -ENOEXEC;
20486 +       if (vs_state_change(new_vxi, VSC_STARTUP))
20487 +               goto out;
20488 +
20489 +       ret = vx_migrate_task(current, new_vxi, (!data));
20490 +       if (ret)
20491 +               goto out;
20492 +
20493 +       /* return context id on success */
20494 +       ret = new_vxi->vx_id;
20495 +
20496 +       /* get a reference for persistent contexts */
20497 +       if ((vc_data.flagword & VXF_PERSISTENT))
20498 +               vx_set_persistent(new_vxi);
20499 +out:
20500 +       release_vx_info(new_vxi, NULL);
20501 +       put_vx_info(new_vxi);
20502 +       return ret;
20503 +}
20504 +
20505 +
20506 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
20507 +{
20508 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
20509 +       int ret;
20510 +
20511 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20512 +               return -EFAULT;
20513 +
20514 +       ret = vx_migrate_task(current, vxi, 0);
20515 +       if (ret)
20516 +               return ret;
20517 +       if (vc_data.flagword & VXM_SET_INIT)
20518 +               ret = vx_set_init(vxi, current);
20519 +       if (ret)
20520 +               return ret;
20521 +       if (vc_data.flagword & VXM_SET_REAPER)
20522 +               ret = vx_set_reaper(vxi, current);
20523 +       return ret;
20524 +}
20525 +
20526 +
20527 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
20528 +{
20529 +       struct vcmd_ctx_flags_v0 vc_data;
20530 +
20531 +       vc_data.flagword = vxi->vx_flags;
20532 +
20533 +       /* special STATE flag handling */
20534 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
20535 +
20536 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20537 +               return -EFAULT;
20538 +       return 0;
20539 +}
20540 +
20541 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
20542 +{
20543 +       struct vcmd_ctx_flags_v0 vc_data;
20544 +       uint64_t mask, trigger;
20545 +
20546 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20547 +               return -EFAULT;
20548 +
20549 +       /* special STATE flag handling */
20550 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
20551 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
20552 +
20553 +       if (vxi == current->vx_info) {
20554 +               if (trigger & VXF_STATE_SETUP)
20555 +                       vx_mask_cap_bset(vxi, current);
20556 +               if (trigger & VXF_STATE_INIT) {
20557 +                       int ret;
20558 +
20559 +                       ret = vx_set_init(vxi, current);
20560 +                       if (ret)
20561 +                               return ret;
20562 +                       ret = vx_set_reaper(vxi, current);
20563 +                       if (ret)
20564 +                               return ret;
20565 +               }
20566 +       }
20567 +
20568 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
20569 +               vc_data.flagword, mask);
20570 +       if (trigger & VXF_PERSISTENT)
20571 +               vx_update_persistent(vxi);
20572 +
20573 +       return 0;
20574 +}
20575 +
20576 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
20577 +{
20578 +       if (bcaps)
20579 +               *bcaps = vxi->vx_bcaps;
20580 +       if (ccaps)
20581 +               *ccaps = vxi->vx_ccaps;
20582 +
20583 +       return 0;
20584 +}
20585 +
20586 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
20587 +{
20588 +       struct vcmd_ctx_caps_v1 vc_data;
20589 +       int ret;
20590 +
20591 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
20592 +       if (ret)
20593 +               return ret;
20594 +       vc_data.cmask = ~0ULL;
20595 +
20596 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20597 +               return -EFAULT;
20598 +       return 0;
20599 +}
20600 +
20601 +static int do_set_caps(struct vx_info *vxi,
20602 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
20603 +{
20604 +       vxi->vx_bcaps = vs_mask_flags(vxi->vx_bcaps, bcaps, bmask);
20605 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
20606 +
20607 +       return 0;
20608 +}
20609 +
20610 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
20611 +{
20612 +       struct vcmd_ctx_caps_v1 vc_data;
20613 +
20614 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20615 +               return -EFAULT;
20616 +
20617 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
20618 +}
20619 +
20620 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
20621 +{
20622 +       struct vcmd_bcaps vc_data;
20623 +       int ret;
20624 +
20625 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
20626 +       if (ret)
20627 +               return ret;
20628 +       vc_data.bmask = ~0ULL;
20629 +
20630 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20631 +               return -EFAULT;
20632 +       return 0;
20633 +}
20634 +
20635 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
20636 +{
20637 +       struct vcmd_bcaps vc_data;
20638 +
20639 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20640 +               return -EFAULT;
20641 +
20642 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
20643 +}
20644 +
20645 +
20646 +int vc_get_badness(struct vx_info *vxi, void __user *data)
20647 +{
20648 +       struct vcmd_badness_v0 vc_data;
20649 +
20650 +       vc_data.bias = vxi->vx_badness_bias;
20651 +
20652 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20653 +               return -EFAULT;
20654 +       return 0;
20655 +}
20656 +
20657 +int vc_set_badness(struct vx_info *vxi, void __user *data)
20658 +{
20659 +       struct vcmd_badness_v0 vc_data;
20660 +
20661 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20662 +               return -EFAULT;
20663 +
20664 +       vxi->vx_badness_bias = vc_data.bias;
20665 +       return 0;
20666 +}
20667 +
20668 +#include <linux/module.h>
20669 +
20670 +EXPORT_SYMBOL_GPL(free_vx_info);
20671 +
20672 diff -Nurp linux-2.6.22.18/kernel/vserver/cvirt.c linux-2.6.22.18-vs2.3.0.32/kernel/vserver/cvirt.c
20673 --- linux-2.6.22.18/kernel/vserver/cvirt.c      1970-01-01 01:00:00.000000000 +0100
20674 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/cvirt.c   2008-02-11 12:35:38.000000000 +0100
20675 @@ -0,0 +1,300 @@
20676 +/*
20677 + *  linux/kernel/vserver/cvirt.c
20678 + *
20679 + *  Virtual Server: Context Virtualization
20680 + *
20681 + *  Copyright (C) 2004-2007  Herbert Pötzl
20682 + *
20683 + *  V0.01  broken out from limit.c
20684 + *  V0.02  added utsname stuff
20685 + *  V0.03  changed vcmds to vxi arg
20686 + *
20687 + */
20688 +
20689 +#include <linux/types.h>
20690 +#include <linux/vs_cvirt.h>
20691 +#include <linux/vserver/switch.h>
20692 +#include <linux/vserver/cvirt_cmd.h>
20693 +
20694 +#include <asm/uaccess.h>
20695 +
20696 +
20697 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
20698 +{
20699 +       struct vx_info *vxi = current->vx_info;
20700 +
20701 +       set_normalized_timespec(uptime,
20702 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
20703 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
20704 +       if (!idle)
20705 +               return;
20706 +       set_normalized_timespec(idle,
20707 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
20708 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
20709 +       return;
20710 +}
20711 +
20712 +uint64_t vx_idle_jiffies(void)
20713 +{
20714 +       return init_task.utime + init_task.stime;
20715 +}
20716 +
20717 +
20718 +
20719 +static inline uint32_t __update_loadavg(uint32_t load,
20720 +       int wsize, int delta, int n)
20721 +{
20722 +       unsigned long long calc, prev;
20723 +
20724 +       /* just set it to n */
20725 +       if (unlikely(delta >= wsize))
20726 +               return (n << FSHIFT);
20727 +
20728 +       calc = delta * n;
20729 +       calc <<= FSHIFT;
20730 +       prev = (wsize - delta);
20731 +       prev *= load;
20732 +       calc += prev;
20733 +       do_div(calc, wsize);
20734 +       return calc;
20735 +}
20736 +
20737 +
20738 +void vx_update_load(struct vx_info *vxi)
20739 +{
20740 +       uint32_t now, last, delta;
20741 +       unsigned int nr_running, nr_uninterruptible;
20742 +       unsigned int total;
20743 +       unsigned long flags;
20744 +
20745 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
20746 +
20747 +       now = jiffies;
20748 +       last = vxi->cvirt.load_last;
20749 +       delta = now - last;
20750 +
20751 +       if (delta < 5*HZ)
20752 +               goto out;
20753 +
20754 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
20755 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
20756 +       total = nr_running + nr_uninterruptible;
20757 +
20758 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
20759 +               60*HZ, delta, total);
20760 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
20761 +               5*60*HZ, delta, total);
20762 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
20763 +               15*60*HZ, delta, total);
20764 +
20765 +       vxi->cvirt.load_last = now;
20766 +out:
20767 +       atomic_inc(&vxi->cvirt.load_updates);
20768 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
20769 +}
20770 +
20771 +
20772 +/*
20773 + * Commands to do_syslog:
20774 + *
20775 + *      0 -- Close the log.  Currently a NOP.
20776 + *      1 -- Open the log. Currently a NOP.
20777 + *      2 -- Read from the log.
20778 + *      3 -- Read all messages remaining in the ring buffer.
20779 + *      4 -- Read and clear all messages remaining in the ring buffer
20780 + *      5 -- Clear ring buffer.
20781 + *      6 -- Disable printk's to console
20782 + *      7 -- Enable printk's to console
20783 + *      8 -- Set level of messages printed to console
20784 + *      9 -- Return number of unread characters in the log buffer
20785 + *     10 -- Return size of the log buffer
20786 + */
20787 +int vx_do_syslog(int type, char __user *buf, int len)
20788 +{
20789 +       int error = 0;
20790 +       int do_clear = 0;
20791 +       struct vx_info *vxi = current->vx_info;
20792 +       struct _vx_syslog *log;
20793 +
20794 +       if (!vxi)
20795 +               return -EINVAL;
20796 +       log = &vxi->cvirt.syslog;
20797 +
20798 +       switch (type) {
20799 +       case 0:         /* Close log */
20800 +       case 1:         /* Open log */
20801 +               break;
20802 +       case 2:         /* Read from log */
20803 +               error = wait_event_interruptible(log->log_wait,
20804 +                       (log->log_start - log->log_end));
20805 +               if (error)
20806 +                       break;
20807 +               spin_lock_irq(&log->logbuf_lock);
20808 +               spin_unlock_irq(&log->logbuf_lock);
20809 +               break;
20810 +       case 4:         /* Read/clear last kernel messages */
20811 +               do_clear = 1;
20812 +               /* fall through */
20813 +       case 3:         /* Read last kernel messages */
20814 +               return 0;
20815 +
20816 +       case 5:         /* Clear ring buffer */
20817 +               return 0;
20818 +
20819 +       case 6:         /* Disable logging to console */
20820 +       case 7:         /* Enable logging to console */
20821 +       case 8:         /* Set level of messages printed to console */
20822 +               break;
20823 +
20824 +       case 9:         /* Number of chars in the log buffer */
20825 +               return 0;
20826 +       case 10:        /* Size of the log buffer */
20827 +               return 0;
20828 +       default:
20829 +               error = -EINVAL;
20830 +               break;
20831 +       }
20832 +       return error;
20833 +}
20834 +
20835 +
20836 +/* virtual host info names */
20837 +
20838 +static char *vx_vhi_name(struct vx_info *vxi, int id)
20839 +{
20840 +       struct nsproxy *nsproxy;
20841 +       struct uts_namespace *uts;
20842 +
20843 +
20844 +       if (id == VHIN_CONTEXT)
20845 +               return vxi->vx_name;
20846 +
20847 +       nsproxy = vxi->vx_nsproxy;
20848 +       if (!nsproxy)
20849 +               return NULL;
20850 +
20851 +       uts = nsproxy->uts_ns;
20852 +       if (!uts)
20853 +               return NULL;
20854 +
20855 +       switch (id) {
20856 +       case VHIN_SYSNAME:
20857 +               return uts->name.sysname;
20858 +       case VHIN_NODENAME:
20859 +               return uts->name.nodename;
20860 +       case VHIN_RELEASE:
20861 +               return uts->name.release;
20862 +       case VHIN_VERSION:
20863 +               return uts->name.version;
20864 +       case VHIN_MACHINE:
20865 +               return uts->name.machine;
20866 +       case VHIN_DOMAINNAME:
20867 +               return uts->name.domainname;
20868 +       default:
20869 +               return NULL;
20870 +       }
20871 +       return NULL;
20872 +}
20873 +
20874 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
20875 +{
20876 +       struct vcmd_vhi_name_v0 vc_data;
20877 +       char *name;
20878 +
20879 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20880 +               return -EFAULT;
20881 +
20882 +       name = vx_vhi_name(vxi, vc_data.field);
20883 +       if (!name)
20884 +               return -EINVAL;
20885 +
20886 +       memcpy(name, vc_data.name, 65);
20887 +       return 0;
20888 +}
20889 +
20890 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
20891 +{
20892 +       struct vcmd_vhi_name_v0 vc_data;
20893 +       char *name;
20894 +
20895 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20896 +               return -EFAULT;
20897 +
20898 +       name = vx_vhi_name(vxi, vc_data.field);
20899 +       if (!name)
20900 +               return -EINVAL;
20901 +
20902 +       memcpy(vc_data.name, name, 65);
20903 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20904 +               return -EFAULT;
20905 +       return 0;
20906 +}
20907 +
20908 +
20909 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
20910 +{
20911 +       struct vcmd_virt_stat_v0 vc_data;
20912 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
20913 +       struct timespec uptime;
20914 +
20915 +       do_posix_clock_monotonic_gettime(&uptime);
20916 +       set_normalized_timespec(&uptime,
20917 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
20918 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
20919 +
20920 +       vc_data.offset = timeval_to_ns(&cvirt->bias_tv);
20921 +       vc_data.uptime = timespec_to_ns(&uptime);
20922 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
20923 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
20924 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
20925 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
20926 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
20927 +       vc_data.load[0] = cvirt->load[0];
20928 +       vc_data.load[1] = cvirt->load[1];
20929 +       vc_data.load[2] = cvirt->load[2];
20930 +
20931 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20932 +               return -EFAULT;
20933 +       return 0;
20934 +}
20935 +
20936 +
20937 +#ifdef CONFIG_VSERVER_VTIME
20938 +
20939 +/* virtualized time base */
20940 +
20941 +void vx_gettimeofday(struct timeval *tv)
20942 +{
20943 +       do_gettimeofday(tv);
20944 +       if (!vx_flags(VXF_VIRT_TIME, 0))
20945 +               return;
20946 +
20947 +       tv->tv_sec += current->vx_info->cvirt.bias_tv.tv_sec;
20948 +       tv->tv_usec += current->vx_info->cvirt.bias_tv.tv_usec;
20949 +
20950 +       if (tv->tv_usec >= USEC_PER_SEC) {
20951 +               tv->tv_sec++;
20952 +               tv->tv_usec -= USEC_PER_SEC;
20953 +       } else if (tv->tv_usec < 0) {
20954 +               tv->tv_sec--;
20955 +               tv->tv_usec += USEC_PER_SEC;
20956 +       }
20957 +}
20958 +
20959 +int vx_settimeofday(struct timespec *ts)
20960 +{
20961 +       struct timeval tv;
20962 +
20963 +       if (!vx_flags(VXF_VIRT_TIME, 0))
20964 +               return do_settimeofday(ts);
20965 +
20966 +       do_gettimeofday(&tv);
20967 +       current->vx_info->cvirt.bias_tv.tv_sec =
20968 +               ts->tv_sec - tv.tv_sec;
20969 +       current->vx_info->cvirt.bias_tv.tv_usec =
20970 +               (ts->tv_nsec/NSEC_PER_USEC) - tv.tv_usec;
20971 +       return 0;
20972 +}
20973 +
20974 +#endif
20975 +
20976 diff -Nurp linux-2.6.22.18/kernel/vserver/cvirt_init.h linux-2.6.22.18-vs2.3.0.32/kernel/vserver/cvirt_init.h
20977 --- linux-2.6.22.18/kernel/vserver/cvirt_init.h 1970-01-01 01:00:00.000000000 +0100
20978 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/cvirt_init.h      2008-02-11 12:35:38.000000000 +0100
20979 @@ -0,0 +1,69 @@
20980 +
20981 +
20982 +extern uint64_t vx_idle_jiffies(void);
20983 +
20984 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
20985 +{
20986 +       uint64_t idle_jiffies = vx_idle_jiffies();
20987 +       uint64_t nsuptime;
20988 +
20989 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
20990 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
20991 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
20992 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
20993 +       cvirt->bias_tv.tv_sec = 0;
20994 +       cvirt->bias_tv.tv_usec = 0;
20995 +
20996 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
20997 +       atomic_set(&cvirt->nr_threads, 0);
20998 +       atomic_set(&cvirt->nr_running, 0);
20999 +       atomic_set(&cvirt->nr_uninterruptible, 0);
21000 +       atomic_set(&cvirt->nr_onhold, 0);
21001 +
21002 +       spin_lock_init(&cvirt->load_lock);
21003 +       cvirt->load_last = jiffies;
21004 +       atomic_set(&cvirt->load_updates, 0);
21005 +       cvirt->load[0] = 0;
21006 +       cvirt->load[1] = 0;
21007 +       cvirt->load[2] = 0;
21008 +       atomic_set(&cvirt->total_forks, 0);
21009 +
21010 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
21011 +       init_waitqueue_head(&cvirt->syslog.log_wait);
21012 +       cvirt->syslog.log_start = 0;
21013 +       cvirt->syslog.log_end = 0;
21014 +       cvirt->syslog.con_start = 0;
21015 +       cvirt->syslog.logged_chars = 0;
21016 +}
21017 +
21018 +static inline
21019 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
21020 +{
21021 +       // cvirt_pc->cpustat = { 0 };
21022 +}
21023 +
21024 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
21025 +{
21026 +       int value;
21027 +
21028 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
21029 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
21030 +               cvirt, value);
21031 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
21032 +               "!!! cvirt: %p[nr_running] = %d on exit.",
21033 +               cvirt, value);
21034 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
21035 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
21036 +               cvirt, value);
21037 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
21038 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
21039 +               cvirt, value);
21040 +       return;
21041 +}
21042 +
21043 +static inline
21044 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
21045 +{
21046 +       return;
21047 +}
21048 +
21049 diff -Nurp linux-2.6.22.18/kernel/vserver/cvirt_proc.h linux-2.6.22.18-vs2.3.0.32/kernel/vserver/cvirt_proc.h
21050 --- linux-2.6.22.18/kernel/vserver/cvirt_proc.h 1970-01-01 01:00:00.000000000 +0100
21051 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/cvirt_proc.h      2008-02-11 12:35:38.000000000 +0100
21052 @@ -0,0 +1,133 @@
21053 +#ifndef _VX_CVIRT_PROC_H
21054 +#define _VX_CVIRT_PROC_H
21055 +
21056 +#include <linux/nsproxy.h>
21057 +#include <linux/mnt_namespace.h>
21058 +#include <linux/utsname.h>
21059 +#include <linux/ipc.h>
21060 +
21061 +
21062 +static inline
21063 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
21064 +{
21065 +       struct mnt_namespace *ns;
21066 +       struct uts_namespace *uts;
21067 +       struct ipc_namespace *ipc;
21068 +       struct vfsmount *mnt;
21069 +       char *path, *root;
21070 +       int length = 0;
21071 +
21072 +       if (!nsproxy)
21073 +               goto out;
21074 +
21075 +       length += sprintf(buffer + length,
21076 +               "NSProxy:\t%p [%p,%p,%p]\n",
21077 +               nsproxy, nsproxy->mnt_ns,
21078 +               nsproxy->uts_ns, nsproxy->ipc_ns);
21079 +
21080 +       ns = nsproxy->mnt_ns;
21081 +       if (!ns)
21082 +               goto skip_ns;
21083 +
21084 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
21085 +       if (!path)
21086 +               goto skip_ns;
21087 +
21088 +       mnt = ns->root;
21089 +       root = d_path(mnt->mnt_root, mnt->mnt_parent, path, PATH_MAX - 2);
21090 +       length += sprintf(buffer + length,
21091 +               "Namespace:\t%p [#%u]\n"
21092 +               "RootPath:\t%s\n",
21093 +               ns, atomic_read(&ns->count),
21094 +               root);
21095 +       kfree(path);
21096 +skip_ns:
21097 +
21098 +       uts = nsproxy->uts_ns;
21099 +       if (!uts)
21100 +               goto skip_uts;
21101 +
21102 +       length += sprintf(buffer + length,
21103 +               "SysName:\t%.*s\n"
21104 +               "NodeName:\t%.*s\n"
21105 +               "Release:\t%.*s\n"
21106 +               "Version:\t%.*s\n"
21107 +               "Machine:\t%.*s\n"
21108 +               "DomainName:\t%.*s\n",
21109 +               __NEW_UTS_LEN, uts->name.sysname,
21110 +               __NEW_UTS_LEN, uts->name.nodename,
21111 +               __NEW_UTS_LEN, uts->name.release,
21112 +               __NEW_UTS_LEN, uts->name.version,
21113 +               __NEW_UTS_LEN, uts->name.machine,
21114 +               __NEW_UTS_LEN, uts->name.domainname);
21115 +skip_uts:
21116 +
21117 +       ipc = nsproxy->ipc_ns;
21118 +       if (!ipc)
21119 +               goto skip_ipc;
21120 +
21121 +       length += sprintf(buffer + length,
21122 +               "SEMS:\t\t%d %d %d %d  %d\n"
21123 +               "MSG:\t\t%d %d %d\n"
21124 +               "SHM:\t\t%lu %lu  %d %d\n",
21125 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
21126 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
21127 +               ipc->used_sems,
21128 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
21129 +               (unsigned long)ipc->shm_ctlmax,
21130 +               (unsigned long)ipc->shm_ctlall,
21131 +               ipc->shm_ctlmni, ipc->shm_tot);
21132 +skip_ipc:
21133 +out:
21134 +       return length;
21135 +}
21136 +
21137 +
21138 +#include <linux/sched.h>
21139 +
21140 +#define LOAD_INT(x) ((x) >> FSHIFT)
21141 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
21142 +
21143 +static inline
21144 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
21145 +{
21146 +       int length = 0;
21147 +       int a, b, c;
21148 +
21149 +       length += sprintf(buffer + length,
21150 +               "BiasUptime:\t%lu.%02lu\n",
21151 +               (unsigned long)cvirt->bias_uptime.tv_sec,
21152 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
21153 +
21154 +       a = cvirt->load[0] + (FIXED_1 / 200);
21155 +       b = cvirt->load[1] + (FIXED_1 / 200);
21156 +       c = cvirt->load[2] + (FIXED_1 / 200);
21157 +       length += sprintf(buffer + length,
21158 +               "nr_threads:\t%d\n"
21159 +               "nr_running:\t%d\n"
21160 +               "nr_unintr:\t%d\n"
21161 +               "nr_onhold:\t%d\n"
21162 +               "load_updates:\t%d\n"
21163 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
21164 +               "total_forks:\t%d\n",
21165 +               atomic_read(&cvirt->nr_threads),
21166 +               atomic_read(&cvirt->nr_running),
21167 +               atomic_read(&cvirt->nr_uninterruptible),
21168 +               atomic_read(&cvirt->nr_onhold),
21169 +               atomic_read(&cvirt->load_updates),
21170 +               LOAD_INT(a), LOAD_FRAC(a),
21171 +               LOAD_INT(b), LOAD_FRAC(b),
21172 +               LOAD_INT(c), LOAD_FRAC(c),
21173 +               atomic_read(&cvirt->total_forks));
21174 +       return length;
21175 +}
21176 +
21177 +static inline
21178 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
21179 +       char *buffer, int cpu)
21180 +{
21181 +       int length = 0;
21182 +       return length;
21183 +}
21184 +
21185 +#endif /* _VX_CVIRT_PROC_H */
21186 diff -Nurp linux-2.6.22.18/kernel/vserver/debug.c linux-2.6.22.18-vs2.3.0.32/kernel/vserver/debug.c
21187 --- linux-2.6.22.18/kernel/vserver/debug.c      1970-01-01 01:00:00.000000000 +0100
21188 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/debug.c   2008-02-11 12:35:38.000000000 +0100
21189 @@ -0,0 +1,32 @@
21190 +/*
21191 + *  kernel/vserver/debug.c
21192 + *
21193 + *  Copyright (C) 2005-2007 Herbert Pötzl
21194 + *
21195 + *  V0.01  vx_info dump support
21196 + *
21197 + */
21198 +
21199 +#include <linux/module.h>
21200 +
21201 +#include <linux/vserver/context.h>
21202 +
21203 +
21204 +void   dump_vx_info(struct vx_info *vxi, int level)
21205 +{
21206 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
21207 +               atomic_read(&vxi->vx_usecnt),
21208 +               atomic_read(&vxi->vx_tasks),
21209 +               vxi->vx_state);
21210 +       if (level > 0) {
21211 +               __dump_vx_limit(&vxi->limit);
21212 +               __dump_vx_sched(&vxi->sched);
21213 +               __dump_vx_cvirt(&vxi->cvirt);
21214 +               __dump_vx_cacct(&vxi->cacct);
21215 +       }
21216 +       printk("---\n");
21217 +}
21218 +
21219 +
21220 +EXPORT_SYMBOL_GPL(dump_vx_info);
21221 +
21222 diff -Nurp linux-2.6.22.18/kernel/vserver/device.c linux-2.6.22.18-vs2.3.0.32/kernel/vserver/device.c
21223 --- linux-2.6.22.18/kernel/vserver/device.c     1970-01-01 01:00:00.000000000 +0100
21224 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/device.c  2008-02-11 12:35:38.000000000 +0100
21225 @@ -0,0 +1,443 @@
21226 +/*
21227 + *  linux/kernel/vserver/device.c
21228 + *
21229 + *  Linux-VServer: Device Support
21230 + *
21231 + *  Copyright (C) 2006  Herbert Pötzl
21232 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
21233 + *
21234 + *  V0.01  device mapping basics
21235 + *  V0.02  added defaults
21236 + *
21237 + */
21238 +
21239 +#include <linux/slab.h>
21240 +#include <linux/rcupdate.h>
21241 +#include <linux/fs.h>
21242 +#include <linux/namei.h>
21243 +#include <linux/hash.h>
21244 +
21245 +#include <asm/errno.h>
21246 +#include <asm/uaccess.h>
21247 +#include <linux/vserver/base.h>
21248 +#include <linux/vserver/debug.h>
21249 +#include <linux/vserver/context.h>
21250 +#include <linux/vserver/device.h>
21251 +#include <linux/vserver/device_cmd.h>
21252 +
21253 +
21254 +#define DMAP_HASH_BITS 4
21255 +
21256 +
21257 +struct vs_mapping {
21258 +       union {
21259 +               struct hlist_node hlist;
21260 +               struct list_head list;
21261 +       } u;
21262 +#define dm_hlist       u.hlist
21263 +#define dm_list                u.list
21264 +       xid_t xid;
21265 +       dev_t device;
21266 +       struct vx_dmap_target target;
21267 +};
21268 +
21269 +
21270 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
21271 +
21272 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
21273 +
21274 +static struct vx_dmap_target dmap_defaults[2] = {
21275 +       { .flags = DATTR_OPEN },
21276 +       { .flags = DATTR_OPEN },
21277 +};
21278 +
21279 +
21280 +struct kmem_cache *dmap_cachep __read_mostly;
21281 +
21282 +int __init dmap_cache_init(void)
21283 +{
21284 +       dmap_cachep = kmem_cache_create("dmap_cache",
21285 +               sizeof(struct vs_mapping), 0,
21286 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
21287 +       return 0;
21288 +}
21289 +
21290 +__initcall(dmap_cache_init);
21291 +
21292 +
21293 +static inline unsigned int __hashval(dev_t dev, int bits)
21294 +{
21295 +       return hash_long((unsigned long)dev, bits);
21296 +}
21297 +
21298 +
21299 +/*     __hash_mapping()
21300 + *     add the mapping to the hash table
21301 + */
21302 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
21303 +{
21304 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
21305 +       struct hlist_head *head, *hash = dmap_main_hash;
21306 +       int device = vdm->device;
21307 +
21308 +       spin_lock(hash_lock);
21309 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
21310 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
21311 +
21312 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
21313 +       hlist_add_head(&vdm->dm_hlist, head);
21314 +       spin_unlock(hash_lock);
21315 +}
21316 +
21317 +
21318 +static inline int __mode_to_default(umode_t mode)
21319 +{
21320 +       switch (mode) {
21321 +       case S_IFBLK:
21322 +               return 0;
21323 +       case S_IFCHR:
21324 +               return 1;
21325 +       default:
21326 +               BUG();
21327 +       }
21328 +}
21329 +
21330 +
21331 +/*     __set_default()
21332 + *     set a default
21333 + */
21334 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
21335 +       struct vx_dmap_target *vdmt)
21336 +{
21337 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
21338 +       spin_lock(hash_lock);
21339 +
21340 +       if (vxi)
21341 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
21342 +       else
21343 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
21344 +
21345 +
21346 +       spin_unlock(hash_lock);
21347 +
21348 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
21349 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
21350 +}
21351 +
21352 +
21353 +/*     __remove_default()
21354 + *     remove a default
21355 + */
21356 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
21357 +{
21358 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
21359 +       spin_lock(hash_lock);
21360 +
21361 +       if (vxi)
21362 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
21363 +       else    /* remove == reset */
21364 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
21365 +
21366 +       spin_unlock(hash_lock);
21367 +       return 0;
21368 +}
21369 +
21370 +
21371 +/*     __find_mapping()
21372 + *     find a mapping in the hash table
21373 + *
21374 + *     caller must hold hash_lock
21375 + */
21376 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
21377 +       struct vs_mapping **local, struct vs_mapping **global)
21378 +{
21379 +       struct hlist_head *hash = dmap_main_hash;
21380 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
21381 +       struct hlist_node *pos;
21382 +       struct vs_mapping *vdm;
21383 +
21384 +       *local = NULL;
21385 +       if (global)
21386 +               *global = NULL;
21387 +
21388 +       hlist_for_each(pos, head) {
21389 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
21390 +
21391 +               if ((vdm->device == device) &&
21392 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
21393 +                       if (vdm->xid == xid) {
21394 +                               *local = vdm;
21395 +                               return 1;
21396 +                       } else if (global && vdm->xid == 0)
21397 +                               *global = vdm;
21398 +               }
21399 +       }
21400 +
21401 +       if (global && *global)
21402 +               return 0;
21403 +       else
21404 +               return -ENOENT;
21405 +}
21406 +
21407 +
21408 +/*     __lookup_mapping()
21409 + *     find a mapping and store the result in target and flags
21410 + */
21411 +static inline int __lookup_mapping(struct vx_info *vxi,
21412 +       dev_t device, dev_t *target, int *flags, umode_t mode)
21413 +{
21414 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
21415 +       struct vs_mapping *vdm, *global;
21416 +       struct vx_dmap_target *vdmt;
21417 +       int ret = 0;
21418 +       xid_t xid = vxi->vx_id;
21419 +       int index;
21420 +
21421 +       spin_lock(hash_lock);
21422 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
21423 +               ret = 1;
21424 +               vdmt = &vdm->target;
21425 +               goto found;
21426 +       }
21427 +
21428 +       index = __mode_to_default(mode);
21429 +       if (vxi && vxi->dmap.targets[index].flags) {
21430 +               ret = 2;
21431 +               vdmt = &vxi->dmap.targets[index];
21432 +       } else if (global) {
21433 +               ret = 3;
21434 +               vdmt = &global->target;
21435 +               goto found;
21436 +       } else {
21437 +               ret = 4;
21438 +               vdmt = &dmap_defaults[index];
21439 +       }
21440 +
21441 +found:
21442 +       if (target && (vdmt->flags & DATTR_REMAP))
21443 +               *target = vdmt->target;
21444 +       else if (target)
21445 +               *target = device;
21446 +       if (flags)
21447 +               *flags = vdmt->flags;
21448 +
21449 +       spin_unlock(hash_lock);
21450 +
21451 +       return ret;
21452 +}
21453 +
21454 +
21455 +/*     __remove_mapping()
21456 + *     remove a mapping from the hash table
21457 + */
21458 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
21459 +       umode_t mode)
21460 +{
21461 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
21462 +       struct vs_mapping *vdm = NULL;
21463 +       int ret = 0;
21464 +
21465 +       spin_lock(hash_lock);
21466 +
21467 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
21468 +               NULL);
21469 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
21470 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
21471 +       if (ret < 0)
21472 +               goto out;
21473 +       hlist_del(&vdm->dm_hlist);
21474 +
21475 +out:
21476 +       spin_unlock(hash_lock);
21477 +       if (vdm)
21478 +               kmem_cache_free(dmap_cachep, vdm);
21479 +       return ret;
21480 +}
21481 +
21482 +
21483 +
21484 +int vs_map_device(struct vx_info *vxi,
21485 +       dev_t device, dev_t *target, umode_t mode)
21486 +{
21487 +       int ret, flags = DATTR_MASK;
21488 +
21489 +       if (!vxi) {
21490 +               if (target)
21491 +                       *target = device;
21492 +               goto out;
21493 +       }
21494 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
21495 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
21496 +               device, target ? *target : 0, flags, mode, ret);
21497 +out:
21498 +       return (flags & DATTR_MASK);
21499 +}
21500 +
21501 +
21502 +
21503 +static int do_set_mapping(struct vx_info *vxi,
21504 +       dev_t device, dev_t target, int flags, umode_t mode)
21505 +{
21506 +       if (device) {
21507 +               struct vs_mapping *new;
21508 +
21509 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
21510 +               if (!new)
21511 +                       return -ENOMEM;
21512 +
21513 +               INIT_HLIST_NODE(&new->dm_hlist);
21514 +               new->device = device;
21515 +               new->target.target = target;
21516 +               new->target.flags = flags | mode;
21517 +               new->xid = (vxi ? vxi->vx_id : 0);
21518 +
21519 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
21520 +               __hash_mapping(vxi, new);
21521 +       } else {
21522 +               struct vx_dmap_target new = {
21523 +                       .target = target,
21524 +                       .flags = flags | mode,
21525 +               };
21526 +               __set_default(vxi, mode, &new);
21527 +       }
21528 +       return 0;
21529 +}
21530 +
21531 +
21532 +static int do_unset_mapping(struct vx_info *vxi,
21533 +       dev_t device, dev_t target, int flags, umode_t mode)
21534 +{
21535 +       int ret = -EINVAL;
21536 +
21537 +       if (device) {
21538 +               ret = __remove_mapping(vxi, device, mode);
21539 +               if (ret < 0)
21540 +                       goto out;
21541 +       } else {
21542 +               ret = __remove_default(vxi, mode);
21543 +               if (ret < 0)
21544 +                       goto out;
21545 +       }
21546 +
21547 +out:
21548 +       return ret;
21549 +}
21550 +
21551 +
21552 +static inline int __user_device(const char __user *name, dev_t *dev,
21553 +       umode_t *mode)
21554 +{
21555 +       struct nameidata nd;
21556 +       int ret;
21557 +
21558 +       if (!name) {
21559 +               *dev = 0;
21560 +               return 0;
21561 +       }
21562 +       ret = user_path_walk_link(name, &nd);
21563 +       if (ret)
21564 +               return ret;
21565 +       if (nd.dentry->d_inode) {
21566 +               *dev = nd.dentry->d_inode->i_rdev;
21567 +               *mode = nd.dentry->d_inode->i_mode;
21568 +       }
21569 +       path_release(&nd);
21570 +       return 0;
21571 +}
21572 +
21573 +static inline int __mapping_mode(dev_t device, dev_t target,
21574 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
21575 +{
21576 +       if (device)
21577 +               *mode = device_mode & S_IFMT;
21578 +       else if (target)
21579 +               *mode = target_mode & S_IFMT;
21580 +       else
21581 +               *mode = 0;
21582 +
21583 +       /* if both given, device and target mode have to match */
21584 +       if (device && target &&
21585 +               ((device_mode ^ target_mode) & S_IFMT))
21586 +               return -EINVAL;
21587 +       return 0;
21588 +}
21589 +
21590 +
21591 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
21592 +       const char __user *target_path, int flags, int set)
21593 +{
21594 +       dev_t device = ~0, target = ~0;
21595 +       umode_t device_mode = 0, target_mode = 0, mode;
21596 +       int ret;
21597 +
21598 +       ret = __user_device(device_path, &device, &device_mode);
21599 +       if (ret)
21600 +               return ret;
21601 +       ret = __user_device(target_path, &target, &target_mode);
21602 +       if (ret)
21603 +               return ret;
21604 +
21605 +       ret = __mapping_mode(device, target,
21606 +               device_mode, target_mode, &mode);
21607 +       if (ret)
21608 +               return ret;
21609 +
21610 +       if (set)
21611 +               return do_set_mapping(vxi, device, target,
21612 +                       flags, mode);
21613 +       else
21614 +               return do_unset_mapping(vxi, device, target,
21615 +                       flags, mode);
21616 +}
21617 +
21618 +
21619 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
21620 +{
21621 +       struct vcmd_set_mapping_v0 vc_data;
21622 +
21623 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21624 +               return -EFAULT;
21625 +
21626 +       return do_mapping(vxi, vc_data.device, vc_data.target,
21627 +               vc_data.flags, 1);
21628 +}
21629 +
21630 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
21631 +{
21632 +       struct vcmd_set_mapping_v0 vc_data;
21633 +
21634 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21635 +               return -EFAULT;
21636 +
21637 +       return do_mapping(vxi, vc_data.device, vc_data.target,
21638 +               vc_data.flags, 0);
21639 +}
21640 +
21641 +
21642 +#ifdef CONFIG_COMPAT
21643 +
21644 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
21645 +{
21646 +       struct vcmd_set_mapping_v0_x32 vc_data;
21647 +
21648 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21649 +               return -EFAULT;
21650 +
21651 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
21652 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
21653 +}
21654 +
21655 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
21656 +{
21657 +       struct vcmd_set_mapping_v0_x32 vc_data;
21658 +
21659 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21660 +               return -EFAULT;
21661 +
21662 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
21663 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
21664 +}
21665 +
21666 +#endif /* CONFIG_COMPAT */
21667 +
21668 +
21669 diff -Nurp linux-2.6.22.18/kernel/vserver/dlimit.c linux-2.6.22.18-vs2.3.0.32/kernel/vserver/dlimit.c
21670 --- linux-2.6.22.18/kernel/vserver/dlimit.c     1970-01-01 01:00:00.000000000 +0100
21671 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/dlimit.c  2008-02-11 12:35:38.000000000 +0100
21672 @@ -0,0 +1,520 @@
21673 +/*
21674 + *  linux/kernel/vserver/dlimit.c
21675 + *
21676 + *  Virtual Server: Context Disk Limits
21677 + *
21678 + *  Copyright (C) 2004-2007  Herbert Pötzl
21679 + *
21680 + *  V0.01  initial version
21681 + *  V0.02  compat32 splitup
21682 + *
21683 + */
21684 +
21685 +#include <linux/statfs.h>
21686 +#include <linux/vs_tag.h>
21687 +#include <linux/vs_dlimit.h>
21688 +#include <linux/vserver/dlimit_cmd.h>
21689 +
21690 +#include <asm/uaccess.h>
21691 +
21692 +/*     __alloc_dl_info()
21693 +
21694 +       * allocate an initialized dl_info struct
21695 +       * doesn't make it visible (hash)                        */
21696 +
21697 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
21698 +{
21699 +       struct dl_info *new = NULL;
21700 +
21701 +       vxdprintk(VXD_CBIT(dlim, 5),
21702 +               "alloc_dl_info(%p,%d)*", sb, tag);
21703 +
21704 +       /* would this benefit from a slab cache? */
21705 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
21706 +       if (!new)
21707 +               return 0;
21708 +
21709 +       memset(new, 0, sizeof(struct dl_info));
21710 +       new->dl_tag = tag;
21711 +       new->dl_sb = sb;
21712 +       INIT_RCU_HEAD(&new->dl_rcu);
21713 +       INIT_HLIST_NODE(&new->dl_hlist);
21714 +       spin_lock_init(&new->dl_lock);
21715 +       atomic_set(&new->dl_refcnt, 0);
21716 +       atomic_set(&new->dl_usecnt, 0);
21717 +
21718 +       /* rest of init goes here */
21719 +
21720 +       vxdprintk(VXD_CBIT(dlim, 4),
21721 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
21722 +       return new;
21723 +}
21724 +
21725 +/*     __dealloc_dl_info()
21726 +
21727 +       * final disposal of dl_info                             */
21728 +
21729 +static void __dealloc_dl_info(struct dl_info *dli)
21730 +{
21731 +       vxdprintk(VXD_CBIT(dlim, 4),
21732 +               "dealloc_dl_info(%p)", dli);
21733 +
21734 +       dli->dl_hlist.next = LIST_POISON1;
21735 +       dli->dl_tag = -1;
21736 +       dli->dl_sb = 0;
21737 +
21738 +       BUG_ON(atomic_read(&dli->dl_usecnt));
21739 +       BUG_ON(atomic_read(&dli->dl_refcnt));
21740 +
21741 +       kfree(dli);
21742 +}
21743 +
21744 +
21745 +/*     hash table for dl_info hash */
21746 +
21747 +#define DL_HASH_SIZE   13
21748 +
21749 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
21750 +
21751 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
21752 +
21753 +
21754 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
21755 +{
21756 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
21757 +}
21758 +
21759 +
21760 +
21761 +/*     __hash_dl_info()
21762 +
21763 +       * add the dli to the global hash table
21764 +       * requires the hash_lock to be held                     */
21765 +
21766 +static inline void __hash_dl_info(struct dl_info *dli)
21767 +{
21768 +       struct hlist_head *head;
21769 +
21770 +       vxdprintk(VXD_CBIT(dlim, 6),
21771 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
21772 +       get_dl_info(dli);
21773 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
21774 +       hlist_add_head_rcu(&dli->dl_hlist, head);
21775 +}
21776 +
21777 +/*     __unhash_dl_info()
21778 +
21779 +       * remove the dli from the global hash table
21780 +       * requires the hash_lock to be held                     */
21781 +
21782 +static inline void __unhash_dl_info(struct dl_info *dli)
21783 +{
21784 +       vxdprintk(VXD_CBIT(dlim, 6),
21785 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
21786 +       hlist_del_rcu(&dli->dl_hlist);
21787 +       put_dl_info(dli);
21788 +}
21789 +
21790 +
21791 +/*     __lookup_dl_info()
21792 +
21793 +       * requires the rcu_read_lock()
21794 +       * doesn't increment the dl_refcnt                       */
21795 +
21796 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
21797 +{
21798 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
21799 +       struct hlist_node *pos;
21800 +       struct dl_info *dli;
21801 +
21802 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
21803 +
21804 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
21805 +                       return dli;
21806 +               }
21807 +       }
21808 +       return NULL;
21809 +}
21810 +
21811 +
21812 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
21813 +{
21814 +       struct dl_info *dli;
21815 +
21816 +       rcu_read_lock();
21817 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
21818 +       vxdprintk(VXD_CBIT(dlim, 7),
21819 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
21820 +       rcu_read_unlock();
21821 +       return dli;
21822 +}
21823 +
21824 +void rcu_free_dl_info(struct rcu_head *head)
21825 +{
21826 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
21827 +       int usecnt, refcnt;
21828 +
21829 +       BUG_ON(!dli || !head);
21830 +
21831 +       usecnt = atomic_read(&dli->dl_usecnt);
21832 +       BUG_ON(usecnt < 0);
21833 +
21834 +       refcnt = atomic_read(&dli->dl_refcnt);
21835 +       BUG_ON(refcnt < 0);
21836 +
21837 +       vxdprintk(VXD_CBIT(dlim, 3),
21838 +               "rcu_free_dl_info(%p)", dli);
21839 +       if (!usecnt)
21840 +               __dealloc_dl_info(dli);
21841 +       else
21842 +               printk("!!! rcu didn't free\n");
21843 +}
21844 +
21845 +
21846 +
21847 +
21848 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
21849 +       uint32_t flags, int add)
21850 +{
21851 +       struct nameidata nd;
21852 +       int ret;
21853 +
21854 +       ret = user_path_walk_link(name, &nd);
21855 +       if (!ret) {
21856 +               struct super_block *sb;
21857 +               struct dl_info *dli;
21858 +
21859 +               ret = -EINVAL;
21860 +               if (!nd.dentry->d_inode)
21861 +                       goto out_release;
21862 +               if (!(sb = nd.dentry->d_inode->i_sb))
21863 +                       goto out_release;
21864 +
21865 +               if (add) {
21866 +                       dli = __alloc_dl_info(sb, id);
21867 +                       spin_lock(&dl_info_hash_lock);
21868 +
21869 +                       ret = -EEXIST;
21870 +                       if (__lookup_dl_info(sb, id))
21871 +                               goto out_unlock;
21872 +                       __hash_dl_info(dli);
21873 +                       dli = NULL;
21874 +               } else {
21875 +                       spin_lock(&dl_info_hash_lock);
21876 +                       dli = __lookup_dl_info(sb, id);
21877 +
21878 +                       ret = -ESRCH;
21879 +                       if (!dli)
21880 +                               goto out_unlock;
21881 +                       __unhash_dl_info(dli);
21882 +               }
21883 +               ret = 0;
21884 +       out_unlock:
21885 +               spin_unlock(&dl_info_hash_lock);
21886 +               if (add && dli)
21887 +                       __dealloc_dl_info(dli);
21888 +       out_release:
21889 +               path_release(&nd);
21890 +       }
21891 +       return ret;
21892 +}
21893 +
21894 +int vc_add_dlimit(uint32_t id, void __user *data)
21895 +{
21896 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
21897 +
21898 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21899 +               return -EFAULT;
21900 +
21901 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
21902 +}
21903 +
21904 +int vc_rem_dlimit(uint32_t id, void __user *data)
21905 +{
21906 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
21907 +
21908 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21909 +               return -EFAULT;
21910 +
21911 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
21912 +}
21913 +
21914 +#ifdef CONFIG_COMPAT
21915 +
21916 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
21917 +{
21918 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
21919 +
21920 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21921 +               return -EFAULT;
21922 +
21923 +       return do_addrem_dlimit(id,
21924 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
21925 +}
21926 +
21927 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
21928 +{
21929 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
21930 +
21931 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21932 +               return -EFAULT;
21933 +
21934 +       return do_addrem_dlimit(id,
21935 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
21936 +}
21937 +
21938 +#endif /* CONFIG_COMPAT */
21939 +
21940 +
21941 +static inline
21942 +int do_set_dlimit(uint32_t id, const char __user *name,
21943 +       uint32_t space_used, uint32_t space_total,
21944 +       uint32_t inodes_used, uint32_t inodes_total,
21945 +       uint32_t reserved, uint32_t flags)
21946 +{
21947 +       struct nameidata nd;
21948 +       int ret;
21949 +
21950 +       ret = user_path_walk_link(name, &nd);
21951 +       if (!ret) {
21952 +               struct super_block *sb;
21953 +               struct dl_info *dli;
21954 +
21955 +               ret = -EINVAL;
21956 +               if (!nd.dentry->d_inode)
21957 +                       goto out_release;
21958 +               if (!(sb = nd.dentry->d_inode->i_sb))
21959 +                       goto out_release;
21960 +               if ((reserved != CDLIM_KEEP &&
21961 +                       reserved > 100) ||
21962 +                       (inodes_used != CDLIM_KEEP &&
21963 +                       inodes_used > inodes_total) ||
21964 +                       (space_used != CDLIM_KEEP &&
21965 +                       space_used > space_total))
21966 +                       goto out_release;
21967 +
21968 +               ret = -ESRCH;
21969 +               dli = locate_dl_info(sb, id);
21970 +               if (!dli)
21971 +                       goto out_release;
21972 +
21973 +               spin_lock(&dli->dl_lock);
21974 +
21975 +               if (inodes_used != CDLIM_KEEP)
21976 +                       dli->dl_inodes_used = inodes_used;
21977 +               if (inodes_total != CDLIM_KEEP)
21978 +                       dli->dl_inodes_total = inodes_total;
21979 +               if (space_used != CDLIM_KEEP) {
21980 +                       dli->dl_space_used = space_used;
21981 +                       dli->dl_space_used <<= 10;
21982 +               }
21983 +               if (space_total == CDLIM_INFINITY)
21984 +                       dli->dl_space_total = DLIM_INFINITY;
21985 +               else if (space_total != CDLIM_KEEP) {
21986 +                       dli->dl_space_total = space_total;
21987 +                       dli->dl_space_total <<= 10;
21988 +               }
21989 +               if (reserved != CDLIM_KEEP)
21990 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
21991 +
21992 +               spin_unlock(&dli->dl_lock);
21993 +
21994 +               put_dl_info(dli);
21995 +               ret = 0;
21996 +
21997 +       out_release:
21998 +               path_release(&nd);
21999 +       }
22000 +       return ret;
22001 +}
22002 +
22003 +int vc_set_dlimit(uint32_t id, void __user *data)
22004 +{
22005 +       struct vcmd_ctx_dlimit_v0 vc_data;
22006 +
22007 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22008 +               return -EFAULT;
22009 +
22010 +       return do_set_dlimit(id, vc_data.name,
22011 +               vc_data.space_used, vc_data.space_total,
22012 +               vc_data.inodes_used, vc_data.inodes_total,
22013 +               vc_data.reserved, vc_data.flags);
22014 +}
22015 +
22016 +#ifdef CONFIG_COMPAT
22017 +
22018 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
22019 +{
22020 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
22021 +
22022 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22023 +               return -EFAULT;
22024 +
22025 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
22026 +               vc_data.space_used, vc_data.space_total,
22027 +               vc_data.inodes_used, vc_data.inodes_total,
22028 +               vc_data.reserved, vc_data.flags);
22029 +}
22030 +
22031 +#endif /* CONFIG_COMPAT */
22032 +
22033 +
22034 +static inline
22035 +int do_get_dlimit(uint32_t id, const char __user *name,
22036 +       uint32_t *space_used, uint32_t *space_total,
22037 +       uint32_t *inodes_used, uint32_t *inodes_total,
22038 +       uint32_t *reserved, uint32_t *flags)
22039 +{
22040 +       struct nameidata nd;
22041 +       int ret;
22042 +
22043 +       ret = user_path_walk_link(name, &nd);
22044 +       if (!ret) {
22045 +               struct super_block *sb;
22046 +               struct dl_info *dli;
22047 +
22048 +               ret = -EINVAL;
22049 +               if (!nd.dentry->d_inode)
22050 +                       goto out_release;
22051 +               if (!(sb = nd.dentry->d_inode->i_sb))
22052 +                       goto out_release;
22053 +
22054 +               ret = -ESRCH;
22055 +               dli = locate_dl_info(sb, id);
22056 +               if (!dli)
22057 +                       goto out_release;
22058 +
22059 +               spin_lock(&dli->dl_lock);
22060 +               *inodes_used = dli->dl_inodes_used;
22061 +               *inodes_total = dli->dl_inodes_total;
22062 +               *space_used = dli->dl_space_used >> 10;
22063 +               if (dli->dl_space_total == DLIM_INFINITY)
22064 +                       *space_total = CDLIM_INFINITY;
22065 +               else
22066 +                       *space_total = dli->dl_space_total >> 10;
22067 +
22068 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
22069 +               spin_unlock(&dli->dl_lock);
22070 +
22071 +               put_dl_info(dli);
22072 +               ret = -EFAULT;
22073 +
22074 +               ret = 0;
22075 +       out_release:
22076 +               path_release(&nd);
22077 +       }
22078 +       return ret;
22079 +}
22080 +
22081 +
22082 +int vc_get_dlimit(uint32_t id, void __user *data)
22083 +{
22084 +       struct vcmd_ctx_dlimit_v0 vc_data;
22085 +       int ret;
22086 +
22087 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22088 +               return -EFAULT;
22089 +
22090 +       ret = do_get_dlimit(id, vc_data.name,
22091 +               &vc_data.space_used, &vc_data.space_total,
22092 +               &vc_data.inodes_used, &vc_data.inodes_total,
22093 +               &vc_data.reserved, &vc_data.flags);
22094 +       if (ret)
22095 +               return ret;
22096 +
22097 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22098 +               return -EFAULT;
22099 +       return 0;
22100 +}
22101 +
22102 +#ifdef CONFIG_COMPAT
22103 +
22104 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
22105 +{
22106 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
22107 +       int ret;
22108 +
22109 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22110 +               return -EFAULT;
22111 +
22112 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
22113 +               &vc_data.space_used, &vc_data.space_total,
22114 +               &vc_data.inodes_used, &vc_data.inodes_total,
22115 +               &vc_data.reserved, &vc_data.flags);
22116 +       if (ret)
22117 +               return ret;
22118 +
22119 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22120 +               return -EFAULT;
22121 +       return 0;
22122 +}
22123 +
22124 +#endif /* CONFIG_COMPAT */
22125 +
22126 +
22127 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
22128 +{
22129 +       struct dl_info *dli;
22130 +       __u64 blimit, bfree, bavail;
22131 +       __u32 ifree;
22132 +
22133 +       dli = locate_dl_info(sb, dx_current_tag());
22134 +       if (!dli)
22135 +               return;
22136 +
22137 +       spin_lock(&dli->dl_lock);
22138 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
22139 +               goto no_ilim;
22140 +
22141 +       /* reduce max inodes available to limit */
22142 +       if (buf->f_files > dli->dl_inodes_total)
22143 +               buf->f_files = dli->dl_inodes_total;
22144 +
22145 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
22146 +       /* reduce free inodes to min */
22147 +       if (ifree < buf->f_ffree)
22148 +               buf->f_ffree = ifree;
22149 +
22150 +no_ilim:
22151 +       if (dli->dl_space_total == DLIM_INFINITY)
22152 +               goto no_blim;
22153 +
22154 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
22155 +
22156 +       if (dli->dl_space_total < dli->dl_space_used)
22157 +               bfree = 0;
22158 +       else
22159 +               bfree = (dli->dl_space_total - dli->dl_space_used)
22160 +                       >> sb->s_blocksize_bits;
22161 +
22162 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
22163 +       if (bavail < dli->dl_space_used)
22164 +               bavail = 0;
22165 +       else
22166 +               bavail = (bavail - dli->dl_space_used)
22167 +                       >> sb->s_blocksize_bits;
22168 +
22169 +       /* reduce max space available to limit */
22170 +       if (buf->f_blocks > blimit)
22171 +               buf->f_blocks = blimit;
22172 +
22173 +       /* reduce free space to min */
22174 +       if (bfree < buf->f_bfree)
22175 +               buf->f_bfree = bfree;
22176 +
22177 +       /* reduce avail space to min */
22178 +       if (bavail < buf->f_bavail)
22179 +               buf->f_bavail = bavail;
22180 +
22181 +no_blim:
22182 +       spin_unlock(&dli->dl_lock);
22183 +       put_dl_info(dli);
22184 +
22185 +       return;
22186 +}
22187 +
22188 +#include <linux/module.h>
22189 +
22190 +EXPORT_SYMBOL_GPL(locate_dl_info);
22191 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
22192 +
22193 diff -Nurp linux-2.6.22.18/kernel/vserver/helper.c linux-2.6.22.18-vs2.3.0.32/kernel/vserver/helper.c
22194 --- linux-2.6.22.18/kernel/vserver/helper.c     1970-01-01 01:00:00.000000000 +0100
22195 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/helper.c  2008-02-11 12:35:38.000000000 +0100
22196 @@ -0,0 +1,199 @@
22197 +/*
22198 + *  linux/kernel/vserver/helper.c
22199 + *
22200 + *  Virtual Context Support
22201 + *
22202 + *  Copyright (C) 2004-2007  Herbert Pötzl
22203 + *
22204 + *  V0.01  basic helper
22205 + *
22206 + */
22207 +
22208 +#include <linux/kmod.h>
22209 +#include <linux/reboot.h>
22210 +#include <linux/vs_context.h>
22211 +#include <linux/vs_network.h>
22212 +#include <linux/vserver/signal.h>
22213 +
22214 +
22215 +char vshelper_path[255] = "/sbin/vshelper";
22216 +
22217 +
22218 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
22219 +{
22220 +       int ret;
22221 +
22222 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
22223 +               printk( KERN_WARNING
22224 +                       "%s: (%s %s) returned %s with %d\n",
22225 +                       name, argv[1], argv[2],
22226 +                       sync ? "sync" : "async", ret);
22227 +       }
22228 +       vxdprintk(VXD_CBIT(switch, 4),
22229 +               "%s: (%s %s) returned %s with %d",
22230 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
22231 +       return ret;
22232 +}
22233 +
22234 +/*
22235 + *      vshelper path is set via /proc/sys
22236 + *      invoked by vserver sys_reboot(), with
22237 + *      the following arguments
22238 + *
22239 + *      argv [0] = vshelper_path;
22240 + *      argv [1] = action: "restart", "halt", "poweroff", ...
22241 + *      argv [2] = context identifier
22242 + *
22243 + *      envp [*] = type-specific parameters
22244 + */
22245 +
22246 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
22247 +{
22248 +       char id_buf[8], cmd_buf[16];
22249 +       char uid_buf[16], pid_buf[16];
22250 +       int ret;
22251 +
22252 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
22253 +       char *envp[] = {"HOME=/", "TERM=linux",
22254 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
22255 +                       uid_buf, pid_buf, cmd_buf, 0};
22256 +
22257 +       if (vx_info_state(vxi, VXS_HELPER))
22258 +               return -EAGAIN;
22259 +       vxi->vx_state |= VXS_HELPER;
22260 +
22261 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
22262 +
22263 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
22264 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current->uid);
22265 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
22266 +
22267 +       switch (cmd) {
22268 +       case LINUX_REBOOT_CMD_RESTART:
22269 +               argv[1] = "restart";
22270 +               break;
22271 +
22272 +       case LINUX_REBOOT_CMD_HALT:
22273 +               argv[1] = "halt";
22274 +               break;
22275 +
22276 +       case LINUX_REBOOT_CMD_POWER_OFF:
22277 +               argv[1] = "poweroff";
22278 +               break;
22279 +
22280 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
22281 +               argv[1] = "swsusp";
22282 +               break;
22283 +
22284 +       default:
22285 +               vxi->vx_state &= ~VXS_HELPER;
22286 +               return 0;
22287 +       }
22288 +
22289 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
22290 +       vxi->vx_state &= ~VXS_HELPER;
22291 +       __wakeup_vx_info(vxi);
22292 +       return (ret) ? -EPERM : 0;
22293 +}
22294 +
22295 +
22296 +long vs_reboot(unsigned int cmd, void __user *arg)
22297 +{
22298 +       struct vx_info *vxi = current->vx_info;
22299 +       long ret = 0;
22300 +
22301 +       vxdprintk(VXD_CBIT(misc, 5),
22302 +               "vs_reboot(%p[#%d],%d)",
22303 +               vxi, vxi ? vxi->vx_id : 0, cmd);
22304 +
22305 +       ret = vs_reboot_helper(vxi, cmd, arg);
22306 +       if (ret)
22307 +               return ret;
22308 +
22309 +       vxi->reboot_cmd = cmd;
22310 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
22311 +               switch (cmd) {
22312 +               case LINUX_REBOOT_CMD_RESTART:
22313 +               case LINUX_REBOOT_CMD_HALT:
22314 +               case LINUX_REBOOT_CMD_POWER_OFF:
22315 +                       vx_info_kill(vxi, 0, SIGKILL);
22316 +                       vx_info_kill(vxi, 1, SIGKILL);
22317 +               default:
22318 +                       break;
22319 +               }
22320 +       }
22321 +       return 0;
22322 +}
22323 +
22324 +
22325 +/*
22326 + *      argv [0] = vshelper_path;
22327 + *      argv [1] = action: "startup", "shutdown"
22328 + *      argv [2] = context identifier
22329 + *
22330 + *      envp [*] = type-specific parameters
22331 + */
22332 +
22333 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
22334 +{
22335 +       char id_buf[8], cmd_buf[16];
22336 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
22337 +       char *envp[] = {"HOME=/", "TERM=linux",
22338 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
22339 +
22340 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
22341 +               return 0;
22342 +
22343 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
22344 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
22345 +
22346 +       switch (cmd) {
22347 +       case VSC_STARTUP:
22348 +               argv[1] = "startup";
22349 +               break;
22350 +       case VSC_SHUTDOWN:
22351 +               argv[1] = "shutdown";
22352 +               break;
22353 +       default:
22354 +               return 0;
22355 +       }
22356 +
22357 +       return do_vshelper(vshelper_path, argv, envp, 1);
22358 +}
22359 +
22360 +
22361 +/*
22362 + *      argv [0] = vshelper_path;
22363 + *      argv [1] = action: "netup", "netdown"
22364 + *      argv [2] = context identifier
22365 + *
22366 + *      envp [*] = type-specific parameters
22367 + */
22368 +
22369 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
22370 +{
22371 +       char id_buf[8], cmd_buf[16];
22372 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
22373 +       char *envp[] = {"HOME=/", "TERM=linux",
22374 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
22375 +
22376 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
22377 +               return 0;
22378 +
22379 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
22380 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
22381 +
22382 +       switch (cmd) {
22383 +       case VSC_NETUP:
22384 +               argv[1] = "netup";
22385 +               break;
22386 +       case VSC_NETDOWN:
22387 +               argv[1] = "netdown";
22388 +               break;
22389 +       default:
22390 +               return 0;
22391 +       }
22392 +
22393 +       return do_vshelper(vshelper_path, argv, envp, 1);
22394 +}
22395 +
22396 diff -Nurp linux-2.6.22.18/kernel/vserver/history.c linux-2.6.22.18-vs2.3.0.32/kernel/vserver/history.c
22397 --- linux-2.6.22.18/kernel/vserver/history.c    1970-01-01 01:00:00.000000000 +0100
22398 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/history.c 2008-02-11 12:35:38.000000000 +0100
22399 @@ -0,0 +1,258 @@
22400 +/*
22401 + *  kernel/vserver/history.c
22402 + *
22403 + *  Virtual Context History Backtrace
22404 + *
22405 + *  Copyright (C) 2004-2007  Herbert Pötzl
22406 + *
22407 + *  V0.01  basic structure
22408 + *  V0.02  hash/unhash and trace
22409 + *  V0.03  preemption fixes
22410 + *
22411 + */
22412 +
22413 +#include <linux/module.h>
22414 +#include <asm/uaccess.h>
22415 +
22416 +#include <linux/vserver/context.h>
22417 +#include <linux/vserver/debug.h>
22418 +#include <linux/vserver/debug_cmd.h>
22419 +#include <linux/vserver/history.h>
22420 +
22421 +
22422 +#ifdef CONFIG_VSERVER_HISTORY
22423 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
22424 +#else
22425 +#define VXH_SIZE       64
22426 +#endif
22427 +
22428 +struct _vx_history {
22429 +       unsigned int counter;
22430 +
22431 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
22432 +};
22433 +
22434 +
22435 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
22436 +
22437 +unsigned volatile int vxh_active = 1;
22438 +
22439 +static atomic_t sequence = ATOMIC_INIT(0);
22440 +
22441 +
22442 +/*     vxh_advance()
22443 +
22444 +       * requires disabled preemption                          */
22445 +
22446 +struct _vx_hist_entry *vxh_advance(void *loc)
22447 +{
22448 +       unsigned int cpu = smp_processor_id();
22449 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
22450 +       struct _vx_hist_entry *entry;
22451 +       unsigned int index;
22452 +
22453 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
22454 +       entry = &hist->entry[index];
22455 +
22456 +       entry->seq = atomic_inc_return(&sequence);
22457 +       entry->loc = loc;
22458 +       return entry;
22459 +}
22460 +
22461 +EXPORT_SYMBOL_GPL(vxh_advance);
22462 +
22463 +
22464 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
22465 +
22466 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
22467 +
22468 +
22469 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
22470 +
22471 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
22472 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
22473 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
22474 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
22475 +
22476 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
22477 +{
22478 +       switch (e->type) {
22479 +       case VXH_THROW_OOPS:
22480 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
22481 +               break;
22482 +
22483 +       case VXH_GET_VX_INFO:
22484 +       case VXH_PUT_VX_INFO:
22485 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
22486 +                       VXH_LOC_ARGS(e),
22487 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
22488 +                       VXH_VXI_ARGS(e));
22489 +               break;
22490 +
22491 +       case VXH_INIT_VX_INFO:
22492 +       case VXH_SET_VX_INFO:
22493 +       case VXH_CLR_VX_INFO:
22494 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
22495 +                       VXH_LOC_ARGS(e),
22496 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
22497 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
22498 +                       VXH_VXI_ARGS(e), e->sc.data);
22499 +               break;
22500 +
22501 +       case VXH_CLAIM_VX_INFO:
22502 +       case VXH_RELEASE_VX_INFO:
22503 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
22504 +                       VXH_LOC_ARGS(e),
22505 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
22506 +                       VXH_VXI_ARGS(e), e->sc.data);
22507 +               break;
22508 +
22509 +       case VXH_ALLOC_VX_INFO:
22510 +       case VXH_DEALLOC_VX_INFO:
22511 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
22512 +                       VXH_LOC_ARGS(e),
22513 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
22514 +                       VXH_VXI_ARGS(e));
22515 +               break;
22516 +
22517 +       case VXH_HASH_VX_INFO:
22518 +       case VXH_UNHASH_VX_INFO:
22519 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
22520 +                       VXH_LOC_ARGS(e),
22521 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
22522 +                       VXH_VXI_ARGS(e));
22523 +               break;
22524 +
22525 +       case VXH_LOC_VX_INFO:
22526 +       case VXH_LOOKUP_VX_INFO:
22527 +       case VXH_CREATE_VX_INFO:
22528 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
22529 +                       VXH_LOC_ARGS(e),
22530 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
22531 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
22532 +                       e->ll.arg, VXH_VXI_ARGS(e));
22533 +               break;
22534 +       }
22535 +}
22536 +
22537 +static void __vxh_dump_history(void)
22538 +{
22539 +       unsigned int i, cpu;
22540 +
22541 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
22542 +               atomic_read(&sequence), NR_CPUS);
22543 +
22544 +       for (i = 0; i < VXH_SIZE; i++) {
22545 +               for_each_online_cpu(cpu) {
22546 +                       struct _vx_history *hist =
22547 +                               &per_cpu(vx_history_buffer, cpu);
22548 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
22549 +                       struct _vx_hist_entry *entry = &hist->entry[index];
22550 +
22551 +                       vxh_dump_entry(entry, cpu);
22552 +               }
22553 +       }
22554 +}
22555 +
22556 +void   vxh_dump_history(void)
22557 +{
22558 +       vxh_active = 0;
22559 +#ifdef CONFIG_SMP
22560 +       local_irq_enable();
22561 +       smp_send_stop();
22562 +       local_irq_disable();
22563 +#endif
22564 +       __vxh_dump_history();
22565 +}
22566 +
22567 +
22568 +/* vserver syscall commands below here */
22569 +
22570 +
22571 +int vc_dump_history(uint32_t id)
22572 +{
22573 +       vxh_active = 0;
22574 +       __vxh_dump_history();
22575 +       vxh_active = 1;
22576 +
22577 +       return 0;
22578 +}
22579 +
22580 +
22581 +int do_read_history(struct __user _vx_hist_entry *data,
22582 +       int cpu, uint32_t *index, uint32_t *count)
22583 +{
22584 +       int pos, ret = 0;
22585 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
22586 +       int end = hist->counter;
22587 +       int start = end - VXH_SIZE + 2;
22588 +       int idx = *index;
22589 +
22590 +       /* special case: get current pos */
22591 +       if (!*count) {
22592 +               *index = end;
22593 +               return 0;
22594 +       }
22595 +
22596 +       /* have we lost some data? */
22597 +       if (idx < start)
22598 +               idx = start;
22599 +
22600 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
22601 +               struct _vx_hist_entry *entry =
22602 +                       &hist->entry[idx % VXH_SIZE];
22603 +
22604 +               /* send entry to userspace */
22605 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
22606 +               if (ret)
22607 +                       break;
22608 +       }
22609 +       /* save new index and count */
22610 +       *index = idx;
22611 +       *count = pos;
22612 +       return ret ? ret : (*index < end);
22613 +}
22614 +
22615 +int vc_read_history(uint32_t id, void __user *data)
22616 +{
22617 +       struct vcmd_read_history_v0 vc_data;
22618 +       int ret;
22619 +
22620 +       if (id >= NR_CPUS)
22621 +               return -EINVAL;
22622 +
22623 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22624 +               return -EFAULT;
22625 +
22626 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
22627 +               id, &vc_data.index, &vc_data.count);
22628 +
22629 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22630 +               return -EFAULT;
22631 +       return ret;
22632 +}
22633 +
22634 +#ifdef CONFIG_COMPAT
22635 +
22636 +int vc_read_history_x32(uint32_t id, void __user *data)
22637 +{
22638 +       struct vcmd_read_history_v0_x32 vc_data;
22639 +       int ret;
22640 +
22641 +       if (id >= NR_CPUS)
22642 +               return -EINVAL;
22643 +
22644 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22645 +               return -EFAULT;
22646 +
22647 +       ret = do_read_history((struct __user _vx_hist_entry *)
22648 +               compat_ptr(vc_data.data_ptr),
22649 +               id, &vc_data.index, &vc_data.count);
22650 +
22651 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22652 +               return -EFAULT;
22653 +       return ret;
22654 +}
22655 +
22656 +#endif /* CONFIG_COMPAT */
22657 +
22658 diff -Nurp linux-2.6.22.18/kernel/vserver/inet.c linux-2.6.22.18-vs2.3.0.32/kernel/vserver/inet.c
22659 --- linux-2.6.22.18/kernel/vserver/inet.c       1970-01-01 01:00:00.000000000 +0100
22660 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/inet.c    2008-02-11 12:35:38.000000000 +0100
22661 @@ -0,0 +1,222 @@
22662 +
22663 +#include <linux/in.h>
22664 +#include <linux/inetdevice.h>
22665 +#include <linux/vs_inet6.h>
22666 +#include <linux/vserver/debug.h>
22667 +#include <net/route.h>
22668 +#include <net/addrconf.h>
22669 +
22670 +
22671 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
22672 +{
22673 +       int ret = 0;
22674 +
22675 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
22676 +               ret = 1;
22677 +       else {
22678 +               struct nx_addr_v4 *ptr;
22679 +
22680 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
22681 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
22682 +                               ret = 1;
22683 +                               break;
22684 +                       }
22685 +               }
22686 +       }
22687 +
22688 +       vxdprintk(VXD_CBIT(net, 2),
22689 +               "nx_v4_addr_conflict(%p,%p): %d",
22690 +               nxi1, nxi2, ret);
22691 +
22692 +       return ret;
22693 +}
22694 +
22695 +
22696 +#ifdef CONFIG_IPV6
22697 +
22698 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
22699 +{
22700 +       int ret = 0;
22701 +
22702 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
22703 +               ret = 1;
22704 +       else {
22705 +               struct nx_addr_v6 *ptr;
22706 +
22707 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
22708 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
22709 +                               ret = 1;
22710 +                               break;
22711 +                       }
22712 +               }
22713 +       }
22714 +
22715 +       vxdprintk(VXD_CBIT(net, 2),
22716 +               "nx_v6_addr_conflict(%p,%p): %d",
22717 +               nxi1, nxi2, ret);
22718 +
22719 +       return ret;
22720 +}
22721 +
22722 +#endif
22723 +
22724 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
22725 +{
22726 +       struct in_device *in_dev;
22727 +       struct in_ifaddr **ifap;
22728 +       struct in_ifaddr *ifa;
22729 +       int ret = 0;
22730 +
22731 +       if (!dev)
22732 +               goto out;
22733 +       in_dev = in_dev_get(dev);
22734 +       if (!in_dev)
22735 +               goto out;
22736 +
22737 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
22738 +               ifap = &ifa->ifa_next) {
22739 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
22740 +                       ret = 1;
22741 +                       break;
22742 +               }
22743 +       }
22744 +       in_dev_put(in_dev);
22745 +out:
22746 +       return ret;
22747 +}
22748 +
22749 +
22750 +#ifdef CONFIG_IPV6
22751 +
22752 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
22753 +{
22754 +       struct inet6_dev *in_dev;
22755 +       struct inet6_ifaddr **ifap;
22756 +       struct inet6_ifaddr *ifa;
22757 +       int ret = 0;
22758 +
22759 +       if (!dev)
22760 +               goto out;
22761 +       in_dev = in6_dev_get(dev);
22762 +       if (!in_dev)
22763 +               goto out;
22764 +
22765 +       for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
22766 +               ifap = &ifa->if_next) {
22767 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
22768 +                       ret = 1;
22769 +                       break;
22770 +               }
22771 +       }
22772 +       in6_dev_put(in_dev);
22773 +out:
22774 +       return ret;
22775 +}
22776 +
22777 +#endif
22778 +
22779 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
22780 +{
22781 +       int ret = 1;
22782 +
22783 +       if (!nxi)
22784 +               goto out;
22785 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
22786 +               goto out;
22787 +#ifdef CONFIG_IPV6
22788 +       ret = 2;
22789 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
22790 +               goto out;
22791 +#endif
22792 +       ret = 0;
22793 +out:
22794 +       vxdprintk(VXD_CBIT(net, 3),
22795 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
22796 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
22797 +       return ret;
22798 +}
22799 +
22800 +int ip_v4_find_src(struct nx_info *nxi, struct rtable **rp, struct flowi *fl)
22801 +{
22802 +       if (!nxi)
22803 +               return 0;
22804 +
22805 +       /* FIXME: handle lback only case */
22806 +       if (!NX_IPV4(nxi))
22807 +               return -EPERM;
22808 +
22809 +       vxdprintk(VXD_CBIT(net, 4),
22810 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
22811 +               nxi, nxi ? nxi->nx_id : 0,
22812 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
22813 +
22814 +       /* single IP is unconditional */
22815 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
22816 +               (fl->fl4_src == INADDR_ANY))
22817 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
22818 +
22819 +       if (fl->fl4_src == INADDR_ANY) {
22820 +               struct nx_addr_v4 *ptr;
22821 +               __be32 found;
22822 +               int err;
22823 +
22824 +               err = __ip_route_output_key(rp, fl);
22825 +               if (!err) {
22826 +                       found = (*rp)->rt_src;
22827 +                       ip_rt_put(*rp);
22828 +                       vxdprintk(VXD_CBIT(net, 4),
22829 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
22830 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
22831 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
22832 +                               goto found;
22833 +               }
22834 +
22835 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
22836 +                       __be32 primary = ptr->ip[0].s_addr;
22837 +                       __be32 mask = ptr->mask.s_addr;
22838 +                       __be32 net = primary & mask;
22839 +
22840 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
22841 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
22842 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
22843 +                               NIPQUAD(mask), NIPQUAD(net));
22844 +                       if ((found & mask) != net)
22845 +                               continue;
22846 +
22847 +                       fl->fl4_src = primary;
22848 +                       err = __ip_route_output_key(rp, fl);
22849 +                       vxdprintk(VXD_CBIT(net, 4),
22850 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
22851 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
22852 +                       if (!err) {
22853 +                               found = (*rp)->rt_src;
22854 +                               ip_rt_put(*rp);
22855 +                               if (found == primary)
22856 +                                       goto found;
22857 +                       }
22858 +               }
22859 +               /* still no source ip? */
22860 +               found = LOOPBACK(fl->fl4_dst)
22861 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
22862 +       found:
22863 +               /* assign src ip to flow */
22864 +               fl->fl4_src = found;
22865 +
22866 +       } else {
22867 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
22868 +                       return -EPERM;
22869 +       }
22870 +
22871 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
22872 +               if (LOOPBACK(fl->fl4_dst))
22873 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
22874 +               if (LOOPBACK(fl->fl4_src))
22875 +                       fl->fl4_src = nxi->v4_lback.s_addr;
22876 +       } else if (LOOPBACK(fl->fl4_dst))
22877 +               return -EPERM;
22878 +
22879 +       return 0;
22880 +}
22881 +
22882 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
22883 +
22884 diff -Nurp linux-2.6.22.18/kernel/vserver/init.c linux-2.6.22.18-vs2.3.0.32/kernel/vserver/init.c
22885 --- linux-2.6.22.18/kernel/vserver/init.c       1970-01-01 01:00:00.000000000 +0100
22886 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/init.c    2008-02-11 12:35:38.000000000 +0100
22887 @@ -0,0 +1,45 @@
22888 +/*
22889 + *  linux/kernel/init.c
22890 + *
22891 + *  Virtual Server Init
22892 + *
22893 + *  Copyright (C) 2004-2007  Herbert Pötzl
22894 + *
22895 + *  V0.01  basic structure
22896 + *
22897 + */
22898 +
22899 +#include <linux/init.h>
22900 +
22901 +int    vserver_register_sysctl(void);
22902 +void   vserver_unregister_sysctl(void);
22903 +
22904 +
22905 +static int __init init_vserver(void)
22906 +{
22907 +       int ret = 0;
22908 +
22909 +#ifdef CONFIG_VSERVER_DEBUG
22910 +       vserver_register_sysctl();
22911 +#endif
22912 +       return ret;
22913 +}
22914 +
22915 +
22916 +static void __exit exit_vserver(void)
22917 +{
22918 +
22919 +#ifdef CONFIG_VSERVER_DEBUG
22920 +       vserver_unregister_sysctl();
22921 +#endif
22922 +       return;
22923 +}
22924 +
22925 +/* FIXME: GFP_ZONETYPES gone
22926 +long vx_slab[GFP_ZONETYPES]; */
22927 +long vx_area;
22928 +
22929 +
22930 +module_init(init_vserver);
22931 +module_exit(exit_vserver);
22932 +
22933 diff -Nurp linux-2.6.22.18/kernel/vserver/inode.c linux-2.6.22.18-vs2.3.0.32/kernel/vserver/inode.c
22934 --- linux-2.6.22.18/kernel/vserver/inode.c      1970-01-01 01:00:00.000000000 +0100
22935 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/inode.c   2008-02-11 12:35:38.000000000 +0100
22936 @@ -0,0 +1,409 @@
22937 +/*
22938 + *  linux/kernel/vserver/inode.c
22939 + *
22940 + *  Virtual Server: File System Support
22941 + *
22942 + *  Copyright (C) 2004-2007  Herbert Pötzl
22943 + *
22944 + *  V0.01  separated from vcontext V0.05
22945 + *  V0.02  moved to tag (instead of xid)
22946 + *
22947 + */
22948 +
22949 +#include <linux/tty.h>
22950 +#include <linux/proc_fs.h>
22951 +#include <linux/devpts_fs.h>
22952 +#include <linux/fs.h>
22953 +#include <linux/file.h>
22954 +#include <linux/mount.h>
22955 +#include <linux/parser.h>
22956 +#include <linux/vserver/inode.h>
22957 +#include <linux/vserver/inode_cmd.h>
22958 +#include <linux/vs_base.h>
22959 +#include <linux/vs_tag.h>
22960 +
22961 +#include <asm/uaccess.h>
22962 +
22963 +
22964 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
22965 +{
22966 +       struct proc_dir_entry *entry;
22967 +
22968 +       if (!in || !in->i_sb)
22969 +               return -ESRCH;
22970 +
22971 +       *flags = IATTR_TAG
22972 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
22973 +               | (IS_IUNLINK(in) ? IATTR_IUNLINK : 0)
22974 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0);
22975 +       *mask = IATTR_IUNLINK | IATTR_IMMUTABLE;
22976 +
22977 +       if (S_ISDIR(in->i_mode))
22978 +               *mask |= IATTR_BARRIER;
22979 +
22980 +       if (IS_TAGGED(in)) {
22981 +               *tag = in->i_tag;
22982 +               *mask |= IATTR_TAG;
22983 +       }
22984 +
22985 +       switch (in->i_sb->s_magic) {
22986 +       case PROC_SUPER_MAGIC:
22987 +               entry = PROC_I(in)->pde;
22988 +
22989 +               /* check for specific inodes? */
22990 +               if (entry)
22991 +                       *mask |= IATTR_FLAGS;
22992 +               if (entry)
22993 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
22994 +               else
22995 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
22996 +               break;
22997 +
22998 +       case DEVPTS_SUPER_MAGIC:
22999 +               *tag = in->i_tag;
23000 +               *mask |= IATTR_TAG;
23001 +               break;
23002 +
23003 +       default:
23004 +               break;
23005 +       }
23006 +       return 0;
23007 +}
23008 +
23009 +int vc_get_iattr(void __user *data)
23010 +{
23011 +       struct nameidata nd;
23012 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
23013 +       int ret;
23014 +
23015 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23016 +               return -EFAULT;
23017 +
23018 +       ret = user_path_walk_link(vc_data.name, &nd);
23019 +       if (!ret) {
23020 +               ret = __vc_get_iattr(nd.dentry->d_inode,
23021 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
23022 +               path_release(&nd);
23023 +       }
23024 +       if (ret)
23025 +               return ret;
23026 +
23027 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23028 +               ret = -EFAULT;
23029 +       return ret;
23030 +}
23031 +
23032 +#ifdef CONFIG_COMPAT
23033 +
23034 +int vc_get_iattr_x32(void __user *data)
23035 +{
23036 +       struct nameidata nd;
23037 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
23038 +       int ret;
23039 +
23040 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23041 +               return -EFAULT;
23042 +
23043 +       ret = user_path_walk_link(compat_ptr(vc_data.name_ptr), &nd);
23044 +       if (!ret) {
23045 +               ret = __vc_get_iattr(nd.dentry->d_inode,
23046 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
23047 +               path_release(&nd);
23048 +       }
23049 +       if (ret)
23050 +               return ret;
23051 +
23052 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23053 +               ret = -EFAULT;
23054 +       return ret;
23055 +}
23056 +
23057 +#endif /* CONFIG_COMPAT */
23058 +
23059 +
23060 +int vc_fget_iattr(uint32_t fd, void __user *data)
23061 +{
23062 +       struct file *filp;
23063 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
23064 +       int ret;
23065 +
23066 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23067 +               return -EFAULT;
23068 +
23069 +       filp = fget(fd);
23070 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
23071 +               return -EBADF;
23072 +
23073 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
23074 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
23075 +
23076 +       fput(filp);
23077 +
23078 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23079 +               ret = -EFAULT;
23080 +       return ret;
23081 +}
23082 +
23083 +
23084 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
23085 +{
23086 +       struct inode *in = de->d_inode;
23087 +       int error = 0, is_proc = 0, has_tag = 0;
23088 +       struct iattr attr = { 0 };
23089 +
23090 +       if (!in || !in->i_sb)
23091 +               return -ESRCH;
23092 +
23093 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
23094 +       if ((*mask & IATTR_FLAGS) && !is_proc)
23095 +               return -EINVAL;
23096 +
23097 +       has_tag = IS_TAGGED(in) ||
23098 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
23099 +       if ((*mask & IATTR_TAG) && !has_tag)
23100 +               return -EINVAL;
23101 +
23102 +       mutex_lock(&in->i_mutex);
23103 +       if (*mask & IATTR_TAG) {
23104 +               attr.ia_tag = *tag;
23105 +               attr.ia_valid |= ATTR_TAG;
23106 +       }
23107 +
23108 +       if (*mask & IATTR_FLAGS) {
23109 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
23110 +               unsigned int iflags = PROC_I(in)->vx_flags;
23111 +
23112 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
23113 +                       | (*flags & IATTR_FLAGS);
23114 +               PROC_I(in)->vx_flags = iflags;
23115 +               if (entry)
23116 +                       entry->vx_flags = iflags;
23117 +       }
23118 +
23119 +       if (*mask & (IATTR_BARRIER | IATTR_IUNLINK | IATTR_IMMUTABLE)) {
23120 +               if (*mask & IATTR_IMMUTABLE) {
23121 +                       if (*flags & IATTR_IMMUTABLE)
23122 +                               in->i_flags |= S_IMMUTABLE;
23123 +                       else
23124 +                               in->i_flags &= ~S_IMMUTABLE;
23125 +               }
23126 +               if (*mask & IATTR_IUNLINK) {
23127 +                       if (*flags & IATTR_IUNLINK)
23128 +                               in->i_flags |= S_IUNLINK;
23129 +                       else
23130 +                               in->i_flags &= ~S_IUNLINK;
23131 +               }
23132 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
23133 +                       if (*flags & IATTR_BARRIER)
23134 +                               in->i_flags |= S_BARRIER;
23135 +                       else
23136 +                               in->i_flags &= ~S_BARRIER;
23137 +               }
23138 +               if (in->i_op && in->i_op->sync_flags) {
23139 +                       error = in->i_op->sync_flags(in);
23140 +                       if (error)
23141 +                               goto out;
23142 +               }
23143 +       }
23144 +
23145 +       if (attr.ia_valid) {
23146 +               if (in->i_op && in->i_op->setattr)
23147 +                       error = in->i_op->setattr(de, &attr);
23148 +               else {
23149 +                       error = inode_change_ok(in, &attr);
23150 +                       if (!error)
23151 +                               error = inode_setattr(in, &attr);
23152 +               }
23153 +       }
23154 +
23155 +out:
23156 +       mutex_unlock(&in->i_mutex);
23157 +       return error;
23158 +}
23159 +
23160 +int vc_set_iattr(void __user *data)
23161 +{
23162 +       struct nameidata nd;
23163 +       struct vcmd_ctx_iattr_v1 vc_data;
23164 +       int ret;
23165 +
23166 +       if (!capable(CAP_LINUX_IMMUTABLE))
23167 +               return -EPERM;
23168 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23169 +               return -EFAULT;
23170 +
23171 +       ret = user_path_walk_link(vc_data.name, &nd);
23172 +       if (!ret) {
23173 +               ret = __vc_set_iattr(nd.dentry,
23174 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
23175 +               path_release(&nd);
23176 +       }
23177 +
23178 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23179 +               ret = -EFAULT;
23180 +       return ret;
23181 +}
23182 +
23183 +#ifdef CONFIG_COMPAT
23184 +
23185 +int vc_set_iattr_x32(void __user *data)
23186 +{
23187 +       struct nameidata nd;
23188 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
23189 +       int ret;
23190 +
23191 +       if (!capable(CAP_LINUX_IMMUTABLE))
23192 +               return -EPERM;
23193 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23194 +               return -EFAULT;
23195 +
23196 +       ret = user_path_walk_link(compat_ptr(vc_data.name_ptr), &nd);
23197 +       if (!ret) {
23198 +               ret = __vc_set_iattr(nd.dentry,
23199 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
23200 +               path_release(&nd);
23201 +       }
23202 +
23203 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23204 +               ret = -EFAULT;
23205 +       return ret;
23206 +}
23207 +
23208 +#endif /* CONFIG_COMPAT */
23209 +
23210 +int vc_fset_iattr(uint32_t fd, void __user *data)
23211 +{
23212 +       struct file *filp;
23213 +       struct vcmd_ctx_fiattr_v0 vc_data;
23214 +       int ret;
23215 +
23216 +       if (!capable(CAP_LINUX_IMMUTABLE))
23217 +               return -EPERM;
23218 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23219 +               return -EFAULT;
23220 +
23221 +       filp = fget(fd);
23222 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
23223 +               return -EBADF;
23224 +
23225 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
23226 +               &vc_data.flags, &vc_data.mask);
23227 +
23228 +       fput(filp);
23229 +
23230 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23231 +               return -EFAULT;
23232 +       return ret;
23233 +}
23234 +
23235 +
23236 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
23237 +
23238 +static match_table_t tokens = {
23239 +       {Opt_notagcheck, "notagcheck"},
23240 +#ifdef CONFIG_PROPAGATE
23241 +       {Opt_notag, "notag"},
23242 +       {Opt_tag, "tag"},
23243 +       {Opt_tagid, "tagid=%u"},
23244 +#endif
23245 +       {Opt_err, NULL}
23246 +};
23247 +
23248 +
23249 +static void __dx_parse_remove(char *string, char *opt)
23250 +{
23251 +       char *p = strstr(string, opt);
23252 +       char *q = p;
23253 +
23254 +       if (p) {
23255 +               while (*q != '\0' && *q != ',')
23256 +                       q++;
23257 +               while (*q)
23258 +                       *p++ = *q++;
23259 +               while (*p)
23260 +                       *p++ = '\0';
23261 +       }
23262 +}
23263 +
23264 +static inline
23265 +int __dx_parse_tag(char *string, tag_t *tag, int remove)
23266 +{
23267 +       substring_t args[MAX_OPT_ARGS];
23268 +       int token, option = 0;
23269 +
23270 +       if (!string)
23271 +               return 0;
23272 +
23273 +       token = match_token(string, tokens, args);
23274 +
23275 +       vxdprintk(VXD_CBIT(tag, 7),
23276 +               "dx_parse_tag(»%s«): %d:#%d",
23277 +               string, token, option);
23278 +
23279 +       switch (token) {
23280 +       case Opt_tag:
23281 +               if (tag)
23282 +                       *tag = 0;
23283 +               if (remove)
23284 +                       __dx_parse_remove(string, "tag");
23285 +               return MNT_TAGID;
23286 +       case Opt_notag:
23287 +               if (remove)
23288 +                       __dx_parse_remove(string, "notag");
23289 +               return MNT_NOTAG;
23290 +       case Opt_notagcheck:
23291 +               if (remove)
23292 +                       __dx_parse_remove(string, "notagcheck");
23293 +               return MNT_NOTAGCHECK;
23294 +       case Opt_tagid:
23295 +               if (tag && !match_int(args, &option))
23296 +                       *tag = option;
23297 +               if (remove)
23298 +                       __dx_parse_remove(string, "tagid");
23299 +               return MNT_TAGID;
23300 +       }
23301 +       return 0;
23302 +}
23303 +
23304 +int dx_parse_tag(char *string, tag_t *tag, int remove)
23305 +{
23306 +       int retval, flags = 0;
23307 +
23308 +       while ((retval = __dx_parse_tag(string, tag, remove)))
23309 +               flags |= retval;
23310 +       return flags;
23311 +}
23312 +
23313 +#ifdef CONFIG_PROPAGATE
23314 +
23315 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
23316 +{
23317 +       tag_t new_tag = 0;
23318 +       struct vfsmount *mnt;
23319 +       int propagate;
23320 +
23321 +       if (!nd)
23322 +               return;
23323 +       mnt = nd->mnt;
23324 +       if (!mnt)
23325 +               return;
23326 +
23327 +       propagate = (mnt->mnt_flags & MNT_TAGID);
23328 +       if (propagate)
23329 +               new_tag = mnt->mnt_tag;
23330 +
23331 +       vxdprintk(VXD_CBIT(tag, 7),
23332 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
23333 +               inode, inode->i_ino, inode->i_tag,
23334 +               new_tag, (propagate) ? 1 : 0);
23335 +
23336 +       if (propagate)
23337 +               inode->i_tag = new_tag;
23338 +}
23339 +
23340 +#include <linux/module.h>
23341 +
23342 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
23343 +
23344 +#endif /* CONFIG_PROPAGATE */
23345 +
23346 diff -Nurp linux-2.6.22.18/kernel/vserver/Kconfig linux-2.6.22.18-vs2.3.0.32/kernel/vserver/Kconfig
23347 --- linux-2.6.22.18/kernel/vserver/Kconfig      1970-01-01 01:00:00.000000000 +0100
23348 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/Kconfig   2008-02-11 12:35:38.000000000 +0100
23349 @@ -0,0 +1,249 @@
23350 +#
23351 +# Linux VServer configuration
23352 +#
23353 +
23354 +menu "Linux VServer"
23355 +
23356 +config VSERVER_AUTO_LBACK
23357 +       bool    "Automatically Assign Loopback IP"
23358 +       default y
23359 +       help
23360 +         Automatically assign a guest specific loopback
23361 +         IP and add it to the kernel network stack on
23362 +         startup.
23363 +
23364 +config VSERVER_AUTO_SINGLE
23365 +       bool    "Automatic Single IP Special Casing"
23366 +       depends on EXPERIMENTAL
23367 +       default y
23368 +       help
23369 +         This allows network contexts with a single IP to
23370 +         automatically remap 0.0.0.0 bindings to that IP,
23371 +         avoiding further network checks and improving
23372 +         performance.
23373 +
23374 +         (note: such guests do not allow to change the ip
23375 +          on the fly and do not show loopback addresses)
23376 +
23377 +config VSERVER_COWBL
23378 +       bool    "Enable COW Immutable Link Breaking"
23379 +       default y
23380 +       help
23381 +         This enables the COW (Copy-On-Write) link break code.
23382 +         It allows you to treat unified files like normal files
23383 +         when writing to them (which will implicitely break the
23384 +         link and create a copy of the unified file)
23385 +
23386 +config VSERVER_VTIME
23387 +       bool    "Enable Virtualized Guest Time"
23388 +       depends on EXPERIMENTAL
23389 +       default n
23390 +       help
23391 +         This enables per guest time offsets to allow for
23392 +         adjusting the system clock individually per guest.
23393 +         this adds some overhead to the time functions and
23394 +         therefore should not be enabled without good reason.
23395 +
23396 +config VSERVER_DEVICE
23397 +       bool    "Enable Guest Device Mapping"
23398 +       depends on EXPERIMENTAL
23399 +       default n
23400 +       help
23401 +         This enables generic device remapping.
23402 +
23403 +config VSERVER_PROC_SECURE
23404 +       bool    "Enable Proc Security"
23405 +       depends on PROC_FS
23406 +       default y
23407 +       help
23408 +         This configures ProcFS security to initially hide
23409 +         non-process entries for all contexts except the main and
23410 +         spectator context (i.e. for all guests), which is a secure
23411 +         default.
23412 +
23413 +         (note: on 1.2x the entries were visible by default)
23414 +
23415 +config VSERVER_HARDCPU
23416 +       bool    "Enable Hard CPU Limits"
23417 +       default y
23418 +       help
23419 +         Activate the Hard CPU Limits
23420 +
23421 +         This will compile in code that allows the Token Bucket
23422 +         Scheduler to put processes on hold when a context's
23423 +         tokens are depleted (provided that its per-context
23424 +         sched_hard flag is set).
23425 +
23426 +         Processes belonging to that context will not be able
23427 +         to consume CPU resources again until a per-context
23428 +         configured minimum of tokens has been reached.
23429 +
23430 +config VSERVER_IDLETIME
23431 +       bool    "Avoid idle CPUs by skipping Time"
23432 +       depends on VSERVER_HARDCPU
23433 +       default y
23434 +       help
23435 +         This option allows the scheduler to artificially
23436 +         advance time (per cpu) when otherwise the idle
23437 +         task would be scheduled, thus keeping the cpu
23438 +         busy and sharing the available resources among
23439 +         certain contexts.
23440 +
23441 +config VSERVER_IDLELIMIT
23442 +       bool    "Limit the IDLE task"
23443 +       depends on VSERVER_HARDCPU
23444 +       default n
23445 +       help
23446 +         Limit the idle slices, so the the next context
23447 +         will be scheduled as soon as possible.
23448 +
23449 +         This might improve interactivity and latency, but
23450 +         will also marginally increase scheduling overhead.
23451 +
23452 +choice
23453 +       prompt  "Persistent Inode Tagging"
23454 +       default TAGGING_ID24
23455 +       help
23456 +         This adds persistent context information to filesystems
23457 +         mounted with the tagxid option. Tagging is a requirement
23458 +         for per-context disk limits and per-context quota.
23459 +
23460 +
23461 +config TAGGING_NONE
23462 +       bool    "Disabled"
23463 +       help
23464 +         do not store per-context information in inodes.
23465 +
23466 +config TAGGING_UID16
23467 +       bool    "UID16/GID32"
23468 +       help
23469 +         reduces UID to 16 bit, but leaves GID at 32 bit.
23470 +
23471 +config TAGGING_GID16
23472 +       bool    "UID32/GID16"
23473 +       help
23474 +         reduces GID to 16 bit, but leaves UID at 32 bit.
23475 +
23476 +config TAGGING_ID24
23477 +       bool    "UID24/GID24"
23478 +       help
23479 +         uses the upper 8bit from UID and GID for XID tagging
23480 +         which leaves 24bit for UID/GID each, which should be
23481 +         more than sufficient for normal use.
23482 +
23483 +config TAGGING_INTERN
23484 +       bool    "UID32/GID32"
23485 +       help
23486 +         this uses otherwise reserved inode fields in the on
23487 +         disk representation, which limits the use to a few
23488 +         filesystems (currently ext2 and ext3)
23489 +
23490 +endchoice
23491 +
23492 +config TAG_NFSD
23493 +       bool    "Tag NFSD User Auth and Files"
23494 +       default n
23495 +       help
23496 +         Enable this if you do want the in-kernel NFS
23497 +         Server to use the tagging specified above.
23498 +         (will require patched clients too)
23499 +
23500 +config VSERVER_PRIVACY
23501 +       bool    "Honor Privacy Aspects of Guests"
23502 +       default n
23503 +       help
23504 +         When enabled, most context checks will disallow
23505 +         access to structures assigned to a specific context,
23506 +         like ptys or loop devices.
23507 +
23508 +config VSERVER_CONTEXTS
23509 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
23510 +       range 1 65533
23511 +       default "768"   if 64BIT
23512 +       default "256"
23513 +       help
23514 +         This setting will optimize certain data structures
23515 +         and memory allocations according to the expected
23516 +         maximum.
23517 +
23518 +         note: this is not a strict upper limit.
23519 +
23520 +config VSERVER_WARN
23521 +       bool    "VServer Warnings"
23522 +       default y
23523 +       help
23524 +         This enables various runtime warnings, which will
23525 +         notify about potential manipulation attempts or
23526 +         resource shortage. It is generally considered to
23527 +         be a good idea to have that enabled.
23528 +
23529 +config VSERVER_DEBUG
23530 +       bool    "VServer Debugging Code"
23531 +       default n
23532 +       help
23533 +         Set this to yes if you want to be able to activate
23534 +         debugging output at runtime. It adds a very small
23535 +         overhead to all vserver related functions and
23536 +         increases the kernel size by about 20k.
23537 +
23538 +config VSERVER_HISTORY
23539 +       bool    "VServer History Tracing"
23540 +       depends on VSERVER_DEBUG
23541 +       default n
23542 +       help
23543 +         Set this to yes if you want to record the history of
23544 +         linux-vserver activities, so they can be replayed in
23545 +         the event of a kernel panic or oops.
23546 +
23547 +config VSERVER_HISTORY_SIZE
23548 +       int     "Per-CPU History Size (32-65536)"
23549 +       depends on VSERVER_HISTORY
23550 +       range 32 65536
23551 +       default 64
23552 +       help
23553 +         This allows you to specify the number of entries in
23554 +         the per-CPU history buffer.
23555 +
23556 +config VSERVER_MONITOR
23557 +       bool    "VServer Scheduling Monitor"
23558 +       depends on VSERVER_DEBUG
23559 +       default n
23560 +       help
23561 +         Set this to yes if you want to record the scheduling
23562 +         decisions, so that they can be relayed to userspace
23563 +         for detailed analysis.
23564 +
23565 +config VSERVER_MONITOR_SIZE
23566 +       int     "Per-CPU Monitor Queue Size (32-65536)"
23567 +       depends on VSERVER_MONITOR
23568 +       range 32 65536
23569 +       default 1024
23570 +       help
23571 +         This allows you to specify the number of entries in
23572 +         the per-CPU scheduling monitor buffer.
23573 +
23574 +config VSERVER_MONITOR_SYNC
23575 +       int     "Per-CPU Monitor Sync Interval (0-65536)"
23576 +       depends on VSERVER_MONITOR
23577 +       range 0 65536
23578 +       default 256
23579 +       help
23580 +         This allows you to specify the interval in ticks
23581 +         when a time sync entry is inserted.
23582 +
23583 +endmenu
23584 +
23585 +
23586 +config VSERVER
23587 +       bool
23588 +       default y
23589 +       select UTS_NS
23590 +       select SYSVIPC
23591 +       select IPC_NS
23592 +
23593 +config VSERVER_SECURITY
23594 +       bool
23595 +       depends on SECURITY
23596 +       default y
23597 +       select SECURITY_CAPABILITIES
23598 +
23599 diff -Nurp linux-2.6.22.18/kernel/vserver/limit.c linux-2.6.22.18-vs2.3.0.32/kernel/vserver/limit.c
23600 --- linux-2.6.22.18/kernel/vserver/limit.c      1970-01-01 01:00:00.000000000 +0100
23601 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/limit.c   2008-02-11 12:35:38.000000000 +0100
23602 @@ -0,0 +1,318 @@
23603 +/*
23604 + *  linux/kernel/vserver/limit.c
23605 + *
23606 + *  Virtual Server: Context Limits
23607 + *
23608 + *  Copyright (C) 2004-2007  Herbert Pötzl
23609 + *
23610 + *  V0.01  broken out from vcontext V0.05
23611 + *  V0.02  changed vcmds to vxi arg
23612 + *
23613 + */
23614 +
23615 +#include <linux/module.h>
23616 +#include <linux/vs_limit.h>
23617 +#include <linux/vserver/limit.h>
23618 +#include <linux/vserver/limit_cmd.h>
23619 +
23620 +#include <asm/uaccess.h>
23621 +
23622 +
23623 +const char *vlimit_name[NUM_LIMITS] = {
23624 +       [RLIMIT_CPU]            = "CPU",
23625 +       [RLIMIT_RSS]            = "RSS",
23626 +       [RLIMIT_NPROC]          = "NPROC",
23627 +       [RLIMIT_NOFILE]         = "NOFILE",
23628 +       [RLIMIT_MEMLOCK]        = "VML",
23629 +       [RLIMIT_AS]             = "VM",
23630 +       [RLIMIT_LOCKS]          = "LOCKS",
23631 +       [RLIMIT_SIGPENDING]     = "SIGP",
23632 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
23633 +
23634 +       [VLIMIT_NSOCK]          = "NSOCK",
23635 +       [VLIMIT_OPENFD]         = "OPENFD",
23636 +       [VLIMIT_ANON]           = "ANON",
23637 +       [VLIMIT_SHMEM]          = "SHMEM",
23638 +       [VLIMIT_DENTRY]         = "DENTRY",
23639 +};
23640 +
23641 +EXPORT_SYMBOL_GPL(vlimit_name);
23642 +
23643 +#define MASK_ENTRY(x)  (1 << (x))
23644 +
23645 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
23646 +               /* minimum */
23647 +       0
23648 +       ,       /* softlimit */
23649 +       MASK_ENTRY( RLIMIT_RSS          ) |
23650 +       MASK_ENTRY( VLIMIT_ANON         ) |
23651 +       0
23652 +       ,       /* maximum */
23653 +       MASK_ENTRY( RLIMIT_RSS          ) |
23654 +       MASK_ENTRY( RLIMIT_NPROC        ) |
23655 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
23656 +       MASK_ENTRY( RLIMIT_MEMLOCK      ) |
23657 +       MASK_ENTRY( RLIMIT_AS           ) |
23658 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
23659 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
23660 +
23661 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
23662 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
23663 +       MASK_ENTRY( VLIMIT_ANON         ) |
23664 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
23665 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
23666 +       0
23667 +};
23668 +               /* accounting only */
23669 +uint32_t account_mask =
23670 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
23671 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
23672 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
23673 +       0;
23674 +
23675 +
23676 +static int is_valid_vlimit(int id)
23677 +{
23678 +       uint32_t mask = vlimit_mask.minimum |
23679 +               vlimit_mask.softlimit | vlimit_mask.maximum;
23680 +       return mask & (1 << id);
23681 +}
23682 +
23683 +static int is_accounted_vlimit(int id)
23684 +{
23685 +       if (is_valid_vlimit(id))
23686 +               return 1;
23687 +       return account_mask & (1 << id);
23688 +}
23689 +
23690 +
23691 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
23692 +{
23693 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
23694 +       return VX_VLIM(limit);
23695 +}
23696 +
23697 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
23698 +{
23699 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
23700 +       return VX_VLIM(limit);
23701 +}
23702 +
23703 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
23704 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
23705 +{
23706 +       if (!is_valid_vlimit(id))
23707 +               return -EINVAL;
23708 +
23709 +       if (minimum)
23710 +               *minimum = CRLIM_UNSET;
23711 +       if (softlimit)
23712 +               *softlimit = vc_get_soft(vxi, id);
23713 +       if (maximum)
23714 +               *maximum = vc_get_hard(vxi, id);
23715 +       return 0;
23716 +}
23717 +
23718 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
23719 +{
23720 +       struct vcmd_ctx_rlimit_v0 vc_data;
23721 +       int ret;
23722 +
23723 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23724 +               return -EFAULT;
23725 +
23726 +       ret = do_get_rlimit(vxi, vc_data.id,
23727 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
23728 +       if (ret)
23729 +               return ret;
23730 +
23731 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23732 +               return -EFAULT;
23733 +       return 0;
23734 +}
23735 +
23736 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
23737 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
23738 +{
23739 +       if (!is_valid_vlimit(id))
23740 +               return -EINVAL;
23741 +
23742 +       if (maximum != CRLIM_KEEP)
23743 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
23744 +       if (softlimit != CRLIM_KEEP)
23745 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
23746 +
23747 +       /* clamp soft limit */
23748 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
23749 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
23750 +
23751 +       return 0;
23752 +}
23753 +
23754 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
23755 +{
23756 +       struct vcmd_ctx_rlimit_v0 vc_data;
23757 +
23758 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23759 +               return -EFAULT;
23760 +
23761 +       return do_set_rlimit(vxi, vc_data.id,
23762 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
23763 +}
23764 +
23765 +#ifdef CONFIG_IA32_EMULATION
23766 +
23767 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
23768 +{
23769 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
23770 +
23771 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23772 +               return -EFAULT;
23773 +
23774 +       return do_set_rlimit(vxi, vc_data.id,
23775 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
23776 +}
23777 +
23778 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
23779 +{
23780 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
23781 +       int ret;
23782 +
23783 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23784 +               return -EFAULT;
23785 +
23786 +       ret = do_get_rlimit(vxi, vc_data.id,
23787 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
23788 +       if (ret)
23789 +               return ret;
23790 +
23791 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23792 +               return -EFAULT;
23793 +       return 0;
23794 +}
23795 +
23796 +#endif /* CONFIG_IA32_EMULATION */
23797 +
23798 +
23799 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
23800 +{
23801 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
23802 +               return -EFAULT;
23803 +       return 0;
23804 +}
23805 +
23806 +
23807 +static inline void vx_reset_minmax(struct _vx_limit *limit)
23808 +{
23809 +       rlim_t value;
23810 +       int lim;
23811 +
23812 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
23813 +               value = __rlim_get(limit, lim);
23814 +               __rlim_rmax(limit, lim) = value;
23815 +               __rlim_rmin(limit, lim) = value;
23816 +       }
23817 +}
23818 +
23819 +
23820 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
23821 +{
23822 +       vx_reset_minmax(&vxi->limit);
23823 +       return 0;
23824 +}
23825 +
23826 +
23827 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
23828 +{
23829 +       struct vcmd_rlimit_stat_v0 vc_data;
23830 +       struct _vx_limit *limit = &vxi->limit;
23831 +       int id;
23832 +
23833 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23834 +               return -EFAULT;
23835 +
23836 +       id = vc_data.id;
23837 +       if (!is_accounted_vlimit(id))
23838 +               return -EINVAL;
23839 +
23840 +       vx_limit_fixup(limit, id);
23841 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
23842 +       vc_data.value = __rlim_get(limit, id);
23843 +       vc_data.minimum = __rlim_rmin(limit, id);
23844 +       vc_data.maximum = __rlim_rmax(limit, id);
23845 +
23846 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23847 +               return -EFAULT;
23848 +       return 0;
23849 +}
23850 +
23851 +
23852 +void vx_vsi_meminfo(struct sysinfo *val)
23853 +{
23854 +       struct vx_info *vxi = current->vx_info;
23855 +       unsigned long totalram, freeram;
23856 +       rlim_t v;
23857 +
23858 +       /* we blindly accept the max */
23859 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
23860 +       totalram = (v != RLIM_INFINITY) ? v : val->totalram;
23861 +
23862 +       /* total minus used equals free */
23863 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
23864 +       freeram = (v < totalram) ? totalram - v : 0;
23865 +
23866 +       val->totalram = totalram;
23867 +       val->freeram = freeram;
23868 +       val->bufferram = 0;
23869 +       val->totalhigh = 0;
23870 +       val->freehigh = 0;
23871 +       return;
23872 +}
23873 +
23874 +void vx_vsi_swapinfo(struct sysinfo *val)
23875 +{
23876 +       struct vx_info *vxi = current->vx_info;
23877 +       unsigned long totalswap, freeswap;
23878 +       rlim_t v, w;
23879 +
23880 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
23881 +       if (v == RLIM_INFINITY) {
23882 +               val->freeswap = val->totalswap;
23883 +               return;
23884 +       }
23885 +
23886 +       /* we blindly accept the max */
23887 +       w = __rlim_hard(&vxi->limit, RLIMIT_RSS);
23888 +       totalswap = (w != RLIM_INFINITY) ? (w - v) : val->totalswap;
23889 +
23890 +       /* currently 'used' swap */
23891 +       w = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
23892 +       w -= (w > v) ? v : w;
23893 +
23894 +       /* total minus used equals free */
23895 +       freeswap = (w < totalswap) ? totalswap - w : 0;
23896 +
23897 +       val->totalswap = totalswap;
23898 +       val->freeswap = freeswap;
23899 +       return;
23900 +}
23901 +
23902 +
23903 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
23904 +{
23905 +       struct vx_info *vxi = mm->mm_vx_info;
23906 +       unsigned long points;
23907 +       rlim_t v, w;
23908 +
23909 +       if (!vxi)
23910 +               return 0;
23911 +
23912 +       points = vxi->vx_badness_bias;
23913 +
23914 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
23915 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
23916 +       points += (v > w) ? (v - w) : 0;
23917 +
23918 +       return points;
23919 +}
23920 +
23921 diff -Nurp linux-2.6.22.18/kernel/vserver/limit_init.h linux-2.6.22.18-vs2.3.0.32/kernel/vserver/limit_init.h
23922 --- linux-2.6.22.18/kernel/vserver/limit_init.h 1970-01-01 01:00:00.000000000 +0100
23923 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/limit_init.h      2008-02-11 12:35:38.000000000 +0100
23924 @@ -0,0 +1,33 @@
23925 +
23926 +
23927 +static inline void vx_info_init_limit(struct _vx_limit *limit)
23928 +{
23929 +       int lim;
23930 +
23931 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
23932 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
23933 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
23934 +               __rlim_set(limit, lim, 0);
23935 +               atomic_set(&__rlim_lhit(limit, lim), 0);
23936 +               __rlim_rmin(limit, lim) = 0;
23937 +               __rlim_rmax(limit, lim) = 0;
23938 +       }
23939 +}
23940 +
23941 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
23942 +{
23943 +#ifdef CONFIG_VSERVER_WARN
23944 +       rlim_t value;
23945 +       int lim;
23946 +
23947 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
23948 +               if ((1 << lim) & VLIM_NOCHECK)
23949 +                       continue;
23950 +               value = __rlim_get(limit, lim);
23951 +               vxwprintk_xid(value,
23952 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
23953 +                       limit, vlimit_name[lim], lim, (long)value);
23954 +       }
23955 +#endif
23956 +}
23957 +
23958 diff -Nurp linux-2.6.22.18/kernel/vserver/limit_proc.h linux-2.6.22.18-vs2.3.0.32/kernel/vserver/limit_proc.h
23959 --- linux-2.6.22.18/kernel/vserver/limit_proc.h 1970-01-01 01:00:00.000000000 +0100
23960 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/limit_proc.h      2008-02-11 12:35:38.000000000 +0100
23961 @@ -0,0 +1,57 @@
23962 +#ifndef _VX_LIMIT_PROC_H
23963 +#define _VX_LIMIT_PROC_H
23964 +
23965 +#include <linux/vserver/limit_int.h>
23966 +
23967 +
23968 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
23969 +#define VX_LIMIT_TOP   \
23970 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
23971 +
23972 +#define VX_LIMIT_ARG(r)                                \
23973 +       (unsigned long)__rlim_get(limit, r),    \
23974 +       (unsigned long)__rlim_rmin(limit, r),   \
23975 +       (unsigned long)__rlim_rmax(limit, r),   \
23976 +       VX_VLIM(__rlim_soft(limit, r)),         \
23977 +       VX_VLIM(__rlim_hard(limit, r)),         \
23978 +       atomic_read(&__rlim_lhit(limit, r))
23979 +
23980 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
23981 +{
23982 +       vx_limit_fixup(limit, -1);
23983 +       return sprintf(buffer, VX_LIMIT_TOP
23984 +               "PROC"  VX_LIMIT_FMT
23985 +               "VM"    VX_LIMIT_FMT
23986 +               "VML"   VX_LIMIT_FMT
23987 +               "RSS"   VX_LIMIT_FMT
23988 +               "ANON"  VX_LIMIT_FMT
23989 +               "RMAP"  VX_LIMIT_FMT
23990 +               "FILES" VX_LIMIT_FMT
23991 +               "OFD"   VX_LIMIT_FMT
23992 +               "LOCKS" VX_LIMIT_FMT
23993 +               "SOCK"  VX_LIMIT_FMT
23994 +               "MSGQ"  VX_LIMIT_FMT
23995 +               "SHM"   VX_LIMIT_FMT
23996 +               "SEMA"  VX_LIMIT_FMT
23997 +               "SEMS"  VX_LIMIT_FMT
23998 +               "DENT"  VX_LIMIT_FMT,
23999 +               VX_LIMIT_ARG(RLIMIT_NPROC),
24000 +               VX_LIMIT_ARG(RLIMIT_AS),
24001 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
24002 +               VX_LIMIT_ARG(RLIMIT_RSS),
24003 +               VX_LIMIT_ARG(VLIMIT_ANON),
24004 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
24005 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
24006 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
24007 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
24008 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
24009 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
24010 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
24011 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
24012 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
24013 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
24014 +}
24015 +
24016 +#endif /* _VX_LIMIT_PROC_H */
24017 +
24018 +
24019 diff -Nurp linux-2.6.22.18/kernel/vserver/Makefile linux-2.6.22.18-vs2.3.0.32/kernel/vserver/Makefile
24020 --- linux-2.6.22.18/kernel/vserver/Makefile     1970-01-01 01:00:00.000000000 +0100
24021 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/Makefile  2008-02-11 12:35:38.000000000 +0100
24022 @@ -0,0 +1,18 @@
24023 +#
24024 +# Makefile for the Linux vserver routines.
24025 +#
24026 +
24027 +
24028 +obj-y          += vserver.o
24029 +
24030 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
24031 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
24032 +                  dlimit.o tag.o
24033 +
24034 +vserver-$(CONFIG_INET) += inet.o
24035 +vserver-$(CONFIG_PROC_FS) += proc.o
24036 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
24037 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
24038 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
24039 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
24040 +
24041 diff -Nurp linux-2.6.22.18/kernel/vserver/monitor.c linux-2.6.22.18-vs2.3.0.32/kernel/vserver/monitor.c
24042 --- linux-2.6.22.18/kernel/vserver/monitor.c    1970-01-01 01:00:00.000000000 +0100
24043 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/monitor.c 2008-02-11 12:35:38.000000000 +0100
24044 @@ -0,0 +1,138 @@
24045 +/*
24046 + *  kernel/vserver/monitor.c
24047 + *
24048 + *  Virtual Context Scheduler Monitor
24049 + *
24050 + *  Copyright (C) 2006-2007 Herbert Pötzl
24051 + *
24052 + *  V0.01  basic design
24053 + *
24054 + */
24055 +
24056 +#include <linux/module.h>
24057 +#include <linux/jiffies.h>
24058 +#include <asm/uaccess.h>
24059 +#include <asm/atomic.h>
24060 +
24061 +#include <linux/vserver/monitor.h>
24062 +#include <linux/vserver/debug_cmd.h>
24063 +
24064 +
24065 +#ifdef CONFIG_VSERVER_MONITOR
24066 +#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
24067 +#else
24068 +#define VXM_SIZE       64
24069 +#endif
24070 +
24071 +struct _vx_monitor {
24072 +       unsigned int counter;
24073 +
24074 +       struct _vx_mon_entry entry[VXM_SIZE+1];
24075 +};
24076 +
24077 +
24078 +DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
24079 +
24080 +unsigned volatile int vxm_active = 1;
24081 +
24082 +static atomic_t sequence = ATOMIC_INIT(0);
24083 +
24084 +
24085 +/*     vxm_advance()
24086 +
24087 +       * requires disabled preemption                          */
24088 +
24089 +struct _vx_mon_entry *vxm_advance(int cpu)
24090 +{
24091 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
24092 +       struct _vx_mon_entry *entry;
24093 +       unsigned int index;
24094 +
24095 +       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
24096 +       entry = &mon->entry[index];
24097 +
24098 +       entry->ev.seq = atomic_inc_return(&sequence);
24099 +       entry->ev.jif = jiffies;
24100 +       return entry;
24101 +}
24102 +
24103 +EXPORT_SYMBOL_GPL(vxm_advance);
24104 +
24105 +
24106 +int do_read_monitor(struct __user _vx_mon_entry *data,
24107 +       int cpu, uint32_t *index, uint32_t *count)
24108 +{
24109 +       int pos, ret = 0;
24110 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
24111 +       int end = mon->counter;
24112 +       int start = end - VXM_SIZE + 2;
24113 +       int idx = *index;
24114 +
24115 +       /* special case: get current pos */
24116 +       if (!*count) {
24117 +               *index = end;
24118 +               return 0;
24119 +       }
24120 +
24121 +       /* have we lost some data? */
24122 +       if (idx < start)
24123 +               idx = start;
24124 +
24125 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
24126 +               struct _vx_mon_entry *entry =
24127 +                       &mon->entry[idx % VXM_SIZE];
24128 +
24129 +               /* send entry to userspace */
24130 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
24131 +               if (ret)
24132 +                       break;
24133 +       }
24134 +       /* save new index and count */
24135 +       *index = idx;
24136 +       *count = pos;
24137 +       return ret ? ret : (*index < end);
24138 +}
24139 +
24140 +int vc_read_monitor(uint32_t id, void __user *data)
24141 +{
24142 +       struct vcmd_read_monitor_v0 vc_data;
24143 +       int ret;
24144 +
24145 +       if (id >= NR_CPUS)
24146 +               return -EINVAL;
24147 +
24148 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24149 +               return -EFAULT;
24150 +
24151 +       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
24152 +               id, &vc_data.index, &vc_data.count);
24153 +
24154 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24155 +               return -EFAULT;
24156 +       return ret;
24157 +}
24158 +
24159 +#ifdef CONFIG_COMPAT
24160 +
24161 +int vc_read_monitor_x32(uint32_t id, void __user *data)
24162 +{
24163 +       struct vcmd_read_monitor_v0_x32 vc_data;
24164 +       int ret;
24165 +
24166 +       if (id >= NR_CPUS)
24167 +               return -EINVAL;
24168 +
24169 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24170 +               return -EFAULT;
24171 +
24172 +       ret = do_read_monitor((struct __user _vx_mon_entry *)
24173 +               compat_ptr(vc_data.data_ptr),
24174 +               id, &vc_data.index, &vc_data.count);
24175 +
24176 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24177 +               return -EFAULT;
24178 +       return ret;
24179 +}
24180 +
24181 +#endif /* CONFIG_COMPAT */
24182 +
24183 diff -Nurp linux-2.6.22.18/kernel/vserver/network.c linux-2.6.22.18-vs2.3.0.32/kernel/vserver/network.c
24184 --- linux-2.6.22.18/kernel/vserver/network.c    1970-01-01 01:00:00.000000000 +0100
24185 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/network.c 2008-02-11 12:35:38.000000000 +0100
24186 @@ -0,0 +1,862 @@
24187 +/*
24188 + *  linux/kernel/vserver/network.c
24189 + *
24190 + *  Virtual Server: Network Support
24191 + *
24192 + *  Copyright (C) 2003-2007  Herbert Pötzl
24193 + *
24194 + *  V0.01  broken out from vcontext V0.05
24195 + *  V0.02  cleaned up implementation
24196 + *  V0.03  added equiv nx commands
24197 + *  V0.04  switch to RCU based hash
24198 + *  V0.05  and back to locking again
24199 + *  V0.06  changed vcmds to nxi arg
24200 + *  V0.07  have __create claim() the nxi
24201 + *
24202 + */
24203 +
24204 +#include <linux/err.h>
24205 +#include <linux/slab.h>
24206 +#include <linux/rcupdate.h>
24207 +
24208 +#include <linux/vs_network.h>
24209 +#include <linux/vserver/network_cmd.h>
24210 +
24211 +
24212 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
24213 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
24214 +
24215 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
24216 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
24217 +
24218 +
24219 +static int __init init_network(void)
24220 +{
24221 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
24222 +               sizeof(struct nx_addr_v4), 0, SLAB_PANIC, NULL, NULL);
24223 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
24224 +               sizeof(struct nx_addr_v6), 0, SLAB_PANIC, NULL, NULL);
24225 +       return 0;
24226 +}
24227 +
24228 +
24229 +/*     __alloc_nx_addr_v4()                                    */
24230 +
24231 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
24232 +{
24233 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
24234 +               nx_addr_v4_cachep, GFP_KERNEL);
24235 +
24236 +       if (!IS_ERR(nxa))
24237 +               memset(nxa, 0, sizeof(*nxa));
24238 +       return nxa;
24239 +}
24240 +
24241 +/*     __dealloc_nx_addr_v4()                                  */
24242 +
24243 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
24244 +{
24245 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
24246 +}
24247 +
24248 +/*     __dealloc_nx_addr_v4_all()                              */
24249 +
24250 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
24251 +{
24252 +       while (nxa) {
24253 +               struct nx_addr_v4 *next = nxa->next;
24254 +
24255 +               __dealloc_nx_addr_v4(nxa);
24256 +               nxa = next;
24257 +       }
24258 +}
24259 +
24260 +
24261 +#ifdef CONFIG_IPV6
24262 +
24263 +/*     __alloc_nx_addr_v6()                                    */
24264 +
24265 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
24266 +{
24267 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
24268 +               nx_addr_v6_cachep, GFP_KERNEL);
24269 +
24270 +       if (!IS_ERR(nxa))
24271 +               memset(nxa, 0, sizeof(*nxa));
24272 +       return nxa;
24273 +}
24274 +
24275 +/*     __dealloc_nx_addr_v6()                                  */
24276 +
24277 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
24278 +{
24279 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
24280 +}
24281 +
24282 +/*     __dealloc_nx_addr_v6_all()                              */
24283 +
24284 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
24285 +{
24286 +       while (nxa) {
24287 +               struct nx_addr_v6 *next = nxa->next;
24288 +
24289 +               __dealloc_nx_addr_v6(nxa);
24290 +               nxa = next;
24291 +       }
24292 +}
24293 +
24294 +#endif /* CONFIG_IPV6 */
24295 +
24296 +
24297 +/*     __alloc_nx_info()
24298 +
24299 +       * allocate an initialized nx_info struct
24300 +       * doesn't make it visible (hash)                        */
24301 +
24302 +static struct nx_info *__alloc_nx_info(nid_t nid)
24303 +{
24304 +       struct nx_info *new = NULL;
24305 +
24306 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
24307 +
24308 +       /* would this benefit from a slab cache? */
24309 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
24310 +       if (!new)
24311 +               return 0;
24312 +
24313 +       memset(new, 0, sizeof(struct nx_info));
24314 +       new->nx_id = nid;
24315 +       INIT_HLIST_NODE(&new->nx_hlist);
24316 +       atomic_set(&new->nx_usecnt, 0);
24317 +       atomic_set(&new->nx_tasks, 0);
24318 +       new->nx_state = 0;
24319 +
24320 +       new->nx_flags = NXF_INIT_SET;
24321 +
24322 +       /* rest of init goes here */
24323 +
24324 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
24325 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
24326 +
24327 +       vxdprintk(VXD_CBIT(nid, 0),
24328 +               "alloc_nx_info(%d) = %p", nid, new);
24329 +       atomic_inc(&nx_global_ctotal);
24330 +       return new;
24331 +}
24332 +
24333 +/*     __dealloc_nx_info()
24334 +
24335 +       * final disposal of nx_info                             */
24336 +
24337 +static void __dealloc_nx_info(struct nx_info *nxi)
24338 +{
24339 +       vxdprintk(VXD_CBIT(nid, 0),
24340 +               "dealloc_nx_info(%p)", nxi);
24341 +
24342 +       nxi->nx_hlist.next = LIST_POISON1;
24343 +       nxi->nx_id = -1;
24344 +
24345 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
24346 +       BUG_ON(atomic_read(&nxi->nx_tasks));
24347 +
24348 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
24349 +
24350 +       nxi->nx_state |= NXS_RELEASED;
24351 +       kfree(nxi);
24352 +       atomic_dec(&nx_global_ctotal);
24353 +}
24354 +
24355 +static void __shutdown_nx_info(struct nx_info *nxi)
24356 +{
24357 +       nxi->nx_state |= NXS_SHUTDOWN;
24358 +       vs_net_change(nxi, VSC_NETDOWN);
24359 +}
24360 +
24361 +/*     exported stuff                                          */
24362 +
24363 +void free_nx_info(struct nx_info *nxi)
24364 +{
24365 +       /* context shutdown is mandatory */
24366 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
24367 +
24368 +       /* context must not be hashed */
24369 +       BUG_ON(nxi->nx_state & NXS_HASHED);
24370 +
24371 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
24372 +       BUG_ON(atomic_read(&nxi->nx_tasks));
24373 +
24374 +       __dealloc_nx_info(nxi);
24375 +}
24376 +
24377 +
24378 +void __nx_set_lback(struct nx_info *nxi)
24379 +{
24380 +       int nid = nxi->nx_id;
24381 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
24382 +
24383 +       nxi->v4_lback.s_addr = lback;
24384 +}
24385 +
24386 +extern int __nx_inet_add_lback(__be32 addr);
24387 +extern int __nx_inet_del_lback(__be32 addr);
24388 +
24389 +
24390 +/*     hash table for nx_info hash */
24391 +
24392 +#define NX_HASH_SIZE   13
24393 +
24394 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
24395 +
24396 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
24397 +
24398 +
24399 +static inline unsigned int __hashval(nid_t nid)
24400 +{
24401 +       return (nid % NX_HASH_SIZE);
24402 +}
24403 +
24404 +
24405 +
24406 +/*     __hash_nx_info()
24407 +
24408 +       * add the nxi to the global hash table
24409 +       * requires the hash_lock to be held                     */
24410 +
24411 +static inline void __hash_nx_info(struct nx_info *nxi)
24412 +{
24413 +       struct hlist_head *head;
24414 +
24415 +       vxd_assert_lock(&nx_info_hash_lock);
24416 +       vxdprintk(VXD_CBIT(nid, 4),
24417 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
24418 +
24419 +       /* context must not be hashed */
24420 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
24421 +
24422 +       nxi->nx_state |= NXS_HASHED;
24423 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
24424 +       hlist_add_head(&nxi->nx_hlist, head);
24425 +       atomic_inc(&nx_global_cactive);
24426 +}
24427 +
24428 +/*     __unhash_nx_info()
24429 +
24430 +       * remove the nxi from the global hash table
24431 +       * requires the hash_lock to be held                     */
24432 +
24433 +static inline void __unhash_nx_info(struct nx_info *nxi)
24434 +{
24435 +       vxd_assert_lock(&nx_info_hash_lock);
24436 +       vxdprintk(VXD_CBIT(nid, 4),
24437 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
24438 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
24439 +
24440 +       /* context must be hashed */
24441 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
24442 +       /* but without tasks */
24443 +       BUG_ON(atomic_read(&nxi->nx_tasks));
24444 +
24445 +       nxi->nx_state &= ~NXS_HASHED;
24446 +       hlist_del(&nxi->nx_hlist);
24447 +       atomic_dec(&nx_global_cactive);
24448 +}
24449 +
24450 +
24451 +/*     __lookup_nx_info()
24452 +
24453 +       * requires the hash_lock to be held
24454 +       * doesn't increment the nx_refcnt                       */
24455 +
24456 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
24457 +{
24458 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
24459 +       struct hlist_node *pos;
24460 +       struct nx_info *nxi;
24461 +
24462 +       vxd_assert_lock(&nx_info_hash_lock);
24463 +       hlist_for_each(pos, head) {
24464 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
24465 +
24466 +               if (nxi->nx_id == nid)
24467 +                       goto found;
24468 +       }
24469 +       nxi = NULL;
24470 +found:
24471 +       vxdprintk(VXD_CBIT(nid, 0),
24472 +               "__lookup_nx_info(#%u): %p[#%u]",
24473 +               nid, nxi, nxi ? nxi->nx_id : 0);
24474 +       return nxi;
24475 +}
24476 +
24477 +
24478 +/*     __create_nx_info()
24479 +
24480 +       * create the requested context
24481 +       * get(), claim() and hash it                            */
24482 +
24483 +static struct nx_info *__create_nx_info(int id)
24484 +{
24485 +       struct nx_info *new, *nxi = NULL;
24486 +
24487 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
24488 +
24489 +       if (!(new = __alloc_nx_info(id)))
24490 +               return ERR_PTR(-ENOMEM);
24491 +
24492 +       /* required to make dynamic xids unique */
24493 +       spin_lock(&nx_info_hash_lock);
24494 +
24495 +       /* static context requested */
24496 +       if ((nxi = __lookup_nx_info(id))) {
24497 +               vxdprintk(VXD_CBIT(nid, 0),
24498 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
24499 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
24500 +                       nxi = ERR_PTR(-EBUSY);
24501 +               else
24502 +                       nxi = ERR_PTR(-EEXIST);
24503 +               goto out_unlock;
24504 +       }
24505 +       /* new context */
24506 +       vxdprintk(VXD_CBIT(nid, 0),
24507 +               "create_nx_info(%d) = %p (new)", id, new);
24508 +       claim_nx_info(new, NULL);
24509 +       __nx_set_lback(new);
24510 +       __hash_nx_info(get_nx_info(new));
24511 +       nxi = new, new = NULL;
24512 +
24513 +out_unlock:
24514 +       spin_unlock(&nx_info_hash_lock);
24515 +       if (new)
24516 +               __dealloc_nx_info(new);
24517 +       return nxi;
24518 +}
24519 +
24520 +
24521 +
24522 +/*     exported stuff                                          */
24523 +
24524 +
24525 +void unhash_nx_info(struct nx_info *nxi)
24526 +{
24527 +       __shutdown_nx_info(nxi);
24528 +       spin_lock(&nx_info_hash_lock);
24529 +       __unhash_nx_info(nxi);
24530 +       spin_unlock(&nx_info_hash_lock);
24531 +}
24532 +
24533 +/*     lookup_nx_info()
24534 +
24535 +       * search for a nx_info and get() it
24536 +       * negative id means current                             */
24537 +
24538 +struct nx_info *lookup_nx_info(int id)
24539 +{
24540 +       struct nx_info *nxi = NULL;
24541 +
24542 +       if (id < 0) {
24543 +               nxi = get_nx_info(current->nx_info);
24544 +       } else if (id > 1) {
24545 +               spin_lock(&nx_info_hash_lock);
24546 +               nxi = get_nx_info(__lookup_nx_info(id));
24547 +               spin_unlock(&nx_info_hash_lock);
24548 +       }
24549 +       return nxi;
24550 +}
24551 +
24552 +/*     nid_is_hashed()
24553 +
24554 +       * verify that nid is still hashed                       */
24555 +
24556 +int nid_is_hashed(nid_t nid)
24557 +{
24558 +       int hashed;
24559 +
24560 +       spin_lock(&nx_info_hash_lock);
24561 +       hashed = (__lookup_nx_info(nid) != NULL);
24562 +       spin_unlock(&nx_info_hash_lock);
24563 +       return hashed;
24564 +}
24565 +
24566 +
24567 +#ifdef CONFIG_PROC_FS
24568 +
24569 +/*     get_nid_list()
24570 +
24571 +       * get a subset of hashed nids for proc
24572 +       * assumes size is at least one                          */
24573 +
24574 +int get_nid_list(int index, unsigned int *nids, int size)
24575 +{
24576 +       int hindex, nr_nids = 0;
24577 +
24578 +       /* only show current and children */
24579 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
24580 +               if (index > 0)
24581 +                       return 0;
24582 +               nids[nr_nids] = nx_current_nid();
24583 +               return 1;
24584 +       }
24585 +
24586 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
24587 +               struct hlist_head *head = &nx_info_hash[hindex];
24588 +               struct hlist_node *pos;
24589 +
24590 +               spin_lock(&nx_info_hash_lock);
24591 +               hlist_for_each(pos, head) {
24592 +                       struct nx_info *nxi;
24593 +
24594 +                       if (--index > 0)
24595 +                               continue;
24596 +
24597 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
24598 +                       nids[nr_nids] = nxi->nx_id;
24599 +                       if (++nr_nids >= size) {
24600 +                               spin_unlock(&nx_info_hash_lock);
24601 +                               goto out;
24602 +                       }
24603 +               }
24604 +               /* keep the lock time short */
24605 +               spin_unlock(&nx_info_hash_lock);
24606 +       }
24607 +out:
24608 +       return nr_nids;
24609 +}
24610 +#endif
24611 +
24612 +
24613 +/*
24614 + *     migrate task to new network
24615 + *     gets nxi, puts old_nxi on change
24616 + */
24617 +
24618 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
24619 +{
24620 +       struct nx_info *old_nxi;
24621 +       int ret = 0;
24622 +
24623 +       if (!p || !nxi)
24624 +               BUG();
24625 +
24626 +       vxdprintk(VXD_CBIT(nid, 5),
24627 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
24628 +               p, nxi, nxi->nx_id,
24629 +               atomic_read(&nxi->nx_usecnt),
24630 +               atomic_read(&nxi->nx_tasks));
24631 +
24632 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
24633 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
24634 +               return -EACCES;
24635 +
24636 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
24637 +               return -EFAULT;
24638 +
24639 +       /* maybe disallow this completely? */
24640 +       old_nxi = task_get_nx_info(p);
24641 +       if (old_nxi == nxi)
24642 +               goto out;
24643 +
24644 +       task_lock(p);
24645 +       if (old_nxi)
24646 +               clr_nx_info(&p->nx_info);
24647 +       claim_nx_info(nxi, p);
24648 +       set_nx_info(&p->nx_info, nxi);
24649 +       p->nid = nxi->nx_id;
24650 +       task_unlock(p);
24651 +
24652 +       vxdprintk(VXD_CBIT(nid, 5),
24653 +               "moved task %p into nxi:%p[#%d]",
24654 +               p, nxi, nxi->nx_id);
24655 +
24656 +       if (old_nxi)
24657 +               release_nx_info(old_nxi, p);
24658 +       ret = 0;
24659 +out:
24660 +       put_nx_info(old_nxi);
24661 +       return ret;
24662 +}
24663 +
24664 +
24665 +void nx_set_persistent(struct nx_info *nxi)
24666 +{
24667 +       vxdprintk(VXD_CBIT(nid, 6),
24668 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
24669 +
24670 +       get_nx_info(nxi);
24671 +       claim_nx_info(nxi, NULL);
24672 +}
24673 +
24674 +void nx_clear_persistent(struct nx_info *nxi)
24675 +{
24676 +       vxdprintk(VXD_CBIT(nid, 6),
24677 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
24678 +
24679 +       release_nx_info(nxi, NULL);
24680 +       put_nx_info(nxi);
24681 +}
24682 +
24683 +void nx_update_persistent(struct nx_info *nxi)
24684 +{
24685 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
24686 +               nx_set_persistent(nxi);
24687 +       else
24688 +               nx_clear_persistent(nxi);
24689 +}
24690 +
24691 +/* vserver syscall commands below here */
24692 +
24693 +/* taks nid and nx_info functions */
24694 +
24695 +#include <asm/uaccess.h>
24696 +
24697 +
24698 +int vc_task_nid(uint32_t id)
24699 +{
24700 +       nid_t nid;
24701 +
24702 +       if (id) {
24703 +               struct task_struct *tsk;
24704 +
24705 +               read_lock(&tasklist_lock);
24706 +               tsk = find_task_by_real_pid(id);
24707 +               nid = (tsk) ? tsk->nid : -ESRCH;
24708 +               read_unlock(&tasklist_lock);
24709 +       } else
24710 +               nid = nx_current_nid();
24711 +       return nid;
24712 +}
24713 +
24714 +
24715 +int vc_nx_info(struct nx_info *nxi, void __user *data)
24716 +{
24717 +       struct vcmd_nx_info_v0 vc_data;
24718 +
24719 +       vc_data.nid = nxi->nx_id;
24720 +
24721 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24722 +               return -EFAULT;
24723 +       return 0;
24724 +}
24725 +
24726 +
24727 +/* network functions */
24728 +
24729 +int vc_net_create(uint32_t nid, void __user *data)
24730 +{
24731 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
24732 +       struct nx_info *new_nxi;
24733 +       int ret;
24734 +
24735 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24736 +               return -EFAULT;
24737 +
24738 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
24739 +               return -EINVAL;
24740 +
24741 +       new_nxi = __create_nx_info(nid);
24742 +       if (IS_ERR(new_nxi))
24743 +               return PTR_ERR(new_nxi);
24744 +
24745 +       /* initial flags */
24746 +       new_nxi->nx_flags = vc_data.flagword;
24747 +
24748 +       ret = -ENOEXEC;
24749 +       if (vs_net_change(new_nxi, VSC_NETUP))
24750 +               goto out;
24751 +
24752 +       ret = nx_migrate_task(current, new_nxi);
24753 +       if (ret)
24754 +               goto out;
24755 +
24756 +       /* return context id on success */
24757 +       ret = new_nxi->nx_id;
24758 +
24759 +       /* get a reference for persistent contexts */
24760 +       if ((vc_data.flagword & NXF_PERSISTENT))
24761 +               nx_set_persistent(new_nxi);
24762 +out:
24763 +       release_nx_info(new_nxi, NULL);
24764 +       put_nx_info(new_nxi);
24765 +       return ret;
24766 +}
24767 +
24768 +
24769 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
24770 +{
24771 +       return nx_migrate_task(current, nxi);
24772 +}
24773 +
24774 +
24775 +
24776 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
24777 +       uint16_t type, uint16_t flags)
24778 +{
24779 +       struct nx_addr_v4 *nxa = &nxi->v4;
24780 +
24781 +       if (NX_IPV4(nxi)) {
24782 +               /* locate last entry */
24783 +               for (; nxa->next; nxa = nxa->next);
24784 +               nxa->next = __alloc_nx_addr_v4();
24785 +               nxa = nxa->next;
24786 +
24787 +               if (IS_ERR(nxa))
24788 +                       return PTR_ERR(nxa);
24789 +       }
24790 +
24791 +       if (nxi->v4.next)
24792 +               /* remove single ip for ip list */
24793 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
24794 +
24795 +       nxa->ip[0].s_addr = ip;
24796 +       nxa->ip[1].s_addr = ip2;
24797 +       nxa->mask.s_addr = mask;
24798 +       nxa->type = type;
24799 +       nxa->flags = flags;
24800 +       return 0;
24801 +}
24802 +
24803 +
24804 +int vc_net_add(struct nx_info *nxi, void __user *data)
24805 +{
24806 +       struct vcmd_net_addr_v0 vc_data;
24807 +       int index, ret = 0;
24808 +
24809 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24810 +               return -EFAULT;
24811 +
24812 +       switch (vc_data.type) {
24813 +       case NXA_TYPE_IPV4:
24814 +               if ((vc_data.count < 1) || (vc_data.count > 4))
24815 +                       return -EINVAL;
24816 +
24817 +               index = 0;
24818 +               while (index < vc_data.count) {
24819 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
24820 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
24821 +                       if (ret)
24822 +                               return ret;
24823 +                       index++;
24824 +               }
24825 +               ret = index;
24826 +               break;
24827 +
24828 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
24829 +               nxi->v4_bcast = vc_data.ip[0];
24830 +               ret = 1;
24831 +               break;
24832 +
24833 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
24834 +               nxi->v4_lback = vc_data.ip[0];
24835 +               ret = 1;
24836 +               break;
24837 +
24838 +       default:
24839 +               ret = -EINVAL;
24840 +               break;
24841 +       }
24842 +       return ret;
24843 +}
24844 +
24845 +int vc_net_remove(struct nx_info *nxi, void __user *data)
24846 +{
24847 +       struct vcmd_net_addr_v0 vc_data;
24848 +
24849 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24850 +               return -EFAULT;
24851 +
24852 +       switch (vc_data.type) {
24853 +       case NXA_TYPE_ANY:
24854 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
24855 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
24856 +               break;
24857 +
24858 +       default:
24859 +               return -EINVAL;
24860 +       }
24861 +       return 0;
24862 +}
24863 +
24864 +
24865 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
24866 +{
24867 +       struct vcmd_net_addr_ipv4_v1 vc_data;
24868 +
24869 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24870 +               return -EFAULT;
24871 +
24872 +       switch (vc_data.type) {
24873 +       case NXA_TYPE_ADDR:
24874 +       case NXA_TYPE_RANGE:
24875 +       case NXA_TYPE_MASK:
24876 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
24877 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
24878 +
24879 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
24880 +               nxi->v4_bcast = vc_data.ip;
24881 +               break;
24882 +
24883 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
24884 +               nxi->v4_lback = vc_data.ip;
24885 +               break;
24886 +
24887 +       default:
24888 +               return -EINVAL;
24889 +       }
24890 +       return 0;
24891 +}
24892 +
24893 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
24894 +{
24895 +       struct vcmd_net_addr_ipv4_v1 vc_data;
24896 +
24897 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24898 +               return -EFAULT;
24899 +
24900 +       switch (vc_data.type) {
24901 +/*     case NXA_TYPE_ADDR:
24902 +               break;          */
24903 +
24904 +       case NXA_TYPE_ANY:
24905 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
24906 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
24907 +               break;
24908 +
24909 +       default:
24910 +               return -EINVAL;
24911 +       }
24912 +       return 0;
24913 +}
24914 +
24915 +
24916 +#ifdef CONFIG_IPV6
24917 +
24918 +int do_add_v6_addr(struct nx_info *nxi,
24919 +       struct in6_addr *ip, struct in6_addr *mask,
24920 +       uint32_t prefix, uint16_t type, uint16_t flags)
24921 +{
24922 +       struct nx_addr_v6 *nxa = &nxi->v6;
24923 +
24924 +       if (NX_IPV6(nxi)) {
24925 +               /* locate last entry */
24926 +               for (; nxa->next; nxa = nxa->next);
24927 +               nxa->next = __alloc_nx_addr_v6();
24928 +               nxa = nxa->next;
24929 +
24930 +               if (IS_ERR(nxa))
24931 +                       return PTR_ERR(nxa);
24932 +       }
24933 +
24934 +       nxa->ip = *ip;
24935 +       nxa->mask = *mask;
24936 +       nxa->prefix = prefix;
24937 +       nxa->type = type;
24938 +       nxa->flags = flags;
24939 +       return 0;
24940 +}
24941 +
24942 +
24943 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
24944 +{
24945 +       struct vcmd_net_addr_ipv6_v1 vc_data;
24946 +
24947 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24948 +               return -EFAULT;
24949 +
24950 +       switch (vc_data.type) {
24951 +       case NXA_TYPE_ADDR:
24952 +       case NXA_TYPE_MASK:
24953 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
24954 +                       vc_data.prefix, vc_data.type, vc_data.flags);
24955 +       default:
24956 +               return -EINVAL;
24957 +       }
24958 +       return 0;
24959 +}
24960 +
24961 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
24962 +{
24963 +       struct vcmd_net_addr_ipv6_v1 vc_data;
24964 +
24965 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24966 +               return -EFAULT;
24967 +
24968 +       switch (vc_data.type) {
24969 +       case NXA_TYPE_ANY:
24970 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
24971 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
24972 +               break;
24973 +
24974 +       default:
24975 +               return -EINVAL;
24976 +       }
24977 +       return 0;
24978 +}
24979 +
24980 +#endif /* CONFIG_IPV6 */
24981 +
24982 +
24983 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
24984 +{
24985 +       struct vcmd_net_flags_v0 vc_data;
24986 +
24987 +       vc_data.flagword = nxi->nx_flags;
24988 +
24989 +       /* special STATE flag handling */
24990 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
24991 +
24992 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24993 +               return -EFAULT;
24994 +       return 0;
24995 +}
24996 +
24997 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
24998 +{
24999 +       struct vcmd_net_flags_v0 vc_data;
25000 +       uint64_t mask, trigger;
25001 +
25002 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
25003 +               return -EFAULT;
25004 +
25005 +       /* special STATE flag handling */
25006 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
25007 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
25008 +
25009 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
25010 +               vc_data.flagword, mask);
25011 +       if (trigger & NXF_PERSISTENT)
25012 +               nx_update_persistent(nxi);
25013 +
25014 +       return 0;
25015 +}
25016 +
25017 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
25018 +{
25019 +       struct vcmd_net_caps_v0 vc_data;
25020 +
25021 +       vc_data.ncaps = nxi->nx_ncaps;
25022 +       vc_data.cmask = ~0ULL;
25023 +
25024 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
25025 +               return -EFAULT;
25026 +       return 0;
25027 +}
25028 +
25029 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
25030 +{
25031 +       struct vcmd_net_caps_v0 vc_data;
25032 +
25033 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
25034 +               return -EFAULT;
25035 +
25036 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
25037 +               vc_data.ncaps, vc_data.cmask);
25038 +       return 0;
25039 +}
25040 +
25041 +
25042 +#include <linux/module.h>
25043 +
25044 +module_init(init_network);
25045 +
25046 +EXPORT_SYMBOL_GPL(free_nx_info);
25047 +EXPORT_SYMBOL_GPL(unhash_nx_info);
25048 +
25049 diff -Nurp linux-2.6.22.18/kernel/vserver/proc.c linux-2.6.22.18-vs2.3.0.32/kernel/vserver/proc.c
25050 --- linux-2.6.22.18/kernel/vserver/proc.c       1970-01-01 01:00:00.000000000 +0100
25051 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/proc.c    2008-02-11 12:35:38.000000000 +0100
25052 @@ -0,0 +1,1065 @@
25053 +/*
25054 + *  linux/kernel/vserver/proc.c
25055 + *
25056 + *  Virtual Context Support
25057 + *
25058 + *  Copyright (C) 2003-2007  Herbert Pötzl
25059 + *
25060 + *  V0.01  basic structure
25061 + *  V0.02  adaptation vs1.3.0
25062 + *  V0.03  proc permissions
25063 + *  V0.04  locking/generic
25064 + *  V0.05  next generation procfs
25065 + *  V0.06  inode validation
25066 + *  V0.07  generic rewrite vid
25067 + *  V0.08  remove inode type
25068 + *
25069 + */
25070 +
25071 +#include <linux/proc_fs.h>
25072 +#include <asm/unistd.h>
25073 +
25074 +#include <linux/vs_context.h>
25075 +#include <linux/vs_network.h>
25076 +#include <linux/vs_cvirt.h>
25077 +#include <linux/vs_inet.h>
25078 +#include <linux/vs_inet6.h>
25079 +
25080 +#include <linux/vserver/global.h>
25081 +
25082 +#include "cvirt_proc.h"
25083 +#include "cacct_proc.h"
25084 +#include "limit_proc.h"
25085 +#include "sched_proc.h"
25086 +#include "vci_config.h"
25087 +
25088 +static struct proc_dir_entry *proc_virtual;
25089 +
25090 +static struct proc_dir_entry *proc_virtnet;
25091 +
25092 +
25093 +/* first the actual feeds */
25094 +
25095 +
25096 +static int proc_vci(char *buffer)
25097 +{
25098 +       return sprintf(buffer,
25099 +               "VCIVersion:\t%04x:%04x\n"
25100 +               "VCISyscall:\t%d\n"
25101 +               "VCIKernel:\t%08x\n",
25102 +               VCI_VERSION >> 16,
25103 +               VCI_VERSION & 0xFFFF,
25104 +               __NR_vserver,
25105 +               vci_kernel_config());
25106 +}
25107 +
25108 +static int proc_virtual_info(char *buffer)
25109 +{
25110 +       return proc_vci(buffer);
25111 +}
25112 +
25113 +static int proc_virtual_status(char *buffer)
25114 +{
25115 +       return sprintf(buffer,
25116 +               "#CTotal:\t%d\n"
25117 +               "#CActive:\t%d\n"
25118 +               "#NSProxy:\t%d\t%d %d %d %d\n",
25119 +               atomic_read(&vx_global_ctotal),
25120 +               atomic_read(&vx_global_cactive),
25121 +               atomic_read(&vs_global_nsproxy),
25122 +               atomic_read(&vs_global_fs),
25123 +               atomic_read(&vs_global_mnt_ns),
25124 +               atomic_read(&vs_global_uts_ns),
25125 +               atomic_read(&vs_global_ipc_ns));
25126 +}
25127 +
25128 +
25129 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
25130 +{
25131 +       int length;
25132 +
25133 +       length = sprintf(buffer,
25134 +               "ID:\t%d\n"
25135 +               "Info:\t%p\n"
25136 +               "Init:\t%d\n"
25137 +               "OOM:\t%lld\n",
25138 +               vxi->vx_id,
25139 +               vxi,
25140 +               vxi->vx_initpid,
25141 +               vxi->vx_badness_bias);
25142 +       return length;
25143 +}
25144 +
25145 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
25146 +{
25147 +       int length;
25148 +
25149 +       length = sprintf(buffer,
25150 +               "UseCnt:\t%d\n"
25151 +               "Tasks:\t%d\n"
25152 +               "Flags:\t%016llx\n"
25153 +               "BCaps:\t%016llx\n"
25154 +               "CCaps:\t%016llx\n"
25155 +               "Spaces:\t%08lx\n",
25156 +               atomic_read(&vxi->vx_usecnt),
25157 +               atomic_read(&vxi->vx_tasks),
25158 +               (unsigned long long)vxi->vx_flags,
25159 +               (unsigned long long)vxi->vx_bcaps,
25160 +               (unsigned long long)vxi->vx_ccaps,
25161 +               vxi->vx_nsmask);
25162 +       return length;
25163 +}
25164 +
25165 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
25166 +{
25167 +       return vx_info_proc_limit(&vxi->limit, buffer);
25168 +}
25169 +
25170 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
25171 +{
25172 +       int cpu, length;
25173 +
25174 +       length = vx_info_proc_sched(&vxi->sched, buffer);
25175 +       for_each_online_cpu(cpu) {
25176 +               length += vx_info_proc_sched_pc(
25177 +                       &vx_per_cpu(vxi, sched_pc, cpu),
25178 +                       buffer + length, cpu);
25179 +       }
25180 +       return length;
25181 +}
25182 +
25183 +int proc_vxi_nsproxy(struct vx_info *vxi, char *buffer)
25184 +{
25185 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy, buffer);
25186 +}
25187 +
25188 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
25189 +{
25190 +       int cpu, length;
25191 +
25192 +       vx_update_load(vxi);
25193 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
25194 +       for_each_online_cpu(cpu) {
25195 +               length += vx_info_proc_cvirt_pc(
25196 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
25197 +                       buffer + length, cpu);
25198 +       }
25199 +       return length;
25200 +}
25201 +
25202 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
25203 +{
25204 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
25205 +}
25206 +
25207 +
25208 +static int proc_virtnet_info(char *buffer)
25209 +{
25210 +       return proc_vci(buffer);
25211 +}
25212 +
25213 +static int proc_virtnet_status(char *buffer)
25214 +{
25215 +       return sprintf(buffer,
25216 +               "#CTotal:\t%d\n"
25217 +               "#CActive:\t%d\n",
25218 +               atomic_read(&nx_global_ctotal),
25219 +               atomic_read(&nx_global_cactive));
25220 +}
25221 +
25222 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
25223 +{
25224 +       struct nx_addr_v4 *v4a;
25225 +#ifdef CONFIG_IPV6
25226 +       struct nx_addr_v6 *v6a;
25227 +#endif
25228 +       int length, i;
25229 +
25230 +       length = sprintf(buffer,
25231 +               "ID:\t%d\n"
25232 +               "Info:\t%p\n"
25233 +               "Bcast:\t" NIPQUAD_FMT "\n"
25234 +               "Lback:\t" NIPQUAD_FMT "\n",
25235 +               nxi->nx_id,
25236 +               nxi,
25237 +               NIPQUAD(nxi->v4_bcast.s_addr),
25238 +               NIPQUAD(nxi->v4_lback.s_addr));
25239 +
25240 +       if (!NX_IPV4(nxi))
25241 +               goto skip_v4;
25242 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
25243 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
25244 +                       i, NXAV4(v4a));
25245 +skip_v4:
25246 +#ifdef CONFIG_IPV6
25247 +       if (!NX_IPV6(nxi))
25248 +               goto skip_v6;
25249 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
25250 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
25251 +                       i, NXAV6(v6a));
25252 +skip_v6:
25253 +#endif
25254 +       return length;
25255 +}
25256 +
25257 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
25258 +{
25259 +       int length;
25260 +
25261 +       length = sprintf(buffer,
25262 +               "UseCnt:\t%d\n"
25263 +               "Tasks:\t%d\n"
25264 +               "Flags:\t%016llx\n"
25265 +               "NCaps:\t%016llx\n",
25266 +               atomic_read(&nxi->nx_usecnt),
25267 +               atomic_read(&nxi->nx_tasks),
25268 +               (unsigned long long)nxi->nx_flags,
25269 +               (unsigned long long)nxi->nx_ncaps);
25270 +       return length;
25271 +}
25272 +
25273 +
25274 +
25275 +/* here the inode helpers */
25276 +
25277 +struct vs_entry {
25278 +       int len;
25279 +       char *name;
25280 +       mode_t mode;
25281 +       struct inode_operations *iop;
25282 +       struct file_operations *fop;
25283 +       union proc_op op;
25284 +};
25285 +
25286 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
25287 +{
25288 +       struct inode *inode = new_inode(sb);
25289 +
25290 +       if (!inode)
25291 +               goto out;
25292 +
25293 +       inode->i_mode = p->mode;
25294 +       if (p->iop)
25295 +               inode->i_op = p->iop;
25296 +       if (p->fop)
25297 +               inode->i_fop = p->fop;
25298 +
25299 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
25300 +       inode->i_flags |= S_IMMUTABLE;
25301 +
25302 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
25303 +
25304 +       inode->i_uid = 0;
25305 +       inode->i_gid = 0;
25306 +       inode->i_tag = 0;
25307 +out:
25308 +       return inode;
25309 +}
25310 +
25311 +static struct dentry *vs_proc_instantiate(struct inode *dir,
25312 +       struct dentry *dentry, int id, void *ptr)
25313 +{
25314 +       struct vs_entry *p = ptr;
25315 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
25316 +       struct dentry *error = ERR_PTR(-EINVAL);
25317 +
25318 +       if (!inode)
25319 +               goto out;
25320 +
25321 +       PROC_I(inode)->op = p->op;
25322 +       PROC_I(inode)->fd = id;
25323 +       d_add(dentry, inode);
25324 +       error = NULL;
25325 +out:
25326 +       return error;
25327 +}
25328 +
25329 +/* Lookups */
25330 +
25331 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
25332 +
25333 +/*
25334 + * Fill a directory entry.
25335 + *
25336 + * If possible create the dcache entry and derive our inode number and
25337 + * file type from dcache entry.
25338 + *
25339 + * Since all of the proc inode numbers are dynamically generated, the inode
25340 + * numbers do not exist until the inode is cache.  This means creating the
25341 + * the dcache entry in readdir is necessary to keep the inode numbers
25342 + * reported by readdir in sync with the inode numbers reported
25343 + * by stat.
25344 + */
25345 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
25346 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
25347 +{
25348 +       struct dentry *child, *dir = filp->f_dentry;
25349 +       struct inode *inode;
25350 +       struct qstr qname;
25351 +       ino_t ino = 0;
25352 +       unsigned type = DT_UNKNOWN;
25353 +
25354 +       qname.name = name;
25355 +       qname.len  = len;
25356 +       qname.hash = full_name_hash(name, len);
25357 +
25358 +       child = d_lookup(dir, &qname);
25359 +       if (!child) {
25360 +               struct dentry *new;
25361 +               new = d_alloc(dir, &qname);
25362 +               if (new) {
25363 +                       child = instantiate(dir->d_inode, new, id, ptr);
25364 +                       if (child)
25365 +                               dput(new);
25366 +                       else
25367 +                               child = new;
25368 +               }
25369 +       }
25370 +       if (!child || IS_ERR(child) || !child->d_inode)
25371 +               goto end_instantiate;
25372 +       inode = child->d_inode;
25373 +       if (inode) {
25374 +               ino = inode->i_ino;
25375 +               type = inode->i_mode >> 12;
25376 +       }
25377 +       dput(child);
25378 +end_instantiate:
25379 +       if (!ino)
25380 +               ino = find_inode_number(dir, &qname);
25381 +       if (!ino)
25382 +               ino = 1;
25383 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
25384 +}
25385 +
25386 +
25387 +
25388 +/* get and revalidate vx_info/xid */
25389 +
25390 +static inline
25391 +struct vx_info *get_proc_vx_info(struct inode *inode)
25392 +{
25393 +       return lookup_vx_info(PROC_I(inode)->fd);
25394 +}
25395 +
25396 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
25397 +{
25398 +       struct inode *inode = dentry->d_inode;
25399 +       xid_t xid = PROC_I(inode)->fd;
25400 +
25401 +       if (!xid || xid_is_hashed(xid))
25402 +               return 1;
25403 +       d_drop(dentry);
25404 +       return 0;
25405 +}
25406 +
25407 +
25408 +/* get and revalidate nx_info/nid */
25409 +
25410 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
25411 +{
25412 +       struct inode *inode = dentry->d_inode;
25413 +       nid_t nid = PROC_I(inode)->fd;
25414 +
25415 +       if (!nid || nid_is_hashed(nid))
25416 +               return 1;
25417 +       d_drop(dentry);
25418 +       return 0;
25419 +}
25420 +
25421 +
25422 +
25423 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
25424 +
25425 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
25426 +                         size_t count, loff_t *ppos)
25427 +{
25428 +       struct inode *inode = file->f_dentry->d_inode;
25429 +       unsigned long page;
25430 +       ssize_t length = 0;
25431 +
25432 +       if (count > PROC_BLOCK_SIZE)
25433 +               count = PROC_BLOCK_SIZE;
25434 +
25435 +       /* fade that out as soon as stable */
25436 +       WARN_ON(PROC_I(inode)->fd);
25437 +
25438 +       if (!(page = __get_free_page(GFP_KERNEL)))
25439 +               return -ENOMEM;
25440 +
25441 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
25442 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
25443 +
25444 +       if (length >= 0)
25445 +               length = simple_read_from_buffer(buf, count, ppos,
25446 +                       (char *)page, length);
25447 +
25448 +       free_page(page);
25449 +       return length;
25450 +}
25451 +
25452 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
25453 +                         size_t count, loff_t *ppos)
25454 +{
25455 +       struct inode *inode = file->f_dentry->d_inode;
25456 +       struct vx_info *vxi = NULL;
25457 +       xid_t xid = PROC_I(inode)->fd;
25458 +       unsigned long page;
25459 +       ssize_t length = 0;
25460 +
25461 +       if (count > PROC_BLOCK_SIZE)
25462 +               count = PROC_BLOCK_SIZE;
25463 +
25464 +       /* fade that out as soon as stable */
25465 +       WARN_ON(!xid);
25466 +       vxi = lookup_vx_info(xid);
25467 +       if (!vxi)
25468 +               goto out;
25469 +
25470 +       length = -ENOMEM;
25471 +       if (!(page = __get_free_page(GFP_KERNEL)))
25472 +               goto out_put;
25473 +
25474 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
25475 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
25476 +
25477 +       if (length >= 0)
25478 +               length = simple_read_from_buffer(buf, count, ppos,
25479 +                       (char *)page, length);
25480 +
25481 +       free_page(page);
25482 +out_put:
25483 +       put_vx_info(vxi);
25484 +out:
25485 +       return length;
25486 +}
25487 +
25488 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
25489 +                         size_t count, loff_t *ppos)
25490 +{
25491 +       struct inode *inode = file->f_dentry->d_inode;
25492 +       struct nx_info *nxi = NULL;
25493 +       nid_t nid = PROC_I(inode)->fd;
25494 +       unsigned long page;
25495 +       ssize_t length = 0;
25496 +
25497 +       if (count > PROC_BLOCK_SIZE)
25498 +               count = PROC_BLOCK_SIZE;
25499 +
25500 +       /* fade that out as soon as stable */
25501 +       WARN_ON(!nid);
25502 +       nxi = lookup_nx_info(nid);
25503 +       if (!nxi)
25504 +               goto out;
25505 +
25506 +       length = -ENOMEM;
25507 +       if (!(page = __get_free_page(GFP_KERNEL)))
25508 +               goto out_put;
25509 +
25510 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
25511 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
25512 +
25513 +       if (length >= 0)
25514 +               length = simple_read_from_buffer(buf, count, ppos,
25515 +                       (char *)page, length);
25516 +
25517 +       free_page(page);
25518 +out_put:
25519 +       put_nx_info(nxi);
25520 +out:
25521 +       return length;
25522 +}
25523 +
25524 +
25525 +
25526 +/* here comes the lower level */
25527 +
25528 +
25529 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
25530 +       .len  = sizeof(NAME) - 1,       \
25531 +       .name = (NAME),                 \
25532 +       .mode = MODE,                   \
25533 +       .iop  = IOP,                    \
25534 +       .fop  = FOP,                    \
25535 +       .op   = OP,                     \
25536 +}
25537 +
25538 +
25539 +#define DIR(NAME, MODE, OTYPE)                         \
25540 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
25541 +               &proc_ ## OTYPE ## _inode_operations,   \
25542 +               &proc_ ## OTYPE ## _file_operations, { } )
25543 +
25544 +#define INF(NAME, MODE, OTYPE)                         \
25545 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
25546 +               &proc_vs_info_file_operations,          \
25547 +               { .proc_vs_read = &proc_##OTYPE } )
25548 +
25549 +#define VINF(NAME, MODE, OTYPE)                                \
25550 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
25551 +               &proc_vx_info_file_operations,          \
25552 +               { .proc_vxi_read = &proc_##OTYPE } )
25553 +
25554 +#define NINF(NAME, MODE, OTYPE)                                \
25555 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
25556 +               &proc_nx_info_file_operations,          \
25557 +               { .proc_nxi_read = &proc_##OTYPE } )
25558 +
25559 +
25560 +static struct file_operations proc_vs_info_file_operations = {
25561 +       .read =         proc_vs_info_read,
25562 +};
25563 +
25564 +static struct file_operations proc_vx_info_file_operations = {
25565 +       .read =         proc_vx_info_read,
25566 +};
25567 +
25568 +static struct dentry_operations proc_xid_dentry_operations = {
25569 +       .d_revalidate = proc_xid_revalidate,
25570 +};
25571 +
25572 +static struct vs_entry vx_base_stuff[] = {
25573 +       VINF("info",    S_IRUGO, vxi_info),
25574 +       VINF("status",  S_IRUGO, vxi_status),
25575 +       VINF("limit",   S_IRUGO, vxi_limit),
25576 +       VINF("sched",   S_IRUGO, vxi_sched),
25577 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy),
25578 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
25579 +       VINF("cacct",   S_IRUGO, vxi_cacct),
25580 +       {}
25581 +};
25582 +
25583 +
25584 +
25585 +
25586 +static struct dentry *proc_xid_instantiate(struct inode *dir,
25587 +       struct dentry *dentry, int id, void *ptr)
25588 +{
25589 +       dentry->d_op = &proc_xid_dentry_operations;
25590 +       return vs_proc_instantiate(dir, dentry, id, ptr);
25591 +}
25592 +
25593 +static struct dentry *proc_xid_lookup(struct inode *dir,
25594 +       struct dentry *dentry, struct nameidata *nd)
25595 +{
25596 +       struct vs_entry *p = vx_base_stuff;
25597 +       struct dentry *error = ERR_PTR(-ENOENT);
25598 +
25599 +       for (; p->name; p++) {
25600 +               if (p->len != dentry->d_name.len)
25601 +                       continue;
25602 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
25603 +                       break;
25604 +       }
25605 +       if (!p->name)
25606 +               goto out;
25607 +
25608 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
25609 +out:
25610 +       return error;
25611 +}
25612 +
25613 +static int proc_xid_readdir(struct file *filp,
25614 +       void *dirent, filldir_t filldir)
25615 +{
25616 +       struct dentry *dentry = filp->f_dentry;
25617 +       struct inode *inode = dentry->d_inode;
25618 +       struct vs_entry *p = vx_base_stuff;
25619 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
25620 +       int pos, index;
25621 +       u64 ino;
25622 +
25623 +       pos = filp->f_pos;
25624 +       switch (pos) {
25625 +       case 0:
25626 +               ino = inode->i_ino;
25627 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
25628 +                       goto out;
25629 +               pos++;
25630 +               /* fall through */
25631 +       case 1:
25632 +               ino = parent_ino(dentry);
25633 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
25634 +                       goto out;
25635 +               pos++;
25636 +               /* fall through */
25637 +       default:
25638 +               index = pos - 2;
25639 +               if (index >= size)
25640 +                       goto out;
25641 +               for (p += index; p->name; p++) {
25642 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
25643 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
25644 +                               goto out;
25645 +                       pos++;
25646 +               }
25647 +       }
25648 +out:
25649 +       filp->f_pos = pos;
25650 +       return 1;
25651 +}
25652 +
25653 +
25654 +
25655 +static struct file_operations proc_nx_info_file_operations = {
25656 +       .read =         proc_nx_info_read,
25657 +};
25658 +
25659 +static struct dentry_operations proc_nid_dentry_operations = {
25660 +       .d_revalidate = proc_nid_revalidate,
25661 +};
25662 +
25663 +static struct vs_entry nx_base_stuff[] = {
25664 +       NINF("info",    S_IRUGO, nxi_info),
25665 +       NINF("status",  S_IRUGO, nxi_status),
25666 +       {}
25667 +};
25668 +
25669 +
25670 +static struct dentry *proc_nid_instantiate(struct inode *dir,
25671 +       struct dentry *dentry, int id, void *ptr)
25672 +{
25673 +       dentry->d_op = &proc_nid_dentry_operations;
25674 +       return vs_proc_instantiate(dir, dentry, id, ptr);
25675 +}
25676 +
25677 +static struct dentry *proc_nid_lookup(struct inode *dir,
25678 +       struct dentry *dentry, struct nameidata *nd)
25679 +{
25680 +       struct vs_entry *p = nx_base_stuff;
25681 +       struct dentry *error = ERR_PTR(-ENOENT);
25682 +
25683 +       for (; p->name; p++) {
25684 +               if (p->len != dentry->d_name.len)
25685 +                       continue;
25686 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
25687 +                       break;
25688 +       }
25689 +       if (!p->name)
25690 +               goto out;
25691 +
25692 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
25693 +out:
25694 +       return error;
25695 +}
25696 +
25697 +static int proc_nid_readdir(struct file *filp,
25698 +       void *dirent, filldir_t filldir)
25699 +{
25700 +       struct dentry *dentry = filp->f_dentry;
25701 +       struct inode *inode = dentry->d_inode;
25702 +       struct vs_entry *p = nx_base_stuff;
25703 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
25704 +       int pos, index;
25705 +       u64 ino;
25706 +
25707 +       pos = filp->f_pos;
25708 +       switch (pos) {
25709 +       case 0:
25710 +               ino = inode->i_ino;
25711 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
25712 +                       goto out;
25713 +               pos++;
25714 +               /* fall through */
25715 +       case 1:
25716 +               ino = parent_ino(dentry);
25717 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
25718 +                       goto out;
25719 +               pos++;
25720 +               /* fall through */
25721 +       default:
25722 +               index = pos - 2;
25723 +               if (index >= size)
25724 +                       goto out;
25725 +               for (p += index; p->name; p++) {
25726 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
25727 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
25728 +                               goto out;
25729 +                       pos++;
25730 +               }
25731 +       }
25732 +out:
25733 +       filp->f_pos = pos;
25734 +       return 1;
25735 +}
25736 +
25737 +
25738 +#define MAX_MULBY10    ((~0U - 9) / 10)
25739 +
25740 +static inline int atovid(const char *str, int len)
25741 +{
25742 +       int vid, c;
25743 +
25744 +       vid = 0;
25745 +       while (len-- > 0) {
25746 +               c = *str - '0';
25747 +               str++;
25748 +               if (c > 9)
25749 +                       return -1;
25750 +               if (vid >= MAX_MULBY10)
25751 +                       return -1;
25752 +               vid *= 10;
25753 +               vid += c;
25754 +               if (!vid)
25755 +                       return -1;
25756 +       }
25757 +       return vid;
25758 +}
25759 +
25760 +/* now the upper level (virtual) */
25761 +
25762 +
25763 +static struct file_operations proc_xid_file_operations = {
25764 +       .read =         generic_read_dir,
25765 +       .readdir =      proc_xid_readdir,
25766 +};
25767 +
25768 +static struct inode_operations proc_xid_inode_operations = {
25769 +       .lookup =       proc_xid_lookup,
25770 +};
25771 +
25772 +static struct vs_entry vx_virtual_stuff[] = {
25773 +       INF("info",     S_IRUGO, virtual_info),
25774 +       INF("status",   S_IRUGO, virtual_status),
25775 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
25776 +};
25777 +
25778 +
25779 +static struct dentry *proc_virtual_lookup(struct inode *dir,
25780 +       struct dentry *dentry, struct nameidata *nd)
25781 +{
25782 +       struct vs_entry *p = vx_virtual_stuff;
25783 +       struct dentry *error = ERR_PTR(-ENOENT);
25784 +       int id = 0;
25785 +
25786 +       for (; p->name; p++) {
25787 +               if (p->len != dentry->d_name.len)
25788 +                       continue;
25789 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
25790 +                       break;
25791 +       }
25792 +       if (p->name)
25793 +               goto instantiate;
25794 +
25795 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
25796 +       if ((id < 0) || !xid_is_hashed(id))
25797 +               goto out;
25798 +
25799 +instantiate:
25800 +       error = proc_xid_instantiate(dir, dentry, id, p);
25801 +out:
25802 +       return error;
25803 +}
25804 +
25805 +static struct file_operations proc_nid_file_operations = {
25806 +       .read =         generic_read_dir,
25807 +       .readdir =      proc_nid_readdir,
25808 +};
25809 +
25810 +static struct inode_operations proc_nid_inode_operations = {
25811 +       .lookup =       proc_nid_lookup,
25812 +};
25813 +
25814 +static struct vs_entry nx_virtnet_stuff[] = {
25815 +       INF("info",     S_IRUGO, virtnet_info),
25816 +       INF("status",   S_IRUGO, virtnet_status),
25817 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
25818 +};
25819 +
25820 +
25821 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
25822 +       struct dentry *dentry, struct nameidata *nd)
25823 +{
25824 +       struct vs_entry *p = nx_virtnet_stuff;
25825 +       struct dentry *error = ERR_PTR(-ENOENT);
25826 +       int id = 0;
25827 +
25828 +       for (; p->name; p++) {
25829 +               if (p->len != dentry->d_name.len)
25830 +                       continue;
25831 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
25832 +                       break;
25833 +       }
25834 +       if (p->name)
25835 +               goto instantiate;
25836 +
25837 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
25838 +       if ((id < 0) || !nid_is_hashed(id))
25839 +               goto out;
25840 +
25841 +instantiate:
25842 +       error = proc_nid_instantiate(dir, dentry, id, p);
25843 +out:
25844 +       return error;
25845 +}
25846 +
25847 +
25848 +
25849 +#define PROC_NUMBUF 10
25850 +#define PROC_MAXVIDS 32
25851 +
25852 +int proc_virtual_readdir(struct file *filp,
25853 +       void *dirent, filldir_t filldir)
25854 +{
25855 +       struct dentry *dentry = filp->f_dentry;
25856 +       struct inode *inode = dentry->d_inode;
25857 +       struct vs_entry *p = vx_virtual_stuff;
25858 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
25859 +       int pos, index;
25860 +       unsigned int xid_array[PROC_MAXVIDS];
25861 +       char buf[PROC_NUMBUF];
25862 +       unsigned int nr_xids, i;
25863 +       u64 ino;
25864 +
25865 +       pos = filp->f_pos;
25866 +       switch (pos) {
25867 +       case 0:
25868 +               ino = inode->i_ino;
25869 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
25870 +                       goto out;
25871 +               pos++;
25872 +               /* fall through */
25873 +       case 1:
25874 +               ino = parent_ino(dentry);
25875 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
25876 +                       goto out;
25877 +               pos++;
25878 +               /* fall through */
25879 +       default:
25880 +               index = pos - 2;
25881 +               if (index >= size)
25882 +                       goto entries;
25883 +               for (p += index; p->name; p++) {
25884 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
25885 +                               vs_proc_instantiate, 0, p))
25886 +                               goto out;
25887 +                       pos++;
25888 +               }
25889 +       entries:
25890 +               index = pos - size;
25891 +               p = &vx_virtual_stuff[size - 1];
25892 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
25893 +               for (i = 0; i < nr_xids; i++) {
25894 +                       int n, xid = xid_array[i];
25895 +                       unsigned int j = PROC_NUMBUF;
25896 +
25897 +                       n = xid;
25898 +                       do
25899 +                               buf[--j] = '0' + (n % 10);
25900 +                       while (n /= 10);
25901 +
25902 +                       if (proc_fill_cache(filp, dirent, filldir,
25903 +                               buf + j, PROC_NUMBUF - j,
25904 +                               vs_proc_instantiate, xid, p))
25905 +                               goto out;
25906 +                       pos++;
25907 +               }
25908 +       }
25909 +out:
25910 +       filp->f_pos = pos;
25911 +       return 0;
25912 +}
25913 +
25914 +static int proc_virtual_getattr(struct vfsmount *mnt,
25915 +       struct dentry *dentry, struct kstat *stat)
25916 +{
25917 +       struct inode *inode = dentry->d_inode;
25918 +
25919 +       generic_fillattr(inode, stat);
25920 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
25921 +       return 0;
25922 +}
25923 +
25924 +static struct file_operations proc_virtual_dir_operations = {
25925 +       .read =         generic_read_dir,
25926 +       .readdir =      proc_virtual_readdir,
25927 +};
25928 +
25929 +static struct inode_operations proc_virtual_dir_inode_operations = {
25930 +       .getattr =      proc_virtual_getattr,
25931 +       .lookup =       proc_virtual_lookup,
25932 +};
25933 +
25934 +
25935 +
25936 +
25937 +
25938 +int proc_virtnet_readdir(struct file *filp,
25939 +       void *dirent, filldir_t filldir)
25940 +{
25941 +       struct dentry *dentry = filp->f_dentry;
25942 +       struct inode *inode = dentry->d_inode;
25943 +       struct vs_entry *p = nx_virtnet_stuff;
25944 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
25945 +       int pos, index;
25946 +       unsigned int nid_array[PROC_MAXVIDS];
25947 +       char buf[PROC_NUMBUF];
25948 +       unsigned int nr_nids, i;
25949 +       u64 ino;
25950 +
25951 +       pos = filp->f_pos;
25952 +       switch (pos) {
25953 +       case 0:
25954 +               ino = inode->i_ino;
25955 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
25956 +                       goto out;
25957 +               pos++;
25958 +               /* fall through */
25959 +       case 1:
25960 +               ino = parent_ino(dentry);
25961 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
25962 +                       goto out;
25963 +               pos++;
25964 +               /* fall through */
25965 +       default:
25966 +               index = pos - 2;
25967 +               if (index >= size)
25968 +                       goto entries;
25969 +               for (p += index; p->name; p++) {
25970 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
25971 +                               vs_proc_instantiate, 0, p))
25972 +                               goto out;
25973 +                       pos++;
25974 +               }
25975 +       entries:
25976 +               index = pos - size;
25977 +               p = &nx_virtnet_stuff[size - 1];
25978 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
25979 +               for (i = 0; i < nr_nids; i++) {
25980 +                       int n, nid = nid_array[i];
25981 +                       unsigned int j = PROC_NUMBUF;
25982 +
25983 +                       n = nid;
25984 +                       do
25985 +                               buf[--j] = '0' + (n % 10);
25986 +                       while (n /= 10);
25987 +
25988 +                       if (proc_fill_cache(filp, dirent, filldir,
25989 +                               buf + j, PROC_NUMBUF - j,
25990 +                               vs_proc_instantiate, nid, p))
25991 +                               goto out;
25992 +                       pos++;
25993 +               }
25994 +       }
25995 +out:
25996 +       filp->f_pos = pos;
25997 +       return 0;
25998 +}
25999 +
26000 +static int proc_virtnet_getattr(struct vfsmount *mnt,
26001 +       struct dentry *dentry, struct kstat *stat)
26002 +{
26003 +       struct inode *inode = dentry->d_inode;
26004 +
26005 +       generic_fillattr(inode, stat);
26006 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
26007 +       return 0;
26008 +}
26009 +
26010 +static struct file_operations proc_virtnet_dir_operations = {
26011 +       .read =         generic_read_dir,
26012 +       .readdir =      proc_virtnet_readdir,
26013 +};
26014 +
26015 +static struct inode_operations proc_virtnet_dir_inode_operations = {
26016 +       .getattr =      proc_virtnet_getattr,
26017 +       .lookup =       proc_virtnet_lookup,
26018 +};
26019 +
26020 +
26021 +
26022 +void proc_vx_init(void)
26023 +{
26024 +       struct proc_dir_entry *ent;
26025 +
26026 +       ent = proc_mkdir("virtual", 0);
26027 +       if (ent) {
26028 +               ent->proc_fops = &proc_virtual_dir_operations;
26029 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
26030 +       }
26031 +       proc_virtual = ent;
26032 +
26033 +       ent = proc_mkdir("virtnet", 0);
26034 +       if (ent) {
26035 +               ent->proc_fops = &proc_virtnet_dir_operations;
26036 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
26037 +       }
26038 +       proc_virtnet = ent;
26039 +}
26040 +
26041 +
26042 +
26043 +
26044 +/* per pid info */
26045 +
26046 +
26047 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
26048 +{
26049 +       struct vx_info *vxi;
26050 +       char *orig = buffer;
26051 +
26052 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
26053 +
26054 +       vxi = task_get_vx_info(p);
26055 +       if (!vxi)
26056 +               goto out;
26057 +
26058 +       buffer += sprintf(buffer, "BCaps:\t%016llx\n",
26059 +               (unsigned long long)vxi->vx_bcaps);
26060 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
26061 +               (unsigned long long)vxi->vx_ccaps);
26062 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
26063 +               (unsigned long long)vxi->vx_flags);
26064 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
26065 +
26066 +       put_vx_info(vxi);
26067 +out:
26068 +       return buffer - orig;
26069 +}
26070 +
26071 +
26072 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
26073 +{
26074 +       struct nx_info *nxi;
26075 +       struct nx_addr_v4 *v4a;
26076 +#ifdef CONFIG_IPV6
26077 +       struct nx_addr_v6 *v6a;
26078 +#endif
26079 +       char *orig = buffer;
26080 +       int i;
26081 +
26082 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
26083 +
26084 +       nxi = task_get_nx_info(p);
26085 +       if (!nxi)
26086 +               goto out;
26087 +
26088 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
26089 +               (unsigned long long)nxi->nx_ncaps);
26090 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
26091 +               (unsigned long long)nxi->nx_flags);
26092 +
26093 +       buffer += sprintf(buffer,
26094 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
26095 +               NIPQUAD(nxi->v4_bcast.s_addr));
26096 +       buffer += sprintf (buffer,
26097 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
26098 +               NIPQUAD(nxi->v4_lback.s_addr));
26099 +       if (!NX_IPV4(nxi))
26100 +               goto skip_v4;
26101 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
26102 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
26103 +                       i, NXAV4(v4a));
26104 +skip_v4:
26105 +#ifdef CONFIG_IPV6
26106 +       if (!NX_IPV6(nxi))
26107 +               goto skip_v6;
26108 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
26109 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
26110 +                       i, NXAV6(v6a));
26111 +skip_v6:
26112 +#endif
26113 +       put_nx_info(nxi);
26114 +out:
26115 +       return buffer - orig;
26116 +}
26117 +
26118 diff -Nurp linux-2.6.22.18/kernel/vserver/sched.c linux-2.6.22.18-vs2.3.0.32/kernel/vserver/sched.c
26119 --- linux-2.6.22.18/kernel/vserver/sched.c      1970-01-01 01:00:00.000000000 +0100
26120 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/sched.c   2008-02-11 12:35:38.000000000 +0100
26121 @@ -0,0 +1,413 @@
26122 +/*
26123 + *  linux/kernel/vserver/sched.c
26124 + *
26125 + *  Virtual Server: Scheduler Support
26126 + *
26127 + *  Copyright (C) 2004-2007  Herbert Pötzl
26128 + *
26129 + *  V0.01  adapted Sam Vilains version to 2.6.3
26130 + *  V0.02  removed legacy interface
26131 + *  V0.03  changed vcmds to vxi arg
26132 + *  V0.04  removed older and legacy interfaces
26133 + *
26134 + */
26135 +
26136 +#include <linux/vs_context.h>
26137 +#include <linux/vs_sched.h>
26138 +#include <linux/vserver/sched_cmd.h>
26139 +
26140 +#include <asm/uaccess.h>
26141 +
26142 +
26143 +#define vxd_check_range(val, min, max) do {            \
26144 +       vxlprintk((val < min) || (val > max),           \
26145 +               "check_range(%ld,%ld,%ld)",             \
26146 +               (long)val, (long)min, (long)max,        \
26147 +               __FILE__, __LINE__);                    \
26148 +       } while (0)
26149 +
26150 +
26151 +void vx_update_sched_param(struct _vx_sched *sched,
26152 +       struct _vx_sched_pc *sched_pc)
26153 +{
26154 +       unsigned int set_mask = sched->update_mask;
26155 +
26156 +       if (set_mask & VXSM_FILL_RATE)
26157 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
26158 +       if (set_mask & VXSM_INTERVAL)
26159 +               sched_pc->interval[0] = sched->interval[0];
26160 +       if (set_mask & VXSM_FILL_RATE2)
26161 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
26162 +       if (set_mask & VXSM_INTERVAL2)
26163 +               sched_pc->interval[1] = sched->interval[1];
26164 +       if (set_mask & VXSM_TOKENS)
26165 +               sched_pc->tokens = sched->tokens;
26166 +       if (set_mask & VXSM_TOKENS_MIN)
26167 +               sched_pc->tokens_min = sched->tokens_min;
26168 +       if (set_mask & VXSM_TOKENS_MAX)
26169 +               sched_pc->tokens_max = sched->tokens_max;
26170 +       if (set_mask & VXSM_PRIO_BIAS)
26171 +               sched_pc->prio_bias = sched->prio_bias;
26172 +
26173 +       if (set_mask & VXSM_IDLE_TIME)
26174 +               sched_pc->flags |= VXSF_IDLE_TIME;
26175 +       else
26176 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
26177 +
26178 +       /* reset time */
26179 +       sched_pc->norm_time = jiffies;
26180 +}
26181 +
26182 +
26183 +/*
26184 + * recalculate the context's scheduling tokens
26185 + *
26186 + * ret > 0 : number of tokens available
26187 + * ret < 0 : on hold, check delta_min[]
26188 + *          -1 only jiffies
26189 + *          -2 also idle time
26190 + *
26191 + */
26192 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
26193 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
26194 +{
26195 +       long delta;
26196 +       long tokens = 0;
26197 +       int flags = sched_pc->flags;
26198 +
26199 +       /* how much time did pass? */
26200 +       delta = *norm_time - sched_pc->norm_time;
26201 +       vxd_check_range(delta, 0, INT_MAX);
26202 +
26203 +       if (delta >= sched_pc->interval[0]) {
26204 +               long tokens, integral;
26205 +
26206 +               /* calc integral token part */
26207 +               tokens = delta / sched_pc->interval[0];
26208 +               integral = tokens * sched_pc->interval[0];
26209 +               tokens *= sched_pc->fill_rate[0];
26210 +#ifdef CONFIG_VSERVER_HARDCPU
26211 +               delta_min[0] = delta - integral;
26212 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
26213 +#endif
26214 +               /* advance time */
26215 +               sched_pc->norm_time += delta;
26216 +
26217 +               /* add tokens */
26218 +               sched_pc->tokens += tokens;
26219 +               sched_pc->token_time += tokens;
26220 +       } else
26221 +               delta_min[0] = delta;
26222 +
26223 +#ifdef CONFIG_VSERVER_IDLETIME
26224 +       if (!(flags & VXSF_IDLE_TIME))
26225 +               goto skip_idle;
26226 +
26227 +       /* how much was the idle skip? */
26228 +       delta = *idle_time - sched_pc->idle_time;
26229 +       vxd_check_range(delta, 0, INT_MAX);
26230 +
26231 +       if (delta >= sched_pc->interval[1]) {
26232 +               long tokens, integral;
26233 +
26234 +               /* calc fair share token part */
26235 +               tokens = delta / sched_pc->interval[1];
26236 +               integral = tokens * sched_pc->interval[1];
26237 +               tokens *= sched_pc->fill_rate[1];
26238 +               delta_min[1] = delta - integral;
26239 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
26240 +
26241 +               /* advance idle time */
26242 +               sched_pc->idle_time += integral;
26243 +
26244 +               /* add tokens */
26245 +               sched_pc->tokens += tokens;
26246 +               sched_pc->token_time += tokens;
26247 +       } else
26248 +               delta_min[1] = delta;
26249 +skip_idle:
26250 +#endif
26251 +
26252 +       /* clip at maximum */
26253 +       if (sched_pc->tokens > sched_pc->tokens_max)
26254 +               sched_pc->tokens = sched_pc->tokens_max;
26255 +       tokens = sched_pc->tokens;
26256 +
26257 +       if ((flags & VXSF_ONHOLD)) {
26258 +               /* can we unhold? */
26259 +               if (tokens >= sched_pc->tokens_min) {
26260 +                       flags &= ~VXSF_ONHOLD;
26261 +                       sched_pc->hold_ticks +=
26262 +                               *norm_time - sched_pc->onhold;
26263 +               } else
26264 +                       goto on_hold;
26265 +       } else {
26266 +               /* put on hold? */
26267 +               if (tokens <= 0) {
26268 +                       flags |= VXSF_ONHOLD;
26269 +                       sched_pc->onhold = *norm_time;
26270 +                       goto on_hold;
26271 +               }
26272 +       }
26273 +       sched_pc->flags = flags;
26274 +       return tokens;
26275 +
26276 +on_hold:
26277 +       tokens = sched_pc->tokens_min - tokens;
26278 +       sched_pc->flags = flags;
26279 +       BUG_ON(tokens < 0);
26280 +
26281 +#ifdef CONFIG_VSERVER_HARDCPU
26282 +       /* next interval? */
26283 +       if (!sched_pc->fill_rate[0])
26284 +               delta_min[0] = HZ;
26285 +       else if (tokens > sched_pc->fill_rate[0])
26286 +               delta_min[0] += sched_pc->interval[0] *
26287 +                       tokens / sched_pc->fill_rate[0];
26288 +       else
26289 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
26290 +       vxd_check_range(delta_min[0], 0, INT_MAX);
26291 +
26292 +#ifdef CONFIG_VSERVER_IDLETIME
26293 +       if (!(flags & VXSF_IDLE_TIME))
26294 +               return -1;
26295 +
26296 +       /* next interval? */
26297 +       if (!sched_pc->fill_rate[1])
26298 +               delta_min[1] = HZ;
26299 +       else if (tokens > sched_pc->fill_rate[1])
26300 +               delta_min[1] += sched_pc->interval[1] *
26301 +                       tokens / sched_pc->fill_rate[1];
26302 +       else
26303 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
26304 +       vxd_check_range(delta_min[1], 0, INT_MAX);
26305 +
26306 +       return -2;
26307 +#else
26308 +       return -1;
26309 +#endif /* CONFIG_VSERVER_IDLETIME */
26310 +#else
26311 +       return 0;
26312 +#endif /* CONFIG_VSERVER_HARDCPU */
26313 +}
26314 +
26315 +static inline unsigned long msec_to_ticks(unsigned long msec)
26316 +{
26317 +       return msecs_to_jiffies(msec);
26318 +}
26319 +
26320 +static inline unsigned long ticks_to_msec(unsigned long ticks)
26321 +{
26322 +       return jiffies_to_msecs(ticks);
26323 +}
26324 +
26325 +static inline unsigned long ticks_to_usec(unsigned long ticks)
26326 +{
26327 +       return jiffies_to_usecs(ticks);
26328 +}
26329 +
26330 +
26331 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
26332 +{
26333 +       unsigned int set_mask = data->mask;
26334 +       unsigned int update_mask;
26335 +       int i, cpu;
26336 +
26337 +       /* Sanity check data values */
26338 +       if (data->tokens_max <= 0)
26339 +               data->tokens_max = HZ;
26340 +       if (data->tokens_min < 0)
26341 +               data->tokens_min = HZ / 3;
26342 +       if (data->tokens_min >= data->tokens_max)
26343 +               data->tokens_min = data->tokens_max;
26344 +
26345 +       if (data->prio_bias > MAX_PRIO_BIAS)
26346 +               data->prio_bias = MAX_PRIO_BIAS;
26347 +       if (data->prio_bias < MIN_PRIO_BIAS)
26348 +               data->prio_bias = MIN_PRIO_BIAS;
26349 +
26350 +       spin_lock(&vxi->sched.tokens_lock);
26351 +
26352 +       /* sync up on delayed updates */
26353 +       for_each_cpu_mask(cpu, vxi->sched.update)
26354 +               vx_update_sched_param(&vxi->sched,
26355 +                       &vx_per_cpu(vxi, sched_pc, cpu));
26356 +
26357 +       if (set_mask & VXSM_FILL_RATE)
26358 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
26359 +       if (set_mask & VXSM_FILL_RATE2)
26360 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
26361 +       if (set_mask & VXSM_INTERVAL)
26362 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
26363 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
26364 +       if (set_mask & VXSM_INTERVAL2)
26365 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
26366 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
26367 +       if (set_mask & VXSM_TOKENS)
26368 +               vxi->sched.tokens = data->tokens;
26369 +       if (set_mask & VXSM_TOKENS_MIN)
26370 +               vxi->sched.tokens_min = data->tokens_min;
26371 +       if (set_mask & VXSM_TOKENS_MAX)
26372 +               vxi->sched.tokens_max = data->tokens_max;
26373 +       if (set_mask & VXSM_PRIO_BIAS)
26374 +               vxi->sched.prio_bias = data->prio_bias;
26375 +
26376 +       /* Sanity check rate/interval */
26377 +       for (i = 0; i < 2; i++) {
26378 +               if (data->fill_rate[i] < 0)
26379 +                       data->fill_rate[i] = 0;
26380 +               if (data->interval[i] <= 0)
26381 +                       data->interval[i] = HZ;
26382 +       }
26383 +
26384 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
26385 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
26386 +       vxi->sched.update_mask = update_mask;
26387 +
26388 +#ifdef CONFIG_SMP
26389 +       rmb();
26390 +       if (set_mask & VXSM_CPU_ID) {
26391 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
26392 +               cpus_and(vxi->sched.update, cpu_online_map,
26393 +                       vxi->sched.update);
26394 +       } else
26395 +               vxi->sched.update = cpu_online_map;
26396 +
26397 +       /* forced reload? */
26398 +       if (set_mask & VXSM_FORCE) {
26399 +               for_each_cpu_mask(cpu, vxi->sched.update)
26400 +                       vx_update_sched_param(&vxi->sched,
26401 +                               &vx_per_cpu(vxi, sched_pc, cpu));
26402 +               vxi->sched.update = CPU_MASK_NONE;
26403 +       }
26404 +#else
26405 +       /* on UP we update immediately */
26406 +       vx_update_sched_param(&vxi->sched,
26407 +               &vx_per_cpu(vxi, sched_pc, 0));
26408 +#endif
26409 +
26410 +       spin_unlock(&vxi->sched.tokens_lock);
26411 +       return 0;
26412 +}
26413 +
26414 +
26415 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
26416 +#define COPY_PRI(C) C(prio_bias)
26417 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
26418 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
26419 +                   C(fill_rate[1]); C(interval[1]);
26420 +
26421 +#define COPY_VALUE(name) vc_data.name = data->name
26422 +
26423 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
26424 +{
26425 +       struct vcmd_sched_v5 vc_data;
26426 +
26427 +       vc_data.mask = data->set_mask;
26428 +       COPY_IDS(COPY_VALUE);
26429 +       COPY_PRI(COPY_VALUE);
26430 +       COPY_TOK(COPY_VALUE);
26431 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
26432 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
26433 +       return do_set_sched(vxi, &vc_data);
26434 +}
26435 +
26436 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
26437 +{
26438 +       struct vcmd_set_sched_v4 vc_data;
26439 +
26440 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
26441 +               return -EFAULT;
26442 +
26443 +       return do_set_sched_v4(vxi, &vc_data);
26444 +}
26445 +
26446 +       /* latest interface is v5 */
26447 +
26448 +int vc_set_sched(struct vx_info *vxi, void __user *data)
26449 +{
26450 +       struct vcmd_sched_v5 vc_data;
26451 +
26452 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
26453 +               return -EFAULT;
26454 +
26455 +       return do_set_sched(vxi, &vc_data);
26456 +}
26457 +
26458 +
26459 +#define COPY_PRI(C) C(prio_bias)
26460 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
26461 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);    \
26462 +                   C(fill_rate[1]); C(interval[1]);
26463 +
26464 +#define COPY_VALUE(name) vc_data.name = data->name
26465 +
26466 +
26467 +int vc_get_sched(struct vx_info *vxi, void __user *data)
26468 +{
26469 +       struct vcmd_sched_v5 vc_data;
26470 +
26471 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
26472 +               return -EFAULT;
26473 +
26474 +       if (vc_data.mask & VXSM_CPU_ID) {
26475 +               int cpu = vc_data.cpu_id;
26476 +               struct _vx_sched_pc *data;
26477 +
26478 +               if (!cpu_possible(cpu))
26479 +                       return -EINVAL;
26480 +
26481 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
26482 +               COPY_TOK(COPY_VALUE);
26483 +               COPY_PRI(COPY_VALUE);
26484 +               COPY_FRI(COPY_VALUE);
26485 +
26486 +               if (data->flags & VXSF_IDLE_TIME)
26487 +                       vc_data.mask |= VXSM_IDLE_TIME;
26488 +       } else {
26489 +               struct _vx_sched *data = &vxi->sched;
26490 +
26491 +               COPY_TOK(COPY_VALUE);
26492 +               COPY_PRI(COPY_VALUE);
26493 +               COPY_FRI(COPY_VALUE);
26494 +       }
26495 +
26496 +       if (vc_data.mask & VXSM_MSEC) {
26497 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
26498 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
26499 +       }
26500 +
26501 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
26502 +               return -EFAULT;
26503 +       return 0;
26504 +}
26505 +
26506 +
26507 +int vc_sched_info(struct vx_info *vxi, void __user *data)
26508 +{
26509 +       struct vcmd_sched_info vc_data;
26510 +       int cpu;
26511 +
26512 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
26513 +               return -EFAULT;
26514 +
26515 +       cpu = vc_data.cpu_id;
26516 +       if (!cpu_possible(cpu))
26517 +               return -EINVAL;
26518 +
26519 +       if (vxi) {
26520 +               struct _vx_sched_pc *sched_pc =
26521 +                       &vx_per_cpu(vxi, sched_pc, cpu);
26522 +
26523 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
26524 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
26525 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
26526 +               vc_data.vavavoom = sched_pc->vavavoom;
26527 +       }
26528 +       vc_data.token_usec = ticks_to_usec(1);
26529 +
26530 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
26531 +               return -EFAULT;
26532 +       return 0;
26533 +}
26534 +
26535 diff -Nurp linux-2.6.22.18/kernel/vserver/sched_init.h linux-2.6.22.18-vs2.3.0.32/kernel/vserver/sched_init.h
26536 --- linux-2.6.22.18/kernel/vserver/sched_init.h 1970-01-01 01:00:00.000000000 +0100
26537 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/sched_init.h      2008-02-11 12:35:38.000000000 +0100
26538 @@ -0,0 +1,50 @@
26539 +
26540 +static inline void vx_info_init_sched(struct _vx_sched *sched)
26541 +{
26542 +       static struct lock_class_key tokens_lock_key;
26543 +
26544 +       /* scheduling; hard code starting values as constants */
26545 +       sched->fill_rate[0]     = 1;
26546 +       sched->interval[0]      = 4;
26547 +       sched->fill_rate[1]     = 1;
26548 +       sched->interval[1]      = 8;
26549 +       sched->tokens           = HZ >> 2;
26550 +       sched->tokens_min       = HZ >> 4;
26551 +       sched->tokens_max       = HZ >> 1;
26552 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
26553 +       sched->prio_bias        = 0;
26554 +
26555 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
26556 +}
26557 +
26558 +static inline
26559 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
26560 +{
26561 +       sched_pc->fill_rate[0]  = 1;
26562 +       sched_pc->interval[0]   = 4;
26563 +       sched_pc->fill_rate[1]  = 1;
26564 +       sched_pc->interval[1]   = 8;
26565 +       sched_pc->tokens        = HZ >> 2;
26566 +       sched_pc->tokens_min    = HZ >> 4;
26567 +       sched_pc->tokens_max    = HZ >> 1;
26568 +       sched_pc->prio_bias     = 0;
26569 +       sched_pc->vavavoom      = 0;
26570 +       sched_pc->token_time    = 0;
26571 +       sched_pc->idle_time     = 0;
26572 +       sched_pc->norm_time     = jiffies;
26573 +
26574 +       sched_pc->user_ticks = 0;
26575 +       sched_pc->sys_ticks = 0;
26576 +       sched_pc->hold_ticks = 0;
26577 +}
26578 +
26579 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
26580 +{
26581 +       return;
26582 +}
26583 +
26584 +static inline
26585 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
26586 +{
26587 +       return;
26588 +}
26589 diff -Nurp linux-2.6.22.18/kernel/vserver/sched_proc.h linux-2.6.22.18-vs2.3.0.32/kernel/vserver/sched_proc.h
26590 --- linux-2.6.22.18/kernel/vserver/sched_proc.h 1970-01-01 01:00:00.000000000 +0100
26591 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/sched_proc.h      2008-02-11 12:35:38.000000000 +0100
26592 @@ -0,0 +1,57 @@
26593 +#ifndef _VX_SCHED_PROC_H
26594 +#define _VX_SCHED_PROC_H
26595 +
26596 +
26597 +static inline
26598 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
26599 +{
26600 +       int length = 0;
26601 +
26602 +       length += sprintf(buffer,
26603 +               "FillRate:\t%8d,%d\n"
26604 +               "Interval:\t%8d,%d\n"
26605 +               "TokensMin:\t%8d\n"
26606 +               "TokensMax:\t%8d\n"
26607 +               "PrioBias:\t%8d\n",
26608 +               sched->fill_rate[0],
26609 +               sched->fill_rate[1],
26610 +               sched->interval[0],
26611 +               sched->interval[1],
26612 +               sched->tokens_min,
26613 +               sched->tokens_max,
26614 +               sched->prio_bias);
26615 +       return length;
26616 +}
26617 +
26618 +static inline
26619 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
26620 +       char *buffer, int cpu)
26621 +{
26622 +       int length = 0;
26623 +
26624 +       length += sprintf(buffer + length,
26625 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
26626 +               (unsigned long long)sched_pc->user_ticks,
26627 +               (unsigned long long)sched_pc->sys_ticks,
26628 +               (unsigned long long)sched_pc->hold_ticks,
26629 +               sched_pc->token_time,
26630 +               sched_pc->idle_time);
26631 +       length += sprintf(buffer + length,
26632 +               " %c%c %d %d %d %d/%d %d/%d",
26633 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
26634 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
26635 +               sched_pc->tokens,
26636 +               sched_pc->tokens_min,
26637 +               sched_pc->tokens_max,
26638 +               sched_pc->fill_rate[0],
26639 +               sched_pc->interval[0],
26640 +               sched_pc->fill_rate[1],
26641 +               sched_pc->interval[1]);
26642 +       length += sprintf(buffer + length,
26643 +               " %d %d\n",
26644 +               sched_pc->prio_bias,
26645 +               sched_pc->vavavoom);
26646 +       return length;
26647 +}
26648 +
26649 +#endif /* _VX_SCHED_PROC_H */
26650 diff -Nurp linux-2.6.22.18/kernel/vserver/signal.c linux-2.6.22.18-vs2.3.0.32/kernel/vserver/signal.c
26651 --- linux-2.6.22.18/kernel/vserver/signal.c     1970-01-01 01:00:00.000000000 +0100
26652 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/signal.c  2008-02-11 12:35:38.000000000 +0100
26653 @@ -0,0 +1,131 @@
26654 +/*
26655 + *  linux/kernel/vserver/signal.c
26656 + *
26657 + *  Virtual Server: Signal Support
26658 + *
26659 + *  Copyright (C) 2003-2007  Herbert Pötzl
26660 + *
26661 + *  V0.01  broken out from vcontext V0.05
26662 + *  V0.02  changed vcmds to vxi arg
26663 + *  V0.03  adjusted siginfo for kill
26664 + *
26665 + */
26666 +
26667 +#include <asm/uaccess.h>
26668 +
26669 +#include <linux/vs_context.h>
26670 +#include <linux/vserver/signal_cmd.h>
26671 +
26672 +
26673 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
26674 +{
26675 +       int retval, count = 0;
26676 +       struct task_struct *p;
26677 +       struct siginfo *sip = SEND_SIG_PRIV;
26678 +
26679 +       retval = -ESRCH;
26680 +       vxdprintk(VXD_CBIT(misc, 4),
26681 +               "vx_info_kill(%p[#%d],%d,%d)*",
26682 +               vxi, vxi->vx_id, pid, sig);
26683 +       read_lock(&tasklist_lock);
26684 +       switch (pid) {
26685 +       case  0:
26686 +       case -1:
26687 +               for_each_process(p) {
26688 +                       int err = 0;
26689 +
26690 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
26691 +                               (pid && vxi->vx_initpid == p->pid))
26692 +                               continue;
26693 +
26694 +                       err = group_send_sig_info(sig, sip, p);
26695 +                       ++count;
26696 +                       if (err != -EPERM)
26697 +                               retval = err;
26698 +               }
26699 +               break;
26700 +
26701 +       case 1:
26702 +               if (vxi->vx_initpid) {
26703 +                       pid = vxi->vx_initpid;
26704 +                       /* for now, only SIGINT to private init ... */
26705 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
26706 +                               /* ... as long as there are tasks left */
26707 +                               (atomic_read(&vxi->vx_tasks) > 1))
26708 +                               sig = SIGINT;
26709 +               }
26710 +               /* fallthrough */
26711 +       default:
26712 +               p = find_task_by_real_pid(pid);
26713 +               if (p) {
26714 +                       if (vx_task_xid(p) == vxi->vx_id)
26715 +                               retval = group_send_sig_info(sig, sip, p);
26716 +               }
26717 +               break;
26718 +       }
26719 +       read_unlock(&tasklist_lock);
26720 +       vxdprintk(VXD_CBIT(misc, 4),
26721 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
26722 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
26723 +       return retval;
26724 +}
26725 +
26726 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
26727 +{
26728 +       struct vcmd_ctx_kill_v0 vc_data;
26729 +
26730 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
26731 +               return -EFAULT;
26732 +
26733 +       /* special check to allow guest shutdown */
26734 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
26735 +               /* forbid killall pid=0 when init is present */
26736 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
26737 +               (vc_data.pid > 1)))
26738 +               return -EACCES;
26739 +
26740 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
26741 +}
26742 +
26743 +
26744 +static int __wait_exit(struct vx_info *vxi)
26745 +{
26746 +       DECLARE_WAITQUEUE(wait, current);
26747 +       int ret = 0;
26748 +
26749 +       add_wait_queue(&vxi->vx_wait, &wait);
26750 +       set_current_state(TASK_INTERRUPTIBLE);
26751 +
26752 +wait:
26753 +       if (vx_info_state(vxi,
26754 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
26755 +               goto out;
26756 +       if (signal_pending(current)) {
26757 +               ret = -ERESTARTSYS;
26758 +               goto out;
26759 +       }
26760 +       schedule();
26761 +       goto wait;
26762 +
26763 +out:
26764 +       set_current_state(TASK_RUNNING);
26765 +       remove_wait_queue(&vxi->vx_wait, &wait);
26766 +       return ret;
26767 +}
26768 +
26769 +
26770 +
26771 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
26772 +{
26773 +       struct vcmd_wait_exit_v0 vc_data;
26774 +       int ret;
26775 +
26776 +       ret = __wait_exit(vxi);
26777 +       vc_data.reboot_cmd = vxi->reboot_cmd;
26778 +       vc_data.exit_code = vxi->exit_code;
26779 +
26780 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
26781 +               ret = -EFAULT;
26782 +       return ret;
26783 +}
26784 +
26785 diff -Nurp linux-2.6.22.18/kernel/vserver/space.c linux-2.6.22.18-vs2.3.0.32/kernel/vserver/space.c
26786 --- linux-2.6.22.18/kernel/vserver/space.c      1970-01-01 01:00:00.000000000 +0100
26787 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/space.c   2008-02-11 12:35:38.000000000 +0100
26788 @@ -0,0 +1,277 @@
26789 +/*
26790 + *  linux/kernel/vserver/space.c
26791 + *
26792 + *  Virtual Server: Context Space Support
26793 + *
26794 + *  Copyright (C) 2003-2007  Herbert Pötzl
26795 + *
26796 + *  V0.01  broken out from context.c 0.07
26797 + *  V0.02  added task locking for namespace
26798 + *  V0.03  broken out vx_enter_namespace
26799 + *  V0.04  added *space support and commands
26800 + *
26801 + */
26802 +
26803 +#include <linux/utsname.h>
26804 +#include <linux/nsproxy.h>
26805 +#include <linux/err.h>
26806 +#include <asm/uaccess.h>
26807 +
26808 +#include <linux/vs_context.h>
26809 +#include <linux/vserver/space.h>
26810 +#include <linux/vserver/space_cmd.h>
26811 +
26812 +
26813 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
26814 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
26815 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
26816 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
26817 +atomic_t vs_global_ipc_ns      = ATOMIC_INIT(0);
26818 +
26819 +
26820 +/* namespace functions */
26821 +
26822 +#include <linux/mnt_namespace.h>
26823 +
26824 +const struct vcmd_space_mask space_mask = {
26825 +       .mask = CLONE_NEWNS |
26826 +               CLONE_NEWUTS |
26827 +               CLONE_NEWIPC |
26828 +               CLONE_FS
26829 +};
26830 +
26831 +
26832 +/*
26833 + *     build a new nsproxy mix
26834 + *      assumes that both proxies are 'const'
26835 + *     does not touch nsproxy refcounts
26836 + *     will hold a reference on the result.
26837 + */
26838 +
26839 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
26840 +       struct nsproxy *new_nsproxy, unsigned long mask)
26841 +{
26842 +       struct mnt_namespace *old_ns;
26843 +       struct uts_namespace *old_uts;
26844 +       struct ipc_namespace *old_ipc;
26845 +       struct nsproxy *nsproxy;
26846 +
26847 +       nsproxy = copy_nsproxy(old_nsproxy);
26848 +       if (!nsproxy)
26849 +               goto out;
26850 +
26851 +       if (mask & CLONE_NEWNS) {
26852 +               old_ns = nsproxy->mnt_ns;
26853 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
26854 +               if (nsproxy->mnt_ns)
26855 +                       get_mnt_ns(nsproxy->mnt_ns);
26856 +       } else
26857 +               old_ns = NULL;
26858 +
26859 +       if (mask & CLONE_NEWUTS) {
26860 +               old_uts = nsproxy->uts_ns;
26861 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
26862 +               if (nsproxy->uts_ns)
26863 +                       get_uts_ns(nsproxy->uts_ns);
26864 +       } else
26865 +               old_uts = NULL;
26866 +
26867 +       if (mask & CLONE_NEWIPC) {
26868 +               old_ipc = nsproxy->ipc_ns;
26869 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
26870 +               if (nsproxy->ipc_ns)
26871 +                       get_ipc_ns(nsproxy->ipc_ns);
26872 +       } else
26873 +               old_ipc = NULL;
26874 +
26875 +       if (old_ns)
26876 +               put_mnt_ns(old_ns);
26877 +       if (old_uts)
26878 +               put_uts_ns(old_uts);
26879 +       if (old_ipc)
26880 +               put_ipc_ns(old_ipc);
26881 +out:
26882 +       return nsproxy;
26883 +}
26884 +
26885 +
26886 +/*
26887 + *     merge two nsproxy structs into a new one.
26888 + *     will hold a reference on the result.
26889 + */
26890 +
26891 +static inline
26892 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
26893 +       struct nsproxy *proxy, unsigned long mask)
26894 +{
26895 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
26896 +
26897 +       if (!proxy)
26898 +               return NULL;
26899 +
26900 +       if (mask) {
26901 +               /* vs_mix_nsproxy returns with reference */
26902 +               return vs_mix_nsproxy(old ? old : &null_proxy,
26903 +                       proxy, mask);
26904 +       }
26905 +       get_nsproxy(proxy);
26906 +       return proxy;
26907 +}
26908 +
26909 +/*
26910 + *     merge two fs structs into a new one.
26911 + *     will take a reference on the result.
26912 + */
26913 +
26914 +static inline
26915 +struct fs_struct *__vs_merge_fs(struct fs_struct *old,
26916 +       struct fs_struct *fs, unsigned long mask)
26917 +{
26918 +       if (!(mask & CLONE_FS)) {
26919 +               if (old)
26920 +                       atomic_inc(&old->count);
26921 +               return old;
26922 +       }
26923 +
26924 +       if (!fs)
26925 +               return NULL;
26926 +
26927 +       return copy_fs_struct(fs);
26928 +}
26929 +
26930 +
26931 +int vx_enter_space(struct vx_info *vxi, unsigned long mask)
26932 +{
26933 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
26934 +       struct fs_struct *fs, *fs_cur, *fs_new;
26935 +       int ret;
26936 +
26937 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
26938 +               return -EACCES;
26939 +
26940 +       if (!mask)
26941 +               mask = vxi->vx_nsmask;
26942 +
26943 +       if ((mask & vxi->vx_nsmask) != mask)
26944 +               return -EINVAL;
26945 +
26946 +       proxy = vxi->vx_nsproxy;
26947 +       fs = vxi->vx_fs;
26948 +
26949 +       task_lock(current);
26950 +       fs_cur = current->fs;
26951 +       atomic_inc(&fs_cur->count);
26952 +       proxy_cur = current->nsproxy;
26953 +       get_nsproxy(proxy_cur);
26954 +       task_unlock(current);
26955 +
26956 +       fs_new = __vs_merge_fs(fs_cur, fs, mask);
26957 +       if (IS_ERR(fs_new)) {
26958 +               ret = PTR_ERR(fs_new);
26959 +               goto out_put;
26960 +       }
26961 +
26962 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
26963 +       if (IS_ERR(proxy_new)) {
26964 +               ret = PTR_ERR(proxy_new);
26965 +               goto out_put_fs;
26966 +       }
26967 +
26968 +       fs_new = xchg(&current->fs, fs_new);
26969 +       proxy_new = xchg(&current->nsproxy, proxy_new);
26970 +       ret = 0;
26971 +
26972 +       if (proxy_new)
26973 +               put_nsproxy(proxy_new);
26974 +out_put_fs:
26975 +       if (fs_new)
26976 +               put_fs_struct(fs_new);
26977 +out_put:
26978 +       if (proxy_cur)
26979 +               put_nsproxy(proxy_cur);
26980 +       if (fs_cur)
26981 +               put_fs_struct(fs_cur);
26982 +       return ret;
26983 +}
26984 +
26985 +
26986 +int vx_set_space(struct vx_info *vxi, unsigned long mask)
26987 +{
26988 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
26989 +       struct fs_struct *fs_vxi, *fs_cur, *fs_new;
26990 +       int ret;
26991 +
26992 +       if (!mask)
26993 +               mask = space_mask.mask;
26994 +
26995 +       if ((mask & space_mask.mask) != mask)
26996 +               return -EINVAL;
26997 +
26998 +       proxy_vxi = vxi->vx_nsproxy;
26999 +       fs_vxi = vxi->vx_fs;
27000 +
27001 +       task_lock(current);
27002 +       fs_cur = current->fs;
27003 +       atomic_inc(&fs_cur->count);
27004 +       proxy_cur = current->nsproxy;
27005 +       get_nsproxy(proxy_cur);
27006 +       task_unlock(current);
27007 +
27008 +       fs_new = __vs_merge_fs(fs_vxi, fs_cur, mask);
27009 +       if (IS_ERR(fs_new)) {
27010 +               ret = PTR_ERR(fs_new);
27011 +               goto out_put;
27012 +       }
27013 +
27014 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
27015 +       if (IS_ERR(proxy_new)) {
27016 +               ret = PTR_ERR(proxy_new);
27017 +               goto out_put_fs;
27018 +       }
27019 +
27020 +       fs_new = xchg(&vxi->vx_fs, fs_new);
27021 +       proxy_new = xchg(&vxi->vx_nsproxy, proxy_new);
27022 +       vxi->vx_nsmask |= mask;
27023 +       ret = 0;
27024 +
27025 +       if (proxy_new)
27026 +               put_nsproxy(proxy_new);
27027 +out_put_fs:
27028 +       if (fs_new)
27029 +               put_fs_struct(fs_new);
27030 +out_put:
27031 +       if (proxy_cur)
27032 +               put_nsproxy(proxy_cur);
27033 +       if (fs_cur)
27034 +               put_fs_struct(fs_cur);
27035 +       return ret;
27036 +}
27037 +
27038 +
27039 +int vc_enter_space(struct vx_info *vxi, void __user *data)
27040 +{
27041 +       struct vcmd_space_mask vc_data = { .mask = 0 };
27042 +
27043 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
27044 +               return -EFAULT;
27045 +
27046 +       return vx_enter_space(vxi, vc_data.mask);
27047 +}
27048 +
27049 +int vc_set_space(struct vx_info *vxi, void __user *data)
27050 +{
27051 +       struct vcmd_space_mask vc_data = { .mask = 0 };
27052 +
27053 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
27054 +               return -EFAULT;
27055 +
27056 +       return vx_set_space(vxi, vc_data.mask);
27057 +}
27058 +
27059 +int vc_get_space_mask(struct vx_info *vxi, void __user *data)
27060 +{
27061 +       if (copy_to_user(data, &space_mask, sizeof(space_mask)))
27062 +               return -EFAULT;
27063 +       return 0;
27064 +}
27065 +
27066 diff -Nurp linux-2.6.22.18/kernel/vserver/switch.c linux-2.6.22.18-vs2.3.0.32/kernel/vserver/switch.c
27067 --- linux-2.6.22.18/kernel/vserver/switch.c     1970-01-01 01:00:00.000000000 +0100
27068 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/switch.c  2008-02-11 12:35:38.000000000 +0100
27069 @@ -0,0 +1,529 @@
27070 +/*
27071 + *  linux/kernel/vserver/switch.c
27072 + *
27073 + *  Virtual Server: Syscall Switch
27074 + *
27075 + *  Copyright (C) 2003-2007  Herbert Pötzl
27076 + *
27077 + *  V0.01  syscall switch
27078 + *  V0.02  added signal to context
27079 + *  V0.03  added rlimit functions
27080 + *  V0.04  added iattr, task/xid functions
27081 + *  V0.05  added debug/history stuff
27082 + *  V0.06  added compat32 layer
27083 + *  V0.07  vcmd args and perms
27084 + *  V0.08  added status commands
27085 + *  V0.09  added tag commands
27086 + *  V0.10  added oom bias
27087 + *  V0.11  added device commands
27088 + *
27089 + */
27090 +
27091 +#include <linux/vs_context.h>
27092 +#include <linux/vs_network.h>
27093 +#include <linux/vserver/switch.h>
27094 +
27095 +#include "vci_config.h"
27096 +
27097 +
27098 +static inline
27099 +int vc_get_version(uint32_t id)
27100 +{
27101 +       return VCI_VERSION;
27102 +}
27103 +
27104 +static inline
27105 +int vc_get_vci(uint32_t id)
27106 +{
27107 +       return vci_kernel_config();
27108 +}
27109 +
27110 +#include <linux/vserver/context_cmd.h>
27111 +#include <linux/vserver/cvirt_cmd.h>
27112 +#include <linux/vserver/cacct_cmd.h>
27113 +#include <linux/vserver/limit_cmd.h>
27114 +#include <linux/vserver/network_cmd.h>
27115 +#include <linux/vserver/sched_cmd.h>
27116 +#include <linux/vserver/debug_cmd.h>
27117 +#include <linux/vserver/inode_cmd.h>
27118 +#include <linux/vserver/dlimit_cmd.h>
27119 +#include <linux/vserver/signal_cmd.h>
27120 +#include <linux/vserver/space_cmd.h>
27121 +#include <linux/vserver/tag_cmd.h>
27122 +#include <linux/vserver/device_cmd.h>
27123 +
27124 +#include <linux/vserver/inode.h>
27125 +#include <linux/vserver/dlimit.h>
27126 +
27127 +
27128 +#ifdef CONFIG_COMPAT
27129 +#define __COMPAT(name, id, data, compat)       \
27130 +       (compat) ? name ## _x32(id, data) : name(id, data)
27131 +#define __COMPAT_NO_ID(name, data, compat)     \
27132 +       (compat) ? name ## _x32(data) : name(data)
27133 +#else
27134 +#define __COMPAT(name, id, data, compat)       \
27135 +       name(id, data)
27136 +#define __COMPAT_NO_ID(name, data, compat)     \
27137 +       name(data)
27138 +#endif
27139 +
27140 +
27141 +static inline
27142 +long do_vcmd(uint32_t cmd, uint32_t id,
27143 +       struct vx_info *vxi, struct nx_info *nxi,
27144 +       void __user *data, int compat)
27145 +{
27146 +       switch (cmd) {
27147 +
27148 +       case VCMD_get_version:
27149 +               return vc_get_version(id);
27150 +       case VCMD_get_vci:
27151 +               return vc_get_vci(id);
27152 +
27153 +       case VCMD_task_xid:
27154 +               return vc_task_xid(id);
27155 +       case VCMD_vx_info:
27156 +               return vc_vx_info(vxi, data);
27157 +
27158 +       case VCMD_task_nid:
27159 +               return vc_task_nid(id);
27160 +       case VCMD_nx_info:
27161 +               return vc_nx_info(nxi, data);
27162 +
27163 +       case VCMD_task_tag:
27164 +               return vc_task_tag(id);
27165 +
27166 +       /* this is version 1 */
27167 +       case VCMD_set_space:
27168 +               return vc_set_space(vxi, data);
27169 +
27170 +       case VCMD_get_space_mask:
27171 +               return vc_get_space_mask(vxi, data);
27172 +
27173 +#ifdef CONFIG_IA32_EMULATION
27174 +       case VCMD_get_rlimit:
27175 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
27176 +       case VCMD_set_rlimit:
27177 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
27178 +#else
27179 +       case VCMD_get_rlimit:
27180 +               return vc_get_rlimit(vxi, data);
27181 +       case VCMD_set_rlimit:
27182 +               return vc_set_rlimit(vxi, data);
27183 +#endif
27184 +       case VCMD_get_rlimit_mask:
27185 +               return vc_get_rlimit_mask(id, data);
27186 +       case VCMD_reset_minmax:
27187 +               return vc_reset_minmax(vxi, data);
27188 +
27189 +       case VCMD_get_vhi_name:
27190 +               return vc_get_vhi_name(vxi, data);
27191 +       case VCMD_set_vhi_name:
27192 +               return vc_set_vhi_name(vxi, data);
27193 +
27194 +       case VCMD_ctx_stat:
27195 +               return vc_ctx_stat(vxi, data);
27196 +       case VCMD_virt_stat:
27197 +               return vc_virt_stat(vxi, data);
27198 +       case VCMD_sock_stat:
27199 +               return vc_sock_stat(vxi, data);
27200 +       case VCMD_rlimit_stat:
27201 +               return vc_rlimit_stat(vxi, data);
27202 +
27203 +       case VCMD_set_cflags:
27204 +               return vc_set_cflags(vxi, data);
27205 +       case VCMD_get_cflags:
27206 +               return vc_get_cflags(vxi, data);
27207 +
27208 +       /* this is version 1 */
27209 +       case VCMD_set_ccaps:
27210 +               return vc_set_ccaps(vxi, data);
27211 +       /* this is version 1 */
27212 +       case VCMD_get_ccaps:
27213 +               return vc_get_ccaps(vxi, data);
27214 +       case VCMD_set_bcaps:
27215 +               return vc_set_bcaps(vxi, data);
27216 +       case VCMD_get_bcaps:
27217 +               return vc_get_bcaps(vxi, data);
27218 +
27219 +       case VCMD_set_badness:
27220 +               return vc_set_badness(vxi, data);
27221 +       case VCMD_get_badness:
27222 +               return vc_get_badness(vxi, data);
27223 +
27224 +       case VCMD_set_nflags:
27225 +               return vc_set_nflags(nxi, data);
27226 +       case VCMD_get_nflags:
27227 +               return vc_get_nflags(nxi, data);
27228 +
27229 +       case VCMD_set_ncaps:
27230 +               return vc_set_ncaps(nxi, data);
27231 +       case VCMD_get_ncaps:
27232 +               return vc_get_ncaps(nxi, data);
27233 +
27234 +       case VCMD_set_sched_v4:
27235 +               return vc_set_sched_v4(vxi, data);
27236 +       /* this is version 5 */
27237 +       case VCMD_set_sched:
27238 +               return vc_set_sched(vxi, data);
27239 +       case VCMD_get_sched:
27240 +               return vc_get_sched(vxi, data);
27241 +       case VCMD_sched_info:
27242 +               return vc_sched_info(vxi, data);
27243 +
27244 +       case VCMD_add_dlimit:
27245 +               return __COMPAT(vc_add_dlimit, id, data, compat);
27246 +       case VCMD_rem_dlimit:
27247 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
27248 +       case VCMD_set_dlimit:
27249 +               return __COMPAT(vc_set_dlimit, id, data, compat);
27250 +       case VCMD_get_dlimit:
27251 +               return __COMPAT(vc_get_dlimit, id, data, compat);
27252 +
27253 +       case VCMD_ctx_kill:
27254 +               return vc_ctx_kill(vxi, data);
27255 +
27256 +       case VCMD_wait_exit:
27257 +               return vc_wait_exit(vxi, data);
27258 +
27259 +       case VCMD_get_iattr:
27260 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
27261 +       case VCMD_set_iattr:
27262 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
27263 +
27264 +       case VCMD_fget_iattr:
27265 +               return vc_fget_iattr(id, data);
27266 +       case VCMD_fset_iattr:
27267 +               return vc_fset_iattr(id, data);
27268 +
27269 +       case VCMD_enter_space_v0:
27270 +               return vc_enter_space(vxi, NULL);
27271 +       /* this is version 1 */
27272 +       case VCMD_enter_space:
27273 +               return vc_enter_space(vxi, data);
27274 +
27275 +       case VCMD_ctx_create_v0:
27276 +               return vc_ctx_create(id, NULL);
27277 +       case VCMD_ctx_create:
27278 +               return vc_ctx_create(id, data);
27279 +       case VCMD_ctx_migrate_v0:
27280 +               return vc_ctx_migrate(vxi, NULL);
27281 +       case VCMD_ctx_migrate:
27282 +               return vc_ctx_migrate(vxi, data);
27283 +
27284 +       case VCMD_net_create_v0:
27285 +               return vc_net_create(id, NULL);
27286 +       case VCMD_net_create:
27287 +               return vc_net_create(id, data);
27288 +       case VCMD_net_migrate:
27289 +               return vc_net_migrate(nxi, data);
27290 +
27291 +       case VCMD_tag_migrate:
27292 +               return vc_tag_migrate(id);
27293 +
27294 +       case VCMD_net_add:
27295 +               return vc_net_add(nxi, data);
27296 +       case VCMD_net_remove:
27297 +               return vc_net_remove(nxi, data);
27298 +
27299 +       case VCMD_net_add_ipv4:
27300 +               return vc_net_add_ipv4(nxi, data);
27301 +       case VCMD_net_remove_ipv4:
27302 +               return vc_net_remove_ipv4(nxi, data);
27303 +#ifdef CONFIG_IPV6
27304 +       case VCMD_net_add_ipv6:
27305 +               return vc_net_add_ipv6(nxi, data);
27306 +       case VCMD_net_remove_ipv6:
27307 +               return vc_net_remove_ipv6(nxi, data);
27308 +#endif
27309 +/*     case VCMD_add_match_ipv4:
27310 +               return vc_add_match_ipv4(nxi, data);
27311 +       case VCMD_get_match_ipv4:
27312 +               return vc_get_match_ipv4(nxi, data);
27313 +#ifdef CONFIG_IPV6
27314 +       case VCMD_add_match_ipv6:
27315 +               return vc_add_match_ipv6(nxi, data);
27316 +       case VCMD_get_match_ipv6:
27317 +               return vc_get_match_ipv6(nxi, data);
27318 +#endif */
27319 +
27320 +#ifdef CONFIG_VSERVER_DEVICE
27321 +       case VCMD_set_mapping:
27322 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
27323 +       case VCMD_unset_mapping:
27324 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
27325 +#endif
27326 +#ifdef CONFIG_VSERVER_HISTORY
27327 +       case VCMD_dump_history:
27328 +               return vc_dump_history(id);
27329 +       case VCMD_read_history:
27330 +               return __COMPAT(vc_read_history, id, data, compat);
27331 +#endif
27332 +#ifdef CONFIG_VSERVER_MONITOR
27333 +       case VCMD_read_monitor:
27334 +               return __COMPAT(vc_read_monitor, id, data, compat);
27335 +#endif
27336 +       default:
27337 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
27338 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
27339 +       }
27340 +       return -ENOSYS;
27341 +}
27342 +
27343 +
27344 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
27345 +       case VCMD_ ## vcmd: perm = _perm;               \
27346 +               args = _args; flags = _flags; break
27347 +
27348 +
27349 +#define VCA_NONE       0x00
27350 +#define VCA_VXI                0x01
27351 +#define VCA_NXI                0x02
27352 +
27353 +#define VCF_NONE       0x00
27354 +#define VCF_INFO       0x01
27355 +#define VCF_ADMIN      0x02
27356 +#define VCF_ARES       0x06    /* includes admin */
27357 +#define VCF_SETUP      0x08
27358 +
27359 +#define VCF_ZIDOK      0x10    /* zero id okay */
27360 +
27361 +
27362 +static inline
27363 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
27364 +{
27365 +       long ret;
27366 +       int permit = -1, state = 0;
27367 +       int perm = -1, args = 0, flags = 0;
27368 +       struct vx_info *vxi = NULL;
27369 +       struct nx_info *nxi = NULL;
27370 +
27371 +       switch (cmd) {
27372 +       /* unpriviledged commands */
27373 +       __VCMD(get_version,      0, VCA_NONE,   0);
27374 +       __VCMD(get_vci,          0, VCA_NONE,   0);
27375 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
27376 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
27377 +
27378 +       /* info commands */
27379 +       __VCMD(task_xid,         2, VCA_NONE,   0);
27380 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
27381 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
27382 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
27383 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
27384 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
27385 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
27386 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
27387 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
27388 +
27389 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
27390 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
27391 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
27392 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
27393 +
27394 +       __VCMD(task_nid,         2, VCA_NONE,   0);
27395 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
27396 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
27397 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
27398 +
27399 +       __VCMD(task_tag,         2, VCA_NONE,   0);
27400 +
27401 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
27402 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
27403 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
27404 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
27405 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
27406 +
27407 +       /* lower admin commands */
27408 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
27409 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
27410 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
27411 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
27412 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
27413 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
27414 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
27415 +
27416 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
27417 +       __VCMD(net_create,       5, VCA_NONE,   0);
27418 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
27419 +
27420 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
27421 +
27422 +       /* higher admin commands */
27423 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
27424 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27425 +
27426 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27427 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27428 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27429 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27430 +
27431 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27432 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27433 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27434 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27435 +
27436 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
27437 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
27438 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27439 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27440 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27441 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27442 +#ifdef CONFIG_IPV6
27443 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27444 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27445 +#endif
27446 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
27447 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
27448 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
27449 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
27450 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
27451 +
27452 +#ifdef CONFIG_VSERVER_DEVICE
27453 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
27454 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
27455 +#endif
27456 +       /* debug level admin commands */
27457 +#ifdef CONFIG_VSERVER_HISTORY
27458 +       __VCMD(dump_history,     9, VCA_NONE,   0);
27459 +       __VCMD(read_history,     9, VCA_NONE,   0);
27460 +#endif
27461 +#ifdef CONFIG_VSERVER_MONITOR
27462 +       __VCMD(read_monitor,     9, VCA_NONE,   0);
27463 +#endif
27464 +
27465 +       default:
27466 +               perm = -1;
27467 +       }
27468 +
27469 +       vxdprintk(VXD_CBIT(switch, 0),
27470 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
27471 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
27472 +               VC_VERSION(cmd), id, data, compat,
27473 +               perm, args, flags);
27474 +
27475 +       ret = -ENOSYS;
27476 +       if (perm < 0)
27477 +               goto out;
27478 +
27479 +       state = 1;
27480 +       if (!capable(CAP_CONTEXT))
27481 +               goto out;
27482 +
27483 +       state = 2;
27484 +       /* moved here from the individual commands */
27485 +       ret = -EPERM;
27486 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
27487 +               goto out;
27488 +
27489 +       state = 3;
27490 +       /* vcmd involves resource management  */
27491 +       ret = -EPERM;
27492 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
27493 +               goto out;
27494 +
27495 +       state = 4;
27496 +       /* various legacy exceptions */
27497 +       switch (cmd) {
27498 +       /* will go away when spectator is a cap */
27499 +       case VCMD_ctx_migrate_v0:
27500 +       case VCMD_ctx_migrate:
27501 +               if (id == 1) {
27502 +                       current->xid = 1;
27503 +                       ret = 1;
27504 +                       goto out;
27505 +               }
27506 +               break;
27507 +
27508 +       /* will go away when spectator is a cap */
27509 +       case VCMD_net_migrate:
27510 +               if (id == 1) {
27511 +                       current->nid = 1;
27512 +                       ret = 1;
27513 +                       goto out;
27514 +               }
27515 +               break;
27516 +       }
27517 +
27518 +       /* vcmds are fine by default */
27519 +       permit = 1;
27520 +
27521 +       /* admin type vcmds require admin ... */
27522 +       if (flags & VCF_ADMIN)
27523 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
27524 +
27525 +       /* ... but setup type vcmds override that */
27526 +       if (!permit && (flags & VCF_SETUP))
27527 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
27528 +
27529 +       state = 5;
27530 +       ret = -EPERM;
27531 +       if (!permit)
27532 +               goto out;
27533 +
27534 +       state = 6;
27535 +       if (!id && (flags & VCF_ZIDOK))
27536 +               goto skip_id;
27537 +
27538 +       ret = -ESRCH;
27539 +       if (args & VCA_VXI) {
27540 +               vxi = lookup_vx_info(id);
27541 +               if (!vxi)
27542 +                       goto out;
27543 +
27544 +               if ((flags & VCF_ADMIN) &&
27545 +                       /* special case kill for shutdown */
27546 +                       (cmd != VCMD_ctx_kill) &&
27547 +                       /* can context be administrated? */
27548 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
27549 +                       ret = -EACCES;
27550 +                       goto out_vxi;
27551 +               }
27552 +       }
27553 +       state = 7;
27554 +       if (args & VCA_NXI) {
27555 +               nxi = lookup_nx_info(id);
27556 +               if (!nxi)
27557 +                       goto out_vxi;
27558 +
27559 +               if ((flags & VCF_ADMIN) &&
27560 +                       /* can context be administrated? */
27561 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
27562 +                       ret = -EACCES;
27563 +                       goto out_nxi;
27564 +               }
27565 +       }
27566 +skip_id:
27567 +       state = 8;
27568 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
27569 +
27570 +out_nxi:
27571 +       if ((args & VCA_NXI) && nxi)
27572 +               put_nx_info(nxi);
27573 +out_vxi:
27574 +       if ((args & VCA_VXI) && vxi)
27575 +               put_vx_info(vxi);
27576 +out:
27577 +       vxdprintk(VXD_CBIT(switch, 1),
27578 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
27579 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
27580 +               VC_VERSION(cmd), ret, ret, state, permit);
27581 +       return ret;
27582 +}
27583 +
27584 +asmlinkage long
27585 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
27586 +{
27587 +       return do_vserver(cmd, id, data, 0);
27588 +}
27589 +
27590 +#ifdef CONFIG_COMPAT
27591 +
27592 +asmlinkage long
27593 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
27594 +{
27595 +       return do_vserver(cmd, id, data, 1);
27596 +}
27597 +
27598 +#endif /* CONFIG_COMPAT */
27599 diff -Nurp linux-2.6.22.18/kernel/vserver/sysctl.c linux-2.6.22.18-vs2.3.0.32/kernel/vserver/sysctl.c
27600 --- linux-2.6.22.18/kernel/vserver/sysctl.c     1970-01-01 01:00:00.000000000 +0100
27601 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/sysctl.c  2008-02-11 12:35:38.000000000 +0100
27602 @@ -0,0 +1,243 @@
27603 +/*
27604 + *  kernel/vserver/sysctl.c
27605 + *
27606 + *  Virtual Context Support
27607 + *
27608 + *  Copyright (C) 2004-2007  Herbert Pötzl
27609 + *
27610 + *  V0.01  basic structure
27611 + *
27612 + */
27613 +
27614 +#include <linux/module.h>
27615 +#include <linux/ctype.h>
27616 +#include <linux/sysctl.h>
27617 +#include <linux/parser.h>
27618 +#include <asm/uaccess.h>
27619 +
27620 +
27621 +#define CTL_VSERVER    4242    /* unused? */
27622 +
27623 +enum {
27624 +       CTL_DEBUG_ERROR         = 0,
27625 +       CTL_DEBUG_SWITCH        = 1,
27626 +       CTL_DEBUG_XID,
27627 +       CTL_DEBUG_NID,
27628 +       CTL_DEBUG_TAG,
27629 +       CTL_DEBUG_NET,
27630 +       CTL_DEBUG_LIMIT,
27631 +       CTL_DEBUG_CRES,
27632 +       CTL_DEBUG_DLIM,
27633 +       CTL_DEBUG_QUOTA,
27634 +       CTL_DEBUG_CVIRT,
27635 +       CTL_DEBUG_SPACE,
27636 +       CTL_DEBUG_MISC,
27637 +};
27638 +
27639 +
27640 +unsigned int vx_debug_switch   = 0;
27641 +unsigned int vx_debug_xid      = 0;
27642 +unsigned int vx_debug_nid      = 0;
27643 +unsigned int vx_debug_tag      = 0;
27644 +unsigned int vx_debug_net      = 0;
27645 +unsigned int vx_debug_limit    = 0;
27646 +unsigned int vx_debug_cres     = 0;
27647 +unsigned int vx_debug_dlim     = 0;
27648 +unsigned int vx_debug_quota    = 0;
27649 +unsigned int vx_debug_cvirt    = 0;
27650 +unsigned int vx_debug_space    = 0;
27651 +unsigned int vx_debug_misc     = 0;
27652 +
27653 +
27654 +static struct ctl_table_header *vserver_table_header;
27655 +static ctl_table vserver_table[];
27656 +
27657 +
27658 +void vserver_register_sysctl(void)
27659 +{
27660 +       if (!vserver_table_header) {
27661 +               vserver_table_header = register_sysctl_table(vserver_table);
27662 +       }
27663 +
27664 +}
27665 +
27666 +void vserver_unregister_sysctl(void)
27667 +{
27668 +       if (vserver_table_header) {
27669 +               unregister_sysctl_table(vserver_table_header);
27670 +               vserver_table_header = NULL;
27671 +       }
27672 +}
27673 +
27674 +
27675 +static int proc_dodebug(ctl_table *table, int write,
27676 +       struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
27677 +{
27678 +       char            tmpbuf[20], *p, c;
27679 +       unsigned int    value;
27680 +       size_t          left, len;
27681 +
27682 +       if ((*ppos && !write) || !*lenp) {
27683 +               *lenp = 0;
27684 +               return 0;
27685 +       }
27686 +
27687 +       left = *lenp;
27688 +
27689 +       if (write) {
27690 +               if (!access_ok(VERIFY_READ, buffer, left))
27691 +                       return -EFAULT;
27692 +               p = (char *)buffer;
27693 +               while (left && __get_user(c, p) >= 0 && isspace(c))
27694 +                       left--, p++;
27695 +               if (!left)
27696 +                       goto done;
27697 +
27698 +               if (left > sizeof(tmpbuf) - 1)
27699 +                       return -EINVAL;
27700 +               if (copy_from_user(tmpbuf, p, left))
27701 +                       return -EFAULT;
27702 +               tmpbuf[left] = '\0';
27703 +
27704 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
27705 +                       value = 10 * value + (*p - '0');
27706 +               if (*p && !isspace(*p))
27707 +                       return -EINVAL;
27708 +               while (left && isspace(*p))
27709 +                       left--, p++;
27710 +               *(unsigned int *)table->data = value;
27711 +       } else {
27712 +               if (!access_ok(VERIFY_WRITE, buffer, left))
27713 +                       return -EFAULT;
27714 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
27715 +               if (len > left)
27716 +                       len = left;
27717 +               if (__copy_to_user(buffer, tmpbuf, len))
27718 +                       return -EFAULT;
27719 +               if ((left -= len) > 0) {
27720 +                       if (put_user('\n', (char *)buffer + len))
27721 +                               return -EFAULT;
27722 +                       left--;
27723 +               }
27724 +       }
27725 +
27726 +done:
27727 +       *lenp -= left;
27728 +       *ppos += *lenp;
27729 +       return 0;
27730 +}
27731 +
27732 +
27733 +#define        CTL_ENTRY(ctl, name)                            \
27734 +       {                                               \
27735 +               .ctl_name       = ctl,                  \
27736 +               .procname       = #name,                \
27737 +               .data           = &vx_ ## name,         \
27738 +               .maxlen         = sizeof(int),          \
27739 +               .mode           = 0644,                 \
27740 +               .proc_handler   = &proc_dodebug         \
27741 +       }
27742 +
27743 +static ctl_table debug_table[] = {
27744 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
27745 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
27746 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
27747 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
27748 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
27749 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
27750 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
27751 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
27752 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
27753 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
27754 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
27755 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
27756 +       { .ctl_name = 0 }
27757 +};
27758 +
27759 +static ctl_table vserver_table[] = {
27760 +       {
27761 +               .ctl_name       = CTL_VSERVER,
27762 +               .procname       = "vserver",
27763 +               .mode           = 0555,
27764 +               .child          = debug_table
27765 +       },
27766 +       { .ctl_name = 0 }
27767 +};
27768 +
27769 +
27770 +static match_table_t tokens = {
27771 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
27772 +       { CTL_DEBUG_XID,        "xid=%x"        },
27773 +       { CTL_DEBUG_NID,        "nid=%x"        },
27774 +       { CTL_DEBUG_TAG,        "tag=%x"        },
27775 +       { CTL_DEBUG_NET,        "net=%x"        },
27776 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
27777 +       { CTL_DEBUG_CRES,       "cres=%x"       },
27778 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
27779 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
27780 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
27781 +       { CTL_DEBUG_SPACE,      "space=%x"      },
27782 +       { CTL_DEBUG_MISC,       "misc=%x"       },
27783 +       { CTL_DEBUG_ERROR,      NULL            }
27784 +};
27785 +
27786 +#define        HANDLE_CASE(id, name, val)                              \
27787 +       case CTL_DEBUG_ ## id:                                  \
27788 +               vx_debug_ ## name = val;                        \
27789 +               printk("vs_debug_" #name "=0x%x\n", val);       \
27790 +               break
27791 +
27792 +
27793 +static int __init vs_debug_setup(char *str)
27794 +{
27795 +       char *p;
27796 +       int token;
27797 +
27798 +       printk("vs_debug_setup(%s)\n", str);
27799 +       while ((p = strsep(&str, ",")) != NULL) {
27800 +               substring_t args[MAX_OPT_ARGS];
27801 +               unsigned int value;
27802 +
27803 +               if (!*p)
27804 +                       continue;
27805 +
27806 +               token = match_token(p, tokens, args);
27807 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
27808 +
27809 +               switch (token) {
27810 +               HANDLE_CASE(SWITCH, switch, value);
27811 +               HANDLE_CASE(XID,    xid,    value);
27812 +               HANDLE_CASE(NID,    nid,    value);
27813 +               HANDLE_CASE(TAG,    tag,    value);
27814 +               HANDLE_CASE(NET,    net,    value);
27815 +               HANDLE_CASE(LIMIT,  limit,  value);
27816 +               HANDLE_CASE(CRES,   cres,   value);
27817 +               HANDLE_CASE(DLIM,   dlim,   value);
27818 +               HANDLE_CASE(QUOTA,  quota,  value);
27819 +               HANDLE_CASE(CVIRT,  cvirt,  value);
27820 +               HANDLE_CASE(SPACE,  space,  value);
27821 +               HANDLE_CASE(MISC,   misc,   value);
27822 +               default:
27823 +                       return -EINVAL;
27824 +                       break;
27825 +               }
27826 +       }
27827 +       return 1;
27828 +}
27829 +
27830 +__setup("vsdebug=", vs_debug_setup);
27831 +
27832 +
27833 +
27834 +EXPORT_SYMBOL_GPL(vx_debug_switch);
27835 +EXPORT_SYMBOL_GPL(vx_debug_xid);
27836 +EXPORT_SYMBOL_GPL(vx_debug_nid);
27837 +EXPORT_SYMBOL_GPL(vx_debug_net);
27838 +EXPORT_SYMBOL_GPL(vx_debug_limit);
27839 +EXPORT_SYMBOL_GPL(vx_debug_cres);
27840 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
27841 +EXPORT_SYMBOL_GPL(vx_debug_quota);
27842 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
27843 +EXPORT_SYMBOL_GPL(vx_debug_space);
27844 +EXPORT_SYMBOL_GPL(vx_debug_misc);
27845 +
27846 diff -Nurp linux-2.6.22.18/kernel/vserver/tag.c linux-2.6.22.18-vs2.3.0.32/kernel/vserver/tag.c
27847 --- linux-2.6.22.18/kernel/vserver/tag.c        1970-01-01 01:00:00.000000000 +0100
27848 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/tag.c     2008-02-11 12:35:38.000000000 +0100
27849 @@ -0,0 +1,62 @@
27850 +/*
27851 + *  linux/kernel/vserver/tag.c
27852 + *
27853 + *  Virtual Server: Shallow Tag Space
27854 + *
27855 + *  Copyright (C) 2007  Herbert Pötzl
27856 + *
27857 + *  V0.01  basic implementation
27858 + *
27859 + */
27860 +
27861 +#include <linux/sched.h>
27862 +#include <linux/vserver/debug.h>
27863 +#include <linux/vs_tag.h>
27864 +
27865 +#include <linux/vserver/tag_cmd.h>
27866 +
27867 +
27868 +int dx_migrate_task(struct task_struct *p, tag_t tag)
27869 +{
27870 +       if (!p)
27871 +               BUG();
27872 +
27873 +       vxdprintk(VXD_CBIT(tag, 5),
27874 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
27875 +
27876 +       task_lock(p);
27877 +       p->tag = tag;
27878 +       task_unlock(p);
27879 +
27880 +       vxdprintk(VXD_CBIT(tag, 5),
27881 +               "moved task %p into [#%d]", p, tag);
27882 +       return 0;
27883 +}
27884 +
27885 +/* vserver syscall commands below here */
27886 +
27887 +/* taks xid and vx_info functions */
27888 +
27889 +
27890 +int vc_task_tag(uint32_t id)
27891 +{
27892 +       tag_t tag;
27893 +
27894 +       if (id) {
27895 +               struct task_struct *tsk;
27896 +               read_lock(&tasklist_lock);
27897 +               tsk = find_task_by_real_pid(id);
27898 +               tag = (tsk) ? tsk->tag : -ESRCH;
27899 +               read_unlock(&tasklist_lock);
27900 +       } else
27901 +               tag = dx_current_tag();
27902 +       return tag;
27903 +}
27904 +
27905 +
27906 +int vc_tag_migrate(uint32_t tag)
27907 +{
27908 +       return dx_migrate_task(current, tag & 0xFFFF);
27909 +}
27910 +
27911 +
27912 diff -Nurp linux-2.6.22.18/kernel/vserver/vci_config.h linux-2.6.22.18-vs2.3.0.32/kernel/vserver/vci_config.h
27913 --- linux-2.6.22.18/kernel/vserver/vci_config.h 1970-01-01 01:00:00.000000000 +0100
27914 +++ linux-2.6.22.18-vs2.3.0.32/kernel/vserver/vci_config.h      2008-02-11 12:35:38.000000000 +0100
27915 @@ -0,0 +1,81 @@
27916 +
27917 +/*  interface version */
27918 +
27919 +#define VCI_VERSION            0x00020302
27920 +
27921 +
27922 +enum {
27923 +       VCI_KCBIT_NO_DYNAMIC = 0,
27924 +
27925 +       VCI_KCBIT_PROC_SECURE = 4,
27926 +       VCI_KCBIT_HARDCPU = 5,
27927 +       VCI_KCBIT_IDLELIMIT = 6,
27928 +       VCI_KCBIT_IDLETIME = 7,
27929 +
27930 +       VCI_KCBIT_COWBL = 8,
27931 +       VCI_KCBIT_FULLCOWBL = 9,
27932 +       VCI_KCBIT_SPACES = 10,
27933 +       VCI_KCBIT_NETV2 = 11,
27934 +
27935 +       VCI_KCBIT_DEBUG = 16,
27936 +       VCI_KCBIT_HISTORY = 20,
27937 +       VCI_KCBIT_TAGGED = 24,
27938 +       VCI_KCBIT_PPTAG = 28,
27939 +
27940 +       VCI_KCBIT_MORE = 31,
27941 +};
27942 +
27943 +
27944 +static inline uint32_t vci_kernel_config(void)
27945 +{
27946 +       return
27947 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
27948 +
27949 +       /* configured features */
27950 +#ifdef CONFIG_VSERVER_PROC_SECURE
27951 +       (1 << VCI_KCBIT_PROC_SECURE) |
27952 +#endif
27953 +#ifdef CONFIG_VSERVER_HARDCPU
27954 +       (1 << VCI_KCBIT_HARDCPU) |
27955 +#endif
27956 +#ifdef CONFIG_VSERVER_IDLELIMIT
27957 +       (1 << VCI_KCBIT_IDLELIMIT) |
27958 +#endif
27959 +#ifdef CONFIG_VSERVER_IDLETIME
27960 +       (1 << VCI_KCBIT_IDLETIME) |
27961 +#endif
27962 +#ifdef CONFIG_VSERVER_COWBL
27963 +       (1 << VCI_KCBIT_COWBL) |
27964 +       (1 << VCI_KCBIT_FULLCOWBL) |
27965 +#endif
27966 +       (1 << VCI_KCBIT_SPACES) |
27967 +       (1 << VCI_KCBIT_NETV2) |
27968 +
27969 +       /* debug options */
27970 +#ifdef CONFIG_VSERVER_DEBUG
27971 +       (1 << VCI_KCBIT_DEBUG) |
27972 +#endif
27973 +#ifdef CONFIG_VSERVER_HISTORY
27974 +       (1 << VCI_KCBIT_HISTORY) |
27975 +#endif
27976 +
27977 +       /* inode context tagging */
27978 +#if    defined(CONFIG_TAGGING_NONE)
27979 +       (0 << VCI_KCBIT_TAGGED) |
27980 +#elif  defined(CONFIG_TAGGING_UID16)
27981 +       (1 << VCI_KCBIT_TAGGED) |
27982 +#elif  defined(CONFIG_TAGGING_GID16)
27983 +       (2 << VCI_KCBIT_TAGGED) |
27984 +#elif  defined(CONFIG_TAGGING_ID24)
27985 +       (3 << VCI_KCBIT_TAGGED) |
27986 +#elif  defined(CONFIG_TAGGING_INTERN)
27987 +       (4 << VCI_KCBIT_TAGGED) |
27988 +#elif  defined(CONFIG_TAGGING_RUNTIME)
27989 +       (5 << VCI_KCBIT_TAGGED) |
27990 +#else
27991 +       (7 << VCI_KCBIT_TAGGED) |
27992 +#endif
27993 +       (1 << VCI_KCBIT_PPTAG) |
27994 +       0;
27995 +}
27996 +
27997 diff -Nurp linux-2.6.22.18/Makefile linux-2.6.22.18-vs2.3.0.32/Makefile
27998 --- linux-2.6.22.18/Makefile    2008-02-11 12:34:27.000000000 +0100
27999 +++ linux-2.6.22.18-vs2.3.0.32/Makefile 2008-02-11 12:35:55.000000000 +0100
28000 @@ -1,7 +1,7 @@
28001  VERSION = 2
28002  PATCHLEVEL = 6
28003  SUBLEVEL = 22
28004 -EXTRAVERSION = .18
28005 +EXTRAVERSION = .18-vs2.3.0.32
28006  NAME = Holy Dancing Manatees, Batman!
28007  
28008  # *DOCUMENTATION*
28009 diff -Nurp linux-2.6.22.18/mm/filemap_xip.c linux-2.6.22.18-vs2.3.0.32/mm/filemap_xip.c
28010 --- linux-2.6.22.18/mm/filemap_xip.c    2007-07-22 00:00:25.000000000 +0200
28011 +++ linux-2.6.22.18-vs2.3.0.32/mm/filemap_xip.c 2008-02-11 12:35:38.000000000 +0100
28012 @@ -14,6 +14,7 @@
28013  #include <linux/uio.h>
28014  #include <linux/rmap.h>
28015  #include <linux/sched.h>
28016 +#include <linux/vs_memory.h>
28017  #include <asm/tlbflush.h>
28018  #include "filemap.h"
28019  
28020 diff -Nurp linux-2.6.22.18/mm/fremap.c linux-2.6.22.18-vs2.3.0.32/mm/fremap.c
28021 --- linux-2.6.22.18/mm/fremap.c 2007-05-04 15:58:24.000000000 +0200
28022 +++ linux-2.6.22.18-vs2.3.0.32/mm/fremap.c      2008-02-11 12:35:38.000000000 +0100
28023 @@ -15,6 +15,7 @@
28024  #include <linux/rmap.h>
28025  #include <linux/module.h>
28026  #include <linux/syscalls.h>
28027 +#include <linux/vs_memory.h>
28028  
28029  #include <asm/mmu_context.h>
28030  #include <asm/cacheflush.h>
28031 @@ -74,6 +75,8 @@ int install_page(struct mm_struct *mm, s
28032         err = -ENOMEM;
28033         if (page_mapcount(page) > INT_MAX/2)
28034                 goto unlock;
28035 +       if (!vx_rss_avail(mm, 1))
28036 +               goto unlock;
28037  
28038         if (pte_none(*pte) || !zap_pte(mm, vma, addr, pte))
28039                 inc_mm_counter(mm, file_rss);
28040 diff -Nurp linux-2.6.22.18/mm/hugetlb.c linux-2.6.22.18-vs2.3.0.32/mm/hugetlb.c
28041 --- linux-2.6.22.18/mm/hugetlb.c        2007-08-12 03:54:37.000000000 +0200
28042 +++ linux-2.6.22.18-vs2.3.0.32/mm/hugetlb.c     2008-02-11 12:35:38.000000000 +0100
28043 @@ -19,6 +19,7 @@
28044  #include <asm/pgtable.h>
28045  
28046  #include <linux/hugetlb.h>
28047 +#include <linux/vs_memory.h>
28048  #include "internal.h"
28049  
28050  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
28051 diff -Nurp linux-2.6.22.18/mm/memory.c linux-2.6.22.18-vs2.3.0.32/mm/memory.c
28052 --- linux-2.6.22.18/mm/memory.c 2007-07-22 00:00:25.000000000 +0200
28053 +++ linux-2.6.22.18-vs2.3.0.32/mm/memory.c      2008-02-11 12:35:38.000000000 +0100
28054 @@ -498,6 +498,9 @@ static int copy_pte_range(struct mm_stru
28055         int progress = 0;
28056         int rss[2];
28057  
28058 +       if (!vx_rss_avail(dst_mm, ((end - addr)/PAGE_SIZE + 1)))
28059 +               return -ENOMEM;
28060 +
28061  again:
28062         rss[1] = rss[0] = 0;
28063         dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
28064 @@ -2157,6 +2160,11 @@ static int do_swap_page(struct mm_struct
28065                 count_vm_event(PGMAJFAULT);
28066         }
28067  
28068 +       if (!vx_rss_avail(mm, 1)) {
28069 +               ret = VM_FAULT_OOM;
28070 +               goto out;
28071 +       }
28072 +
28073         delayacct_clear_flag(DELAYACCT_PF_SWAPIN);
28074         mark_page_accessed(page);
28075         lock_page(page);
28076 @@ -2229,6 +2237,8 @@ static int do_anonymous_page(struct mm_s
28077                 /* Allocate our own private page. */
28078                 pte_unmap(page_table);
28079  
28080 +               if (!vx_rss_avail(mm, 1))
28081 +                       goto oom;
28082                 if (unlikely(anon_vma_prepare(vma)))
28083                         goto oom;
28084                 page = alloc_zeroed_user_highpage(vma, address);
28085 @@ -2302,6 +2312,9 @@ static int do_no_page(struct mm_struct *
28086         pte_unmap(page_table);
28087         BUG_ON(vma->vm_flags & VM_PFNMAP);
28088  
28089 +       if (!vx_rss_avail(mm, 1))
28090 +               return VM_FAULT_OOM;
28091 +
28092         if (vma->vm_file) {
28093                 mapping = vma->vm_file->f_mapping;
28094                 sequence = mapping->truncate_count;
28095 @@ -2527,6 +2540,7 @@ static inline int handle_pte_fault(struc
28096  {
28097         pte_t entry;
28098         spinlock_t *ptl;
28099 +       int ret, type = VXPT_UNKNOWN;
28100  
28101         entry = *pte;
28102         if (!pte_present(entry)) {
28103 @@ -2555,9 +2569,12 @@ static inline int handle_pte_fault(struc
28104         if (unlikely(!pte_same(*pte, entry)))
28105                 goto unlock;
28106         if (write_access) {
28107 -               if (!pte_write(entry))
28108 -                       return do_wp_page(mm, vma, address,
28109 +               if (!pte_write(entry)) {
28110 +                       ret = do_wp_page(mm, vma, address,
28111                                         pte, pmd, ptl, entry);
28112 +                       type = VXPT_WRITE;
28113 +                       goto out;
28114 +               }
28115                 entry = pte_mkdirty(entry);
28116         }
28117         entry = pte_mkyoung(entry);
28118 @@ -2576,7 +2593,10 @@ static inline int handle_pte_fault(struc
28119         }
28120  unlock:
28121         pte_unmap_unlock(pte, ptl);
28122 -       return VM_FAULT_MINOR;
28123 +       ret = VM_FAULT_MINOR;
28124 +out:
28125 +       vx_page_fault(mm, vma, type, ret);
28126 +       return ret;
28127  }
28128  
28129  /*
28130 diff -Nurp linux-2.6.22.18/mm/mlock.c linux-2.6.22.18-vs2.3.0.32/mm/mlock.c
28131 --- linux-2.6.22.18/mm/mlock.c  2007-08-12 03:54:37.000000000 +0200
28132 +++ linux-2.6.22.18-vs2.3.0.32/mm/mlock.c       2008-02-11 12:35:38.000000000 +0100
28133 @@ -12,6 +12,7 @@
28134  #include <linux/syscalls.h>
28135  #include <linux/sched.h>
28136  #include <linux/module.h>
28137 +#include <linux/vs_memory.h>
28138  
28139  int can_do_mlock(void)
28140  {
28141 @@ -76,7 +77,7 @@ success:
28142                         ret = make_pages_present(start, end);
28143         }
28144  
28145 -       mm->locked_vm -= pages;
28146 +       vx_vmlocked_sub(mm, pages);
28147  out:
28148         if (ret == -ENOMEM)
28149                 ret = -EAGAIN;
28150 @@ -134,7 +135,7 @@ static int do_mlock(unsigned long start,
28151  
28152  asmlinkage long sys_mlock(unsigned long start, size_t len)
28153  {
28154 -       unsigned long locked;
28155 +       unsigned long locked, grow;
28156         unsigned long lock_limit;
28157         int error = -ENOMEM;
28158  
28159 @@ -145,8 +146,10 @@ asmlinkage long sys_mlock(unsigned long 
28160         len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
28161         start &= PAGE_MASK;
28162  
28163 -       locked = len >> PAGE_SHIFT;
28164 -       locked += current->mm->locked_vm;
28165 +       grow = len >> PAGE_SHIFT;
28166 +       if (!vx_vmlocked_avail(current->mm, grow))
28167 +               goto out;
28168 +       locked = current->mm->locked_vm + grow;
28169  
28170         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
28171         lock_limit >>= PAGE_SHIFT;
28172 @@ -154,6 +157,7 @@ asmlinkage long sys_mlock(unsigned long 
28173         /* check against resource limits */
28174         if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
28175                 error = do_mlock(start, len, 1);
28176 +out:
28177         up_write(&current->mm->mmap_sem);
28178         return error;
28179  }
28180 @@ -213,6 +217,8 @@ asmlinkage long sys_mlockall(int flags)
28181         lock_limit >>= PAGE_SHIFT;
28182  
28183         ret = -ENOMEM;
28184 +       if (!vx_vmlocked_avail(current->mm, current->mm->total_vm))
28185 +               goto out;
28186         if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
28187             capable(CAP_IPC_LOCK))
28188                 ret = do_mlockall(flags);
28189 diff -Nurp linux-2.6.22.18/mm/mmap.c linux-2.6.22.18-vs2.3.0.32/mm/mmap.c
28190 --- linux-2.6.22.18/mm/mmap.c   2008-02-11 12:34:20.000000000 +0100
28191 +++ linux-2.6.22.18-vs2.3.0.32/mm/mmap.c        2008-02-11 12:35:38.000000000 +0100
28192 @@ -1144,10 +1144,10 @@ munmap_back:
28193                 kmem_cache_free(vm_area_cachep, vma);
28194         }
28195  out:   
28196 -       mm->total_vm += len >> PAGE_SHIFT;
28197 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
28198         vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
28199         if (vm_flags & VM_LOCKED) {
28200 -               mm->locked_vm += len >> PAGE_SHIFT;
28201 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
28202                 make_pages_present(addr, addr + len);
28203         }
28204         if (flags & MAP_POPULATE) {
28205 @@ -1502,9 +1502,9 @@ static int acct_stack_growth(struct vm_a
28206                 return -ENOMEM;
28207  
28208         /* Ok, everything looks good - let it rip */
28209 -       mm->total_vm += grow;
28210 +       vx_vmpages_add(mm, grow);
28211         if (vma->vm_flags & VM_LOCKED)
28212 -               mm->locked_vm += grow;
28213 +               vx_vmlocked_add(mm, grow);
28214         vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
28215         return 0;
28216  }
28217 @@ -1662,9 +1662,9 @@ static void remove_vma_list(struct mm_st
28218         do {
28219                 long nrpages = vma_pages(vma);
28220  
28221 -               mm->total_vm -= nrpages;
28222 +               vx_vmpages_sub(mm, nrpages);
28223                 if (vma->vm_flags & VM_LOCKED)
28224 -                       mm->locked_vm -= nrpages;
28225 +                       vx_vmlocked_sub(mm, nrpages);
28226                 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
28227                 vma = remove_vma(vma);
28228         } while (vma);
28229 @@ -1903,6 +1903,8 @@ unsigned long do_brk(unsigned long addr,
28230                 lock_limit >>= PAGE_SHIFT;
28231                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
28232                         return -EAGAIN;
28233 +               if (!vx_vmlocked_avail(mm, len >> PAGE_SHIFT))
28234 +                       return -ENOMEM;
28235         }
28236  
28237         /*
28238 @@ -1929,7 +1931,8 @@ unsigned long do_brk(unsigned long addr,
28239         if (mm->map_count > sysctl_max_map_count)
28240                 return -ENOMEM;
28241  
28242 -       if (security_vm_enough_memory(len >> PAGE_SHIFT))
28243 +       if (security_vm_enough_memory(len >> PAGE_SHIFT) ||
28244 +               !vx_vmpages_avail(mm, len >> PAGE_SHIFT))
28245                 return -ENOMEM;
28246  
28247         /* Can we just expand an old private anonymous mapping? */
28248 @@ -1955,9 +1958,9 @@ unsigned long do_brk(unsigned long addr,
28249                                 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)];
28250         vma_link(mm, vma, prev, rb_link, rb_parent);
28251  out:
28252 -       mm->total_vm += len >> PAGE_SHIFT;
28253 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
28254         if (flags & VM_LOCKED) {
28255 -               mm->locked_vm += len >> PAGE_SHIFT;
28256 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
28257                 make_pages_present(addr, addr + len);
28258         }
28259         return addr;
28260 @@ -1986,6 +1989,11 @@ void exit_mmap(struct mm_struct *mm)
28261         free_pgtables(&tlb, vma, FIRST_USER_ADDRESS, 0);
28262         tlb_finish_mmu(tlb, 0, end);
28263  
28264 +       set_mm_counter(mm, file_rss, 0);
28265 +       set_mm_counter(mm, anon_rss, 0);
28266 +       vx_vmpages_sub(mm, mm->total_vm);
28267 +       vx_vmlocked_sub(mm, mm->locked_vm);
28268 +
28269         /*
28270          * Walk the list again, actually closing and freeing it,
28271          * with preemption enabled, without holding any MM locks.
28272 @@ -2025,7 +2033,8 @@ int insert_vm_struct(struct mm_struct * 
28273         if (__vma && __vma->vm_start < vma->vm_end)
28274                 return -ENOMEM;
28275         if ((vma->vm_flags & VM_ACCOUNT) &&
28276 -            security_vm_enough_memory(vma_pages(vma)))
28277 +               (security_vm_enough_memory(vma_pages(vma)) ||
28278 +               !vx_vmpages_avail(mm, vma_pages(vma))))
28279                 return -ENOMEM;
28280         vma_link(mm, vma, prev, rb_link, rb_parent);
28281         return 0;
28282 @@ -2098,6 +2107,8 @@ int may_expand_vm(struct mm_struct *mm, 
28283  
28284         if (cur + npages > lim)
28285                 return 0;
28286 +       if (!vx_vmpages_avail(mm, npages))
28287 +               return 0;
28288         return 1;
28289  }
28290  
28291 @@ -2168,7 +2179,6 @@ int install_special_mapping(struct mm_st
28292                 return -ENOMEM;
28293         }
28294  
28295 -       mm->total_vm += len >> PAGE_SHIFT;
28296 -
28297 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
28298         return 0;
28299  }
28300 diff -Nurp linux-2.6.22.18/mm/mremap.c linux-2.6.22.18-vs2.3.0.32/mm/mremap.c
28301 --- linux-2.6.22.18/mm/mremap.c 2007-05-04 15:58:24.000000000 +0200
28302 +++ linux-2.6.22.18-vs2.3.0.32/mm/mremap.c      2008-02-11 12:35:38.000000000 +0100
28303 @@ -18,6 +18,7 @@
28304  #include <linux/highmem.h>
28305  #include <linux/security.h>
28306  #include <linux/syscalls.h>
28307 +#include <linux/vs_memory.h>
28308  
28309  #include <asm/uaccess.h>
28310  #include <asm/cacheflush.h>
28311 @@ -212,7 +213,7 @@ static unsigned long move_vma(struct vm_
28312          * If this were a serious issue, we'd add a flag to do_munmap().
28313          */
28314         hiwater_vm = mm->hiwater_vm;
28315 -       mm->total_vm += new_len >> PAGE_SHIFT;
28316 +       vx_vmpages_add(mm, new_len >> PAGE_SHIFT);
28317         vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
28318  
28319         if (do_munmap(mm, old_addr, old_len) < 0) {
28320 @@ -230,7 +231,7 @@ static unsigned long move_vma(struct vm_
28321         }
28322  
28323         if (vm_flags & VM_LOCKED) {
28324 -               mm->locked_vm += new_len >> PAGE_SHIFT;
28325 +               vx_vmlocked_add(mm, new_len >> PAGE_SHIFT);
28326                 if (new_len > old_len)
28327                         make_pages_present(new_addr + old_len,
28328                                            new_addr + new_len);
28329 @@ -337,6 +338,9 @@ unsigned long do_mremap(unsigned long ad
28330                 ret = -EAGAIN;
28331                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
28332                         goto out;
28333 +               if (!vx_vmlocked_avail(current->mm,
28334 +                       (new_len - old_len) >> PAGE_SHIFT))
28335 +                       goto out;
28336         }
28337         if (!may_expand_vm(mm, (new_len - old_len) >> PAGE_SHIFT)) {
28338                 ret = -ENOMEM;
28339 @@ -365,10 +369,10 @@ unsigned long do_mremap(unsigned long ad
28340                         vma_adjust(vma, vma->vm_start,
28341                                 addr + new_len, vma->vm_pgoff, NULL);
28342  
28343 -                       mm->total_vm += pages;
28344 +                       vx_vmpages_add(mm, pages);
28345                         vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages);
28346                         if (vma->vm_flags & VM_LOCKED) {
28347 -                               mm->locked_vm += pages;
28348 +                               vx_vmlocked_add(mm, pages);
28349                                 make_pages_present(addr + old_len,
28350                                                    addr + new_len);
28351                         }
28352 diff -Nurp linux-2.6.22.18/mm/nommu.c linux-2.6.22.18-vs2.3.0.32/mm/nommu.c
28353 --- linux-2.6.22.18/mm/nommu.c  2007-07-22 00:00:25.000000000 +0200
28354 +++ linux-2.6.22.18-vs2.3.0.32/mm/nommu.c       2008-02-11 12:35:39.000000000 +0100
28355 @@ -936,7 +936,7 @@ unsigned long do_mmap_pgoff(struct file 
28356         realalloc += kobjsize(vma);
28357         askedalloc += sizeof(*vma);
28358  
28359 -       current->mm->total_vm += len >> PAGE_SHIFT;
28360 +       vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
28361  
28362         add_nommu_vma(vma);
28363  
28364 @@ -1061,7 +1061,7 @@ int do_munmap(struct mm_struct *mm, unsi
28365         kfree(vml);
28366  
28367         update_hiwater_vm(mm);
28368 -       mm->total_vm -= len >> PAGE_SHIFT;
28369 +       vx_vmpages_sub(mm, len >> PAGE_SHIFT);
28370  
28371  #ifdef DEBUG
28372         show_process_blocks();
28373 @@ -1093,7 +1093,7 @@ void exit_mmap(struct mm_struct * mm)
28374                 printk("Exit_mmap:\n");
28375  #endif
28376  
28377 -               mm->total_vm = 0;
28378 +               vx_vmpages_sub(mm, mm->total_vm);
28379  
28380                 while ((tmp = mm->context.vmlist)) {
28381                         mm->context.vmlist = tmp->next;
28382 diff -Nurp linux-2.6.22.18/mm/oom_kill.c linux-2.6.22.18-vs2.3.0.32/mm/oom_kill.c
28383 --- linux-2.6.22.18/mm/oom_kill.c       2007-07-22 00:00:25.000000000 +0200
28384 +++ linux-2.6.22.18-vs2.3.0.32/mm/oom_kill.c    2008-02-11 12:35:39.000000000 +0100
28385 @@ -24,6 +24,7 @@
28386  #include <linux/cpuset.h>
28387  #include <linux/module.h>
28388  #include <linux/notifier.h>
28389 +#include <linux/vs_memory.h>
28390  
28391  int sysctl_panic_on_oom;
28392  /* #define DEBUG */
28393 @@ -66,6 +67,12 @@ unsigned long badness(struct task_struct
28394         points = mm->total_vm;
28395  
28396         /*
28397 +        * add points for context badness
28398 +        */
28399 +
28400 +       points += vx_badness(p, mm);
28401 +
28402 +       /*
28403          * After this unlock we can no longer dereference local variable `mm'
28404          */
28405         task_unlock(p);
28406 @@ -156,8 +163,8 @@ unsigned long badness(struct task_struct
28407         }
28408  
28409  #ifdef DEBUG
28410 -       printk(KERN_DEBUG "OOMkill: task %d (%s) got %d points\n",
28411 -       p->pid, p->comm, points);
28412 +       printk(KERN_DEBUG "OOMkill: task %d:#%u (%s) got %d points\n",
28413 +               p->pid, p->xid, p->comm, points);
28414  #endif
28415         return points;
28416  }
28417 @@ -288,7 +295,8 @@ static void __oom_kill_task(struct task_
28418         }
28419  
28420         if (verbose)
28421 -               printk(KERN_ERR "Killed process %d (%s)\n", p->pid, p->comm);
28422 +               printk(KERN_ERR "Killed process %d:#%u (%s)\n",
28423 +                               p->pid, p->xid, p->comm);
28424  
28425         /*
28426          * We give our sacrificial lamb high priority and access to
28427 @@ -358,8 +366,8 @@ static int oom_kill_process(struct task_
28428                 return 0;
28429         }
28430  
28431 -       printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n",
28432 -                                       message, p->pid, p->comm, points);
28433 +       printk(KERN_ERR "%s: kill process %d:#%u (%s) score %li or a child\n",
28434 +                               message, p->pid, p->xid, p->comm, points);
28435  
28436         /* Try to kill a child first */
28437         list_for_each(tsk, &p->children) {
28438 diff -Nurp linux-2.6.22.18/mm/page_alloc.c linux-2.6.22.18-vs2.3.0.32/mm/page_alloc.c
28439 --- linux-2.6.22.18/mm/page_alloc.c     2007-07-22 00:00:25.000000000 +0200
28440 +++ linux-2.6.22.18-vs2.3.0.32/mm/page_alloc.c  2008-02-11 12:35:39.000000000 +0100
28441 @@ -41,6 +41,8 @@
28442  #include <linux/pfn.h>
28443  #include <linux/backing-dev.h>
28444  #include <linux/fault-inject.h>
28445 +#include <linux/vs_base.h>
28446 +#include <linux/vs_limit.h>
28447  
28448  #include <asm/tlbflush.h>
28449  #include <asm/div64.h>
28450 @@ -1488,6 +1490,9 @@ void si_meminfo(struct sysinfo *val)
28451         val->totalhigh = totalhigh_pages;
28452         val->freehigh = nr_free_highpages();
28453         val->mem_unit = PAGE_SIZE;
28454 +
28455 +       if (vx_flags(VXF_VIRT_MEM, 0))
28456 +               vx_vsi_meminfo(val);
28457  }
28458  
28459  EXPORT_SYMBOL(si_meminfo);
28460 @@ -1508,6 +1513,9 @@ void si_meminfo_node(struct sysinfo *val
28461         val->freehigh = 0;
28462  #endif
28463         val->mem_unit = PAGE_SIZE;
28464 +
28465 +       if (vx_flags(VXF_VIRT_MEM, 0))
28466 +               vx_vsi_meminfo(val);
28467  }
28468  #endif
28469  
28470 diff -Nurp linux-2.6.22.18/mm/rmap.c linux-2.6.22.18-vs2.3.0.32/mm/rmap.c
28471 --- linux-2.6.22.18/mm/rmap.c   2007-07-22 00:00:25.000000000 +0200
28472 +++ linux-2.6.22.18-vs2.3.0.32/mm/rmap.c        2008-02-11 12:35:39.000000000 +0100
28473 @@ -48,6 +48,7 @@
28474  #include <linux/rcupdate.h>
28475  #include <linux/module.h>
28476  #include <linux/kallsyms.h>
28477 +#include <linux/vs_memory.h>
28478  
28479  #include <asm/tlbflush.h>
28480  
28481 diff -Nurp linux-2.6.22.18/mm/shmem.c linux-2.6.22.18-vs2.3.0.32/mm/shmem.c
28482 --- linux-2.6.22.18/mm/shmem.c  2008-01-15 16:00:35.000000000 +0100
28483 +++ linux-2.6.22.18-vs2.3.0.32/mm/shmem.c       2008-02-11 12:35:39.000000000 +0100
28484 @@ -55,7 +55,6 @@
28485  #include <asm/pgtable.h>
28486  
28487  /* This magic number is used in glibc for posix shared memory */
28488 -#define TMPFS_MAGIC    0x01021994
28489  
28490  #define ENTRIES_PER_PAGE (PAGE_CACHE_SIZE/sizeof(unsigned long))
28491  #define ENTRIES_PER_PAGEPAGE (ENTRIES_PER_PAGE*ENTRIES_PER_PAGE)
28492 @@ -1750,7 +1749,7 @@ static int shmem_statfs(struct dentry *d
28493  {
28494         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
28495  
28496 -       buf->f_type = TMPFS_MAGIC;
28497 +       buf->f_type = TMPFS_SUPER_MAGIC;
28498         buf->f_bsize = PAGE_CACHE_SIZE;
28499         buf->f_namelen = NAME_MAX;
28500         spin_lock(&sbinfo->stat_lock);
28501 @@ -2324,7 +2323,7 @@ static int shmem_fill_super(struct super
28502         sb->s_maxbytes = SHMEM_MAX_BYTES;
28503         sb->s_blocksize = PAGE_CACHE_SIZE;
28504         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
28505 -       sb->s_magic = TMPFS_MAGIC;
28506 +       sb->s_magic = TMPFS_SUPER_MAGIC;
28507         sb->s_op = &shmem_ops;
28508         sb->s_time_gran = 1;
28509  #ifdef CONFIG_TMPFS_POSIX_ACL
28510 diff -Nurp linux-2.6.22.18/mm/slab.c linux-2.6.22.18-vs2.3.0.32/mm/slab.c
28511 --- linux-2.6.22.18/mm/slab.c   2007-07-22 00:00:25.000000000 +0200
28512 +++ linux-2.6.22.18-vs2.3.0.32/mm/slab.c        2008-02-11 12:35:40.000000000 +0100
28513 @@ -510,6 +510,8 @@ struct kmem_cache {
28514  #define STATS_INC_FREEMISS(x)  do { } while (0)
28515  #endif
28516  
28517 +#include "slab_vs.h"
28518 +
28519  #if DEBUG
28520  
28521  /*
28522 @@ -3314,6 +3316,7 @@ retry:
28523  
28524         obj = slab_get_obj(cachep, slabp, nodeid);
28525         check_slabp(cachep, slabp);
28526 +       vx_slab_alloc(cachep, flags);
28527         l3->free_objects--;
28528         /* move slabp to correct slabp list: */
28529         list_del(&slabp->list);
28530 @@ -3386,6 +3389,7 @@ __cache_alloc_node(struct kmem_cache *ca
28531         /* ___cache_alloc_node can fall back to other nodes */
28532         ptr = ____cache_alloc_node(cachep, flags, nodeid);
28533    out:
28534 +       vx_slab_alloc(cachep, flags);
28535         local_irq_restore(save_flags);
28536         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
28537  
28538 @@ -3551,6 +3555,7 @@ static inline void __cache_free(struct k
28539  
28540         check_irq_off();
28541         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
28542 +       vx_slab_free(cachep);
28543  
28544         if (cache_free_alien(cachep, objp))
28545                 return;
28546 diff -Nurp linux-2.6.22.18/mm/slab_vs.h linux-2.6.22.18-vs2.3.0.32/mm/slab_vs.h
28547 --- linux-2.6.22.18/mm/slab_vs.h        1970-01-01 01:00:00.000000000 +0100
28548 +++ linux-2.6.22.18-vs2.3.0.32/mm/slab_vs.h     2008-02-11 12:35:40.000000000 +0100
28549 @@ -0,0 +1,27 @@
28550 +
28551 +#include <linux/vserver/context.h>
28552 +
28553 +#include <linux/vs_context.h>
28554 +
28555 +static inline
28556 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
28557 +{
28558 +       int what = gfp_zone(cachep->gfpflags);
28559 +
28560 +       if (!current->vx_info)
28561 +               return;
28562 +
28563 +       atomic_add(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
28564 +}
28565 +
28566 +static inline
28567 +void vx_slab_free(struct kmem_cache *cachep)
28568 +{
28569 +       int what = gfp_zone(cachep->gfpflags);
28570 +
28571 +       if (!current->vx_info)
28572 +               return;
28573 +
28574 +       atomic_sub(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
28575 +}
28576 +
28577 diff -Nurp linux-2.6.22.18/mm/swapfile.c linux-2.6.22.18-vs2.3.0.32/mm/swapfile.c
28578 --- linux-2.6.22.18/mm/swapfile.c       2007-07-22 00:00:25.000000000 +0200
28579 +++ linux-2.6.22.18-vs2.3.0.32/mm/swapfile.c    2008-02-11 12:35:40.000000000 +0100
28580 @@ -31,6 +31,8 @@
28581  #include <asm/pgtable.h>
28582  #include <asm/tlbflush.h>
28583  #include <linux/swapops.h>
28584 +#include <linux/vs_base.h>
28585 +#include <linux/vs_memory.h>
28586  
28587  DEFINE_SPINLOCK(swap_lock);
28588  unsigned int nr_swapfiles;
28589 @@ -1712,6 +1714,8 @@ void si_swapinfo(struct sysinfo *val)
28590         val->freeswap = nr_swap_pages + nr_to_be_unused;
28591         val->totalswap = total_swap_pages + nr_to_be_unused;
28592         spin_unlock(&swap_lock);
28593 +       if (vx_flags(VXF_VIRT_MEM, 0))
28594 +               vx_vsi_swapinfo(val);
28595  }
28596  
28597  /*
28598 diff -Nurp linux-2.6.22.18/net/core/dev.c linux-2.6.22.18-vs2.3.0.32/net/core/dev.c
28599 --- linux-2.6.22.18/net/core/dev.c      2007-09-05 07:07:59.000000000 +0200
28600 +++ linux-2.6.22.18-vs2.3.0.32/net/core/dev.c   2008-02-11 12:35:40.000000000 +0100
28601 @@ -117,6 +117,7 @@
28602  #include <linux/err.h>
28603  #include <linux/ctype.h>
28604  #include <linux/if_arp.h>
28605 +#include <linux/vs_inet.h>
28606  
28607  /*
28608   *     The list of packet types we will receive (as opposed to discard)
28609 @@ -2120,6 +2121,8 @@ static int dev_ifconf(char __user *arg)
28610  
28611         total = 0;
28612         for_each_netdev(dev) {
28613 +               if (!nx_dev_visible(current->nx_info, dev))
28614 +                       continue;
28615                 for (i = 0; i < NPROTO; i++) {
28616                         if (gifconf_list[i]) {
28617                                 int done;
28618 @@ -2184,6 +2187,9 @@ static void dev_seq_printf_stats(struct 
28619  {
28620         struct net_device_stats *stats = dev->get_stats(dev);
28621  
28622 +       if (!nx_dev_visible(current->nx_info, dev))
28623 +               return;
28624 +
28625         seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
28626                    "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
28627                    dev->name, stats->rx_bytes, stats->rx_packets,
28628 diff -Nurp linux-2.6.22.18/net/core/rtnetlink.c linux-2.6.22.18-vs2.3.0.32/net/core/rtnetlink.c
28629 --- linux-2.6.22.18/net/core/rtnetlink.c        2007-07-22 00:00:25.000000000 +0200
28630 +++ linux-2.6.22.18-vs2.3.0.32/net/core/rtnetlink.c     2008-02-11 12:35:40.000000000 +0100
28631 @@ -537,6 +537,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
28632  
28633         idx = 0;
28634         for_each_netdev(dev) {
28635 +               if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
28636 +                       continue;
28637                 if (idx < s_idx)
28638                         goto cont;
28639                 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
28640 @@ -797,6 +799,9 @@ void rtmsg_ifinfo(int type, struct net_d
28641         struct sk_buff *skb;
28642         int err = -ENOBUFS;
28643  
28644 +       if (!nx_dev_visible(current->nx_info, dev))
28645 +               return;
28646 +
28647         skb = nlmsg_new(if_nlmsg_size(), GFP_KERNEL);
28648         if (skb == NULL)
28649                 goto errout;
28650 diff -Nurp linux-2.6.22.18/net/core/sock.c linux-2.6.22.18-vs2.3.0.32/net/core/sock.c
28651 --- linux-2.6.22.18/net/core/sock.c     2007-07-22 00:00:25.000000000 +0200
28652 +++ linux-2.6.22.18-vs2.3.0.32/net/core/sock.c  2008-02-11 12:35:40.000000000 +0100
28653 @@ -125,6 +125,10 @@
28654  #include <linux/ipsec.h>
28655  
28656  #include <linux/filter.h>
28657 +#include <linux/vs_socket.h>
28658 +#include <linux/vs_limit.h>
28659 +#include <linux/vs_context.h>
28660 +#include <linux/vs_network.h>
28661  
28662  #ifdef CONFIG_INET
28663  #include <net/tcp.h>
28664 @@ -812,6 +816,9 @@ int sock_getsockopt(struct socket *sock,
28665         case SO_PEERSEC:
28666                 return security_socket_getpeersec_stream(sock, optval, optlen, len);
28667  
28668 +               case SO_PEERTAG:
28669 +                       return vx_socket_peer_tag(sock, level, optval, optlen, len);
28670 +
28671         default:
28672                 return -ENOPROTOOPT;
28673         }
28674 @@ -869,6 +876,8 @@ struct sock *sk_alloc(int family, gfp_t 
28675                         sk->sk_prot = sk->sk_prot_creator = prot;
28676                         sock_lock_init(sk);
28677                 }
28678 +               sock_vx_init(sk);
28679 +               sock_nx_init(sk);
28680  
28681                 if (security_sk_alloc(sk, family, priority))
28682                         goto out_free;
28683 @@ -907,6 +916,11 @@ void sk_free(struct sock *sk)
28684                        __FUNCTION__, atomic_read(&sk->sk_omem_alloc));
28685  
28686         security_sk_free(sk);
28687 +       vx_sock_dec(sk);
28688 +       clr_vx_info(&sk->sk_vx_info);
28689 +       sk->sk_xid = -1;
28690 +       clr_nx_info(&sk->sk_nx_info);
28691 +       sk->sk_nid = -1;
28692         if (sk->sk_prot_creator->slab != NULL)
28693                 kmem_cache_free(sk->sk_prot_creator->slab, sk);
28694         else
28695 @@ -924,6 +938,8 @@ struct sock *sk_clone(const struct sock 
28696                 sock_copy(newsk, sk);
28697  
28698                 /* SANITY */
28699 +               sock_vx_init(newsk);
28700 +               sock_nx_init(newsk);
28701                 sk_node_init(&newsk->sk_node);
28702                 sock_lock_init(newsk);
28703                 bh_lock_sock(newsk);
28704 @@ -969,6 +985,12 @@ struct sock *sk_clone(const struct sock 
28705                 newsk->sk_priority = 0;
28706                 atomic_set(&newsk->sk_refcnt, 2);
28707  
28708 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
28709 +               newsk->sk_xid = sk->sk_xid;
28710 +               vx_sock_inc(newsk);
28711 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
28712 +               newsk->sk_nid = sk->sk_nid;
28713 +
28714                 /*
28715                  * Increment the counter in the same struct proto as the master
28716                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
28717 @@ -1551,6 +1573,11 @@ void sock_init_data(struct socket *sock,
28718  
28719         sk->sk_stamp = ktime_set(-1L, -1L);
28720  
28721 +       set_vx_info(&sk->sk_vx_info, current->vx_info);
28722 +       sk->sk_xid = vx_current_xid();
28723 +       vx_sock_inc(sk);
28724 +       set_nx_info(&sk->sk_nx_info, current->nx_info);
28725 +       sk->sk_nid = nx_current_nid();
28726         atomic_set(&sk->sk_refcnt, 1);
28727  }
28728  
28729 diff -Nurp linux-2.6.22.18/net/ipv4/af_inet.c linux-2.6.22.18-vs2.3.0.32/net/ipv4/af_inet.c
28730 --- linux-2.6.22.18/net/ipv4/af_inet.c  2007-09-05 07:07:59.000000000 +0200
28731 +++ linux-2.6.22.18-vs2.3.0.32/net/ipv4/af_inet.c       2008-02-11 12:35:40.000000000 +0100
28732 @@ -115,6 +115,7 @@
28733  #ifdef CONFIG_IP_MROUTE
28734  #include <linux/mroute.h>
28735  #endif
28736 +#include <linux/vs_limit.h>
28737  
28738  DEFINE_SNMP_STAT(struct linux_mib, net_statistics) __read_mostly;
28739  
28740 @@ -308,9 +309,12 @@ lookup_protocol:
28741         }
28742  
28743         err = -EPERM;
28744 +       if ((protocol == IPPROTO_ICMP) &&
28745 +               nx_capable(answer->capability, NXC_RAW_ICMP))
28746 +               goto override;
28747         if (answer->capability > 0 && !capable(answer->capability))
28748                 goto out_rcu_unlock;
28749 -
28750 +override:
28751         sock->ops = answer->ops;
28752         answer_prot = answer->prot;
28753         answer_no_check = answer->no_check;
28754 @@ -424,6 +428,7 @@ int inet_bind(struct socket *sock, struc
28755         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
28756         struct sock *sk = sock->sk;
28757         struct inet_sock *inet = inet_sk(sk);
28758 +       struct nx_v4_sock_addr nsa;
28759         unsigned short snum;
28760         int chk_addr_ret;
28761         int err;
28762 @@ -437,7 +442,11 @@ int inet_bind(struct socket *sock, struc
28763         if (addr_len < sizeof(struct sockaddr_in))
28764                 goto out;
28765  
28766 -       chk_addr_ret = inet_addr_type(addr->sin_addr.s_addr);
28767 +       err = v4_map_sock_addr(inet, addr, &nsa);
28768 +       if (err)
28769 +               goto out;
28770 +
28771 +       chk_addr_ret = inet_addr_type(nsa.saddr);
28772  
28773         /* Not specified by any standard per-se, however it breaks too
28774          * many applications when removed.  It is unfortunate since
28775 @@ -449,7 +458,7 @@ int inet_bind(struct socket *sock, struc
28776         err = -EADDRNOTAVAIL;
28777         if (!sysctl_ip_nonlocal_bind &&
28778             !inet->freebind &&
28779 -           addr->sin_addr.s_addr != INADDR_ANY &&
28780 +           nsa.saddr != INADDR_ANY &&
28781             chk_addr_ret != RTN_LOCAL &&
28782             chk_addr_ret != RTN_MULTICAST &&
28783             chk_addr_ret != RTN_BROADCAST)
28784 @@ -474,7 +483,7 @@ int inet_bind(struct socket *sock, struc
28785         if (sk->sk_state != TCP_CLOSE || inet->num)
28786                 goto out_release_sock;
28787  
28788 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
28789 +       v4_set_sock_addr(inet, &nsa);
28790         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
28791                 inet->saddr = 0;  /* Use device */
28792  
28793 @@ -667,11 +676,13 @@ int inet_getname(struct socket *sock, st
28794                      peer == 1))
28795                         return -ENOTCONN;
28796                 sin->sin_port = inet->dport;
28797 -               sin->sin_addr.s_addr = inet->daddr;
28798 +               sin->sin_addr.s_addr =
28799 +                       nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
28800         } else {
28801                 __be32 addr = inet->rcv_saddr;
28802                 if (!addr)
28803                         addr = inet->saddr;
28804 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
28805                 sin->sin_port = inet->sport;
28806                 sin->sin_addr.s_addr = addr;
28807         }
28808 diff -Nurp linux-2.6.22.18/net/ipv4/devinet.c linux-2.6.22.18-vs2.3.0.32/net/ipv4/devinet.c
28809 --- linux-2.6.22.18/net/ipv4/devinet.c  2008-02-11 12:34:20.000000000 +0100
28810 +++ linux-2.6.22.18-vs2.3.0.32/net/ipv4/devinet.c       2008-02-11 12:35:40.000000000 +0100
28811 @@ -427,6 +427,7 @@ struct in_device *inetdev_by_index(int i
28812         return in_dev;
28813  }
28814  
28815 +
28816  /* Called only from RTNL semaphored context. No locks. */
28817  
28818  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
28819 @@ -676,6 +677,8 @@ int devinet_ioctl(unsigned int cmd, void
28820                 *colon = ':';
28821  
28822         if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) {
28823 +               struct nx_info *nxi = current->nx_info;
28824 +
28825                 if (tryaddrmatch) {
28826                         /* Matthias Andree */
28827                         /* compare label and address (4.4BSD style) */
28828 @@ -684,6 +687,8 @@ int devinet_ioctl(unsigned int cmd, void
28829                            This is checked above. */
28830                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
28831                              ifap = &ifa->ifa_next) {
28832 +                               if (!nx_v4_ifa_visible(nxi, ifa))
28833 +                                       continue;
28834                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
28835                                     sin_orig.sin_addr.s_addr ==
28836                                                         ifa->ifa_address) {
28837 @@ -696,9 +701,12 @@ int devinet_ioctl(unsigned int cmd, void
28838                    comparing just the label */
28839                 if (!ifa) {
28840                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
28841 -                            ifap = &ifa->ifa_next)
28842 +                            ifap = &ifa->ifa_next) {
28843 +                               if (!nx_v4_ifa_visible(nxi, ifa))
28844 +                                       continue;
28845                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
28846                                         break;
28847 +                       }
28848                 }
28849         }
28850  
28851 @@ -849,6 +857,8 @@ static int inet_gifconf(struct net_devic
28852                 goto out;
28853  
28854         for (; ifa; ifa = ifa->ifa_next) {
28855 +               if (!nx_v4_ifa_visible(current->nx_info, ifa))
28856 +                       continue;
28857                 if (!buf) {
28858                         done += sizeof(ifr);
28859                         continue;
28860 @@ -1179,6 +1189,7 @@ static int inet_dump_ifaddr(struct sk_bu
28861         struct net_device *dev;
28862         struct in_device *in_dev;
28863         struct in_ifaddr *ifa;
28864 +       struct sock *sk = skb->sk;
28865         int s_ip_idx, s_idx = cb->args[0];
28866  
28867         s_ip_idx = ip_idx = cb->args[1];
28868 @@ -1193,6 +1204,8 @@ static int inet_dump_ifaddr(struct sk_bu
28869  
28870                 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
28871                      ifa = ifa->ifa_next, ip_idx++) {
28872 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
28873 +                               continue;
28874                         if (ip_idx < s_ip_idx)
28875                                 continue;
28876                         if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
28877 diff -Nurp linux-2.6.22.18/net/ipv4/fib_hash.c linux-2.6.22.18-vs2.3.0.32/net/ipv4/fib_hash.c
28878 --- linux-2.6.22.18/net/ipv4/fib_hash.c 2007-07-22 00:00:25.000000000 +0200
28879 +++ linux-2.6.22.18-vs2.3.0.32/net/ipv4/fib_hash.c      2008-02-11 12:35:41.000000000 +0100
28880 @@ -1012,7 +1012,7 @@ static int fib_seq_show(struct seq_file 
28881         prefix  = f->fn_key;
28882         mask    = FZ_MASK(iter->zone);
28883         flags   = fib_flag_trans(fa->fa_type, mask, fi);
28884 -       if (fi)
28885 +       if (fi && nx_dev_visible(current->nx_info, fi->fib_dev))
28886                 snprintf(bf, sizeof(bf),
28887                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u",
28888                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
28889 diff -Nurp linux-2.6.22.18/net/ipv4/inet_connection_sock.c linux-2.6.22.18-vs2.3.0.32/net/ipv4/inet_connection_sock.c
28890 --- linux-2.6.22.18/net/ipv4/inet_connection_sock.c     2007-07-22 00:00:25.000000000 +0200
28891 +++ linux-2.6.22.18-vs2.3.0.32/net/ipv4/inet_connection_sock.c  2008-02-11 12:35:41.000000000 +0100
28892 @@ -34,10 +34,40 @@ EXPORT_SYMBOL(inet_csk_timer_bug_msg);
28893   */
28894  int sysctl_local_port_range[2] = { 32768, 61000 };
28895  
28896 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
28897 +{
28898 +       __be32  sk1_rcv_saddr = inet_rcv_saddr(sk1),
28899 +               sk2_rcv_saddr = inet_rcv_saddr(sk2);
28900 +
28901 +       if (inet_v6_ipv6only(sk2))
28902 +               return 0;
28903 +
28904 +       if (sk1_rcv_saddr &&
28905 +           sk2_rcv_saddr &&
28906 +           sk1_rcv_saddr == sk2_rcv_saddr)
28907 +               return 1;
28908 +
28909 +       if (sk1_rcv_saddr &&
28910 +           !sk2_rcv_saddr &&
28911 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
28912 +               return 1;
28913 +
28914 +       if (sk2_rcv_saddr &&
28915 +           !sk1_rcv_saddr &&
28916 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
28917 +               return 1;
28918 +
28919 +       if (!sk1_rcv_saddr &&
28920 +           !sk2_rcv_saddr &&
28921 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
28922 +               return 1;
28923 +
28924 +       return 0;
28925 +}
28926 +
28927  int inet_csk_bind_conflict(const struct sock *sk,
28928                            const struct inet_bind_bucket *tb)
28929  {
28930 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
28931         struct sock *sk2;
28932         struct hlist_node *node;
28933         int reuse = sk->sk_reuse;
28934 @@ -50,9 +80,7 @@ int inet_csk_bind_conflict(const struct 
28935                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
28936                         if (!reuse || !sk2->sk_reuse ||
28937                             sk2->sk_state == TCP_LISTEN) {
28938 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
28939 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
28940 -                                   sk2_rcv_saddr == sk_rcv_saddr)
28941 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
28942                                         break;
28943                         }
28944                 }
28945 diff -Nurp linux-2.6.22.18/net/ipv4/inet_diag.c linux-2.6.22.18-vs2.3.0.32/net/ipv4/inet_diag.c
28946 --- linux-2.6.22.18/net/ipv4/inet_diag.c        2007-09-29 14:11:49.000000000 +0200
28947 +++ linux-2.6.22.18-vs2.3.0.32/net/ipv4/inet_diag.c     2008-02-11 12:35:41.000000000 +0100
28948 @@ -98,8 +98,8 @@ static int inet_csk_diag_fill(struct soc
28949  
28950         r->id.idiag_sport = inet->sport;
28951         r->id.idiag_dport = inet->dport;
28952 -       r->id.idiag_src[0] = inet->rcv_saddr;
28953 -       r->id.idiag_dst[0] = inet->daddr;
28954 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, inet->rcv_saddr);
28955 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
28956  
28957  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
28958         if (r->idiag_family == AF_INET6) {
28959 @@ -186,8 +186,8 @@ static int inet_twsk_diag_fill(struct in
28960         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
28961         r->id.idiag_sport     = tw->tw_sport;
28962         r->id.idiag_dport     = tw->tw_dport;
28963 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
28964 -       r->id.idiag_dst[0]    = tw->tw_daddr;
28965 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
28966 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
28967         r->idiag_state        = tw->tw_substate;
28968         r->idiag_timer        = 3;
28969         r->idiag_expires      = (tmo * 1000 + HZ - 1) / HZ;
28970 @@ -239,6 +239,7 @@ static int inet_diag_get_exact(struct sk
28971         hashinfo = handler->idiag_hashinfo;
28972  
28973         if (req->idiag_family == AF_INET) {
28974 +               /* TODO: lback */
28975                 sk = inet_lookup(hashinfo, req->id.idiag_dst[0],
28976                                  req->id.idiag_dport, req->id.idiag_src[0],
28977                                  req->id.idiag_sport, req->id.idiag_if);
28978 @@ -478,6 +479,7 @@ static int inet_csk_diag_dump(struct soc
28979                 } else
28980  #endif
28981                 {
28982 +                       /* TODO: lback */
28983                         entry.saddr = &inet->rcv_saddr;
28984                         entry.daddr = &inet->daddr;
28985                 }
28986 @@ -514,6 +516,7 @@ static int inet_twsk_diag_dump(struct in
28987                 } else
28988  #endif
28989                 {
28990 +                       /* TODO: lback */
28991                         entry.saddr = &tw->tw_rcv_saddr;
28992                         entry.daddr = &tw->tw_daddr;
28993                 }
28994 @@ -560,8 +563,8 @@ static int inet_diag_fill_req(struct sk_
28995  
28996         r->id.idiag_sport = inet->sport;
28997         r->id.idiag_dport = ireq->rmt_port;
28998 -       r->id.idiag_src[0] = ireq->loc_addr;
28999 -       r->id.idiag_dst[0] = ireq->rmt_addr;
29000 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
29001 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
29002         r->idiag_expires = jiffies_to_msecs(tmo);
29003         r->idiag_rqueue = 0;
29004         r->idiag_wqueue = 0;
29005 @@ -631,6 +634,7 @@ static int inet_diag_dump_reqs(struct sk
29006                                 continue;
29007  
29008                         if (bc) {
29009 +                               /* TODO: lback */
29010                                 entry.saddr =
29011  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
29012                                         (entry.family == AF_INET6) ?
29013 @@ -697,6 +701,8 @@ static int inet_diag_dump(struct sk_buff
29014                         sk_for_each(sk, node, &hashinfo->listening_hash[i]) {
29015                                 struct inet_sock *inet = inet_sk(sk);
29016  
29017 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29018 +                                       continue;
29019                                 if (num < s_num) {
29020                                         num++;
29021                                         continue;
29022 @@ -757,6 +763,8 @@ skip_listen_ht:
29023                 sk_for_each(sk, node, &head->chain) {
29024                         struct inet_sock *inet = inet_sk(sk);
29025  
29026 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29027 +                               continue;
29028                         if (num < s_num)
29029                                 goto next_normal;
29030                         if (!(r->idiag_states & (1 << sk->sk_state)))
29031 @@ -781,6 +789,8 @@ next_normal:
29032                         inet_twsk_for_each(tw, node,
29033                                     &head->twchain) {
29034  
29035 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
29036 +                                       continue;
29037                                 if (num < s_num)
29038                                         goto next_dying;
29039                                 if (r->id.idiag_sport != tw->tw_sport &&
29040 diff -Nurp linux-2.6.22.18/net/ipv4/inet_hashtables.c linux-2.6.22.18-vs2.3.0.32/net/ipv4/inet_hashtables.c
29041 --- linux-2.6.22.18/net/ipv4/inet_hashtables.c  2007-07-21 23:58:55.000000000 +0200
29042 +++ linux-2.6.22.18-vs2.3.0.32/net/ipv4/inet_hashtables.c       2008-02-11 12:35:41.000000000 +0100
29043 @@ -140,11 +140,10 @@ static struct sock *inet_lookup_listener
29044                         const __be32 rcv_saddr = inet->rcv_saddr;
29045                         int score = sk->sk_family == PF_INET ? 1 : 0;
29046  
29047 -                       if (rcv_saddr) {
29048 -                               if (rcv_saddr != daddr)
29049 -                                       continue;
29050 +                       if (v4_inet_addr_match(sk->sk_nx_info, daddr, rcv_saddr))
29051                                 score += 2;
29052 -                       }
29053 +                       else
29054 +                               continue;
29055                         if (sk->sk_bound_dev_if) {
29056                                 if (sk->sk_bound_dev_if != dif)
29057                                         continue;
29058 @@ -175,7 +174,7 @@ struct sock *__inet_lookup_listener(stru
29059                 const struct inet_sock *inet = inet_sk((sk = __sk_head(head)));
29060  
29061                 if (inet->num == hnum && !sk->sk_node.next &&
29062 -                   (!inet->rcv_saddr || inet->rcv_saddr == daddr) &&
29063 +                   v4_inet_addr_match(sk->sk_nx_info, daddr, inet->rcv_saddr) &&
29064                     (sk->sk_family == PF_INET || !ipv6_only_sock(sk)) &&
29065                     !sk->sk_bound_dev_if)
29066                         goto sherry_cache;
29067 diff -Nurp linux-2.6.22.18/net/ipv4/raw.c linux-2.6.22.18-vs2.3.0.32/net/ipv4/raw.c
29068 --- linux-2.6.22.18/net/ipv4/raw.c      2007-07-22 00:00:27.000000000 +0200
29069 +++ linux-2.6.22.18-vs2.3.0.32/net/ipv4/raw.c   2008-02-11 12:35:41.000000000 +0100
29070 @@ -112,7 +112,7 @@ struct sock *__raw_v4_lookup(struct sock
29071  
29072                 if (inet->num == num                                    &&
29073                     !(inet->daddr && inet->daddr != raddr)              &&
29074 -                   !(inet->rcv_saddr && inet->rcv_saddr != laddr)      &&
29075 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
29076                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
29077                         goto found; /* gotcha */
29078         }
29079 @@ -314,6 +314,12 @@ static int raw_send_hdrinc(struct sock *
29080                 iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
29081         }
29082  
29083 +       err = -EPERM;
29084 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
29085 +               sk->sk_nx_info &&
29086 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
29087 +               goto error_free;
29088 +
29089         err = NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
29090                       dst_output);
29091         if (err > 0)
29092 @@ -325,6 +331,7 @@ out:
29093  
29094  error_fault:
29095         err = -EFAULT;
29096 +error_free:
29097         kfree_skb(skb);
29098  error:
29099         IP_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
29100 @@ -491,6 +498,12 @@ static int raw_sendmsg(struct kiocb *ioc
29101                 }
29102  
29103                 security_sk_classify_flow(sk, &fl);
29104 +               if (sk->sk_nx_info) {
29105 +                       err = ip_v4_find_src(sk->sk_nx_info, &rt, &fl);
29106 +
29107 +                       if (err)
29108 +                               goto done;
29109 +               }
29110                 err = ip_route_output_flow(&rt, &fl, sk, 1);
29111         }
29112         if (err)
29113 @@ -553,17 +566,19 @@ static int raw_bind(struct sock *sk, str
29114  {
29115         struct inet_sock *inet = inet_sk(sk);
29116         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
29117 +       struct nx_v4_sock_addr nsa = { 0 };
29118         int ret = -EINVAL;
29119         int chk_addr_ret;
29120  
29121         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
29122                 goto out;
29123 -       chk_addr_ret = inet_addr_type(addr->sin_addr.s_addr);
29124 +       v4_map_sock_addr(inet, addr, &nsa);
29125 +       chk_addr_ret = inet_addr_type(nsa.saddr);
29126         ret = -EADDRNOTAVAIL;
29127 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
29128 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
29129             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
29130                 goto out;
29131 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
29132 +       v4_set_sock_addr(inet, &nsa);
29133         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
29134                 inet->saddr = 0;  /* Use device */
29135         sk_dst_reset(sk);
29136 @@ -615,7 +630,8 @@ static int raw_recvmsg(struct kiocb *ioc
29137         /* Copy the address. */
29138         if (sin) {
29139                 sin->sin_family = AF_INET;
29140 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
29141 +               sin->sin_addr.s_addr =
29142 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
29143                 sin->sin_port = 0;
29144                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
29145         }
29146 @@ -795,7 +811,8 @@ static struct sock *raw_get_first(struct
29147                 struct hlist_node *node;
29148  
29149                 sk_for_each(sk, node, &raw_v4_htable[state->bucket])
29150 -                       if (sk->sk_family == PF_INET)
29151 +                       if (sk->sk_family == PF_INET &&
29152 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29153                                 goto found;
29154         }
29155         sk = NULL;
29156 @@ -811,7 +828,8 @@ static struct sock *raw_get_next(struct 
29157                 sk = sk_next(sk);
29158  try_again:
29159                 ;
29160 -       } while (sk && sk->sk_family != PF_INET);
29161 +       } while (sk && (sk->sk_family != PF_INET ||
29162 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
29163  
29164         if (!sk && ++state->bucket < RAWV4_HTABLE_SIZE) {
29165                 sk = sk_head(&raw_v4_htable[state->bucket]);
29166 @@ -863,7 +881,10 @@ static __inline__ char *get_raw_sock(str
29167  
29168         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
29169                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p",
29170 -               i, src, srcp, dest, destp, sp->sk_state,
29171 +               i,
29172 +               nx_map_sock_lback(current_nx_info(), src), srcp,
29173 +               nx_map_sock_lback(current_nx_info(), dest), destp,
29174 +               sp->sk_state,
29175                 atomic_read(&sp->sk_wmem_alloc),
29176                 atomic_read(&sp->sk_rmem_alloc),
29177                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
29178 diff -Nurp linux-2.6.22.18/net/ipv4/tcp.c linux-2.6.22.18-vs2.3.0.32/net/ipv4/tcp.c
29179 --- linux-2.6.22.18/net/ipv4/tcp.c      2007-09-05 07:07:59.000000000 +0200
29180 +++ linux-2.6.22.18-vs2.3.0.32/net/ipv4/tcp.c   2008-02-11 12:35:41.000000000 +0100
29181 @@ -258,6 +258,7 @@
29182  #include <linux/cache.h>
29183  #include <linux/err.h>
29184  #include <linux/crypto.h>
29185 +#include <linux/in.h>
29186  
29187  #include <net/icmp.h>
29188  #include <net/tcp.h>
29189 diff -Nurp linux-2.6.22.18/net/ipv4/tcp_ipv4.c linux-2.6.22.18-vs2.3.0.32/net/ipv4/tcp_ipv4.c
29190 --- linux-2.6.22.18/net/ipv4/tcp_ipv4.c 2007-12-09 12:43:41.000000000 +0100
29191 +++ linux-2.6.22.18-vs2.3.0.32/net/ipv4/tcp_ipv4.c      2008-02-11 12:35:42.000000000 +0100
29192 @@ -1974,6 +1974,12 @@ static void *listening_get_next(struct s
29193                 req = req->dl_next;
29194                 while (1) {
29195                         while (req) {
29196 +                               vxdprintk(VXD_CBIT(net, 6),
29197 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
29198 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
29199 +                               if (req->sk &&
29200 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
29201 +                                       continue;
29202                                 if (req->rsk_ops->family == st->family) {
29203                                         cur = req;
29204                                         goto out;
29205 @@ -1998,6 +2004,10 @@ get_req:
29206         }
29207  get_sk:
29208         sk_for_each_from(sk, node) {
29209 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
29210 +                       sk, sk->sk_nid, nx_current_nid());
29211 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29212 +                       continue;
29213                 if (sk->sk_family == st->family) {
29214                         cur = sk;
29215                         goto out;
29216 @@ -2049,18 +2059,26 @@ static void *established_get_first(struc
29217  
29218                 read_lock(&tcp_hashinfo.ehash[st->bucket].lock);
29219                 sk_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
29220 -                       if (sk->sk_family != st->family) {
29221 +                       vxdprintk(VXD_CBIT(net, 6),
29222 +                               "sk,egf: %p [#%d] (from %d)",
29223 +                               sk, sk->sk_nid, nx_current_nid());
29224 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29225 +                               continue;
29226 +                       if (sk->sk_family != st->family)
29227                                 continue;
29228 -                       }
29229                         rc = sk;
29230                         goto out;
29231                 }
29232                 st->state = TCP_SEQ_STATE_TIME_WAIT;
29233                 inet_twsk_for_each(tw, node,
29234                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
29235 -                       if (tw->tw_family != st->family) {
29236 +                       vxdprintk(VXD_CBIT(net, 6),
29237 +                               "tw: %p [#%d] (from %d)",
29238 +                               tw, tw->tw_nid, nx_current_nid());
29239 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
29240 +                               continue;
29241 +                       if (tw->tw_family != st->family)
29242                                 continue;
29243 -                       }
29244                         rc = tw;
29245                         goto out;
29246                 }
29247 @@ -2084,7 +2102,8 @@ static void *established_get_next(struct
29248                 tw = cur;
29249                 tw = tw_next(tw);
29250  get_tw:
29251 -               while (tw && tw->tw_family != st->family) {
29252 +               while (tw && (tw->tw_family != st->family ||
29253 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
29254                         tw = tw_next(tw);
29255                 }
29256                 if (tw) {
29257 @@ -2108,6 +2127,11 @@ get_tw:
29258                 sk = sk_next(sk);
29259  
29260         sk_for_each_from(sk, node) {
29261 +               vxdprintk(VXD_CBIT(net, 6),
29262 +                       "sk,egn: %p [#%d] (from %d)",
29263 +                       sk, sk->sk_nid, nx_current_nid());
29264 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29265 +                       continue;
29266                 if (sk->sk_family == st->family)
29267                         goto found;
29268         }
29269 @@ -2283,9 +2307,9 @@ static void get_openreq4(struct sock *sk
29270         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
29271                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p",
29272                 i,
29273 -               ireq->loc_addr,
29274 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
29275                 ntohs(inet_sk(sk)->sport),
29276 -               ireq->rmt_addr,
29277 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
29278                 ntohs(ireq->rmt_port),
29279                 TCP_SYN_RECV,
29280                 0, 0, /* could print option size, but that is af dependent. */
29281 @@ -2327,7 +2351,10 @@ static void get_tcp4_sock(struct sock *s
29282  
29283         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
29284                         "%08X %5d %8d %lu %d %p %u %u %u %u %d",
29285 -               i, src, srcp, dest, destp, sk->sk_state,
29286 +               i,
29287 +               nx_map_sock_lback(current_nx_info(), src), srcp,
29288 +               nx_map_sock_lback(current_nx_info(), dest), destp,
29289 +               sk->sk_state,
29290                 tp->write_seq - tp->snd_una,
29291                 sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog :
29292                                              (tp->rcv_nxt - tp->copied_seq),
29293 @@ -2362,7 +2389,10 @@ static void get_timewait4_sock(struct in
29294  
29295         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
29296                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p",
29297 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
29298 +               i,
29299 +               nx_map_sock_lback(current_nx_info(), src), srcp,
29300 +               nx_map_sock_lback(current_nx_info(), dest), destp,
29301 +               tw->tw_substate, 0, 0,
29302                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
29303                 atomic_read(&tw->tw_refcnt), tw);
29304  }
29305 diff -Nurp linux-2.6.22.18/net/ipv4/tcp_minisocks.c linux-2.6.22.18-vs2.3.0.32/net/ipv4/tcp_minisocks.c
29306 --- linux-2.6.22.18/net/ipv4/tcp_minisocks.c    2007-07-22 00:00:27.000000000 +0200
29307 +++ linux-2.6.22.18-vs2.3.0.32/net/ipv4/tcp_minisocks.c 2008-02-11 12:35:42.000000000 +0100
29308 @@ -28,6 +28,10 @@
29309  #include <net/inet_common.h>
29310  #include <net/xfrm.h>
29311  
29312 +#include <linux/vs_limit.h>
29313 +#include <linux/vs_socket.h>
29314 +#include <linux/vs_context.h>
29315 +
29316  #ifdef CONFIG_SYSCTL
29317  #define SYNC_INIT 0 /* let the user enable it */
29318  #else
29319 @@ -293,6 +297,11 @@ void tcp_time_wait(struct sock *sk, int 
29320                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
29321                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
29322  
29323 +               tw->tw_xid              = sk->sk_xid;
29324 +               tw->tw_vx_info          = NULL;
29325 +               tw->tw_nid              = sk->sk_nid;
29326 +               tw->tw_nx_info          = NULL;
29327 +
29328  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
29329                 if (tw->tw_family == PF_INET6) {
29330                         struct ipv6_pinfo *np = inet6_sk(sk);
29331 diff -Nurp linux-2.6.22.18/net/ipv4/udp.c linux-2.6.22.18-vs2.3.0.32/net/ipv4/udp.c
29332 --- linux-2.6.22.18/net/ipv4/udp.c      2007-07-22 00:00:27.000000000 +0200
29333 +++ linux-2.6.22.18-vs2.3.0.32/net/ipv4/udp.c   2008-02-11 12:35:42.000000000 +0100
29334 @@ -219,14 +219,7 @@ int udp_get_port(struct sock *sk, unsign
29335         return  __udp_lib_get_port(sk, snum, udp_hash, &udp_port_rover, scmp);
29336  }
29337  
29338 -int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
29339 -{
29340 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
29341 -
29342 -       return  ( !ipv6_only_sock(sk2)  &&
29343 -                 (!inet1->rcv_saddr || !inet2->rcv_saddr ||
29344 -                  inet1->rcv_saddr == inet2->rcv_saddr      ));
29345 -}
29346 +extern int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2);
29347  
29348  static inline int udp_v4_get_port(struct sock *sk, unsigned short snum)
29349  {
29350 @@ -246,15 +239,22 @@ static struct sock *__udp4_lib_lookup(__
29351         int badness = -1;
29352  
29353         read_lock(&udp_hash_lock);
29354 +
29355         sk_for_each(sk, node, &udptable[hnum & (UDP_HTABLE_SIZE - 1)]) {
29356                 struct inet_sock *inet = inet_sk(sk);
29357  
29358                 if (sk->sk_hash == hnum && !ipv6_only_sock(sk)) {
29359                         int score = (sk->sk_family == PF_INET ? 1 : 0);
29360 +
29361                         if (inet->rcv_saddr) {
29362                                 if (inet->rcv_saddr != daddr)
29363                                         continue;
29364                                 score+=2;
29365 +                       } else {
29366 +                               /* block non nx_info ips */
29367 +                               if (!v4_addr_in_nx_info(sk->sk_nx_info,
29368 +                                       daddr, NXA_MASK_BIND))
29369 +                                       continue;
29370                         }
29371                         if (inet->daddr) {
29372                                 if (inet->daddr != saddr)
29373 @@ -280,6 +280,7 @@ static struct sock *__udp4_lib_lookup(__
29374                         }
29375                 }
29376         }
29377 +
29378         if (result)
29379                 sock_hold(result);
29380         read_unlock(&udp_hash_lock);
29381 @@ -301,7 +302,7 @@ static inline struct sock *udp_v4_mcast_
29382                 if (s->sk_hash != hnum                                  ||
29383                     (inet->daddr && inet->daddr != rmt_addr)            ||
29384                     (inet->dport != rmt_port && inet->dport)            ||
29385 -                   (inet->rcv_saddr && inet->rcv_saddr != loc_addr)    ||
29386 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
29387                     ipv6_only_sock(s)                                   ||
29388                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
29389                         continue;
29390 @@ -631,7 +632,14 @@ int udp_sendmsg(struct kiocb *iocb, stru
29391                                     .uli_u = { .ports =
29392                                                { .sport = inet->sport,
29393                                                  .dport = dport } } };
29394 +               struct nx_info *nxi = sk->sk_nx_info;
29395 +
29396                 security_sk_classify_flow(sk, &fl);
29397 +
29398 +               err = ip_v4_find_src(nxi, &rt, &fl);
29399 +               if (err)
29400 +                       goto out;
29401 +
29402                 err = ip_route_output_flow(&rt, &fl, sk, 1);
29403                 if (err) {
29404                         if (err == -ENETUNREACH)
29405 @@ -871,7 +879,8 @@ try_again:
29406         {
29407                 sin->sin_family = AF_INET;
29408                 sin->sin_port = udp_hdr(skb)->source;
29409 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
29410 +               sin->sin_addr.s_addr = nx_map_sock_lback(
29411 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
29412                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
29413         }
29414         if (inet->cmsg_flags)
29415 @@ -1551,7 +1560,8 @@ static struct sock *udp_get_first(struct
29416         for (state->bucket = 0; state->bucket < UDP_HTABLE_SIZE; ++state->bucket) {
29417                 struct hlist_node *node;
29418                 sk_for_each(sk, node, state->hashtable + state->bucket) {
29419 -                       if (sk->sk_family == state->family)
29420 +                       if (sk->sk_family == state->family &&
29421 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29422                                 goto found;
29423                 }
29424         }
29425 @@ -1568,7 +1578,8 @@ static struct sock *udp_get_next(struct 
29426                 sk = sk_next(sk);
29427  try_again:
29428                 ;
29429 -       } while (sk && sk->sk_family != state->family);
29430 +       } while (sk && (sk->sk_family != state->family ||
29431 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
29432  
29433         if (!sk && ++state->bucket < UDP_HTABLE_SIZE) {
29434                 sk = sk_head(state->hashtable + state->bucket);
29435 @@ -1681,7 +1692,10 @@ static void udp4_format_sock(struct sock
29436  
29437         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
29438                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p",
29439 -               bucket, src, srcp, dest, destp, sp->sk_state,
29440 +               bucket,
29441 +               nx_map_sock_lback(current_nx_info(), src), srcp,
29442 +               nx_map_sock_lback(current_nx_info(), dest), destp,
29443 +               sp->sk_state,
29444                 atomic_read(&sp->sk_wmem_alloc),
29445                 atomic_read(&sp->sk_rmem_alloc),
29446                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
29447 diff -Nurp linux-2.6.22.18/net/ipv6/addrconf.c linux-2.6.22.18-vs2.3.0.32/net/ipv6/addrconf.c
29448 --- linux-2.6.22.18/net/ipv6/addrconf.c 2008-01-15 16:00:36.000000000 +0100
29449 +++ linux-2.6.22.18-vs2.3.0.32/net/ipv6/addrconf.c      2008-02-11 12:35:42.000000000 +0100
29450 @@ -86,6 +86,7 @@
29451  
29452  #include <linux/proc_fs.h>
29453  #include <linux/seq_file.h>
29454 +#include <linux/vs_inet6.h>
29455  
29456  /* Set to 3 to get tracing... */
29457  #define ACONF_DEBUG 2
29458 @@ -904,7 +905,8 @@ static inline int ipv6_saddr_label(const
29459  }
29460  
29461  int ipv6_dev_get_saddr(struct net_device *daddr_dev,
29462 -                      struct in6_addr *daddr, struct in6_addr *saddr)
29463 +                      struct in6_addr *daddr, struct in6_addr *saddr,
29464 +                      struct nx_info *nxi)
29465  {
29466         struct ipv6_saddr_score hiscore;
29467         struct inet6_ifaddr *ifa_result = NULL;
29468 @@ -949,6 +951,10 @@ int ipv6_dev_get_saddr(struct net_device
29469  
29470                         score.addr_type = __ipv6_addr_type(&ifa->addr);
29471  
29472 +                       /* Use only addresses assigned to the context */
29473 +                       if (!v6_ifa_in_nx_info(ifa, nxi))
29474 +                               continue;
29475 +
29476                         /* Rule 0:
29477                          * - Tentative Address (RFC2462 section 5.4)
29478                          *  - A tentative address is not considered
29479 @@ -1162,9 +1168,10 @@ record_it:
29480  
29481  
29482  int ipv6_get_saddr(struct dst_entry *dst,
29483 -                  struct in6_addr *daddr, struct in6_addr *saddr)
29484 +                  struct in6_addr *daddr, struct in6_addr *saddr,
29485 +                  struct nx_info *nxi)
29486  {
29487 -       return ipv6_dev_get_saddr(dst ? ip6_dst_idev(dst)->dev : NULL, daddr, saddr);
29488 +       return ipv6_dev_get_saddr(dst ? ip6_dst_idev(dst)->dev : NULL, daddr, saddr, nxi);
29489  }
29490  
29491  EXPORT_SYMBOL(ipv6_get_saddr);
29492 @@ -1260,35 +1267,46 @@ struct inet6_ifaddr * ipv6_get_ifaddr(st
29493         return ifp;
29494  }
29495  
29496 +extern int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2);
29497 +
29498  int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
29499  {
29500         const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
29501         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
29502 -       __be32 sk_rcv_saddr = inet_sk(sk)->rcv_saddr;
29503         __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
29504         int sk_ipv6only = ipv6_only_sock(sk);
29505         int sk2_ipv6only = inet_v6_ipv6only(sk2);
29506         int addr_type = ipv6_addr_type(sk_rcv_saddr6);
29507         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
29508  
29509 -       if (!sk2_rcv_saddr && !sk_ipv6only)
29510 +       /* FIXME: needs handling for v4 ANY */
29511 +       if (!sk2_rcv_saddr && !sk_ipv6only && !sk2->sk_nx_info)
29512                 return 1;
29513  
29514         if (addr_type2 == IPV6_ADDR_ANY &&
29515 -           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
29516 +           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED) &&
29517 +           v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1))
29518                 return 1;
29519  
29520         if (addr_type == IPV6_ADDR_ANY &&
29521 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
29522 +           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED) &&
29523 +           (sk2_rcv_saddr6 && v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1)))
29524 +               return 1;
29525 +
29526 +       if (addr_type == IPV6_ADDR_ANY &&
29527 +           addr_type2 == IPV6_ADDR_ANY &&
29528 +           nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info))
29529                 return 1;
29530  
29531         if (sk2_rcv_saddr6 &&
29532 +           addr_type != IPV6_ADDR_ANY &&
29533 +           addr_type != IPV6_ADDR_ANY &&
29534             ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
29535                 return 1;
29536  
29537         if (addr_type == IPV6_ADDR_MAPPED &&
29538             !sk2_ipv6only &&
29539 -           (!sk2_rcv_saddr || !sk_rcv_saddr || sk_rcv_saddr == sk2_rcv_saddr))
29540 +           ipv4_rcv_saddr_equal(sk, sk2))
29541                 return 1;
29542  
29543         return 0;
29544 @@ -2788,7 +2806,10 @@ static void if6_seq_stop(struct seq_file
29545  static int if6_seq_show(struct seq_file *seq, void *v)
29546  {
29547         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
29548 -       seq_printf(seq,
29549 +
29550 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
29551 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
29552 +               seq_printf(seq,
29553                    NIP6_SEQFMT " %02x %02x %02x %02x %8s\n",
29554                    NIP6(ifp->addr),
29555                    ifp->idev->dev->ifindex,
29556 @@ -3270,6 +3291,11 @@ static int inet6_dump_addr(struct sk_buf
29557         struct inet6_ifaddr *ifa;
29558         struct ifmcaddr6 *ifmca;
29559         struct ifacaddr6 *ifaca;
29560 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
29561 +
29562 +       /* disable ipv6 on non v6 guests */
29563 +       if (nxi && !nx_info_has_v6(nxi))
29564 +               return skb->len;
29565  
29566         s_idx = cb->args[0];
29567         s_ip_idx = ip_idx = cb->args[1];
29568 @@ -3291,6 +3317,8 @@ static int inet6_dump_addr(struct sk_buf
29569                              ifa = ifa->if_next, ip_idx++) {
29570                                 if (ip_idx < s_ip_idx)
29571                                         continue;
29572 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
29573 +                                       continue;
29574                                 if ((err = inet6_fill_ifaddr(skb, ifa,
29575                                     NETLINK_CB(cb->skb).pid,
29576                                     cb->nlh->nlmsg_seq, RTM_NEWADDR,
29577 @@ -3304,6 +3332,8 @@ static int inet6_dump_addr(struct sk_buf
29578                              ifmca = ifmca->next, ip_idx++) {
29579                                 if (ip_idx < s_ip_idx)
29580                                         continue;
29581 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
29582 +                                       continue;
29583                                 if ((err = inet6_fill_ifmcaddr(skb, ifmca,
29584                                     NETLINK_CB(cb->skb).pid,
29585                                     cb->nlh->nlmsg_seq, RTM_GETMULTICAST,
29586 @@ -3317,6 +3347,8 @@ static int inet6_dump_addr(struct sk_buf
29587                              ifaca = ifaca->aca_next, ip_idx++) {
29588                                 if (ip_idx < s_ip_idx)
29589                                         continue;
29590 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
29591 +                                       continue;
29592                                 if ((err = inet6_fill_ifacaddr(skb, ifaca,
29593                                     NETLINK_CB(cb->skb).pid,
29594                                     cb->nlh->nlmsg_seq, RTM_GETANYCAST,
29595 @@ -3593,12 +3625,19 @@ static int inet6_dump_ifinfo(struct sk_b
29596         int s_idx = cb->args[0];
29597         struct net_device *dev;
29598         struct inet6_dev *idev;
29599 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
29600 +
29601 +       /* FIXME: maybe disable ipv6 on non v6 guests?
29602 +       if (skb->sk && skb->sk->sk_vx_info)
29603 +               return skb->len;        */
29604  
29605         read_lock(&dev_base_lock);
29606         idx = 0;
29607         for_each_netdev(dev) {
29608                 if (idx < s_idx)
29609                         goto cont;
29610 +               if (!v6_dev_in_nx_info(dev, nxi))
29611 +                       goto cont;
29612                 if ((idev = in6_dev_get(dev)) == NULL)
29613                         goto cont;
29614                 err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
29615 diff -Nurp linux-2.6.22.18/net/ipv6/af_inet6.c linux-2.6.22.18-vs2.3.0.32/net/ipv6/af_inet6.c
29616 --- linux-2.6.22.18/net/ipv6/af_inet6.c 2007-09-05 07:08:00.000000000 +0200
29617 +++ linux-2.6.22.18-vs2.3.0.32/net/ipv6/af_inet6.c      2008-02-11 12:35:42.000000000 +0100
29618 @@ -43,6 +43,7 @@
29619  #include <linux/netdevice.h>
29620  #include <linux/icmpv6.h>
29621  #include <linux/netfilter_ipv6.h>
29622 +#include <linux/vs_inet6.h>
29623  
29624  #include <net/ip.h>
29625  #include <net/ipv6.h>
29626 @@ -150,9 +151,12 @@ lookup_protocol:
29627         }
29628  
29629         err = -EPERM;
29630 +       if ((protocol == IPPROTO_ICMPV6) &&
29631 +               nx_capable(answer->capability, NXC_RAW_ICMP))
29632 +               goto override;
29633         if (answer->capability > 0 && !capable(answer->capability))
29634                 goto out_rcu_unlock;
29635 -
29636 +override:
29637         sock->ops = answer->ops;
29638         answer_prot = answer->prot;
29639         answer_no_check = answer->no_check;
29640 @@ -250,6 +254,7 @@ int inet6_bind(struct socket *sock, stru
29641         struct sock *sk = sock->sk;
29642         struct inet_sock *inet = inet_sk(sk);
29643         struct ipv6_pinfo *np = inet6_sk(sk);
29644 +       struct nx_v6_sock_addr nsa;
29645         __be32 v4addr = 0;
29646         unsigned short snum;
29647         int addr_type = 0;
29648 @@ -261,6 +266,11 @@ int inet6_bind(struct socket *sock, stru
29649  
29650         if (addr_len < SIN6_LEN_RFC2133)
29651                 return -EINVAL;
29652 +
29653 +       err = v6_map_sock_addr(inet, addr, &nsa);
29654 +       if (err)
29655 +               return err;
29656 +
29657         addr_type = ipv6_addr_type(&addr->sin6_addr);
29658         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
29659                 return -EINVAL;
29660 @@ -284,6 +294,10 @@ int inet6_bind(struct socket *sock, stru
29661                         err = -EADDRNOTAVAIL;
29662                         goto out;
29663                 }
29664 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
29665 +                       err = -EADDRNOTAVAIL;
29666 +                       goto out;
29667 +               }
29668         } else {
29669                 if (addr_type != IPV6_ADDR_ANY) {
29670                         struct net_device *dev = NULL;
29671 @@ -309,6 +323,11 @@ int inet6_bind(struct socket *sock, stru
29672                                 }
29673                         }
29674  
29675 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
29676 +                               err = -EADDRNOTAVAIL;
29677 +                               goto out;
29678 +                       }
29679 +
29680                         /* ipv4 addr of the socket is invalid.  Only the
29681                          * unspecified and mapped address have a v4 equivalent.
29682                          */
29683 @@ -326,6 +345,8 @@ int inet6_bind(struct socket *sock, stru
29684                 }
29685         }
29686  
29687 +       v6_set_sock_addr(inet, &nsa);
29688 +
29689         inet->rcv_saddr = v4addr;
29690         inet->saddr = v4addr;
29691  
29692 @@ -420,9 +441,11 @@ int inet6_getname(struct socket *sock, s
29693                         return -ENOTCONN;
29694                 sin->sin6_port = inet->dport;
29695                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
29696 +               /* FIXME: remap lback? */
29697                 if (np->sndflow)
29698                         sin->sin6_flowinfo = np->flow_label;
29699         } else {
29700 +               /* FIXME: remap lback? */
29701                 if (ipv6_addr_any(&np->rcv_saddr))
29702                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
29703                 else
29704 diff -Nurp linux-2.6.22.18/net/ipv6/fib6_rules.c linux-2.6.22.18-vs2.3.0.32/net/ipv6/fib6_rules.c
29705 --- linux-2.6.22.18/net/ipv6/fib6_rules.c       2007-07-22 00:00:27.000000000 +0200
29706 +++ linux-2.6.22.18-vs2.3.0.32/net/ipv6/fib6_rules.c    2008-02-11 12:35:42.000000000 +0100
29707 @@ -107,7 +107,7 @@ static int fib6_rule_action(struct fib_r
29708                     r->src.plen && !(flags & RT6_LOOKUP_F_HAS_SADDR)) {
29709                         struct in6_addr saddr;
29710                         if (ipv6_get_saddr(&rt->u.dst, &flp->fl6_dst,
29711 -                                          &saddr))
29712 +                                          &saddr, NULL))
29713                                 goto again;
29714                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
29715                                                r->src.plen))
29716 diff -Nurp linux-2.6.22.18/net/ipv6/inet6_hashtables.c linux-2.6.22.18-vs2.3.0.32/net/ipv6/inet6_hashtables.c
29717 --- linux-2.6.22.18/net/ipv6/inet6_hashtables.c 2007-07-21 23:58:56.000000000 +0200
29718 +++ linux-2.6.22.18-vs2.3.0.32/net/ipv6/inet6_hashtables.c      2008-02-11 12:35:42.000000000 +0100
29719 @@ -16,6 +16,7 @@
29720  
29721  #include <linux/module.h>
29722  #include <linux/random.h>
29723 +#include <linux/vs_inet6.h>
29724  
29725  #include <net/inet_connection_sock.h>
29726  #include <net/inet_hashtables.h>
29727 @@ -121,6 +122,9 @@ struct sock *inet6_lookup_listener(struc
29728                                 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
29729                                         continue;
29730                                 score++;
29731 +                       } else {
29732 +                               if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
29733 +                                       continue;
29734                         }
29735                         if (sk->sk_bound_dev_if) {
29736                                 if (sk->sk_bound_dev_if != dif)
29737 diff -Nurp linux-2.6.22.18/net/ipv6/ip6_output.c linux-2.6.22.18-vs2.3.0.32/net/ipv6/ip6_output.c
29738 --- linux-2.6.22.18/net/ipv6/ip6_output.c       2007-09-29 14:11:49.000000000 +0200
29739 +++ linux-2.6.22.18-vs2.3.0.32/net/ipv6/ip6_output.c    2008-02-11 12:35:42.000000000 +0100
29740 @@ -884,7 +884,7 @@ static int ip6_dst_lookup_tail(struct so
29741                 goto out_err_release;
29742  
29743         if (ipv6_addr_any(&fl->fl6_src)) {
29744 -               err = ipv6_get_saddr(*dst, &fl->fl6_dst, &fl->fl6_src);
29745 +               err = ipv6_get_saddr(*dst, &fl->fl6_dst, &fl->fl6_src, sk->sk_nx_info);
29746                 if (err)
29747                         goto out_err_release;
29748         }
29749 diff -Nurp linux-2.6.22.18/net/ipv6/Kconfig linux-2.6.22.18-vs2.3.0.32/net/ipv6/Kconfig
29750 --- linux-2.6.22.18/net/ipv6/Kconfig    2007-07-22 00:00:27.000000000 +0200
29751 +++ linux-2.6.22.18-vs2.3.0.32/net/ipv6/Kconfig 2008-02-11 12:35:42.000000000 +0100
29752 @@ -4,8 +4,8 @@
29753  
29754  #   IPv6 as module will cause a CRASH if you try to unload it
29755  config IPV6
29756 -       tristate "The IPv6 protocol"
29757 -       default m
29758 +       bool "The IPv6 protocol"
29759 +       default n
29760         ---help---
29761           This is complemental support for the IP version 6.
29762           You will still be able to do traditional IPv4 networking as well.
29763 diff -Nurp linux-2.6.22.18/net/ipv6/ndisc.c linux-2.6.22.18-vs2.3.0.32/net/ipv6/ndisc.c
29764 --- linux-2.6.22.18/net/ipv6/ndisc.c    2007-12-09 12:43:41.000000000 +0100
29765 +++ linux-2.6.22.18-vs2.3.0.32/net/ipv6/ndisc.c 2008-02-11 12:35:42.000000000 +0100
29766 @@ -531,7 +531,7 @@ static void ndisc_send_na(struct net_dev
29767                         override = 0;
29768                 in6_ifa_put(ifp);
29769         } else {
29770 -               if (ipv6_dev_get_saddr(dev, daddr, &tmpaddr))
29771 +               if (ipv6_dev_get_saddr(dev, daddr, &tmpaddr, NULL))
29772                         return;
29773                 src_addr = &tmpaddr;
29774         }
29775 diff -Nurp linux-2.6.22.18/net/ipv6/route.c linux-2.6.22.18-vs2.3.0.32/net/ipv6/route.c
29776 --- linux-2.6.22.18/net/ipv6/route.c    2007-07-22 00:00:27.000000000 +0200
29777 +++ linux-2.6.22.18-vs2.3.0.32/net/ipv6/route.c 2008-02-11 12:35:42.000000000 +0100
29778 @@ -2182,7 +2182,7 @@ static int rt6_fill_node(struct sk_buff 
29779                 NLA_PUT_U32(skb, RTA_IIF, iif);
29780         else if (dst) {
29781                 struct in6_addr saddr_buf;
29782 -               if (ipv6_get_saddr(&rt->u.dst, dst, &saddr_buf) == 0)
29783 +               if (ipv6_get_saddr(&rt->u.dst, dst, &saddr_buf, (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
29784                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
29785         }
29786  
29787 diff -Nurp linux-2.6.22.18/net/ipv6/tcp_ipv6.c linux-2.6.22.18-vs2.3.0.32/net/ipv6/tcp_ipv6.c
29788 --- linux-2.6.22.18/net/ipv6/tcp_ipv6.c 2007-12-09 12:43:41.000000000 +0100
29789 +++ linux-2.6.22.18-vs2.3.0.32/net/ipv6/tcp_ipv6.c      2008-02-11 12:35:42.000000000 +0100
29790 @@ -68,6 +68,7 @@
29791  
29792  #include <linux/crypto.h>
29793  #include <linux/scatterlist.h>
29794 +#include <linux/vs_inet6.h>
29795  
29796  /* Socket used for sending RSTs and ACKs */
29797  static struct socket *tcp6_socket;
29798 @@ -160,8 +161,15 @@ static int tcp_v6_connect(struct sock *s
29799          *      connect() to INADDR_ANY means loopback (BSD'ism).
29800          */
29801  
29802 -       if(ipv6_addr_any(&usin->sin6_addr))
29803 -               usin->sin6_addr.s6_addr[15] = 0x1;
29804 +       if(ipv6_addr_any(&usin->sin6_addr)) {
29805 +               struct nx_info *nxi =  sk->sk_nx_info;
29806 +
29807 +               if (nxi && nx_info_has_v6(nxi))
29808 +                       /* FIXME: remap lback? */
29809 +                       usin->sin6_addr = nxi->v6.ip;
29810 +               else
29811 +                       usin->sin6_addr.s6_addr[15] = 0x1;
29812 +       }
29813  
29814         addr_type = ipv6_addr_type(&usin->sin6_addr);
29815  
29816 diff -Nurp linux-2.6.22.18/net/ipv6/udp.c linux-2.6.22.18-vs2.3.0.32/net/ipv6/udp.c
29817 --- linux-2.6.22.18/net/ipv6/udp.c      2007-07-22 00:00:27.000000000 +0200
29818 +++ linux-2.6.22.18-vs2.3.0.32/net/ipv6/udp.c   2008-02-11 12:35:42.000000000 +0100
29819 @@ -48,6 +48,7 @@
29820  
29821  #include <linux/proc_fs.h>
29822  #include <linux/seq_file.h>
29823 +#include <linux/vs_inet6.h>
29824  #include "udp_impl.h"
29825  
29826  DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6) __read_mostly;
29827 @@ -82,6 +83,10 @@ static struct sock *__udp6_lib_lookup(st
29828                                 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
29829                                         continue;
29830                                 score++;
29831 +                       } else {
29832 +                               /* block non nx_info ips */
29833 +                               if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
29834 +                                       continue;
29835                         }
29836                         if (!ipv6_addr_any(&np->daddr)) {
29837                                 if (!ipv6_addr_equal(&np->daddr, saddr))
29838 diff -Nurp linux-2.6.22.18/net/ipv6/xfrm6_policy.c linux-2.6.22.18-vs2.3.0.32/net/ipv6/xfrm6_policy.c
29839 --- linux-2.6.22.18/net/ipv6/xfrm6_policy.c     2007-07-22 00:00:27.000000000 +0200
29840 +++ linux-2.6.22.18-vs2.3.0.32/net/ipv6/xfrm6_policy.c  2008-02-11 12:35:42.000000000 +0100
29841 @@ -49,7 +49,7 @@ static int xfrm6_get_saddr(xfrm_address_
29842  
29843         if (!xfrm6_dst_lookup((struct xfrm_dst **)&rt, &fl_tunnel)) {
29844                 ipv6_get_saddr(&rt->u.dst, (struct in6_addr *)&daddr->a6,
29845 -                              (struct in6_addr *)&saddr->a6);
29846 +                              (struct in6_addr *)&saddr->a6, NULL);
29847                 dst_release(&rt->u.dst);
29848                 return 0;
29849         }
29850 diff -Nurp linux-2.6.22.18/net/netlink/af_netlink.c linux-2.6.22.18-vs2.3.0.32/net/netlink/af_netlink.c
29851 --- linux-2.6.22.18/net/netlink/af_netlink.c    2007-12-09 12:43:53.000000000 +0100
29852 +++ linux-2.6.22.18-vs2.3.0.32/net/netlink/af_netlink.c 2008-02-11 12:35:42.000000000 +0100
29853 @@ -56,6 +56,9 @@
29854  #include <linux/audit.h>
29855  #include <linux/selinux.h>
29856  #include <linux/mutex.h>
29857 +#include <linux/vs_context.h>
29858 +#include <linux/vs_network.h>
29859 +#include <linux/vs_limit.h>
29860  
29861  #include <net/sock.h>
29862  #include <net/scm.h>
29863 @@ -885,6 +888,10 @@ static inline int do_one_broadcast(struc
29864             !test_bit(p->group - 1, nlk->groups))
29865                 goto out;
29866  
29867 +       if (sk->sk_nx_info &&
29868 +           (p->group == RTNLGRP_IPV4_IFADDR || p->group == RTNLGRP_IPV6_IFADDR))
29869 +               goto out;
29870 +
29871         if (p->failure) {
29872                 netlink_overrun(sk);
29873                 goto out;
29874 diff -Nurp linux-2.6.22.18/net/rxrpc/Kconfig linux-2.6.22.18-vs2.3.0.32/net/rxrpc/Kconfig
29875 --- linux-2.6.22.18/net/rxrpc/Kconfig   2008-01-15 16:00:36.000000000 +0100
29876 +++ linux-2.6.22.18-vs2.3.0.32/net/rxrpc/Kconfig        2008-02-11 12:35:42.000000000 +0100
29877 @@ -4,7 +4,7 @@
29878  
29879  config AF_RXRPC
29880         tristate "RxRPC session sockets"
29881 -       depends on INET && EXPERIMENTAL
29882 +       depends on INET && EXPERIMENTAL && !VSERVER_SECURITY
29883         select CRYPTO
29884         select KEYS
29885         help
29886 diff -Nurp linux-2.6.22.18/net/sctp/ipv6.c linux-2.6.22.18-vs2.3.0.32/net/sctp/ipv6.c
29887 --- linux-2.6.22.18/net/sctp/ipv6.c     2007-08-12 03:54:37.000000000 +0200
29888 +++ linux-2.6.22.18-vs2.3.0.32/net/sctp/ipv6.c  2008-02-11 12:35:43.000000000 +0100
29889 @@ -303,7 +303,7 @@ static void sctp_v6_get_saddr(struct sct
29890                           __FUNCTION__, asoc, dst, NIP6(daddr->v6.sin6_addr));
29891  
29892         if (!asoc) {
29893 -               ipv6_get_saddr(dst, &daddr->v6.sin6_addr,&saddr->v6.sin6_addr);
29894 +               ipv6_get_saddr(dst, &daddr->v6.sin6_addr,&saddr->v6.sin6_addr, asoc->base.sk->sk_nx_info);
29895                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: " NIP6_FMT "\n",
29896                                   NIP6(saddr->v6.sin6_addr));
29897                 return;
29898 diff -Nurp linux-2.6.22.18/net/socket.c linux-2.6.22.18-vs2.3.0.32/net/socket.c
29899 --- linux-2.6.22.18/net/socket.c        2007-12-09 12:43:53.000000000 +0100
29900 +++ linux-2.6.22.18-vs2.3.0.32/net/socket.c     2008-02-11 12:35:43.000000000 +0100
29901 @@ -92,6 +92,10 @@
29902  
29903  #include <net/sock.h>
29904  #include <linux/netfilter.h>
29905 +#include <linux/vs_base.h>
29906 +#include <linux/vs_socket.h>
29907 +#include <linux/vs_inet.h>
29908 +#include <linux/vs_inet6.h>
29909  
29910  static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
29911  static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
29912 @@ -543,7 +547,7 @@ static inline int __sock_sendmsg(struct 
29913                                  struct msghdr *msg, size_t size)
29914  {
29915         struct sock_iocb *si = kiocb_to_siocb(iocb);
29916 -       int err;
29917 +       int err, len;
29918  
29919         si->sock = sock;
29920         si->scm = NULL;
29921 @@ -554,7 +558,22 @@ static inline int __sock_sendmsg(struct 
29922         if (err)
29923                 return err;
29924  
29925 -       return sock->ops->sendmsg(iocb, sock, msg, size);
29926 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
29927 +       if (sock->sk) {
29928 +               if (len == size)
29929 +                       vx_sock_send(sock->sk, size);
29930 +               else
29931 +                       vx_sock_fail(sock->sk, size);
29932 +       }
29933 +       vxdprintk(VXD_CBIT(net, 7),
29934 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
29935 +               sock, sock->sk,
29936 +               (sock->sk)?sock->sk->sk_nx_info:0,
29937 +               (sock->sk)?sock->sk->sk_vx_info:0,
29938 +               (sock->sk)?sock->sk->sk_xid:0,
29939 +               (sock->sk)?sock->sk->sk_nid:0,
29940 +               (unsigned int)size, len);
29941 +       return len;
29942  }
29943  
29944  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
29945 @@ -623,7 +642,7 @@ EXPORT_SYMBOL_GPL(__sock_recv_timestamp)
29946  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
29947                                  struct msghdr *msg, size_t size, int flags)
29948  {
29949 -       int err;
29950 +       int err, len;
29951         struct sock_iocb *si = kiocb_to_siocb(iocb);
29952  
29953         si->sock = sock;
29954 @@ -636,7 +655,18 @@ static inline int __sock_recvmsg(struct 
29955         if (err)
29956                 return err;
29957  
29958 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
29959 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
29960 +       if ((len >= 0) && sock->sk)
29961 +               vx_sock_recv(sock->sk, len);
29962 +       vxdprintk(VXD_CBIT(net, 7),
29963 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
29964 +               sock, sock->sk,
29965 +               (sock->sk)?sock->sk->sk_nx_info:0,
29966 +               (sock->sk)?sock->sk->sk_vx_info:0,
29967 +               (sock->sk)?sock->sk->sk_xid:0,
29968 +               (sock->sk)?sock->sk->sk_nid:0,
29969 +               (unsigned int)size, len);
29970 +       return len;
29971  }
29972  
29973  int sock_recvmsg(struct socket *sock, struct msghdr *msg,
29974 @@ -1087,6 +1117,13 @@ static int __sock_create(int family, int
29975         if (type < 0 || type >= SOCK_MAX)
29976                 return -EINVAL;
29977  
29978 +       if (!nx_check(0, VS_ADMIN)) {
29979 +               if (family == PF_INET && !current_nx_info_has_v4())
29980 +                       return -EAFNOSUPPORT;
29981 +               if (family == PF_INET6 && !current_nx_info_has_v6())
29982 +                       return -EAFNOSUPPORT;
29983 +       }
29984 +
29985         /* Compatibility.
29986  
29987            This uglymoron is moved from INET layer to here to avoid
29988 @@ -1204,6 +1241,7 @@ asmlinkage long sys_socket(int family, i
29989         if (retval < 0)
29990                 goto out;
29991  
29992 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
29993         retval = sock_map_fd(sock);
29994         if (retval < 0)
29995                 goto out_release;
29996 @@ -1236,10 +1274,12 @@ asmlinkage long sys_socketpair(int famil
29997         err = sock_create(family, type, protocol, &sock1);
29998         if (err < 0)
29999                 goto out;
30000 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
30001  
30002         err = sock_create(family, type, protocol, &sock2);
30003         if (err < 0)
30004                 goto out_release_1;
30005 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
30006  
30007         err = sock1->ops->socketpair(sock1, sock2);
30008         if (err < 0)
30009 diff -Nurp linux-2.6.22.18/net/sunrpc/auth.c linux-2.6.22.18-vs2.3.0.32/net/sunrpc/auth.c
30010 --- linux-2.6.22.18/net/sunrpc/auth.c   2007-07-21 23:59:04.000000000 +0200
30011 +++ linux-2.6.22.18-vs2.3.0.32/net/sunrpc/auth.c        2008-02-11 12:35:43.000000000 +0100
30012 @@ -13,6 +13,7 @@
30013  #include <linux/errno.h>
30014  #include <linux/sunrpc/clnt.h>
30015  #include <linux/spinlock.h>
30016 +#include <linux/vs_tag.h>
30017  
30018  #ifdef RPC_DEBUG
30019  # define RPCDBG_FACILITY       RPCDBG_AUTH
30020 @@ -263,6 +264,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
30021         struct auth_cred acred = {
30022                 .uid = current->fsuid,
30023                 .gid = current->fsgid,
30024 +               .tag = dx_current_tag(),
30025                 .group_info = current->group_info,
30026         };
30027         struct rpc_cred *ret;
30028 @@ -282,6 +284,7 @@ rpcauth_bindcred(struct rpc_task *task)
30029         struct auth_cred acred = {
30030                 .uid = current->fsuid,
30031                 .gid = current->fsgid,
30032 +               .tag = dx_current_tag(),
30033                 .group_info = current->group_info,
30034         };
30035         struct rpc_cred *ret;
30036 diff -Nurp linux-2.6.22.18/net/sunrpc/auth_unix.c linux-2.6.22.18-vs2.3.0.32/net/sunrpc/auth_unix.c
30037 --- linux-2.6.22.18/net/sunrpc/auth_unix.c      2007-07-21 23:59:04.000000000 +0200
30038 +++ linux-2.6.22.18-vs2.3.0.32/net/sunrpc/auth_unix.c   2008-02-11 12:35:43.000000000 +0100
30039 @@ -11,12 +11,14 @@
30040  #include <linux/module.h>
30041  #include <linux/sunrpc/clnt.h>
30042  #include <linux/sunrpc/auth.h>
30043 +#include <linux/vs_tag.h>
30044  
30045  #define NFS_NGROUPS    16
30046  
30047  struct unx_cred {
30048         struct rpc_cred         uc_base;
30049         gid_t                   uc_gid;
30050 +       tag_t                   uc_tag;
30051         gid_t                   uc_gids[NFS_NGROUPS];
30052  };
30053  #define uc_uid                 uc_base.cr_uid
30054 @@ -79,6 +81,7 @@ unx_create_cred(struct rpc_auth *auth, s
30055         if (flags & RPCAUTH_LOOKUP_ROOTCREDS) {
30056                 cred->uc_uid = 0;
30057                 cred->uc_gid = 0;
30058 +               cred->uc_tag = dx_current_tag();
30059                 cred->uc_gids[0] = NOGROUP;
30060         } else {
30061                 int groups = acred->group_info->ngroups;
30062 @@ -87,6 +90,7 @@ unx_create_cred(struct rpc_auth *auth, s
30063  
30064                 cred->uc_uid = acred->uid;
30065                 cred->uc_gid = acred->gid;
30066 +               cred->uc_tag = acred->tag;
30067                 for (i = 0; i < groups; i++)
30068                         cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
30069                 if (i < NFS_NGROUPS)
30070 @@ -118,7 +122,8 @@ unx_match(struct auth_cred *acred, struc
30071                 int groups;
30072  
30073                 if (cred->uc_uid != acred->uid
30074 -                || cred->uc_gid != acred->gid)
30075 +                || cred->uc_gid != acred->gid
30076 +                || cred->uc_tag != acred->tag)
30077                         return 0;
30078  
30079                 groups = acred->group_info->ngroups;
30080 @@ -144,7 +149,7 @@ unx_marshal(struct rpc_task *task, __be3
30081         struct rpc_clnt *clnt = task->tk_client;
30082         struct unx_cred *cred = (struct unx_cred *) task->tk_msg.rpc_cred;
30083         __be32          *base, *hold;
30084 -       int             i;
30085 +       int             i, tag;
30086  
30087         *p++ = htonl(RPC_AUTH_UNIX);
30088         base = p++;
30089 @@ -154,9 +159,12 @@ unx_marshal(struct rpc_task *task, __be3
30090          * Copy the UTS nodename captured when the client was created.
30091          */
30092         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
30093 +       tag = task->tk_client->cl_tag;
30094  
30095 -       *p++ = htonl((u32) cred->uc_uid);
30096 -       *p++ = htonl((u32) cred->uc_gid);
30097 +       *p++ = htonl((u32) TAGINO_UID(tag,
30098 +               cred->uc_uid, cred->uc_tag));
30099 +       *p++ = htonl((u32) TAGINO_GID(tag,
30100 +               cred->uc_gid, cred->uc_tag));
30101         hold = p++;
30102         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
30103                 *p++ = htonl((u32) cred->uc_gids[i]);
30104 diff -Nurp linux-2.6.22.18/net/sunrpc/clnt.c linux-2.6.22.18-vs2.3.0.32/net/sunrpc/clnt.c
30105 --- linux-2.6.22.18/net/sunrpc/clnt.c   2007-07-22 00:00:28.000000000 +0200
30106 +++ linux-2.6.22.18-vs2.3.0.32/net/sunrpc/clnt.c        2008-02-11 12:35:43.000000000 +0100
30107 @@ -30,6 +30,7 @@
30108  #include <linux/smp_lock.h>
30109  #include <linux/utsname.h>
30110  #include <linux/workqueue.h>
30111 +#include <linux/vs_cvirt.h>
30112  
30113  #include <linux/sunrpc/clnt.h>
30114  #include <linux/sunrpc/rpc_pipe_fs.h>
30115 @@ -249,7 +250,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
30116                 clnt->cl_oneshot = 1;
30117         if (args->flags & RPC_CLNT_CREATE_DISCRTRY)
30118                 clnt->cl_discrtry = 1;
30119 -
30120 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
30121 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
30122 +               clnt->cl_tag = 1; */
30123         return clnt;
30124  }
30125  EXPORT_SYMBOL_GPL(rpc_create);
30126 diff -Nurp linux-2.6.22.18/net/unix/af_unix.c linux-2.6.22.18-vs2.3.0.32/net/unix/af_unix.c
30127 --- linux-2.6.22.18/net/unix/af_unix.c  2008-01-15 16:00:36.000000000 +0100
30128 +++ linux-2.6.22.18-vs2.3.0.32/net/unix/af_unix.c       2008-02-11 12:35:43.000000000 +0100
30129 @@ -115,6 +115,8 @@
30130  #include <linux/mount.h>
30131  #include <net/checksum.h>
30132  #include <linux/security.h>
30133 +#include <linux/vs_context.h>
30134 +#include <linux/vs_limit.h>
30135  
30136  int sysctl_unix_max_dgram_qlen __read_mostly = 10;
30137  
30138 @@ -252,6 +254,8 @@ static struct sock *__unix_find_socket_b
30139         sk_for_each(s, node, &unix_socket_table[hash ^ type]) {
30140                 struct unix_sock *u = unix_sk(s);
30141  
30142 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
30143 +                       continue;
30144                 if (u->addr->len == len &&
30145                     !memcmp(u->addr->name, sunname, len))
30146                         goto found;
30147 @@ -807,7 +811,7 @@ static int unix_bind(struct socket *sock
30148                  */
30149                 mode = S_IFSOCK |
30150                        (SOCK_INODE(sock)->i_mode & ~current->fs->umask);
30151 -               err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);
30152 +               err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0, NULL);
30153                 if (err)
30154                         goto out_mknod_dput;
30155                 mutex_unlock(&nd.dentry->d_inode->i_mutex);
30156 diff -Nurp linux-2.6.22.18/net/x25/af_x25.c linux-2.6.22.18-vs2.3.0.32/net/x25/af_x25.c
30157 --- linux-2.6.22.18/net/x25/af_x25.c    2007-07-22 00:00:28.000000000 +0200
30158 +++ linux-2.6.22.18-vs2.3.0.32/net/x25/af_x25.c 2008-02-11 12:35:43.000000000 +0100
30159 @@ -500,7 +500,10 @@ static int x25_create(struct socket *soc
30160  
30161         x25 = x25_sk(sk);
30162  
30163 -       sock_init_data(sock, sk);
30164 +       sk->sk_socket = sock;
30165 +       sk->sk_type = sock->type;
30166 +       sk->sk_sleep = &sock->wait;
30167 +       sock->sk = sk;
30168  
30169         x25_init_timers(sk);
30170  
30171 diff -Nurp linux-2.6.22.18/security/commoncap.c linux-2.6.22.18-vs2.3.0.32/security/commoncap.c
30172 --- linux-2.6.22.18/security/commoncap.c        2007-07-22 00:00:28.000000000 +0200
30173 +++ linux-2.6.22.18-vs2.3.0.32/security/commoncap.c     2008-02-11 12:35:43.000000000 +0100
30174 @@ -22,10 +22,11 @@
30175  #include <linux/ptrace.h>
30176  #include <linux/xattr.h>
30177  #include <linux/hugetlb.h>
30178 +#include <linux/vs_context.h>
30179  
30180  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
30181  {
30182 -       NETLINK_CB(skb).eff_cap = current->cap_effective;
30183 +       cap_t(NETLINK_CB(skb).eff_cap) = vx_mbcap(cap_effective);
30184         return 0;
30185  }
30186  
30187 @@ -43,7 +44,7 @@ EXPORT_SYMBOL(cap_netlink_recv);
30188  int cap_capable (struct task_struct *tsk, int cap)
30189  {
30190         /* Derived from include/linux/sched.h:capable. */
30191 -       if (cap_raised(tsk->cap_effective, cap))
30192 +       if (vx_cap_raised(tsk->vx_info, tsk->cap_effective, cap))
30193                 return 0;
30194         return -EPERM;
30195  }
30196 @@ -141,7 +142,8 @@ void cap_bprm_apply_creds (struct linux_
30197         /* Derived from fs/exec.c:compute_creds. */
30198         kernel_cap_t new_permitted, working;
30199  
30200 -       new_permitted = cap_intersect (bprm->cap_permitted, cap_bset);
30201 +       new_permitted = cap_intersect (bprm->cap_permitted,
30202 +                                       vx_current_cap_bset());
30203         working = cap_intersect (bprm->cap_inheritable,
30204                                  current->cap_inheritable);
30205         new_permitted = cap_combine (new_permitted, working);
30206 @@ -310,7 +312,8 @@ void cap_task_reparent_to_init (struct t
30207  
30208  int cap_syslog (int type)
30209  {
30210 -       if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
30211 +       if ((type != 3 && type != 10) &&
30212 +               !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
30213                 return -EPERM;
30214         return 0;
30215  }
30216 diff -Nurp linux-2.6.22.18/security/dummy.c linux-2.6.22.18-vs2.3.0.32/security/dummy.c
30217 --- linux-2.6.22.18/security/dummy.c    2007-07-21 23:59:05.000000000 +0200
30218 +++ linux-2.6.22.18-vs2.3.0.32/security/dummy.c 2008-02-11 12:35:43.000000000 +0100
30219 @@ -28,6 +28,7 @@
30220  #include <linux/hugetlb.h>
30221  #include <linux/ptrace.h>
30222  #include <linux/file.h>
30223 +#include <linux/vs_context.h>
30224  
30225  static int dummy_ptrace (struct task_struct *parent, struct task_struct *child)
30226  {
30227 @@ -678,7 +679,7 @@ static int dummy_sem_semop (struct sem_a
30228  
30229  static int dummy_netlink_send (struct sock *sk, struct sk_buff *skb)
30230  {
30231 -       NETLINK_CB(skb).eff_cap = current->cap_effective;
30232 +       cap_t(NETLINK_CB(skb).eff_cap) = vx_mbcap(cap_effective);
30233         return 0;
30234  }
30235  
30236 diff -Nurp linux-2.6.22.18/security/Kconfig linux-2.6.22.18-vs2.3.0.32/security/Kconfig
30237 --- linux-2.6.22.18/security/Kconfig    2007-05-04 15:57:46.000000000 +0200
30238 +++ linux-2.6.22.18-vs2.3.0.32/security/Kconfig 2008-02-11 12:35:43.000000000 +0100
30239 @@ -6,6 +6,7 @@ menu "Security options"
30240  
30241  config KEYS
30242         bool "Enable access key retention support"
30243 +       depends on !VSERVER_SECURITY
30244         help
30245           This option provides support for retaining authentication tokens and
30246           access keys in the kernel.
30247 diff -Nurp linux-2.6.22.18/security/selinux/hooks.c linux-2.6.22.18-vs2.3.0.32/security/selinux/hooks.c
30248 --- linux-2.6.22.18/security/selinux/hooks.c    2007-10-30 02:18:04.000000000 +0100
30249 +++ linux-2.6.22.18-vs2.3.0.32/security/selinux/hooks.c 2008-02-11 12:35:43.000000000 +0100
30250 @@ -60,7 +60,6 @@
30251  #include <linux/dccp.h>
30252  #include <linux/quota.h>
30253  #include <linux/un.h>          /* for Unix socket types */
30254 -#include <net/af_unix.h>       /* for Unix socket types */
30255  #include <linux/parser.h>
30256  #include <linux/nfs_mount.h>
30257  #include <net/ipv6.h>