]> git.pld-linux.org Git - packages/kernel.git/blob - linux-2.6-vs2.3.patch
- 19
[packages/kernel.git] / linux-2.6-vs2.3.patch
1 diff -Nurp linux-2.6.22.15/arch/alpha/Kconfig linux-2.6.22.15-vs2.3.0.29.1/arch/alpha/Kconfig
2 --- linux-2.6.22.15/arch/alpha/Kconfig  2007-07-21 17:59:44.000000000 -0400
3 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/alpha/Kconfig     2007-12-09 06:44:17.000000000 -0500
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.15/arch/alpha/kernel/asm-offsets.c linux-2.6.22.15-vs2.3.0.29.1/arch/alpha/kernel/asm-offsets.c
14 --- linux-2.6.22.15/arch/alpha/kernel/asm-offsets.c     2006-06-17 21:49:35.000000000 -0400
15 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/alpha/kernel/asm-offsets.c        2007-12-09 06:44:17.000000000 -0500
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.15/arch/alpha/kernel/entry.S linux-2.6.22.15-vs2.3.0.29.1/arch/alpha/kernel/entry.S
25 --- linux-2.6.22.15/arch/alpha/kernel/entry.S   2007-07-21 17:59:44.000000000 -0400
26 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/alpha/kernel/entry.S      2007-12-09 06:44:17.000000000 -0500
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.15/arch/alpha/kernel/osf_sys.c linux-2.6.22.15-vs2.3.0.29.1/arch/alpha/kernel/osf_sys.c
69 --- linux-2.6.22.15/arch/alpha/kernel/osf_sys.c 2007-07-21 17:59:44.000000000 -0400
70 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/alpha/kernel/osf_sys.c    2007-12-09 06:44:17.000000000 -0500
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.15/arch/alpha/kernel/ptrace.c linux-2.6.22.15-vs2.3.0.29.1/arch/alpha/kernel/ptrace.c
81 --- linux-2.6.22.15/arch/alpha/kernel/ptrace.c  2006-06-17 21:49:35.000000000 -0400
82 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/alpha/kernel/ptrace.c     2007-12-09 06:44:17.000000000 -0500
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.15/arch/alpha/kernel/semaphore.c linux-2.6.22.15-vs2.3.0.29.1/arch/alpha/kernel/semaphore.c
104 --- linux-2.6.22.15/arch/alpha/kernel/semaphore.c       2006-06-17 21:49:35.000000000 -0400
105 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/alpha/kernel/semaphore.c  2007-12-09 06:44:17.000000000 -0500
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.15/arch/alpha/kernel/systbls.S linux-2.6.22.15-vs2.3.0.29.1/arch/alpha/kernel/systbls.S
140 --- linux-2.6.22.15/arch/alpha/kernel/systbls.S 2007-07-21 17:59:44.000000000 -0400
141 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/alpha/kernel/systbls.S    2007-12-09 06:44:17.000000000 -0500
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.15/arch/alpha/kernel/traps.c linux-2.6.22.15-vs2.3.0.29.1/arch/alpha/kernel/traps.c
152 --- linux-2.6.22.15/arch/alpha/kernel/traps.c   2007-05-04 09:55:03.000000000 -0400
153 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/alpha/kernel/traps.c      2007-12-09 06:44:17.000000000 -0500
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.15/arch/alpha/mm/fault.c linux-2.6.22.15-vs2.3.0.29.1/arch/alpha/mm/fault.c
165 --- linux-2.6.22.15/arch/alpha/mm/fault.c       2007-07-21 17:59:44.000000000 -0400
166 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/alpha/mm/fault.c  2007-12-09 06:44:17.000000000 -0500
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.15/arch/arm/Kconfig linux-2.6.22.15-vs2.3.0.29.1/arch/arm/Kconfig
179 --- linux-2.6.22.15/arch/arm/Kconfig    2007-07-21 17:59:44.000000000 -0400
180 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/arm/Kconfig       2007-12-09 06:44:17.000000000 -0500
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.15/arch/arm/kernel/calls.S linux-2.6.22.15-vs2.3.0.29.1/arch/arm/kernel/calls.S
191 --- linux-2.6.22.15/arch/arm/kernel/calls.S     2007-07-21 17:59:44.000000000 -0400
192 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/arm/kernel/calls.S        2007-12-09 06:44:17.000000000 -0500
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.15/arch/arm/kernel/process.c linux-2.6.22.15-vs2.3.0.29.1/arch/arm/kernel/process.c
203 --- linux-2.6.22.15/arch/arm/kernel/process.c   2007-07-21 17:59:44.000000000 -0400
204 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/arm/kernel/process.c      2007-12-09 06:44:17.000000000 -0500
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.15/arch/arm/kernel/traps.c linux-2.6.22.15-vs2.3.0.29.1/arch/arm/kernel/traps.c
226 --- linux-2.6.22.15/arch/arm/kernel/traps.c     2007-07-21 17:59:44.000000000 -0400
227 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/arm/kernel/traps.c        2007-12-09 06:44:17.000000000 -0500
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.15/arch/arm/mm/fault.c linux-2.6.22.15-vs2.3.0.29.1/arch/arm/mm/fault.c
240 --- linux-2.6.22.15/arch/arm/mm/fault.c 2007-07-21 17:59:44.000000000 -0400
241 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/arm/mm/fault.c    2007-12-09 06:44:17.000000000 -0500
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.15/arch/arm26/Kconfig linux-2.6.22.15-vs2.3.0.29.1/arch/arm26/Kconfig
253 --- linux-2.6.22.15/arch/arm26/Kconfig  2007-07-21 17:59:44.000000000 -0400
254 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/arm26/Kconfig     2007-12-09 06:44:17.000000000 -0500
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.15/arch/arm26/kernel/calls.S linux-2.6.22.15-vs2.3.0.29.1/arch/arm26/kernel/calls.S
265 --- linux-2.6.22.15/arch/arm26/kernel/calls.S   2006-06-17 21:49:35.000000000 -0400
266 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/arm26/kernel/calls.S      2007-12-09 06:44:17.000000000 -0500
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.15/arch/arm26/kernel/process.c linux-2.6.22.15-vs2.3.0.29.1/arch/arm26/kernel/process.c
280 --- linux-2.6.22.15/arch/arm26/kernel/process.c 2007-05-04 09:55:07.000000000 -0400
281 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/arm26/kernel/process.c    2007-12-09 06:44:17.000000000 -0500
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.15/arch/arm26/kernel/traps.c linux-2.6.22.15-vs2.3.0.29.1/arch/arm26/kernel/traps.c
293 --- linux-2.6.22.15/arch/arm26/kernel/traps.c   2007-05-04 09:55:07.000000000 -0400
294 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/arm26/kernel/traps.c      2007-12-09 06:44:17.000000000 -0500
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.15/arch/cris/arch-v10/kernel/process.c linux-2.6.22.15-vs2.3.0.29.1/arch/cris/arch-v10/kernel/process.c
308 --- linux-2.6.22.15/arch/cris/arch-v10/kernel/process.c 2007-05-04 09:55:07.000000000 -0400
309 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/cris/arch-v10/kernel/process.c    2007-12-09 06:44:17.000000000 -0500
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.15/arch/cris/arch-v32/kernel/process.c linux-2.6.22.15-vs2.3.0.29.1/arch/cris/arch-v32/kernel/process.c
321 --- linux-2.6.22.15/arch/cris/arch-v32/kernel/process.c 2007-05-04 09:55:07.000000000 -0400
322 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/cris/arch-v32/kernel/process.c    2007-12-09 06:44:17.000000000 -0500
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.15/arch/cris/Kconfig linux-2.6.22.15-vs2.3.0.29.1/arch/cris/Kconfig
334 --- linux-2.6.22.15/arch/cris/Kconfig   2007-07-21 17:58:14.000000000 -0400
335 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/cris/Kconfig      2007-12-09 06:44:17.000000000 -0500
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.15/arch/frv/kernel/kernel_thread.S linux-2.6.22.15-vs2.3.0.29.1/arch/frv/kernel/kernel_thread.S
346 --- linux-2.6.22.15/arch/frv/kernel/kernel_thread.S     2006-06-17 21:49:35.000000000 -0400
347 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/frv/kernel/kernel_thread.S        2007-12-09 06:44:17.000000000 -0500
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.15/arch/h8300/Kconfig linux-2.6.22.15-vs2.3.0.29.1/arch/h8300/Kconfig
367 --- linux-2.6.22.15/arch/h8300/Kconfig  2007-07-21 17:59:44.000000000 -0400
368 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/h8300/Kconfig     2007-12-09 06:44:17.000000000 -0500
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.15/arch/h8300/kernel/process.c linux-2.6.22.15-vs2.3.0.29.1/arch/h8300/kernel/process.c
379 --- linux-2.6.22.15/arch/h8300/kernel/process.c 2007-05-04 09:55:07.000000000 -0400
380 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/h8300/kernel/process.c    2007-12-09 06:44:17.000000000 -0500
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.15/arch/i386/Kconfig linux-2.6.22.15-vs2.3.0.29.1/arch/i386/Kconfig
391 --- linux-2.6.22.15/arch/i386/Kconfig   2007-07-21 17:59:44.000000000 -0400
392 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/i386/Kconfig      2007-12-09 06:44:17.000000000 -0500
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.15/arch/i386/kernel/process.c linux-2.6.22.15-vs2.3.0.29.1/arch/i386/kernel/process.c
403 --- linux-2.6.22.15/arch/i386/kernel/process.c  2007-07-21 17:59:45.000000000 -0400
404 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/i386/kernel/process.c     2007-12-09 06:44:17.000000000 -0500
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.15/arch/i386/kernel/syscall_table.S linux-2.6.22.15-vs2.3.0.29.1/arch/i386/kernel/syscall_table.S
429 --- linux-2.6.22.15/arch/i386/kernel/syscall_table.S    2007-07-21 17:59:45.000000000 -0400
430 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/i386/kernel/syscall_table.S       2007-12-09 06:44:17.000000000 -0500
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.15/arch/i386/kernel/sysenter.c linux-2.6.22.15-vs2.3.0.29.1/arch/i386/kernel/sysenter.c
441 --- linux-2.6.22.15/arch/i386/kernel/sysenter.c 2007-08-25 21:38:36.000000000 -0400
442 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/i386/kernel/sysenter.c    2007-12-09 06:44:17.000000000 -0500
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.15/arch/i386/kernel/traps.c linux-2.6.22.15-vs2.3.0.29.1/arch/i386/kernel/traps.c
452 --- linux-2.6.22.15/arch/i386/kernel/traps.c    2007-07-21 17:59:45.000000000 -0400
453 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/i386/kernel/traps.c       2007-12-09 06:44:17.000000000 -0500
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.15/arch/i386/mm/fault.c linux-2.6.22.15-vs2.3.0.29.1/arch/i386/mm/fault.c
496 --- linux-2.6.22.15/arch/i386/mm/fault.c        2007-09-05 01:07:59.000000000 -0400
497 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/i386/mm/fault.c   2007-12-09 06:44:17.000000000 -0500
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.15/arch/ia64/ia32/binfmt_elf32.c linux-2.6.22.15-vs2.3.0.29.1/arch/ia64/ia32/binfmt_elf32.c
509 --- linux-2.6.22.15/arch/ia64/ia32/binfmt_elf32.c       2007-07-21 17:58:15.000000000 -0400
510 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/ia64/ia32/binfmt_elf32.c  2007-12-09 06:44:17.000000000 -0500
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.15/arch/ia64/ia32/ia32_entry.S linux-2.6.22.15-vs2.3.0.29.1/arch/ia64/ia32/ia32_entry.S
522 --- linux-2.6.22.15/arch/ia64/ia32/ia32_entry.S 2007-07-21 17:59:45.000000000 -0400
523 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/ia64/ia32/ia32_entry.S    2007-12-09 06:44:17.000000000 -0500
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.15/arch/ia64/ia32/sys_ia32.c linux-2.6.22.15-vs2.3.0.29.1/arch/ia64/ia32/sys_ia32.c
534 --- linux-2.6.22.15/arch/ia64/ia32/sys_ia32.c   2007-07-21 17:58:15.000000000 -0400
535 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/ia64/ia32/sys_ia32.c      2007-12-09 06:44:17.000000000 -0500
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.15/arch/ia64/Kconfig linux-2.6.22.15-vs2.3.0.29.1/arch/ia64/Kconfig
546 --- linux-2.6.22.15/arch/ia64/Kconfig   2007-07-21 17:59:45.000000000 -0400
547 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/ia64/Kconfig      2007-12-09 06:44:17.000000000 -0500
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.15/arch/ia64/kernel/asm-offsets.c linux-2.6.22.15-vs2.3.0.29.1/arch/ia64/kernel/asm-offsets.c
558 --- linux-2.6.22.15/arch/ia64/kernel/asm-offsets.c      2007-07-21 17:58:15.000000000 -0400
559 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/ia64/kernel/asm-offsets.c 2007-12-09 06:44:17.000000000 -0500
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.15/arch/ia64/kernel/entry.S linux-2.6.22.15-vs2.3.0.29.1/arch/ia64/kernel/entry.S
569 --- linux-2.6.22.15/arch/ia64/kernel/entry.S    2007-07-21 17:59:45.000000000 -0400
570 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/ia64/kernel/entry.S       2007-12-09 06:44:17.000000000 -0500
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.15/arch/ia64/kernel/perfmon.c linux-2.6.22.15-vs2.3.0.29.1/arch/ia64/kernel/perfmon.c
581 --- linux-2.6.22.15/arch/ia64/kernel/perfmon.c  2007-07-21 17:59:45.000000000 -0400
582 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/ia64/kernel/perfmon.c     2007-12-09 06:44:17.000000000 -0500
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.15/arch/ia64/kernel/process.c linux-2.6.22.15-vs2.3.0.29.1/arch/ia64/kernel/process.c
601 --- linux-2.6.22.15/arch/ia64/kernel/process.c  2007-07-21 17:59:45.000000000 -0400
602 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/ia64/kernel/process.c     2007-12-09 06:44:17.000000000 -0500
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.15/arch/ia64/kernel/ptrace.c linux-2.6.22.15-vs2.3.0.29.1/arch/ia64/kernel/ptrace.c
624 --- linux-2.6.22.15/arch/ia64/kernel/ptrace.c   2007-07-21 17:58:15.000000000 -0400
625 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/ia64/kernel/ptrace.c      2007-12-09 06:44:18.000000000 -0500
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.15/arch/ia64/kernel/traps.c linux-2.6.22.15-vs2.3.0.29.1/arch/ia64/kernel/traps.c
645 --- linux-2.6.22.15/arch/ia64/kernel/traps.c    2007-07-21 17:59:45.000000000 -0400
646 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/ia64/kernel/traps.c       2007-12-09 06:44:18.000000000 -0500
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.15/arch/ia64/mm/fault.c linux-2.6.22.15-vs2.3.0.29.1/arch/ia64/mm/fault.c
672 --- linux-2.6.22.15/arch/ia64/mm/fault.c        2007-07-21 17:59:45.000000000 -0400
673 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/ia64/mm/fault.c   2007-12-09 06:44:18.000000000 -0500
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.15/arch/m32r/kernel/process.c linux-2.6.22.15-vs2.3.0.29.1/arch/m32r/kernel/process.c
683 --- linux-2.6.22.15/arch/m32r/kernel/process.c  2007-07-21 17:58:15.000000000 -0400
684 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/m32r/kernel/process.c     2007-12-09 06:44:18.000000000 -0500
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.15/arch/m32r/kernel/traps.c linux-2.6.22.15-vs2.3.0.29.1/arch/m32r/kernel/traps.c
697 --- linux-2.6.22.15/arch/m32r/kernel/traps.c    2007-05-04 09:57:13.000000000 -0400
698 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/m32r/kernel/traps.c       2007-12-09 06:44:18.000000000 -0500
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.15/arch/m68k/Kconfig linux-2.6.22.15-vs2.3.0.29.1/arch/m68k/Kconfig
712 --- linux-2.6.22.15/arch/m68k/Kconfig   2007-07-21 17:59:45.000000000 -0400
713 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/m68k/Kconfig      2007-12-09 06:44:18.000000000 -0500
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.15/arch/m68k/kernel/process.c linux-2.6.22.15-vs2.3.0.29.1/arch/m68k/kernel/process.c
724 --- linux-2.6.22.15/arch/m68k/kernel/process.c  2007-05-04 09:57:14.000000000 -0400
725 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/m68k/kernel/process.c     2007-12-09 06:44:18.000000000 -0500
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.15/arch/m68k/kernel/ptrace.c linux-2.6.22.15-vs2.3.0.29.1/arch/m68k/kernel/ptrace.c
737 --- linux-2.6.22.15/arch/m68k/kernel/ptrace.c   2007-07-21 17:59:45.000000000 -0400
738 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/m68k/kernel/ptrace.c      2007-12-09 06:44:18.000000000 -0500
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.15/arch/m68k/kernel/traps.c linux-2.6.22.15-vs2.3.0.29.1/arch/m68k/kernel/traps.c
757 --- linux-2.6.22.15/arch/m68k/kernel/traps.c    2007-07-21 17:58:15.000000000 -0400
758 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/m68k/kernel/traps.c       2007-12-09 06:44:18.000000000 -0500
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.15/arch/m68knommu/Kconfig linux-2.6.22.15-vs2.3.0.29.1/arch/m68knommu/Kconfig
771 --- linux-2.6.22.15/arch/m68knommu/Kconfig      2007-07-21 17:59:45.000000000 -0400
772 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/m68knommu/Kconfig 2007-12-09 06:44:18.000000000 -0500
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.15/arch/m68knommu/kernel/process.c linux-2.6.22.15-vs2.3.0.29.1/arch/m68knommu/kernel/process.c
783 --- linux-2.6.22.15/arch/m68knommu/kernel/process.c     2007-05-04 09:58:04.000000000 -0400
784 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/m68knommu/kernel/process.c        2007-12-09 06:44:18.000000000 -0500
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.15/arch/m68knommu/kernel/traps.c linux-2.6.22.15-vs2.3.0.29.1/arch/m68knommu/kernel/traps.c
795 --- linux-2.6.22.15/arch/m68knommu/kernel/traps.c       2007-07-21 17:58:15.000000000 -0400
796 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/m68knommu/kernel/traps.c  2007-12-09 06:44:18.000000000 -0500
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.15/arch/mips/Kconfig linux-2.6.22.15-vs2.3.0.29.1/arch/mips/Kconfig
810 --- linux-2.6.22.15/arch/mips/Kconfig   2007-07-21 17:59:45.000000000 -0400
811 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/mips/Kconfig      2007-12-09 06:44:18.000000000 -0500
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.15/arch/mips/kernel/linux32.c linux-2.6.22.15-vs2.3.0.29.1/arch/mips/kernel/linux32.c
822 --- linux-2.6.22.15/arch/mips/kernel/linux32.c  2007-07-21 17:59:45.000000000 -0400
823 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/mips/kernel/linux32.c     2007-12-09 06:44:18.000000000 -0500
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.15/arch/mips/kernel/process.c linux-2.6.22.15-vs2.3.0.29.1/arch/mips/kernel/process.c
834 --- linux-2.6.22.15/arch/mips/kernel/process.c  2007-07-21 17:58:16.000000000 -0400
835 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/mips/kernel/process.c     2007-12-09 06:44:18.000000000 -0500
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.15/arch/mips/kernel/ptrace.c linux-2.6.22.15-vs2.3.0.29.1/arch/mips/kernel/ptrace.c
847 --- linux-2.6.22.15/arch/mips/kernel/ptrace.c   2007-07-21 17:59:45.000000000 -0400
848 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/mips/kernel/ptrace.c      2007-12-09 06:44:18.000000000 -0500
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.15/arch/mips/kernel/scall32-o32.S linux-2.6.22.15-vs2.3.0.29.1/arch/mips/kernel/scall32-o32.S
868 --- linux-2.6.22.15/arch/mips/kernel/scall32-o32.S      2007-07-21 17:59:45.000000000 -0400
869 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/mips/kernel/scall32-o32.S 2007-12-09 06:44:18.000000000 -0500
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.15/arch/mips/kernel/scall64-64.S linux-2.6.22.15-vs2.3.0.29.1/arch/mips/kernel/scall64-64.S
880 --- linux-2.6.22.15/arch/mips/kernel/scall64-64.S       2007-07-21 17:59:45.000000000 -0400
881 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/mips/kernel/scall64-64.S  2007-12-09 06:44:18.000000000 -0500
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.15/arch/mips/kernel/scall64-n32.S linux-2.6.22.15-vs2.3.0.29.1/arch/mips/kernel/scall64-n32.S
892 --- linux-2.6.22.15/arch/mips/kernel/scall64-n32.S      2007-07-21 17:59:45.000000000 -0400
893 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/mips/kernel/scall64-n32.S 2007-12-09 06:44:18.000000000 -0500
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.15/arch/mips/kernel/scall64-o32.S linux-2.6.22.15-vs2.3.0.29.1/arch/mips/kernel/scall64-o32.S
904 --- linux-2.6.22.15/arch/mips/kernel/scall64-o32.S      2007-07-21 17:59:45.000000000 -0400
905 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/mips/kernel/scall64-o32.S 2007-12-09 06:44:18.000000000 -0500
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.15/arch/mips/kernel/traps.c linux-2.6.22.15-vs2.3.0.29.1/arch/mips/kernel/traps.c
916 --- linux-2.6.22.15/arch/mips/kernel/traps.c    2007-07-21 17:59:48.000000000 -0400
917 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/mips/kernel/traps.c       2007-12-09 06:44:18.000000000 -0500
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.15/arch/mips/mm/fault.c linux-2.6.22.15-vs2.3.0.29.1/arch/mips/mm/fault.c
931 --- linux-2.6.22.15/arch/mips/mm/fault.c        2007-07-21 17:59:48.000000000 -0400
932 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/mips/mm/fault.c   2007-12-09 06:44:18.000000000 -0500
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.15/arch/parisc/Kconfig linux-2.6.22.15-vs2.3.0.29.1/arch/parisc/Kconfig
944 --- linux-2.6.22.15/arch/parisc/Kconfig 2007-07-21 17:58:18.000000000 -0400
945 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/parisc/Kconfig    2007-12-09 06:44:18.000000000 -0500
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.15/arch/parisc/kernel/entry.S linux-2.6.22.15-vs2.3.0.29.1/arch/parisc/kernel/entry.S
956 --- linux-2.6.22.15/arch/parisc/kernel/entry.S  2007-07-21 17:59:48.000000000 -0400
957 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/parisc/kernel/entry.S     2007-12-09 06:44:18.000000000 -0500
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.15/arch/parisc/kernel/process.c linux-2.6.22.15-vs2.3.0.29.1/arch/parisc/kernel/process.c
967 --- linux-2.6.22.15/arch/parisc/kernel/process.c        2007-07-21 17:59:48.000000000 -0400
968 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/parisc/kernel/process.c   2007-12-09 06:44:18.000000000 -0500
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.15/arch/parisc/kernel/syscall_table.S linux-2.6.22.15-vs2.3.0.29.1/arch/parisc/kernel/syscall_table.S
979 --- linux-2.6.22.15/arch/parisc/kernel/syscall_table.S  2007-07-21 17:59:48.000000000 -0400
980 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/parisc/kernel/syscall_table.S     2007-12-09 06:44:18.000000000 -0500
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.15/arch/parisc/kernel/sys_parisc32.c linux-2.6.22.15-vs2.3.0.29.1/arch/parisc/kernel/sys_parisc32.c
991 --- linux-2.6.22.15/arch/parisc/kernel/sys_parisc32.c   2007-07-21 17:59:48.000000000 -0400
992 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/parisc/kernel/sys_parisc32.c      2007-12-09 06:44:18.000000000 -0500
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.15/arch/parisc/kernel/traps.c linux-2.6.22.15-vs2.3.0.29.1/arch/parisc/kernel/traps.c
1008 --- linux-2.6.22.15/arch/parisc/kernel/traps.c  2007-07-21 17:59:48.000000000 -0400
1009 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/parisc/kernel/traps.c     2007-12-09 06:44:18.000000000 -0500
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.15/arch/parisc/mm/fault.c linux-2.6.22.15-vs2.3.0.29.1/arch/parisc/mm/fault.c
1034 --- linux-2.6.22.15/arch/parisc/mm/fault.c      2007-07-21 17:58:18.000000000 -0400
1035 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/parisc/mm/fault.c 2007-12-09 06:44:18.000000000 -0500
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.15/arch/powerpc/Kconfig linux-2.6.22.15-vs2.3.0.29.1/arch/powerpc/Kconfig
1059 --- linux-2.6.22.15/arch/powerpc/Kconfig        2007-07-21 17:59:48.000000000 -0400
1060 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/powerpc/Kconfig   2007-12-09 06:44:18.000000000 -0500
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.15/arch/powerpc/kernel/asm-offsets.c linux-2.6.22.15-vs2.3.0.29.1/arch/powerpc/kernel/asm-offsets.c
1071 --- linux-2.6.22.15/arch/powerpc/kernel/asm-offsets.c   2007-07-21 17:59:48.000000000 -0400
1072 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/powerpc/kernel/asm-offsets.c      2007-12-09 06:44:18.000000000 -0500
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.15/arch/powerpc/kernel/irq.c linux-2.6.22.15-vs2.3.0.29.1/arch/powerpc/kernel/irq.c
1082 --- linux-2.6.22.15/arch/powerpc/kernel/irq.c   2007-07-21 17:59:48.000000000 -0400
1083 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/powerpc/kernel/irq.c      2007-12-09 06:44:18.000000000 -0500
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.15/arch/powerpc/kernel/misc_32.S linux-2.6.22.15-vs2.3.0.29.1/arch/powerpc/kernel/misc_32.S
1093 --- linux-2.6.22.15/arch/powerpc/kernel/misc_32.S       2007-07-21 17:59:48.000000000 -0400
1094 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/powerpc/kernel/misc_32.S  2007-12-09 06:44:18.000000000 -0500
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.15/arch/powerpc/kernel/misc_64.S linux-2.6.22.15-vs2.3.0.29.1/arch/powerpc/kernel/misc_64.S
1105 --- linux-2.6.22.15/arch/powerpc/kernel/misc_64.S       2007-07-21 17:58:18.000000000 -0400
1106 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/powerpc/kernel/misc_64.S  2007-12-09 06:44:18.000000000 -0500
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.15/arch/powerpc/kernel/process.c linux-2.6.22.15-vs2.3.0.29.1/arch/powerpc/kernel/process.c
1117 --- linux-2.6.22.15/arch/powerpc/kernel/process.c       2007-09-29 08:11:48.000000000 -0400
1118 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/powerpc/kernel/process.c  2007-12-09 06:44:18.000000000 -0500
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.15/arch/powerpc/kernel/sys_ppc32.c linux-2.6.22.15-vs2.3.0.29.1/arch/powerpc/kernel/sys_ppc32.c
1132 --- linux-2.6.22.15/arch/powerpc/kernel/sys_ppc32.c     2007-07-21 17:59:48.000000000 -0400
1133 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/powerpc/kernel/sys_ppc32.c        2007-12-09 06:44:18.000000000 -0500
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.15/arch/powerpc/kernel/traps.c linux-2.6.22.15-vs2.3.0.29.1/arch/powerpc/kernel/traps.c
1144 --- linux-2.6.22.15/arch/powerpc/kernel/traps.c 2007-07-21 17:59:48.000000000 -0400
1145 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/powerpc/kernel/traps.c    2007-12-09 06:44:18.000000000 -0500
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.15/arch/powerpc/kernel/vdso.c linux-2.6.22.15-vs2.3.0.29.1/arch/powerpc/kernel/vdso.c
1159 --- linux-2.6.22.15/arch/powerpc/kernel/vdso.c  2007-07-21 17:59:48.000000000 -0400
1160 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/powerpc/kernel/vdso.c     2007-12-09 06:44:18.000000000 -0500
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.15/arch/powerpc/mm/fault.c linux-2.6.22.15-vs2.3.0.29.1/arch/powerpc/mm/fault.c
1170 --- linux-2.6.22.15/arch/powerpc/mm/fault.c     2007-07-21 17:59:48.000000000 -0400
1171 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/powerpc/mm/fault.c        2007-12-09 06:44:18.000000000 -0500
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.15/arch/ppc/Kconfig linux-2.6.22.15-vs2.3.0.29.1/arch/ppc/Kconfig
1183 --- linux-2.6.22.15/arch/ppc/Kconfig    2007-07-21 17:58:19.000000000 -0400
1184 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/ppc/Kconfig       2007-12-09 06:44:18.000000000 -0500
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.15/arch/ppc/kernel/asm-offsets.c linux-2.6.22.15-vs2.3.0.29.1/arch/ppc/kernel/asm-offsets.c
1195 --- linux-2.6.22.15/arch/ppc/kernel/asm-offsets.c       2007-07-21 17:59:49.000000000 -0400
1196 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/ppc/kernel/asm-offsets.c  2007-12-09 06:44:18.000000000 -0500
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.15/arch/ppc/kernel/misc.S linux-2.6.22.15-vs2.3.0.29.1/arch/ppc/kernel/misc.S
1206 --- linux-2.6.22.15/arch/ppc/kernel/misc.S      2007-05-04 09:57:15.000000000 -0400
1207 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/ppc/kernel/misc.S 2007-12-09 06:44:18.000000000 -0500
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.15/arch/ppc/kernel/traps.c linux-2.6.22.15-vs2.3.0.29.1/arch/ppc/kernel/traps.c
1218 --- linux-2.6.22.15/arch/ppc/kernel/traps.c     2007-07-21 17:59:49.000000000 -0400
1219 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/ppc/kernel/traps.c        2007-12-09 06:44:18.000000000 -0500
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.15/arch/ppc/mm/fault.c linux-2.6.22.15-vs2.3.0.29.1/arch/ppc/mm/fault.c
1233 --- linux-2.6.22.15/arch/ppc/mm/fault.c 2007-05-04 09:57:15.000000000 -0400
1234 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/ppc/mm/fault.c    2007-12-09 06:44:18.000000000 -0500
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.15/arch/s390/Kconfig linux-2.6.22.15-vs2.3.0.29.1/arch/s390/Kconfig
1246 --- linux-2.6.22.15/arch/s390/Kconfig   2007-07-21 17:59:49.000000000 -0400
1247 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/s390/Kconfig      2007-12-09 06:44:18.000000000 -0500
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.15/arch/s390/kernel/compat_linux.c linux-2.6.22.15-vs2.3.0.29.1/arch/s390/kernel/compat_linux.c
1258 --- linux-2.6.22.15/arch/s390/kernel/compat_linux.c     2007-07-21 17:59:49.000000000 -0400
1259 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/s390/kernel/compat_linux.c        2007-12-09 06:44:18.000000000 -0500
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.15/arch/s390/kernel/process.c linux-2.6.22.15-vs2.3.0.29.1/arch/s390/kernel/process.c
1270 --- linux-2.6.22.15/arch/s390/kernel/process.c  2007-07-21 17:59:49.000000000 -0400
1271 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/s390/kernel/process.c     2007-12-09 06:44:18.000000000 -0500
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.15/arch/s390/kernel/ptrace.c linux-2.6.22.15-vs2.3.0.29.1/arch/s390/kernel/ptrace.c
1295 --- linux-2.6.22.15/arch/s390/kernel/ptrace.c   2007-07-21 17:58:19.000000000 -0400
1296 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/s390/kernel/ptrace.c      2007-12-09 06:44:18.000000000 -0500
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.15/arch/s390/kernel/syscalls.S linux-2.6.22.15-vs2.3.0.29.1/arch/s390/kernel/syscalls.S
1320 --- linux-2.6.22.15/arch/s390/kernel/syscalls.S 2007-07-21 17:59:49.000000000 -0400
1321 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/s390/kernel/syscalls.S    2007-12-09 06:44:18.000000000 -0500
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.15/arch/s390/mm/fault.c linux-2.6.22.15-vs2.3.0.29.1/arch/s390/mm/fault.c
1332 --- linux-2.6.22.15/arch/s390/mm/fault.c        2007-07-21 17:59:49.000000000 -0400
1333 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/s390/mm/fault.c   2007-12-09 06:44:18.000000000 -0500
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.15/arch/sh/Kconfig linux-2.6.22.15-vs2.3.0.29.1/arch/sh/Kconfig
1345 --- linux-2.6.22.15/arch/sh/Kconfig     2007-07-21 17:59:49.000000000 -0400
1346 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/sh/Kconfig        2007-12-09 06:44:18.000000000 -0500
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.15/arch/sh/kernel/irq.c linux-2.6.22.15-vs2.3.0.29.1/arch/sh/kernel/irq.c
1357 --- linux-2.6.22.15/arch/sh/kernel/irq.c        2007-07-21 17:59:49.000000000 -0400
1358 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/sh/kernel/irq.c   2007-12-09 06:44:19.000000000 -0500
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.15/arch/sh/kernel/process.c linux-2.6.22.15-vs2.3.0.29.1/arch/sh/kernel/process.c
1368 --- linux-2.6.22.15/arch/sh/kernel/process.c    2007-07-21 17:59:49.000000000 -0400
1369 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/sh/kernel/process.c       2007-12-09 06:44:19.000000000 -0500
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.15/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.22.15-vs2.3.0.29.1/arch/sh/kernel/vsyscall/vsyscall.c
1390 --- linux-2.6.22.15/arch/sh/kernel/vsyscall/vsyscall.c  2007-07-21 17:59:49.000000000 -0400
1391 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/sh/kernel/vsyscall/vsyscall.c     2007-12-09 06:44:19.000000000 -0500
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.15/arch/sh/mm/fault.c linux-2.6.22.15-vs2.3.0.29.1/arch/sh/mm/fault.c
1401 --- linux-2.6.22.15/arch/sh/mm/fault.c  2007-07-21 17:59:49.000000000 -0400
1402 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/sh/mm/fault.c     2007-12-09 06:44:19.000000000 -0500
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.15/arch/sh64/kernel/process.c linux-2.6.22.15-vs2.3.0.29.1/arch/sh64/kernel/process.c
1414 --- linux-2.6.22.15/arch/sh64/kernel/process.c  2007-07-21 17:59:49.000000000 -0400
1415 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/sh64/kernel/process.c     2007-12-09 06:44:19.000000000 -0500
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.15/arch/sh64/mm/fault.c linux-2.6.22.15-vs2.3.0.29.1/arch/sh64/mm/fault.c
1428 --- linux-2.6.22.15/arch/sh64/mm/fault.c        2007-07-21 17:59:49.000000000 -0400
1429 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/sh64/mm/fault.c   2007-12-09 06:44:19.000000000 -0500
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.15/arch/sparc/Kconfig linux-2.6.22.15-vs2.3.0.29.1/arch/sparc/Kconfig
1450 --- linux-2.6.22.15/arch/sparc/Kconfig  2007-07-21 17:59:49.000000000 -0400
1451 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/sparc/Kconfig     2007-12-09 06:44:19.000000000 -0500
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.15/arch/sparc/kernel/process.c linux-2.6.22.15-vs2.3.0.29.1/arch/sparc/kernel/process.c
1462 --- linux-2.6.22.15/arch/sparc/kernel/process.c 2007-07-21 17:59:49.000000000 -0400
1463 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/sparc/kernel/process.c    2007-12-09 06:44:19.000000000 -0500
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.15/arch/sparc/kernel/ptrace.c linux-2.6.22.15-vs2.3.0.29.1/arch/sparc/kernel/ptrace.c
1475 --- linux-2.6.22.15/arch/sparc/kernel/ptrace.c  2007-05-04 09:58:05.000000000 -0400
1476 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/sparc/kernel/ptrace.c     2007-12-09 06:44:19.000000000 -0500
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.15/arch/sparc/kernel/systbls.S linux-2.6.22.15-vs2.3.0.29.1/arch/sparc/kernel/systbls.S
1497 --- linux-2.6.22.15/arch/sparc/kernel/systbls.S 2007-07-21 17:59:49.000000000 -0400
1498 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/sparc/kernel/systbls.S    2007-12-09 06:44:19.000000000 -0500
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.15/arch/sparc/kernel/traps.c linux-2.6.22.15-vs2.3.0.29.1/arch/sparc/kernel/traps.c
1509 --- linux-2.6.22.15/arch/sparc/kernel/traps.c   2007-07-21 17:59:49.000000000 -0400
1510 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/sparc/kernel/traps.c      2007-12-09 06:44:19.000000000 -0500
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.15/arch/sparc/mm/fault.c linux-2.6.22.15-vs2.3.0.29.1/arch/sparc/mm/fault.c
1522 --- linux-2.6.22.15/arch/sparc/mm/fault.c       2007-07-21 17:59:49.000000000 -0400
1523 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/sparc/mm/fault.c  2007-12-09 06:44:19.000000000 -0500
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.15/arch/sparc64/Kconfig linux-2.6.22.15-vs2.3.0.29.1/arch/sparc64/Kconfig
1535 --- linux-2.6.22.15/arch/sparc64/Kconfig        2007-07-21 17:59:49.000000000 -0400
1536 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/sparc64/Kconfig   2007-12-09 06:44:19.000000000 -0500
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.15/arch/sparc64/kernel/binfmt_aout32.c linux-2.6.22.15-vs2.3.0.29.1/arch/sparc64/kernel/binfmt_aout32.c
1547 --- linux-2.6.22.15/arch/sparc64/kernel/binfmt_aout32.c 2007-05-04 09:58:05.000000000 -0400
1548 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/sparc64/kernel/binfmt_aout32.c    2007-12-09 06:44:19.000000000 -0500
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.15/arch/sparc64/kernel/process.c linux-2.6.22.15-vs2.3.0.29.1/arch/sparc64/kernel/process.c
1558 --- linux-2.6.22.15/arch/sparc64/kernel/process.c       2007-07-21 17:59:49.000000000 -0400
1559 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/sparc64/kernel/process.c  2007-12-09 06:44:19.000000000 -0500
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.15/arch/sparc64/kernel/ptrace.c linux-2.6.22.15-vs2.3.0.29.1/arch/sparc64/kernel/ptrace.c
1571 --- linux-2.6.22.15/arch/sparc64/kernel/ptrace.c        2007-05-04 09:58:05.000000000 -0400
1572 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/sparc64/kernel/ptrace.c   2007-12-09 06:44:19.000000000 -0500
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.15/arch/sparc64/kernel/sys_sparc32.c linux-2.6.22.15-vs2.3.0.29.1/arch/sparc64/kernel/sys_sparc32.c
1593 --- linux-2.6.22.15/arch/sparc64/kernel/sys_sparc32.c   2007-07-21 17:59:49.000000000 -0400
1594 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/sparc64/kernel/sys_sparc32.c      2007-12-09 06:44:19.000000000 -0500
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.15/arch/sparc64/kernel/systbls.S linux-2.6.22.15-vs2.3.0.29.1/arch/sparc64/kernel/systbls.S
1605 --- linux-2.6.22.15/arch/sparc64/kernel/systbls.S       2007-07-21 17:59:49.000000000 -0400
1606 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/sparc64/kernel/systbls.S  2007-12-09 06:44:19.000000000 -0500
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.15/arch/sparc64/kernel/traps.c linux-2.6.22.15-vs2.3.0.29.1/arch/sparc64/kernel/traps.c
1626 --- linux-2.6.22.15/arch/sparc64/kernel/traps.c 2007-09-05 01:07:59.000000000 -0400
1627 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/sparc64/kernel/traps.c    2007-12-09 06:44:19.000000000 -0500
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.15/arch/sparc64/mm/fault.c linux-2.6.22.15-vs2.3.0.29.1/arch/sparc64/mm/fault.c
1639 --- linux-2.6.22.15/arch/sparc64/mm/fault.c     2007-09-05 01:07:59.000000000 -0400
1640 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/sparc64/mm/fault.c        2007-12-09 06:44:19.000000000 -0500
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.15/arch/sparc64/solaris/fs.c linux-2.6.22.15-vs2.3.0.29.1/arch/sparc64/solaris/fs.c
1652 --- linux-2.6.22.15/arch/sparc64/solaris/fs.c   2007-05-04 09:58:05.000000000 -0400
1653 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/sparc64/solaris/fs.c      2007-12-09 06:44:19.000000000 -0500
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.15/arch/um/Kconfig linux-2.6.22.15-vs2.3.0.29.1/arch/um/Kconfig
1673 --- linux-2.6.22.15/arch/um/Kconfig     2007-07-21 17:59:49.000000000 -0400
1674 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/um/Kconfig        2007-12-09 06:44:19.000000000 -0500
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.15/arch/um/kernel/trap.c linux-2.6.22.15-vs2.3.0.29.1/arch/um/kernel/trap.c
1685 --- linux-2.6.22.15/arch/um/kernel/trap.c       2007-07-21 17:59:50.000000000 -0400
1686 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/um/kernel/trap.c  2007-12-09 06:44:19.000000000 -0500
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.15/arch/v850/Kconfig linux-2.6.22.15-vs2.3.0.29.1/arch/v850/Kconfig
1698 --- linux-2.6.22.15/arch/v850/Kconfig   2007-07-21 17:59:50.000000000 -0400
1699 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/v850/Kconfig      2007-12-09 06:44:19.000000000 -0500
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.15/arch/v850/kernel/process.c linux-2.6.22.15-vs2.3.0.29.1/arch/v850/kernel/process.c
1710 --- linux-2.6.22.15/arch/v850/kernel/process.c  2007-07-21 17:59:50.000000000 -0400
1711 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/v850/kernel/process.c     2007-12-09 06:44:19.000000000 -0500
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.15/arch/v850/kernel/ptrace.c linux-2.6.22.15-vs2.3.0.29.1/arch/v850/kernel/ptrace.c
1722 --- linux-2.6.22.15/arch/v850/kernel/ptrace.c   2007-07-21 17:59:50.000000000 -0400
1723 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/v850/kernel/ptrace.c      2007-12-09 06:44:19.000000000 -0500
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.15/arch/x86_64/ia32/ia32_aout.c linux-2.6.22.15-vs2.3.0.29.1/arch/x86_64/ia32/ia32_aout.c
1743 --- linux-2.6.22.15/arch/x86_64/ia32/ia32_aout.c        2007-05-04 09:58:05.000000000 -0400
1744 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/x86_64/ia32/ia32_aout.c   2007-12-09 06:44:20.000000000 -0500
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.15/arch/x86_64/ia32/ia32_binfmt.c linux-2.6.22.15-vs2.3.0.29.1/arch/x86_64/ia32/ia32_binfmt.c
1754 --- linux-2.6.22.15/arch/x86_64/ia32/ia32_binfmt.c      2007-07-21 17:59:50.000000000 -0400
1755 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/x86_64/ia32/ia32_binfmt.c 2007-12-09 06:44:20.000000000 -0500
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.15/arch/x86_64/ia32/ia32entry.S linux-2.6.22.15-vs2.3.0.29.1/arch/x86_64/ia32/ia32entry.S
1767 --- linux-2.6.22.15/arch/x86_64/ia32/ia32entry.S        2007-09-29 08:11:36.000000000 -0400
1768 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/x86_64/ia32/ia32entry.S   2007-12-09 06:44:20.000000000 -0500
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.15/arch/x86_64/ia32/syscall32.c linux-2.6.22.15-vs2.3.0.29.1/arch/x86_64/ia32/syscall32.c
1779 --- linux-2.6.22.15/arch/x86_64/ia32/syscall32.c        2007-07-21 17:59:50.000000000 -0400
1780 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/x86_64/ia32/syscall32.c   2007-12-09 06:44:20.000000000 -0500
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.15/arch/x86_64/ia32/sys_ia32.c linux-2.6.22.15-vs2.3.0.29.1/arch/x86_64/ia32/sys_ia32.c
1790 --- linux-2.6.22.15/arch/x86_64/ia32/sys_ia32.c 2007-07-21 17:59:50.000000000 -0400
1791 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/x86_64/ia32/sys_ia32.c    2007-12-09 06:44:20.000000000 -0500
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.15/arch/x86_64/Kconfig linux-2.6.22.15-vs2.3.0.29.1/arch/x86_64/Kconfig
1802 --- linux-2.6.22.15/arch/x86_64/Kconfig 2007-07-21 17:59:50.000000000 -0400
1803 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/x86_64/Kconfig    2007-12-09 06:44:20.000000000 -0500
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.15/arch/x86_64/kernel/process.c linux-2.6.22.15-vs2.3.0.29.1/arch/x86_64/kernel/process.c
1814 --- linux-2.6.22.15/arch/x86_64/kernel/process.c        2007-07-21 17:59:50.000000000 -0400
1815 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/x86_64/kernel/process.c   2007-12-09 06:44:20.000000000 -0500
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.15/arch/x86_64/kernel/traps.c linux-2.6.22.15-vs2.3.0.29.1/arch/x86_64/kernel/traps.c
1838 --- linux-2.6.22.15/arch/x86_64/kernel/traps.c  2007-07-21 17:59:50.000000000 -0400
1839 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/x86_64/kernel/traps.c     2007-12-09 06:44:20.000000000 -0500
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.15/arch/x86_64/mm/fault.c linux-2.6.22.15-vs2.3.0.29.1/arch/x86_64/mm/fault.c
1915 --- linux-2.6.22.15/arch/x86_64/mm/fault.c      2007-07-21 17:59:50.000000000 -0400
1916 +++ linux-2.6.22.15-vs2.3.0.29.1/arch/x86_64/mm/fault.c 2007-12-09 06:44:20.000000000 -0500
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.15/Documentation/vserver/debug.txt linux-2.6.22.15-vs2.3.0.29.1/Documentation/vserver/debug.txt
1942 --- linux-2.6.22.15/Documentation/vserver/debug.txt     1969-12-31 19:00:00.000000000 -0500
1943 +++ linux-2.6.22.15-vs2.3.0.29.1/Documentation/vserver/debug.txt        2007-12-09 06:44:17.000000000 -0500
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.15/drivers/block/Kconfig linux-2.6.22.15-vs2.3.0.29.1/drivers/block/Kconfig
2100 --- linux-2.6.22.15/drivers/block/Kconfig       2007-07-21 17:59:50.000000000 -0400
2101 +++ linux-2.6.22.15-vs2.3.0.29.1/drivers/block/Kconfig  2007-12-09 06:44:20.000000000 -0500
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.15/drivers/block/loop.c linux-2.6.22.15-vs2.3.0.29.1/drivers/block/loop.c
2117 --- linux-2.6.22.15/drivers/block/loop.c        2007-07-21 17:59:50.000000000 -0400
2118 +++ linux-2.6.22.15-vs2.3.0.29.1/drivers/block/loop.c   2007-12-09 06:44:20.000000000 -0500
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.15/drivers/block/Makefile linux-2.6.22.15-vs2.3.0.29.1/drivers/block/Makefile
2173 --- linux-2.6.22.15/drivers/block/Makefile      2007-05-04 09:58:05.000000000 -0400
2174 +++ linux-2.6.22.15-vs2.3.0.29.1/drivers/block/Makefile 2007-12-09 06:44:20.000000000 -0500
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.15/drivers/block/vroot.c linux-2.6.22.15-vs2.3.0.29.1/drivers/block/vroot.c
2182 --- linux-2.6.22.15/drivers/block/vroot.c       1969-12-31 19:00:00.000000000 -0500
2183 +++ linux-2.6.22.15-vs2.3.0.29.1/drivers/block/vroot.c  2007-12-09 06:44:20.000000000 -0500
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.15/drivers/char/sysrq.c linux-2.6.22.15-vs2.3.0.29.1/drivers/char/sysrq.c
2467 --- linux-2.6.22.15/drivers/char/sysrq.c        2007-07-21 17:59:53.000000000 -0400
2468 +++ linux-2.6.22.15-vs2.3.0.29.1/drivers/char/sysrq.c   2007-12-09 06:44:20.000000000 -0500
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.15/drivers/char/tty_io.c linux-2.6.22.15-vs2.3.0.29.1/drivers/char/tty_io.c
2522 --- linux-2.6.22.15/drivers/char/tty_io.c       2007-07-21 17:59:53.000000000 -0400
2523 +++ linux-2.6.22.15-vs2.3.0.29.1/drivers/char/tty_io.c  2007-12-09 06:44:20.000000000 -0500
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.15/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.22.15-vs2.3.0.29.1/drivers/infiniband/hw/ipath/ipath_user_pages.c
2558 --- linux-2.6.22.15/drivers/infiniband/hw/ipath/ipath_user_pages.c      2007-05-04 09:58:07.000000000 -0400
2559 +++ linux-2.6.22.15-vs2.3.0.29.1/drivers/infiniband/hw/ipath/ipath_user_pages.c 2007-12-09 06:44:20.000000000 -0500
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.15/drivers/md/dm.c linux-2.6.22.15-vs2.3.0.29.1/drivers/md/dm.c
2606 --- linux-2.6.22.15/drivers/md/dm.c     2007-08-11 21:54:36.000000000 -0400
2607 +++ linux-2.6.22.15-vs2.3.0.29.1/drivers/md/dm.c        2007-12-09 06:44:20.000000000 -0500
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.15/drivers/md/dm.h linux-2.6.22.15-vs2.3.0.29.1/drivers/md/dm.h
2682 --- linux-2.6.22.15/drivers/md/dm.h     2007-05-04 09:58:08.000000000 -0400
2683 +++ linux-2.6.22.15-vs2.3.0.29.1/drivers/md/dm.h        2007-12-09 06:44:20.000000000 -0500
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.15/drivers/md/dm-ioctl.c linux-2.6.22.15-vs2.3.0.29.1/drivers/md/dm-ioctl.c
2694 --- linux-2.6.22.15/drivers/md/dm-ioctl.c       2007-07-21 17:58:29.000000000 -0400
2695 +++ linux-2.6.22.15-vs2.3.0.29.1/drivers/md/dm-ioctl.c  2007-12-09 06:44:20.000000000 -0500
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.15/fs/attr.c linux-2.6.22.15-vs2.3.0.29.1/fs/attr.c
2778 --- linux-2.6.22.15/fs/attr.c   2007-07-21 18:00:15.000000000 -0400
2779 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/attr.c      2007-12-09 06:44:20.000000000 -0500
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.15/fs/binfmt_aout.c linux-2.6.22.15-vs2.3.0.29.1/fs/binfmt_aout.c
2838 --- linux-2.6.22.15/fs/binfmt_aout.c    2007-05-04 09:58:21.000000000 -0400
2839 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/binfmt_aout.c       2007-12-09 06:44:20.000000000 -0500
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.15/fs/binfmt_elf.c linux-2.6.22.15-vs2.3.0.29.1/fs/binfmt_elf.c
2849 --- linux-2.6.22.15/fs/binfmt_elf.c     2007-07-21 18:00:15.000000000 -0400
2850 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/binfmt_elf.c        2007-12-09 06:44:20.000000000 -0500
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.15/fs/binfmt_flat.c linux-2.6.22.15-vs2.3.0.29.1/fs/binfmt_flat.c
2860 --- linux-2.6.22.15/fs/binfmt_flat.c    2007-07-21 18:00:15.000000000 -0400
2861 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/binfmt_flat.c       2007-12-09 06:44:20.000000000 -0500
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.15/fs/binfmt_som.c linux-2.6.22.15-vs2.3.0.29.1/fs/binfmt_som.c
2871 --- linux-2.6.22.15/fs/binfmt_som.c     2007-05-04 09:57:29.000000000 -0400
2872 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/binfmt_som.c        2007-12-09 06:44:20.000000000 -0500
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.15/fs/block_dev.c linux-2.6.22.15-vs2.3.0.29.1/fs/block_dev.c
2882 --- linux-2.6.22.15/fs/block_dev.c      2007-07-21 18:00:15.000000000 -0400
2883 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/block_dev.c 2007-12-09 06:44:20.000000000 -0500
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.15/fs/char_dev.c linux-2.6.22.15-vs2.3.0.29.1/fs/char_dev.c
2922 --- linux-2.6.22.15/fs/char_dev.c       2007-07-21 17:58:44.000000000 -0400
2923 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/char_dev.c  2007-12-09 06:44:20.000000000 -0500
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.15/fs/dcache.c linux-2.6.22.15-vs2.3.0.29.1/fs/dcache.c
2956 --- linux-2.6.22.15/fs/dcache.c 2007-07-21 18:00:15.000000000 -0400
2957 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/dcache.c    2007-12-09 06:44:20.000000000 -0500
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.15/fs/devpts/inode.c linux-2.6.22.15-vs2.3.0.29.1/fs/devpts/inode.c
3018 --- linux-2.6.22.15/fs/devpts/inode.c   2007-07-21 18:00:15.000000000 -0400
3019 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/devpts/inode.c      2007-12-09 06:44:20.000000000 -0500
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.15/fs/ecryptfs/inode.c linux-2.6.22.15-vs2.3.0.29.1/fs/ecryptfs/inode.c
3097 --- linux-2.6.22.15/fs/ecryptfs/inode.c 2007-08-11 21:54:36.000000000 -0400
3098 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ecryptfs/inode.c    2007-12-09 06:44:20.000000000 -0500
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.15/fs/exec.c linux-2.6.22.15-vs2.3.0.29.1/fs/exec.c
3154 --- linux-2.6.22.15/fs/exec.c   2007-09-05 01:07:59.000000000 -0400
3155 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/exec.c      2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext2/balloc.c linux-2.6.22.15-vs2.3.0.29.1/fs/ext2/balloc.c
3184 --- linux-2.6.22.15/fs/ext2/balloc.c    2007-07-21 17:58:45.000000000 -0400
3185 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext2/balloc.c       2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext2/ext2.h linux-2.6.22.15-vs2.3.0.29.1/fs/ext2/ext2.h
3240 --- linux-2.6.22.15/fs/ext2/ext2.h      2007-07-21 18:00:15.000000000 -0400
3241 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext2/ext2.h 2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext2/file.c linux-2.6.22.15-vs2.3.0.29.1/fs/ext2/file.c
3251 --- linux-2.6.22.15/fs/ext2/file.c      2007-07-21 17:58:45.000000000 -0400
3252 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext2/file.c 2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext2/ialloc.c linux-2.6.22.15-vs2.3.0.29.1/fs/ext2/ialloc.c
3260 --- linux-2.6.22.15/fs/ext2/ialloc.c    2007-05-04 09:57:35.000000000 -0400
3261 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext2/ialloc.c       2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext2/inode.c linux-2.6.22.15-vs2.3.0.29.1/fs/ext2/inode.c
3318 --- linux-2.6.22.15/fs/ext2/inode.c     2007-07-21 18:00:15.000000000 -0400
3319 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext2/inode.c        2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext2/ioctl.c linux-2.6.22.15-vs2.3.0.29.1/fs/ext2/ioctl.c
3453 --- linux-2.6.22.15/fs/ext2/ioctl.c     2007-07-21 18:00:15.000000000 -0400
3454 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext2/ioctl.c        2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext2/namei.c linux-2.6.22.15-vs2.3.0.29.1/fs/ext2/namei.c
3495 --- linux-2.6.22.15/fs/ext2/namei.c     2007-07-21 17:58:45.000000000 -0400
3496 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext2/namei.c        2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext2/super.c linux-2.6.22.15-vs2.3.0.29.1/fs/ext2/super.c
3528 --- linux-2.6.22.15/fs/ext2/super.c     2007-07-21 18:00:15.000000000 -0400
3529 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext2/super.c        2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext2/symlink.c linux-2.6.22.15-vs2.3.0.29.1/fs/ext2/symlink.c
3594 --- linux-2.6.22.15/fs/ext2/symlink.c   2007-07-21 17:58:45.000000000 -0400
3595 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext2/symlink.c      2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext2/xattr.c linux-2.6.22.15-vs2.3.0.29.1/fs/ext2/xattr.c
3611 --- linux-2.6.22.15/fs/ext2/xattr.c     2007-05-04 09:58:21.000000000 -0400
3612 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext2/xattr.c        2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext3/balloc.c linux-2.6.22.15-vs2.3.0.29.1/fs/ext3/balloc.c
3651 --- linux-2.6.22.15/fs/ext3/balloc.c    2007-07-21 17:58:45.000000000 -0400
3652 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext3/balloc.c       2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext3/file.c linux-2.6.22.15-vs2.3.0.29.1/fs/ext3/file.c
3760 --- linux-2.6.22.15/fs/ext3/file.c      2007-07-21 17:58:45.000000000 -0400
3761 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext3/file.c 2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext3/ialloc.c linux-2.6.22.15-vs2.3.0.29.1/fs/ext3/ialloc.c
3770 --- linux-2.6.22.15/fs/ext3/ialloc.c    2007-05-04 09:57:35.000000000 -0400
3771 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext3/ialloc.c       2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext3/inode.c linux-2.6.22.15-vs2.3.0.29.1/fs/ext3/inode.c
3830 --- linux-2.6.22.15/fs/ext3/inode.c     2007-07-21 18:00:15.000000000 -0400
3831 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext3/inode.c        2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext3/ioctl.c linux-2.6.22.15-vs2.3.0.29.1/fs/ext3/ioctl.c
4018 --- linux-2.6.22.15/fs/ext3/ioctl.c     2007-07-21 18:00:15.000000000 -0400
4019 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext3/ioctl.c        2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext3/namei.c linux-2.6.22.15-vs2.3.0.29.1/fs/ext3/namei.c
4098 --- linux-2.6.22.15/fs/ext3/namei.c     2007-09-29 08:11:49.000000000 -0400
4099 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext3/namei.c        2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext3/super.c linux-2.6.22.15-vs2.3.0.29.1/fs/ext3/super.c
4131 --- linux-2.6.22.15/fs/ext3/super.c     2007-07-21 18:00:15.000000000 -0400
4132 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext3/super.c        2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext3/symlink.c linux-2.6.22.15-vs2.3.0.29.1/fs/ext3/symlink.c
4197 --- linux-2.6.22.15/fs/ext3/symlink.c   2007-07-21 17:58:45.000000000 -0400
4198 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext3/symlink.c      2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext3/xattr.c linux-2.6.22.15-vs2.3.0.29.1/fs/ext3/xattr.c
4214 --- linux-2.6.22.15/fs/ext3/xattr.c     2007-07-21 17:58:45.000000000 -0400
4215 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext3/xattr.c        2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext4/balloc.c linux-2.6.22.15-vs2.3.0.29.1/fs/ext4/balloc.c
4258 --- linux-2.6.22.15/fs/ext4/balloc.c    2007-07-21 18:00:15.000000000 -0400
4259 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext4/balloc.c       2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext4/file.c linux-2.6.22.15-vs2.3.0.29.1/fs/ext4/file.c
4366 --- linux-2.6.22.15/fs/ext4/file.c      2007-07-21 17:58:45.000000000 -0400
4367 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext4/file.c 2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext4/ialloc.c linux-2.6.22.15-vs2.3.0.29.1/fs/ext4/ialloc.c
4376 --- linux-2.6.22.15/fs/ext4/ialloc.c    2007-05-04 09:57:35.000000000 -0400
4377 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext4/ialloc.c       2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext4/inode.c linux-2.6.22.15-vs2.3.0.29.1/fs/ext4/inode.c
4436 --- linux-2.6.22.15/fs/ext4/inode.c     2007-07-21 18:00:15.000000000 -0400
4437 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext4/inode.c        2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext4/ioctl.c linux-2.6.22.15-vs2.3.0.29.1/fs/ext4/ioctl.c
4623 --- linux-2.6.22.15/fs/ext4/ioctl.c     2007-05-04 09:58:21.000000000 -0400
4624 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext4/ioctl.c        2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext4/namei.c linux-2.6.22.15-vs2.3.0.29.1/fs/ext4/namei.c
4703 --- linux-2.6.22.15/fs/ext4/namei.c     2007-09-29 08:11:49.000000000 -0400
4704 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext4/namei.c        2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext4/super.c linux-2.6.22.15-vs2.3.0.29.1/fs/ext4/super.c
4736 --- linux-2.6.22.15/fs/ext4/super.c     2007-07-21 18:00:15.000000000 -0400
4737 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext4/super.c        2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext4/symlink.c linux-2.6.22.15-vs2.3.0.29.1/fs/ext4/symlink.c
4802 --- linux-2.6.22.15/fs/ext4/symlink.c   2007-07-21 17:58:45.000000000 -0400
4803 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext4/symlink.c      2007-12-09 06:44:20.000000000 -0500
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.15/fs/ext4/xattr.c linux-2.6.22.15-vs2.3.0.29.1/fs/ext4/xattr.c
4819 --- linux-2.6.22.15/fs/ext4/xattr.c     2007-07-21 17:58:45.000000000 -0400
4820 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ext4/xattr.c        2007-12-09 06:44:20.000000000 -0500
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.15/fs/fcntl.c linux-2.6.22.15-vs2.3.0.29.1/fs/fcntl.c
4863 --- linux-2.6.22.15/fs/fcntl.c  2007-05-04 09:58:21.000000000 -0400
4864 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/fcntl.c     2007-12-09 06:44:20.000000000 -0500
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.15/fs/file_table.c linux-2.6.22.15-vs2.3.0.29.1/fs/file_table.c
4901 --- linux-2.6.22.15/fs/file_table.c     2007-07-21 18:00:15.000000000 -0400
4902 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/file_table.c        2007-12-09 06:44:20.000000000 -0500
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.15/fs/hfsplus/ioctl.c linux-2.6.22.15-vs2.3.0.29.1/fs/hfsplus/ioctl.c
4940 --- linux-2.6.22.15/fs/hfsplus/ioctl.c  2007-05-04 09:57:35.000000000 -0400
4941 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/hfsplus/ioctl.c     2007-12-09 06:44:20.000000000 -0500
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.15/fs/inode.c linux-2.6.22.15-vs2.3.0.29.1/fs/inode.c
4961 --- linux-2.6.22.15/fs/inode.c  2007-07-21 18:00:16.000000000 -0400
4962 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/inode.c     2007-12-09 06:44:20.000000000 -0500
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.15/fs/ioctl.c linux-2.6.22.15-vs2.3.0.29.1/fs/ioctl.c
5003 --- linux-2.6.22.15/fs/ioctl.c  2007-07-21 18:00:16.000000000 -0400
5004 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ioctl.c     2007-12-09 06:44:20.000000000 -0500
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.15/fs/ioprio.c linux-2.6.22.15-vs2.3.0.29.1/fs/ioprio.c
5016 --- linux-2.6.22.15/fs/ioprio.c 2007-07-21 17:58:45.000000000 -0400
5017 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ioprio.c    2007-12-09 06:44:21.000000000 -0500
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.15/fs/jffs2/dir.c linux-2.6.22.15-vs2.3.0.29.1/fs/jffs2/dir.c
5063 --- linux-2.6.22.15/fs/jffs2/dir.c      2007-07-21 18:00:17.000000000 -0400
5064 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/jffs2/dir.c 2007-12-09 06:44:21.000000000 -0500
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.15/fs/jffs2/file.c linux-2.6.22.15-vs2.3.0.29.1/fs/jffs2/file.c
5085 --- linux-2.6.22.15/fs/jffs2/file.c     2007-07-21 18:00:17.000000000 -0400
5086 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/jffs2/file.c        2007-12-09 06:44:21.000000000 -0500
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.15/fs/jffs2/fs.c linux-2.6.22.15-vs2.3.0.29.1/fs/jffs2/fs.c
5151 --- linux-2.6.22.15/fs/jffs2/fs.c       2007-09-29 08:11:49.000000000 -0400
5152 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/jffs2/fs.c  2007-12-09 06:44:21.000000000 -0500
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.15/fs/jffs2/gc.c linux-2.6.22.15-vs2.3.0.29.1/fs/jffs2/gc.c
5309 --- linux-2.6.22.15/fs/jffs2/gc.c       2007-07-21 18:00:17.000000000 -0400
5310 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/jffs2/gc.c  2007-12-09 06:44:21.000000000 -0500
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.15/fs/jffs2/ioctl.c linux-2.6.22.15-vs2.3.0.29.1/fs/jffs2/ioctl.c
5336 --- linux-2.6.22.15/fs/jffs2/ioctl.c    2007-07-21 18:00:17.000000000 -0400
5337 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/jffs2/ioctl.c       2007-12-09 06:44:21.000000000 -0500
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.15/fs/jffs2/jffs2_fs_sb.h linux-2.6.22.15-vs2.3.0.29.1/fs/jffs2/jffs2_fs_sb.h
5410 --- linux-2.6.22.15/fs/jffs2/jffs2_fs_sb.h      2007-07-21 18:00:17.000000000 -0400
5411 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/jffs2/jffs2_fs_sb.h 2007-12-09 06:44:21.000000000 -0500
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.15/fs/jffs2/nodelist.h linux-2.6.22.15-vs2.3.0.29.1/fs/jffs2/nodelist.h
5421 --- linux-2.6.22.15/fs/jffs2/nodelist.h 2007-07-21 18:00:17.000000000 -0400
5422 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/jffs2/nodelist.h    2007-12-09 06:44:21.000000000 -0500
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.15/fs/jffs2/os-linux.h linux-2.6.22.15-vs2.3.0.29.1/fs/jffs2/os-linux.h
5454 --- linux-2.6.22.15/fs/jffs2/os-linux.h 2007-07-21 18:00:17.000000000 -0400
5455 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/jffs2/os-linux.h    2007-12-09 06:44:21.000000000 -0500
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.15/fs/jffs2/readinode.c linux-2.6.22.15-vs2.3.0.29.1/fs/jffs2/readinode.c
5475 --- linux-2.6.22.15/fs/jffs2/readinode.c        2007-07-21 18:00:17.000000000 -0400
5476 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/jffs2/readinode.c   2007-12-09 06:44:21.000000000 -0500
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.15/fs/jffs2/super.c linux-2.6.22.15-vs2.3.0.29.1/fs/jffs2/super.c
5487 --- linux-2.6.22.15/fs/jffs2/super.c    2007-07-21 18:00:17.000000000 -0400
5488 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/jffs2/super.c       2007-12-09 06:44:21.000000000 -0500
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.15/fs/jffs2/write.c linux-2.6.22.15-vs2.3.0.29.1/fs/jffs2/write.c
5561 --- linux-2.6.22.15/fs/jffs2/write.c    2007-08-25 21:38:36.000000000 -0400
5562 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/jffs2/write.c       2007-12-09 06:44:21.000000000 -0500
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.15/fs/jfs/acl.c linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/acl.c
5572 --- linux-2.6.22.15/fs/jfs/acl.c        2007-05-04 09:57:35.000000000 -0400
5573 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/acl.c   2007-12-09 06:44:21.000000000 -0500
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.15/fs/jfs/file.c linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/file.c
5585 --- linux-2.6.22.15/fs/jfs/file.c       2007-07-21 17:58:46.000000000 -0400
5586 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/file.c  2007-12-09 06:44:21.000000000 -0500
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.15/fs/jfs/inode.c linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/inode.c
5596 --- linux-2.6.22.15/fs/jfs/inode.c      2007-07-21 18:00:17.000000000 -0400
5597 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/inode.c 2007-12-09 06:44:21.000000000 -0500
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.15/fs/jfs/ioctl.c linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/ioctl.c
5615 --- linux-2.6.22.15/fs/jfs/ioctl.c      2007-07-21 18:00:17.000000000 -0400
5616 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/ioctl.c 2007-12-09 06:44:21.000000000 -0500
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.15/fs/jfs/jfs_dinode.h linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/jfs_dinode.h
5647 --- linux-2.6.22.15/fs/jfs/jfs_dinode.h 2007-05-04 09:57:35.000000000 -0400
5648 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/jfs_dinode.h    2007-12-09 06:44:21.000000000 -0500
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.15/fs/jfs/jfs_dtree.c linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/jfs_dtree.c
5665 --- linux-2.6.22.15/fs/jfs/jfs_dtree.c  2007-05-04 09:58:21.000000000 -0400
5666 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/jfs_dtree.c     2007-12-09 06:44:21.000000000 -0500
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.15/fs/jfs/jfs_extent.c linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/jfs_extent.c
5779 --- linux-2.6.22.15/fs/jfs/jfs_extent.c 2007-05-04 09:57:36.000000000 -0400
5780 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/jfs_extent.c    2007-12-09 06:44:21.000000000 -0500
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.15/fs/jfs/jfs_filsys.h linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/jfs_filsys.h
5843 --- linux-2.6.22.15/fs/jfs/jfs_filsys.h 2007-05-04 09:58:21.000000000 -0400
5844 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/jfs_filsys.h    2007-12-09 06:44:21.000000000 -0500
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.15/fs/jfs/jfs_imap.c linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/jfs_imap.c
5854 --- linux-2.6.22.15/fs/jfs/jfs_imap.c   2007-07-21 18:00:17.000000000 -0400
5855 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/jfs_imap.c      2007-12-09 06:44:21.000000000 -0500
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.15/fs/jfs/jfs_inode.c linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/jfs_inode.c
5916 --- linux-2.6.22.15/fs/jfs/jfs_inode.c  2007-07-21 18:00:17.000000000 -0400
5917 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/jfs_inode.c     2007-12-09 06:44:21.000000000 -0500
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.15/fs/jfs/jfs_inode.h linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/jfs_inode.h
5998 --- linux-2.6.22.15/fs/jfs/jfs_inode.h  2007-07-21 18:00:17.000000000 -0400
5999 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/jfs_inode.h     2007-12-09 06:44:21.000000000 -0500
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.15/fs/jfs/jfs_xtree.c linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/jfs_xtree.c
6009 --- linux-2.6.22.15/fs/jfs/jfs_xtree.c  2007-07-21 17:58:46.000000000 -0400
6010 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/jfs_xtree.c     2007-12-09 06:44:21.000000000 -0500
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.15/fs/jfs/namei.c linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/namei.c
6095 --- linux-2.6.22.15/fs/jfs/namei.c      2007-07-21 17:58:46.000000000 -0400
6096 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/namei.c 2007-12-09 06:44:21.000000000 -0500
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.15/fs/jfs/super.c linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/super.c
6122 --- linux-2.6.22.15/fs/jfs/super.c      2007-07-21 18:00:17.000000000 -0400
6123 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/super.c 2007-12-09 06:44:21.000000000 -0500
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.15/fs/jfs/xattr.c linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/xattr.c
6191 --- linux-2.6.22.15/fs/jfs/xattr.c      2007-05-04 09:57:36.000000000 -0400
6192 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/jfs/xattr.c 2007-12-09 06:44:21.000000000 -0500
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.15/fs/libfs.c linux-2.6.22.15-vs2.3.0.29.1/fs/libfs.c
6271 --- linux-2.6.22.15/fs/libfs.c  2007-07-21 18:00:17.000000000 -0400
6272 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/libfs.c     2007-12-09 06:44:21.000000000 -0500
6273 @@ -124,7 +124,8 @@ static inline unsigned char dt_type(stru
6274   * both impossible due to the lock on directory.
6275   */
6276  
6277 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
6278 +static inline int do_dcache_readdir_filter(struct file *filp,
6279 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
6280  {
6281         struct dentry *dentry = filp->f_path.dentry;
6282         struct dentry *cursor = filp->private_data;
6283 @@ -157,6 +158,8 @@ int dcache_readdir(struct file * filp, v
6284                                 next = list_entry(p, struct dentry, d_u.d_child);
6285                                 if (d_unhashed(next) || !next->d_inode)
6286                                         continue;
6287 +                               if (filter && !filter(next))
6288 +                                       continue;
6289  
6290                                 spin_unlock(&dcache_lock);
6291                                 if (filldir(dirent, next->d_name.name, 
6292 @@ -175,6 +178,18 @@ int dcache_readdir(struct file * filp, v
6293         return 0;
6294  }
6295  
6296 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
6297 +{
6298 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
6299 +}
6300 +
6301 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
6302 +       int (*filter)(struct dentry *))
6303 +{
6304 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
6305 +}
6306 +
6307 +
6308  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
6309  {
6310         return -EISDIR;
6311 @@ -640,6 +655,7 @@ EXPORT_SYMBOL(dcache_dir_close);
6312  EXPORT_SYMBOL(dcache_dir_lseek);
6313  EXPORT_SYMBOL(dcache_dir_open);
6314  EXPORT_SYMBOL(dcache_readdir);
6315 +EXPORT_SYMBOL(dcache_readdir_filter);
6316  EXPORT_SYMBOL(generic_read_dir);
6317  EXPORT_SYMBOL(get_sb_pseudo);
6318  EXPORT_SYMBOL(simple_commit_write);
6319 diff -Nurp linux-2.6.22.15/fs/locks.c linux-2.6.22.15-vs2.3.0.29.1/fs/locks.c
6320 --- linux-2.6.22.15/fs/locks.c  2007-09-29 08:11:49.000000000 -0400
6321 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/locks.c     2007-12-09 06:44:21.000000000 -0500
6322 @@ -125,6 +125,8 @@
6323  #include <linux/syscalls.h>
6324  #include <linux/time.h>
6325  #include <linux/rcupdate.h>
6326 +#include <linux/vs_base.h>
6327 +#include <linux/vs_limit.h>
6328  
6329  #include <asm/semaphore.h>
6330  #include <asm/uaccess.h>
6331 @@ -147,6 +149,8 @@ static struct kmem_cache *filelock_cache
6332  /* Allocate an empty lock structure. */
6333  static struct file_lock *locks_alloc_lock(void)
6334  {
6335 +       if (!vx_locks_avail(1))
6336 +               return NULL;
6337         return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
6338  }
6339  
6340 @@ -172,6 +176,7 @@ static void locks_free_lock(struct file_
6341         BUG_ON(!list_empty(&fl->fl_block));
6342         BUG_ON(!list_empty(&fl->fl_link));
6343  
6344 +       vx_locks_dec(fl);
6345         locks_release_private(fl);
6346         kmem_cache_free(filelock_cache, fl);
6347  }
6348 @@ -191,6 +196,7 @@ void locks_init_lock(struct file_lock *f
6349         fl->fl_start = fl->fl_end = 0;
6350         fl->fl_ops = NULL;
6351         fl->fl_lmops = NULL;
6352 +       fl->fl_xid = -1;
6353  }
6354  
6355  EXPORT_SYMBOL(locks_init_lock);
6356 @@ -244,6 +250,7 @@ void locks_copy_lock(struct file_lock *n
6357         new->fl_file = fl->fl_file;
6358         new->fl_ops = fl->fl_ops;
6359         new->fl_lmops = fl->fl_lmops;
6360 +       new->fl_xid = fl->fl_xid;
6361  
6362         locks_copy_private(new, fl);
6363  }
6364 @@ -282,6 +289,11 @@ static int flock_make_lock(struct file *
6365         fl->fl_flags = FL_FLOCK;
6366         fl->fl_type = type;
6367         fl->fl_end = OFFSET_MAX;
6368 +
6369 +       vxd_assert(filp->f_xid == vx_current_xid(),
6370 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
6371 +       fl->fl_xid = filp->f_xid;
6372 +       vx_locks_inc(fl);
6373         
6374         *lock = fl;
6375         return 0;
6376 @@ -447,6 +459,7 @@ static int lease_init(struct file *filp,
6377  
6378         fl->fl_owner = current->files;
6379         fl->fl_pid = current->tgid;
6380 +       fl->fl_xid = vx_current_xid();
6381  
6382         fl->fl_file = filp;
6383         fl->fl_flags = FL_LEASE;
6384 @@ -466,6 +479,11 @@ static int lease_alloc(struct file *filp
6385         if (fl == NULL)
6386                 goto out;
6387  
6388 +       fl->fl_xid = vx_current_xid();
6389 +       if (filp)
6390 +               vxd_assert(filp->f_xid == fl->fl_xid,
6391 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
6392 +       vx_locks_inc(fl);
6393         error = lease_init(filp, type, fl);
6394         if (error) {
6395                 locks_free_lock(fl);
6396 @@ -769,6 +787,7 @@ static int flock_lock_file(struct file *
6397         if (found)
6398                 cond_resched();
6399  
6400 +       new_fl->fl_xid = -1;
6401  find_conflict:
6402         for_each_lock(inode, before) {
6403                 struct file_lock *fl = *before;
6404 @@ -787,6 +806,7 @@ find_conflict:
6405                 goto out;
6406         locks_copy_lock(new_fl, request);
6407         locks_insert_lock(before, new_fl);
6408 +       vx_locks_inc(new_fl);
6409         new_fl = NULL;
6410         error = 0;
6411  
6412 @@ -797,7 +817,8 @@ out:
6413         return error;
6414  }
6415  
6416 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
6417 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
6418 +       struct file_lock *conflock, xid_t xid)
6419  {
6420         struct file_lock *fl;
6421         struct file_lock *new_fl = NULL;
6422 @@ -807,6 +828,8 @@ static int __posix_lock_file(struct inod
6423         struct file_lock **before;
6424         int error, added = 0;
6425  
6426 +       vxd_assert(xid == vx_current_xid(),
6427 +               "xid(%d) == current(%d)", xid, vx_current_xid());
6428         /*
6429          * We may need two file_lock structures for this operation,
6430          * so we get them in advance to avoid races.
6431 @@ -817,7 +840,11 @@ static int __posix_lock_file(struct inod
6432             (request->fl_type != F_UNLCK ||
6433              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
6434                 new_fl = locks_alloc_lock();
6435 +               new_fl->fl_xid = xid;
6436 +               vx_locks_inc(new_fl);
6437                 new_fl2 = locks_alloc_lock();
6438 +               new_fl2->fl_xid = xid;
6439 +               vx_locks_inc(new_fl2);
6440         }
6441  
6442         lock_kernel();
6443 @@ -1016,7 +1043,8 @@ static int __posix_lock_file(struct inod
6444  int posix_lock_file(struct file *filp, struct file_lock *fl,
6445                         struct file_lock *conflock)
6446  {
6447 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
6448 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
6449 +               fl, conflock, filp->f_xid);
6450  }
6451  EXPORT_SYMBOL(posix_lock_file);
6452  
6453 @@ -1106,7 +1134,7 @@ int locks_mandatory_area(int read_write,
6454         fl.fl_end = offset + count - 1;
6455  
6456         for (;;) {
6457 -               error = __posix_lock_file(inode, &fl, NULL);
6458 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
6459                 if (error != -EAGAIN)
6460                         break;
6461                 if (!(fl.fl_flags & FL_SLEEP))
6462 @@ -1410,8 +1438,8 @@ static int __setlease(struct file *filp,
6463                 goto out;
6464  
6465         locks_copy_lock(fl, lease);
6466 -
6467         locks_insert_lock(before, fl);
6468 +       vx_locks_inc(fl);
6469  
6470         *flp = fl;
6471         error = 0;
6472 @@ -1738,6 +1766,11 @@ int fcntl_setlk(unsigned int fd, struct 
6473         if (file_lock == NULL)
6474                 return -ENOLCK;
6475  
6476 +       vxd_assert(filp->f_xid == vx_current_xid(),
6477 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
6478 +       file_lock->fl_xid = filp->f_xid;
6479 +       vx_locks_inc(file_lock);
6480 +
6481         /*
6482          * This might block, so we do it before checking the inode.
6483          */
6484 @@ -1864,6 +1897,11 @@ int fcntl_setlk64(unsigned int fd, struc
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 @@ -2168,6 +2206,10 @@ int get_locks_status(char *buffer, char 
6497         list_for_each(tmp, &file_lock_list) {
6498                 struct list_head *btmp;
6499                 struct file_lock *fl = list_entry(tmp, struct file_lock, fl_link);
6500 +
6501 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
6502 +                       continue;
6503 +
6504                 lock_get_status(q, fl, ++i, "");
6505                 move_lock_status(&q, &pos, offset);
6506  
6507 diff -Nurp linux-2.6.22.15/fs/namei.c linux-2.6.22.15-vs2.3.0.29.1/fs/namei.c
6508 --- linux-2.6.22.15/fs/namei.c  2007-07-21 18:00:17.000000000 -0400
6509 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/namei.c     2007-12-09 06:44:21.000000000 -0500
6510 @@ -31,6 +31,13 @@
6511  #include <linux/file.h>
6512  #include <linux/fcntl.h>
6513  #include <linux/namei.h>
6514 +#include <linux/proc_fs.h>
6515 +#include <linux/vserver/inode.h>
6516 +#include <linux/vs_base.h>
6517 +#include <linux/vs_tag.h>
6518 +#include <linux/vs_cowbl.h>
6519 +#include <linux/vs_device.h>
6520 +#include <linux/vs_context.h>
6521  #include <asm/namei.h>
6522  #include <asm/uaccess.h>
6523  
6524 @@ -224,6 +231,28 @@ int generic_permission(struct inode *ino
6525         return -EACCES;
6526  }
6527  
6528 +static inline int dx_barrier(struct inode *inode)
6529 +{
6530 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN)) {
6531 +               vxwprintk_task(1, "did hit the barrier.");
6532 +               return 1;
6533 +       }
6534 +       return 0;
6535 +}
6536 +
6537 +static inline int dx_permission(struct inode *inode, int mask, struct nameidata *nd)
6538 +{
6539 +       if (dx_barrier(inode))
6540 +               return -EACCES;
6541 +       if (dx_notagcheck(nd) ||
6542 +           dx_check(inode->i_tag, DX_HOSTID|DX_ADMIN|DX_WATCH|DX_IDENT))
6543 +               return 0;
6544 +
6545 +       vxwprintk_task(1, "denied access to %p[#%d,%lu] Â»%s«.",
6546 +               inode, inode->i_tag, inode->i_ino, vxd_cond_path(nd));
6547 +       return -EACCES;
6548 +}
6549 +
6550  int permission(struct inode *inode, int mask, struct nameidata *nd)
6551  {
6552         umode_t mode = inode->i_mode;
6553 @@ -234,14 +263,14 @@ int permission(struct inode *inode, int 
6554                 /*
6555                  * Nobody gets write access to a read-only fs.
6556                  */
6557 -               if (IS_RDONLY(inode) &&
6558 +               if ((IS_RDONLY(inode) || (nd && MNT_IS_RDONLY(nd->mnt))) &&
6559                     (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)))
6560                         return -EROFS;
6561  
6562                 /*
6563                  * Nobody gets write access to an immutable file.
6564                  */
6565 -               if (IS_IMMUTABLE(inode))
6566 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
6567                         return -EACCES;
6568         }
6569  
6570 @@ -257,6 +286,12 @@ int permission(struct inode *inode, int 
6571  
6572         /* Ordinary permission routines do not understand MAY_APPEND. */
6573         submask = mask & ~MAY_APPEND;
6574 +
6575 +       if ((inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC) &&
6576 +               (inode->i_sb->s_magic != PROC_SUPER_MAGIC) &&
6577 +               (retval = dx_permission(inode, mask, nd)))
6578 +               return retval;
6579 +
6580         if (inode->i_op && inode->i_op->permission)
6581                 retval = inode->i_op->permission(inode, submask, nd);
6582         else
6583 @@ -432,6 +467,8 @@ static int exec_permission_lite(struct i
6584  {
6585         umode_t mode = inode->i_mode;
6586  
6587 +       if (dx_barrier(inode))
6588 +               return -EACCES;
6589         if (inode->i_op && inode->i_op->permission)
6590                 return -EAGAIN;
6591  
6592 @@ -732,7 +769,8 @@ static __always_inline void follow_dotdo
6593                 if (nd->dentry == fs->root &&
6594                     nd->mnt == fs->rootmnt) {
6595                          read_unlock(&fs->lock);
6596 -                       break;
6597 +                       /* for sane '/' avoid follow_mount() */
6598 +                       return;
6599                 }
6600                  read_unlock(&fs->lock);
6601                 spin_lock(&dcache_lock);
6602 @@ -769,16 +807,39 @@ static int do_lookup(struct nameidata *n
6603  {
6604         struct vfsmount *mnt = nd->mnt;
6605         struct dentry *dentry = __d_lookup(nd->dentry, name);
6606 +       struct inode *inode;
6607  
6608         if (!dentry)
6609                 goto need_lookup;
6610         if (dentry->d_op && dentry->d_op->d_revalidate)
6611                 goto need_revalidate;
6612 +       inode = dentry->d_inode;
6613 +       if (!inode)
6614 +               goto done;
6615 +
6616 +       if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
6617 +               struct proc_dir_entry *de = PDE(inode);
6618 +
6619 +               if (de && !vx_hide_check(0, de->vx_flags))
6620 +                       goto hidden;
6621 +       } else if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
6622 +               if (!vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
6623 +                       goto hidden;
6624 +       } else {
6625 +               if (!dx_notagcheck(nd) && !dx_check(inode->i_tag,
6626 +                       DX_WATCH | DX_ADMIN | DX_HOSTID | DX_IDENT))
6627 +                       goto hidden;
6628 +       }
6629  done:
6630         path->mnt = mnt;
6631         path->dentry = dentry;
6632         __follow_mount(path);
6633         return 0;
6634 +hidden:
6635 +       vxwprintk_task(1, "did lookup hidden %p[#%d,%lu] Â»%s«.",
6636 +               inode, inode->i_tag, inode->i_ino, vxd_path(dentry, mnt));
6637 +       dput(dentry);
6638 +       return -ENOENT;
6639  
6640  need_lookup:
6641         dentry = real_lookup(nd->dentry, name, nd);
6642 @@ -1399,7 +1460,8 @@ static inline int check_sticky(struct in
6643   * 10. We don't allow removal of NFS sillyrenamed files; it's handled by
6644   *     nfs_async_unlink().
6645   */
6646 -static int may_delete(struct inode *dir,struct dentry *victim,int isdir)
6647 +static int may_delete(struct inode *dir, struct dentry *victim,
6648 +       int isdir, struct nameidata *nd)
6649  {
6650         int error;
6651  
6652 @@ -1409,13 +1471,13 @@ static int may_delete(struct inode *dir,
6653         BUG_ON(victim->d_parent->d_inode != dir);
6654         audit_inode_child(victim->d_name.name, victim->d_inode, dir);
6655  
6656 -       error = permission(dir,MAY_WRITE | MAY_EXEC, NULL);
6657 +       error = permission(dir,MAY_WRITE | MAY_EXEC, nd);
6658         if (error)
6659                 return error;
6660         if (IS_APPEND(dir))
6661                 return -EPERM;
6662         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
6663 -           IS_IMMUTABLE(victim->d_inode))
6664 +               IS_IXORUNLINK(victim->d_inode))
6665                 return -EPERM;
6666         if (isdir) {
6667                 if (!S_ISDIR(victim->d_inode->i_mode))
6668 @@ -1546,6 +1608,14 @@ int may_open(struct nameidata *nd, int a
6669         if (S_ISDIR(inode->i_mode) && (flag & FMODE_WRITE))
6670                 return -EISDIR;
6671  
6672 +#ifdef CONFIG_VSERVER_COWBL
6673 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
6674 +               if (IS_COW_LINK(inode))
6675 +                       return -EMLINK;
6676 +               inode->i_flags &= ~(S_IUNLINK|S_IMMUTABLE);
6677 +               mark_inode_dirty(inode);
6678 +       }
6679 +#endif
6680         error = vfs_permission(nd, acc_mode);
6681         if (error)
6682                 return error;
6683 @@ -1562,7 +1632,8 @@ int may_open(struct nameidata *nd, int a
6684                         return -EACCES;
6685  
6686                 flag &= ~O_TRUNC;
6687 -       } else if (IS_RDONLY(inode) && (acc_mode & MAY_WRITE))
6688 +       } else if ((IS_RDONLY(inode) || MNT_IS_RDONLY(nd->mnt))
6689 +               && (acc_mode & MAY_WRITE))
6690                 return -EROFS;
6691         /*
6692          * An append-only file must be opened in append mode for writing.
6693 @@ -1650,6 +1721,11 @@ int open_namei(int dfd, const char *path
6694         struct dentry *dir;
6695         int count = 0;
6696  
6697 +#ifdef CONFIG_VSERVER_COWBL
6698 +       int rflag = flag;
6699 +       int rmode = mode;
6700 +restart:
6701 +#endif
6702         acc_mode = ACC_MODE(flag);
6703  
6704         /* O_TRUNC implies we need access checks for write permissions */
6705 @@ -1743,6 +1819,22 @@ do_last:
6706                 goto exit;
6707  ok:
6708         error = may_open(nd, acc_mode, flag);
6709 +#ifdef CONFIG_VSERVER_COWBL
6710 +       if (error == -EMLINK) {
6711 +               struct dentry *dentry;
6712 +               dentry = cow_break_link(pathname);
6713 +               if (IS_ERR(dentry)) {
6714 +                       error = PTR_ERR(dentry);
6715 +                       goto exit;
6716 +               }
6717 +               dput(dentry);
6718 +               release_open_intent(nd);
6719 +               path_release(nd);
6720 +               flag = rflag;
6721 +               mode = rmode;
6722 +               goto restart;
6723 +       }
6724 +#endif
6725         if (error)
6726                 goto exit;
6727         return 0;
6728 @@ -1854,16 +1946,25 @@ fail:
6729  }
6730  EXPORT_SYMBOL_GPL(lookup_create);
6731  
6732 -int vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
6733 +int vfs_mknod(struct inode *dir, struct dentry *dentry,
6734 +       int mode, dev_t dev, struct nameidata *nd)
6735  {
6736 -       int error = may_create(dir, dentry, NULL);
6737 +       int error = may_create(dir, dentry, nd);
6738  
6739         if (error)
6740                 return error;
6741  
6742 -       if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
6743 +       if (!(S_ISCHR(mode) || S_ISBLK(mode)))
6744 +               goto okay;
6745 +
6746 +       if (!capable(CAP_MKNOD))
6747                 return -EPERM;
6748  
6749 +       if (S_ISCHR(mode) && !vs_chrdev_perm(dev, DATTR_CREATE))
6750 +               return -EPERM;
6751 +       if (S_ISBLK(mode) && !vs_blkdev_perm(dev, DATTR_CREATE))
6752 +               return -EPERM;
6753 +okay:
6754         if (!dir->i_op || !dir->i_op->mknod)
6755                 return -EPERM;
6756  
6757 @@ -1906,11 +2007,12 @@ asmlinkage long sys_mknodat(int dfd, con
6758                         error = vfs_create(nd.dentry->d_inode,dentry,mode,&nd);
6759                         break;
6760                 case S_IFCHR: case S_IFBLK:
6761 -                       error = vfs_mknod(nd.dentry->d_inode,dentry,mode,
6762 -                                       new_decode_dev(dev));
6763 +                       error = vfs_mknod(nd.dentry->d_inode, dentry, mode,
6764 +                                       new_decode_dev(dev), &nd);
6765                         break;
6766                 case S_IFIFO: case S_IFSOCK:
6767 -                       error = vfs_mknod(nd.dentry->d_inode,dentry,mode,0);
6768 +                       error = vfs_mknod(nd.dentry->d_inode, dentry, mode,
6769 +                                       0, &nd);
6770                         break;
6771                 case S_IFDIR:
6772                         error = -EPERM;
6773 @@ -1933,9 +2035,10 @@ asmlinkage long sys_mknod(const char __u
6774         return sys_mknodat(AT_FDCWD, filename, mode, dev);
6775  }
6776  
6777 -int vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
6778 +int vfs_mkdir(struct inode *dir, struct dentry *dentry,
6779 +       int mode, struct nameidata *nd)
6780  {
6781 -       int error = may_create(dir, dentry, NULL);
6782 +       int error = may_create(dir, dentry, nd);
6783  
6784         if (error)
6785                 return error;
6786 @@ -1977,7 +2080,7 @@ asmlinkage long sys_mkdirat(int dfd, con
6787  
6788         if (!IS_POSIXACL(nd.dentry->d_inode))
6789                 mode &= ~current->fs->umask;
6790 -       error = vfs_mkdir(nd.dentry->d_inode, dentry, mode);
6791 +       error = vfs_mkdir(nd.dentry->d_inode, dentry, mode, &nd);
6792         dput(dentry);
6793  out_unlock:
6794         mutex_unlock(&nd.dentry->d_inode->i_mutex);
6795 @@ -2020,9 +2123,10 @@ void dentry_unhash(struct dentry *dentry
6796         spin_unlock(&dcache_lock);
6797  }
6798  
6799 -int vfs_rmdir(struct inode *dir, struct dentry *dentry)
6800 +int vfs_rmdir(struct inode *dir, struct dentry *dentry,
6801 +       struct nameidata *nd)
6802  {
6803 -       int error = may_delete(dir, dentry, 1);
6804 +       int error = may_delete(dir, dentry, 1, nd);
6805  
6806         if (error)
6807                 return error;
6808 @@ -2084,7 +2188,7 @@ static long do_rmdir(int dfd, const char
6809         error = PTR_ERR(dentry);
6810         if (IS_ERR(dentry))
6811                 goto exit2;
6812 -       error = vfs_rmdir(nd.dentry->d_inode, dentry);
6813 +       error = vfs_rmdir(nd.dentry->d_inode, dentry, &nd);
6814         dput(dentry);
6815  exit2:
6816         mutex_unlock(&nd.dentry->d_inode->i_mutex);
6817 @@ -2100,9 +2204,10 @@ asmlinkage long sys_rmdir(const char __u
6818         return do_rmdir(AT_FDCWD, pathname);
6819  }
6820  
6821 -int vfs_unlink(struct inode *dir, struct dentry *dentry)
6822 +int vfs_unlink(struct inode *dir, struct dentry *dentry,
6823 +       struct nameidata *nd)
6824  {
6825 -       int error = may_delete(dir, dentry, 0);
6826 +       int error = may_delete(dir, dentry, 0, nd);
6827  
6828         if (error)
6829                 return error;
6830 @@ -2164,7 +2269,7 @@ static long do_unlinkat(int dfd, const c
6831                 inode = dentry->d_inode;
6832                 if (inode)
6833                         atomic_inc(&inode->i_count);
6834 -               error = vfs_unlink(nd.dentry->d_inode, dentry);
6835 +               error = vfs_unlink(nd.dentry->d_inode, dentry, &nd);
6836         exit2:
6837                 dput(dentry);
6838         }
6839 @@ -2199,9 +2304,10 @@ asmlinkage long sys_unlink(const char __
6840         return do_unlinkat(AT_FDCWD, pathname);
6841  }
6842  
6843 -int vfs_symlink(struct inode *dir, struct dentry *dentry, const char *oldname, int mode)
6844 +int vfs_symlink(struct inode *dir, struct dentry *dentry,
6845 +       const char *oldname, int mode, struct nameidata *nd)
6846  {
6847 -       int error = may_create(dir, dentry, NULL);
6848 +       int error = may_create(dir, dentry, nd);
6849  
6850         if (error)
6851                 return error;
6852 @@ -2245,7 +2351,7 @@ asmlinkage long sys_symlinkat(const char
6853         if (IS_ERR(dentry))
6854                 goto out_unlock;
6855  
6856 -       error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO);
6857 +       error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO, &nd);
6858         dput(dentry);
6859  out_unlock:
6860         mutex_unlock(&nd.dentry->d_inode->i_mutex);
6861 @@ -2262,7 +2368,8 @@ asmlinkage long sys_symlink(const char _
6862         return sys_symlinkat(oldname, AT_FDCWD, newname);
6863  }
6864  
6865 -int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry)
6866 +int vfs_link(struct dentry *old_dentry, struct inode *dir,
6867 +       struct dentry *new_dentry, struct nameidata *nd)
6868  {
6869         struct inode *inode = old_dentry->d_inode;
6870         int error;
6871 @@ -2270,7 +2377,7 @@ int vfs_link(struct dentry *old_dentry, 
6872         if (!inode)
6873                 return -ENOENT;
6874  
6875 -       error = may_create(dir, new_dentry, NULL);
6876 +       error = may_create(dir, new_dentry, nd);
6877         if (error)
6878                 return error;
6879  
6880 @@ -2280,7 +2387,7 @@ int vfs_link(struct dentry *old_dentry, 
6881         /*
6882          * A link to an append-only or immutable file cannot be created.
6883          */
6884 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
6885 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
6886                 return -EPERM;
6887         if (!dir->i_op || !dir->i_op->link)
6888                 return -EPERM;
6889 @@ -2340,7 +2447,7 @@ asmlinkage long sys_linkat(int olddfd, c
6890         error = PTR_ERR(new_dentry);
6891         if (IS_ERR(new_dentry))
6892                 goto out_unlock;
6893 -       error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry);
6894 +       error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry, &nd);
6895         dput(new_dentry);
6896  out_unlock:
6897         mutex_unlock(&nd.dentry->d_inode->i_mutex);
6898 @@ -2472,14 +2579,14 @@ int vfs_rename(struct inode *old_dir, st
6899         if (old_dentry->d_inode == new_dentry->d_inode)
6900                 return 0;
6901   
6902 -       error = may_delete(old_dir, old_dentry, is_dir);
6903 +       error = may_delete(old_dir, old_dentry, is_dir, NULL);
6904         if (error)
6905                 return error;
6906  
6907         if (!new_dentry->d_inode)
6908                 error = may_create(new_dir, new_dentry, NULL);
6909         else
6910 -               error = may_delete(new_dir, new_dentry, is_dir);
6911 +               error = may_delete(new_dir, new_dentry, is_dir, NULL);
6912         if (error)
6913                 return error;
6914  
6915 @@ -2557,6 +2664,9 @@ static int do_rename(int olddfd, const c
6916         error = -EINVAL;
6917         if (old_dentry == trap)
6918                 goto exit4;
6919 +       error = -EROFS;
6920 +       if (MNT_IS_RDONLY(newnd.mnt))
6921 +               goto exit4;
6922         new_dentry = lookup_hash(&newnd);
6923         error = PTR_ERR(new_dentry);
6924         if (IS_ERR(new_dentry))
6925 @@ -2650,6 +2760,216 @@ int vfs_follow_link(struct nameidata *nd
6926         return __vfs_follow_link(nd, link);
6927  }
6928  
6929 +
6930 +#ifdef CONFIG_VSERVER_COWBL
6931 +
6932 +#include <linux/file.h>
6933 +
6934 +static inline
6935 +long do_cow_splice(struct file *in, struct file *out, size_t len)
6936 +{
6937 +       loff_t ppos = 0;
6938 +
6939 +       return do_splice_direct(in, &ppos, out, len, 0);
6940 +}
6941 +
6942 +struct dentry *cow_break_link(const char *pathname)
6943 +{
6944 +       int ret, mode, pathlen, redo = 0;
6945 +       struct nameidata old_nd, dir_nd;
6946 +       struct dentry *old_dentry, *new_dentry;
6947 +       struct dentry *dir, *res = NULL;
6948 +       struct vfsmount *old_mnt, *new_mnt;
6949 +       struct file *old_file;
6950 +       struct file *new_file;
6951 +       char *to, *path, pad='\251';
6952 +       loff_t size;
6953 +
6954 +       vxdprintk(VXD_CBIT(misc, 1), "cow_break_link(»%s«)", pathname);
6955 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
6956 +       ret = -ENOMEM;
6957 +       if (!path)
6958 +               goto out;
6959 +
6960 +       /* old_nd will have refs to dentry and mnt */
6961 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
6962 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
6963 +       if (ret < 0)
6964 +               goto out_free_path;
6965 +
6966 +       old_dentry = old_nd.dentry;
6967 +       old_mnt = old_nd.mnt;
6968 +       mode = old_dentry->d_inode->i_mode;
6969 +
6970 +       to = d_path(old_dentry, old_mnt, path, PATH_MAX-2);
6971 +       pathlen = strlen(to);
6972 +       vxdprintk(VXD_CBIT(misc, 2), "old path Â»%s« [»%.*s«:%d]", to,
6973 +               old_dentry->d_name.len, old_dentry->d_name.name,
6974 +               old_dentry->d_name.len);
6975 +
6976 +       to[pathlen + 1] = 0;
6977 +retry:
6978 +       to[pathlen] = pad--;
6979 +       ret = -EMLINK;
6980 +       if (pad <= '\240')
6981 +               goto out_rel_old;
6982 +
6983 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy Â»%s«", to);
6984 +       /* dir_nd will have refs to dentry and mnt */
6985 +       ret = path_lookup(to,
6986 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
6987 +       vxdprintk(VXD_CBIT(misc, 2),
6988 +               "path_lookup(new): %d", ret);
6989 +       if (ret < 0)
6990 +               goto retry;
6991 +
6992 +       /* this puppy downs the inode mutex */
6993 +       new_dentry = lookup_create(&dir_nd, 0);
6994 +       vxdprintk(VXD_CBIT(misc, 2),
6995 +               "lookup_create(new): %p [»%.*s«:%d]", new_dentry,
6996 +               new_dentry->d_name.len, new_dentry->d_name.name,
6997 +               new_dentry->d_name.len);
6998 +       if (!new_dentry || IS_ERR(new_dentry)) {
6999 +               path_release(&dir_nd);
7000 +               goto retry;
7001 +       }
7002 +       dir = dir_nd.dentry;
7003 +
7004 +       ret = vfs_create(dir_nd.dentry->d_inode, new_dentry, mode, &dir_nd);
7005 +       vxdprintk(VXD_CBIT(misc, 2),
7006 +               "vfs_create(new): %d", ret);
7007 +       if (ret == -EEXIST) {
7008 +               mutex_unlock(&dir->d_inode->i_mutex);
7009 +               dput(new_dentry);
7010 +               path_release(&dir_nd);
7011 +               goto retry;
7012 +       }
7013 +       else if (ret < 0)
7014 +               goto out_unlock_new;
7015 +
7016 +       /* drop out early, ret passes ENOENT */
7017 +       ret = -ENOENT;
7018 +       if ((redo = d_unhashed(old_dentry)))
7019 +               goto out_unlock_new;
7020 +
7021 +       new_mnt = dir_nd.mnt;
7022 +       dget(old_dentry);
7023 +       mntget(old_mnt);
7024 +       /* this one cleans up the dentry/mnt in case of failure */
7025 +       old_file = dentry_open(old_dentry, old_mnt, O_RDONLY);
7026 +       vxdprintk(VXD_CBIT(misc, 2),
7027 +               "dentry_open(old): %p", old_file);
7028 +       if (!old_file || IS_ERR(old_file)) {
7029 +               res = IS_ERR(old_file) ? (void *) old_file : res;
7030 +               goto out_unlock_new;
7031 +       }
7032 +
7033 +       dget(new_dentry);
7034 +       mntget(new_mnt);
7035 +       /* this one cleans up the dentry/mnt in case of failure */
7036 +       new_file = dentry_open(new_dentry, new_mnt, O_WRONLY);
7037 +       vxdprintk(VXD_CBIT(misc, 2),
7038 +               "dentry_open(new): %p", new_file);
7039 +
7040 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
7041 +       if (!new_file || IS_ERR(new_file))
7042 +               goto out_fput_old;
7043 +
7044 +       size = i_size_read(old_file->f_dentry->d_inode);
7045 +       ret = do_cow_splice(old_file, new_file, size);
7046 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
7047 +       if (ret < 0) {
7048 +               goto out_fput_both;
7049 +       } else if (ret < size) {
7050 +               ret = -ENOSPC;
7051 +               goto out_fput_both;
7052 +       } else {
7053 +               struct inode *old_inode = old_dentry->d_inode;
7054 +               struct inode *new_inode = new_dentry->d_inode;
7055 +               struct iattr attr = {
7056 +                       .ia_uid = old_inode->i_uid,
7057 +                       .ia_gid = old_inode->i_gid,
7058 +                       .ia_valid = ATTR_UID | ATTR_GID
7059 +                       };
7060 +
7061 +               ret = inode_setattr(new_inode, &attr);
7062 +               if (ret)
7063 +                       goto out_fput_both;
7064 +       }
7065 +
7066 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
7067 +
7068 +       /* drop out late */
7069 +       ret = -ENOENT;
7070 +       if ((redo = d_unhashed(old_dentry)))
7071 +               goto out_unlock;
7072 +
7073 +       vxdprintk(VXD_CBIT(misc, 2),
7074 +               "vfs_rename: [»%*s«:%d] -> [»%*s«:%d]",
7075 +               new_dentry->d_name.len, new_dentry->d_name.name,
7076 +               new_dentry->d_name.len,
7077 +               old_dentry->d_name.len, old_dentry->d_name.name,
7078 +               old_dentry->d_name.len);
7079 +       ret = vfs_rename(dir_nd.dentry->d_inode, new_dentry,
7080 +               old_nd.dentry->d_parent->d_inode, old_dentry);
7081 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
7082 +       res = new_dentry;
7083 +
7084 +out_unlock:
7085 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
7086 +
7087 +out_fput_both:
7088 +       vxdprintk(VXD_CBIT(misc, 3),
7089 +               "fput(new_file=%p[#%d])", new_file,
7090 +               atomic_read(&new_file->f_count));
7091 +       fput(new_file);
7092 +
7093 +out_fput_old:
7094 +       vxdprintk(VXD_CBIT(misc, 3),
7095 +               "fput(old_file=%p[#%d])", old_file,
7096 +               atomic_read(&old_file->f_count));
7097 +       fput(old_file);
7098 +
7099 +out_unlock_new:
7100 +       mutex_unlock(&dir->d_inode->i_mutex);
7101 +       if (!ret)
7102 +               goto out_redo;
7103 +
7104 +       /* error path cleanup */
7105 +       vfs_unlink(dir->d_inode, new_dentry, &dir_nd);
7106 +       dput(new_dentry);
7107 +
7108 +out_redo:
7109 +       if (!redo)
7110 +               goto out_rel_both;
7111 +       /* lookup dentry once again */
7112 +       path_release(&old_nd);
7113 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
7114 +       if (ret)
7115 +               goto out_rel_both;
7116 +
7117 +       new_dentry = old_nd.dentry;
7118 +       vxdprintk(VXD_CBIT(misc, 2),
7119 +               "path_lookup(redo): %p [»%.*s«:%d]", new_dentry,
7120 +               new_dentry->d_name.len, new_dentry->d_name.name,
7121 +               new_dentry->d_name.len);
7122 +       dget(new_dentry);
7123 +       res = new_dentry;
7124 +
7125 +out_rel_both:
7126 +       path_release(&dir_nd);
7127 +out_rel_old:
7128 +       path_release(&old_nd);
7129 +out_free_path:
7130 +       kfree(path);
7131 +out:
7132 +       if (ret)
7133 +               res = ERR_PTR(ret);
7134 +       return res;
7135 +}
7136 +
7137 +#endif
7138 +
7139  /* get the link contents into pagecache */
7140  static char *page_getlink(struct dentry * dentry, struct page **ppage)
7141  {
7142 diff -Nurp linux-2.6.22.15/fs/namespace.c linux-2.6.22.15-vs2.3.0.29.1/fs/namespace.c
7143 --- linux-2.6.22.15/fs/namespace.c      2007-07-21 18:00:17.000000000 -0400
7144 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/namespace.c 2007-12-09 06:44:21.000000000 -0500
7145 @@ -25,6 +25,11 @@
7146  #include <linux/security.h>
7147  #include <linux/mount.h>
7148  #include <linux/ramfs.h>
7149 +#include <linux/vs_base.h>
7150 +#include <linux/vs_context.h>
7151 +#include <linux/vs_tag.h>
7152 +#include <linux/vserver/space.h>
7153 +#include <linux/vserver/global.h>
7154  #include <asm/uaccess.h>
7155  #include <asm/unistd.h>
7156  #include "pnode.h"
7157 @@ -240,6 +245,7 @@ static struct vfsmount *clone_mnt(struct
7158                 mnt->mnt_root = dget(root);
7159                 mnt->mnt_mountpoint = mnt->mnt_root;
7160                 mnt->mnt_parent = mnt;
7161 +               mnt->mnt_tag = old->mnt_tag;
7162  
7163                 if (flag & CL_SLAVE) {
7164                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
7165 @@ -348,48 +354,91 @@ static inline void mangle(struct seq_fil
7166         seq_escape(m, s, " \t\n\\");
7167  }
7168  
7169 +static int mnt_is_reachable(struct vfsmount *mnt)
7170 +{
7171 +       struct vfsmount *root_mnt;
7172 +       struct dentry *root, *point;
7173 +       int ret;
7174 +
7175 +       if (mnt == mnt->mnt_ns->root)
7176 +               return 1;
7177 +
7178 +       spin_lock(&vfsmount_lock);
7179 +       root_mnt = current->fs->rootmnt;
7180 +       root = current->fs->root;
7181 +       point = root;
7182 +
7183 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
7184 +               point = mnt->mnt_mountpoint;
7185 +               mnt = mnt->mnt_parent;
7186 +       }
7187 +
7188 +       ret = (mnt == root_mnt) && is_subdir(point, root);
7189 +
7190 +       spin_unlock(&vfsmount_lock);
7191 +
7192 +       return ret;
7193 +}
7194 +
7195  static int show_vfsmnt(struct seq_file *m, void *v)
7196  {
7197         struct vfsmount *mnt = v;
7198         int err = 0;
7199         static struct proc_fs_info {
7200 -               int flag;
7201 -               char *str;
7202 +               int s_flag;
7203 +               int mnt_flag;
7204 +               char *set_str;
7205 +               char *unset_str;
7206         } fs_info[] = {
7207 -               { MS_SYNCHRONOUS, ",sync" },
7208 -               { MS_DIRSYNC, ",dirsync" },
7209 -               { MS_MANDLOCK, ",mand" },
7210 -               { 0, NULL }
7211 -       };
7212 -       static struct proc_fs_info mnt_info[] = {
7213 -               { MNT_NOSUID, ",nosuid" },
7214 -               { MNT_NODEV, ",nodev" },
7215 -               { MNT_NOEXEC, ",noexec" },
7216 -               { MNT_NOATIME, ",noatime" },
7217 -               { MNT_NODIRATIME, ",nodiratime" },
7218 -               { MNT_RELATIME, ",relatime" },
7219 -               { 0, NULL }
7220 +               { MS_RDONLY, MNT_RDONLY, "ro", "rw" },
7221 +               { MS_SYNCHRONOUS, 0, ",sync", NULL },
7222 +               { MS_DIRSYNC, 0, ",dirsync", NULL },
7223 +               { MS_MANDLOCK, 0, ",mand", NULL },
7224 +               { MS_TAGGED, 0, ",tag", NULL },
7225 +               { MS_NOATIME, MNT_NOATIME, ",noatime", NULL },
7226 +               { MS_NODIRATIME, MNT_NODIRATIME, ",nodiratime", NULL },
7227 +               { MS_RELATIME, MNT_RELATIME, ",relatime", NULL },
7228 +               { 0, MNT_NOSUID, ",nosuid", NULL },
7229 +               { 0, MNT_NODEV, ",nodev", NULL },
7230 +               { 0, MNT_NOEXEC, ",noexec", NULL },
7231 +               { 0, 0, NULL, NULL }
7232         };
7233 -       struct proc_fs_info *fs_infop;
7234 +       struct proc_fs_info *p;
7235 +       unsigned long s_flags = mnt->mnt_sb->s_flags;
7236 +       int mnt_flags = mnt->mnt_flags;
7237  
7238 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
7239 -       seq_putc(m, ' ');
7240 -       seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
7241 -       seq_putc(m, ' ');
7242 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
7243 +               return 0;
7244 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
7245 +               return 0;
7246 +
7247 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
7248 +               mnt == current->fs->rootmnt) {
7249 +               seq_puts(m, "/dev/root / ");
7250 +       } else {
7251 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
7252 +               seq_putc(m, ' ');
7253 +               seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
7254 +               seq_putc(m, ' ');
7255 +
7256 +               if (mnt->mnt_sb->s_subtype && mnt->mnt_sb->s_subtype[0]) {
7257 +                       seq_putc(m, '.');
7258 +                       mangle(m, mnt->mnt_sb->s_subtype);
7259 +               }
7260 +       }
7261         mangle(m, mnt->mnt_sb->s_type->name);
7262 -       if (mnt->mnt_sb->s_subtype && mnt->mnt_sb->s_subtype[0]) {
7263 -               seq_putc(m, '.');
7264 -               mangle(m, mnt->mnt_sb->s_subtype);
7265 -       }
7266 -       seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? " ro" : " rw");
7267 -       for (fs_infop = fs_info; fs_infop->flag; fs_infop++) {
7268 -               if (mnt->mnt_sb->s_flags & fs_infop->flag)
7269 -                       seq_puts(m, fs_infop->str);
7270 -       }
7271 -       for (fs_infop = mnt_info; fs_infop->flag; fs_infop++) {
7272 -               if (mnt->mnt_flags & fs_infop->flag)
7273 -                       seq_puts(m, fs_infop->str);
7274 +       seq_putc(m, ' ');
7275 +       for (p = fs_info; (p->s_flag | p->mnt_flag) ; p++) {
7276 +               if ((s_flags & p->s_flag) || (mnt_flags & p->mnt_flag)) {
7277 +                       if (p->set_str)
7278 +                               seq_puts(m, p->set_str);
7279 +               } else {
7280 +                       if (p->unset_str)
7281 +                               seq_puts(m, p->unset_str);
7282 +               }
7283         }
7284 +       if (mnt->mnt_flags & MNT_TAGID)
7285 +               seq_printf(m, ",tag=%d", mnt->mnt_tag);
7286         if (mnt->mnt_sb->s_op->show_options)
7287                 err = mnt->mnt_sb->s_op->show_options(m, mnt);
7288         seq_puts(m, " 0 0\n");
7289 @@ -408,17 +457,27 @@ static int show_vfsstat(struct seq_file 
7290         struct vfsmount *mnt = v;
7291         int err = 0;
7292  
7293 -       /* device */
7294 -       if (mnt->mnt_devname) {
7295 -               seq_puts(m, "device ");
7296 -               mangle(m, mnt->mnt_devname);
7297 -       } else
7298 -               seq_puts(m, "no device");
7299 -
7300 -       /* mount point */
7301 -       seq_puts(m, " mounted on ");
7302 -       seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
7303 -       seq_putc(m, ' ');
7304 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
7305 +               return 0;
7306 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
7307 +               return 0;
7308 +
7309 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
7310 +               mnt == current->fs->rootmnt) {
7311 +               seq_puts(m, "device /dev/root mounted on / ");
7312 +       } else {
7313 +               /* device */
7314 +               if (mnt->mnt_devname) {
7315 +                       seq_puts(m, "device ");
7316 +                       mangle(m, mnt->mnt_devname);
7317 +               } else
7318 +                       seq_puts(m, "no device");
7319 +
7320 +               /* mount point */
7321 +               seq_puts(m, " mounted on ");
7322 +               seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
7323 +               seq_putc(m, ' ');
7324 +       }
7325  
7326         /* file system type */
7327         seq_puts(m, "with fstype ");
7328 @@ -648,7 +707,7 @@ asmlinkage long sys_umount(char __user *
7329                 goto dput_and_out;
7330  
7331         retval = -EPERM;
7332 -       if (!capable(CAP_SYS_ADMIN))
7333 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
7334                 goto dput_and_out;
7335  
7336         retval = do_umount(nd.mnt, flags);
7337 @@ -672,7 +731,7 @@ asmlinkage long sys_oldumount(char __use
7338  
7339  static int mount_is_safe(struct nameidata *nd)
7340  {
7341 -       if (capable(CAP_SYS_ADMIN))
7342 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
7343                 return 0;
7344         return -EPERM;
7345  #ifdef notyet
7346 @@ -904,11 +963,13 @@ static int do_change_type(struct nameida
7347  /*
7348   * do loopback mount.
7349   */
7350 -static int do_loopback(struct nameidata *nd, char *old_name, int recurse)
7351 +static int do_loopback(struct nameidata *nd, char *old_name, tag_t tag,
7352 +       unsigned long flags, int mnt_flags)
7353  {
7354         struct nameidata old_nd;
7355         struct vfsmount *mnt = NULL;
7356         int err = mount_is_safe(nd);
7357 +       int recurse = flags & MS_REC;
7358         if (err)
7359                 return err;
7360         if (!old_name || !*old_name)
7361 @@ -934,6 +995,12 @@ static int do_loopback(struct nameidata 
7362         if (!mnt)
7363                 goto out;
7364  
7365 +       mnt->mnt_flags = mnt_flags;
7366 +       if (flags & MS_TAGID) {
7367 +               mnt->mnt_tag = tag;
7368 +               mnt->mnt_flags |= MNT_TAGID;
7369 +       }
7370 +
7371         err = graft_tree(mnt, nd);
7372         if (err) {
7373                 LIST_HEAD(umount_list);
7374 @@ -942,6 +1009,7 @@ static int do_loopback(struct nameidata 
7375                 spin_unlock(&vfsmount_lock);
7376                 release_mounts(&umount_list);
7377         }
7378 +       mnt->mnt_flags = mnt_flags;
7379  
7380  out:
7381         up_write(&namespace_sem);
7382 @@ -955,12 +1023,12 @@ out:
7383   * on it - tough luck.
7384   */
7385  static int do_remount(struct nameidata *nd, int flags, int mnt_flags,
7386 -                     void *data)
7387 +                     void *data, xid_t xid)
7388  {
7389         int err;
7390         struct super_block *sb = nd->mnt->mnt_sb;
7391  
7392 -       if (!capable(CAP_SYS_ADMIN))
7393 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
7394                 return -EPERM;
7395  
7396         if (!check_mnt(nd->mnt))
7397 @@ -994,7 +1062,7 @@ static int do_move_mount(struct nameidat
7398         struct nameidata old_nd, parent_nd;
7399         struct vfsmount *p;
7400         int err = 0;
7401 -       if (!capable(CAP_SYS_ADMIN))
7402 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
7403                 return -EPERM;
7404         if (!old_name || !*old_name)
7405                 return -EINVAL;
7406 @@ -1074,7 +1142,7 @@ static int do_new_mount(struct nameidata
7407                 return -EINVAL;
7408  
7409         /* we need capabilities... */
7410 -       if (!capable(CAP_SYS_ADMIN))
7411 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
7412                 return -EPERM;
7413  
7414         mnt = do_kern_mount(type, flags, name, data);
7415 @@ -1386,6 +1454,7 @@ long do_mount(char *dev_name, char *dir_
7416         struct nameidata nd;
7417         int retval = 0;
7418         int mnt_flags = 0;
7419 +       tag_t tag = 0;
7420  
7421         /* Discard magic */
7422         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
7423 @@ -1401,7 +1470,17 @@ long do_mount(char *dev_name, char *dir_
7424         if (data_page)
7425                 ((char *)data_page)[PAGE_SIZE - 1] = 0;
7426  
7427 +       retval = dx_parse_tag(data_page, &tag, 1);
7428 +       if (retval) {
7429 +               mnt_flags |= retval;
7430 +               /* FIXME: bind and re-mounts get the tag flag? */
7431 +               if (flags & (MS_BIND|MS_REMOUNT))
7432 +                       flags |= MS_TAGID;
7433 +       }
7434 +
7435         /* Separate the per-mountpoint flags */
7436 +       if (flags & MS_RDONLY)
7437 +               mnt_flags |= MNT_RDONLY;
7438         if (flags & MS_NOSUID)
7439                 mnt_flags |= MNT_NOSUID;
7440         if (flags & MS_NODEV)
7441 @@ -1415,6 +1494,8 @@ long do_mount(char *dev_name, char *dir_
7442         if (flags & MS_RELATIME)
7443                 mnt_flags |= MNT_RELATIME;
7444  
7445 +       if (!capable(CAP_SYS_ADMIN))
7446 +               mnt_flags |= MNT_NODEV;
7447         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
7448                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME);
7449  
7450 @@ -1429,9 +1510,9 @@ long do_mount(char *dev_name, char *dir_
7451  
7452         if (flags & MS_REMOUNT)
7453                 retval = do_remount(&nd, flags & ~MS_REMOUNT, mnt_flags,
7454 -                                   data_page);
7455 +                                   data_page, tag);
7456         else if (flags & MS_BIND)
7457 -               retval = do_loopback(&nd, dev_name, flags & MS_REC);
7458 +               retval = do_loopback(&nd, dev_name, tag, flags, mnt_flags);
7459         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
7460                 retval = do_change_type(&nd, flags);
7461         else if (flags & MS_MOVE)
7462 @@ -1504,6 +1585,7 @@ static struct mnt_namespace *dup_mnt_ns(
7463                 q = next_mnt(q, new_ns->root);
7464         }
7465         up_write(&namespace_sem);
7466 +       atomic_inc(&vs_global_mnt_ns);
7467  
7468         if (rootmnt)
7469                 mntput(rootmnt);
7470 @@ -1866,5 +1948,6 @@ void __put_mnt_ns(struct mnt_namespace *
7471         spin_unlock(&vfsmount_lock);
7472         up_write(&namespace_sem);
7473         release_mounts(&umount_list);
7474 +       atomic_dec(&vs_global_mnt_ns);
7475         kfree(ns);
7476  }
7477 diff -Nurp linux-2.6.22.15/fs/nfs/client.c linux-2.6.22.15-vs2.3.0.29.1/fs/nfs/client.c
7478 --- linux-2.6.22.15/fs/nfs/client.c     2007-07-21 18:00:17.000000000 -0400
7479 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/nfs/client.c        2007-12-09 06:44:21.000000000 -0500
7480 @@ -521,6 +521,9 @@ static int nfs_init_server_rpcclient(str
7481         if (server->flags & NFS4_MOUNT_INTR)
7482                 server->client->cl_intr = 1;
7483  
7484 +       server->client->cl_tag = 0;
7485 +       if (server->flags & NFS_MOUNT_TAGGED)
7486 +               server->client->cl_tag = 1;
7487         return 0;
7488  }
7489  
7490 @@ -678,6 +681,10 @@ static void nfs_server_set_fsinfo(struct
7491                 server->acdirmin = server->acdirmax = 0;
7492         }
7493  
7494 +       /* FIXME: needs fsinfo
7495 +       if (server->flags & NFS_MOUNT_TAGGED)
7496 +               sb->s_flags |= MS_TAGGED;       */
7497 +
7498         server->maxfilesize = fsinfo->maxfilesize;
7499  
7500         /* We're airborne Set socket buffersize */
7501 diff -Nurp linux-2.6.22.15/fs/nfs/dir.c linux-2.6.22.15-vs2.3.0.29.1/fs/nfs/dir.c
7502 --- linux-2.6.22.15/fs/nfs/dir.c        2007-07-21 18:00:17.000000000 -0400
7503 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/nfs/dir.c   2007-12-09 06:44:21.000000000 -0500
7504 @@ -34,6 +34,7 @@
7505  #include <linux/namei.h>
7506  #include <linux/mount.h>
7507  #include <linux/sched.h>
7508 +#include <linux/vs_tag.h>
7509  
7510  #include "nfs4_fs.h"
7511  #include "delegation.h"
7512 @@ -956,6 +957,7 @@ static struct dentry *nfs_lookup(struct 
7513         if (IS_ERR(res))
7514                 goto out_unlock;
7515  
7516 +       dx_propagate_tag(nd, inode);
7517  no_entry:
7518         res = d_materialise_unique(dentry, inode);
7519         if (res != NULL) {
7520 @@ -998,7 +1000,8 @@ static int is_atomic_open(struct inode *
7521         if (nd->flags & LOOKUP_DIRECTORY)
7522                 return 0;
7523         /* Are we trying to write to a read only partition? */
7524 -       if (IS_RDONLY(dir) && (nd->intent.open.flags & (O_CREAT|O_TRUNC|FMODE_WRITE)))
7525 +       if ((IS_RDONLY(dir) || MNT_IS_RDONLY(nd->mnt)) &&
7526 +               (nd->intent.open.flags & (O_CREAT|O_TRUNC|FMODE_WRITE)))
7527                 return 0;
7528         return 1;
7529  }
7530 diff -Nurp linux-2.6.22.15/fs/nfs/inode.c linux-2.6.22.15-vs2.3.0.29.1/fs/nfs/inode.c
7531 --- linux-2.6.22.15/fs/nfs/inode.c      2007-07-21 18:00:17.000000000 -0400
7532 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/nfs/inode.c 2007-12-09 06:44:21.000000000 -0500
7533 @@ -37,6 +37,7 @@
7534  #include <linux/vfs.h>
7535  #include <linux/inet.h>
7536  #include <linux/nfs_xdr.h>
7537 +#include <linux/vs_tag.h>
7538  
7539  #include <asm/system.h>
7540  #include <asm/uaccess.h>
7541 @@ -285,8 +286,10 @@ nfs_fhget(struct super_block *sb, struct
7542                         nfsi->change_attr = fattr->change_attr;
7543                 inode->i_size = nfs_size_to_loff_t(fattr->size);
7544                 inode->i_nlink = fattr->nlink;
7545 -               inode->i_uid = fattr->uid;
7546 -               inode->i_gid = fattr->gid;
7547 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
7548 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
7549 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
7550 +                                        /* maybe fattr->xid someday */
7551                 if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
7552                         /*
7553                          * report the blocks in 512byte units
7554 @@ -377,6 +380,8 @@ void nfs_setattr_update_inode(struct ino
7555                         inode->i_uid = attr->ia_uid;
7556                 if ((attr->ia_valid & ATTR_GID) != 0)
7557                         inode->i_gid = attr->ia_gid;
7558 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
7559 +                       inode->i_tag = attr->ia_tag;
7560                 spin_lock(&inode->i_lock);
7561                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
7562                 spin_unlock(&inode->i_lock);
7563 @@ -825,6 +830,9 @@ static int nfs_check_inode_attributes(st
7564         struct nfs_inode *nfsi = NFS_I(inode);
7565         loff_t cur_size, new_isize;
7566         int data_unstable;
7567 +       uid_t uid;
7568 +       gid_t gid;
7569 +       tag_t tag;
7570  
7571  
7572         /* Has the inode gone and changed behind our back? */
7573 @@ -852,10 +860,15 @@ static int nfs_check_inode_attributes(st
7574         if (cur_size != new_isize && nfsi->npages == 0)
7575                 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
7576  
7577 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
7578 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
7579 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
7580 +
7581         /* Have any file permissions changed? */
7582         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)
7583 -                       || inode->i_uid != fattr->uid
7584 -                       || inode->i_gid != fattr->gid)
7585 +                       || inode->i_uid != uid
7586 +                       || inode->i_gid != gid
7587 +                       || inode->i_tag != tag)
7588                 nfsi->cache_validity |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
7589  
7590         /* Has the link count changed? */
7591 @@ -946,6 +959,9 @@ static int nfs_update_inode(struct inode
7592         unsigned int    invalid = 0;
7593         unsigned long now = jiffies;
7594         int data_stable;
7595 +       uid_t uid;
7596 +       gid_t gid;
7597 +       tag_t tag;
7598  
7599         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
7600                         __FUNCTION__, inode->i_sb->s_id, inode->i_ino,
7601 @@ -1022,15 +1038,21 @@ static int nfs_update_inode(struct inode
7602         }
7603         memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
7604  
7605 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
7606 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
7607 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
7608 +
7609         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO) ||
7610 -           inode->i_uid != fattr->uid ||
7611 -           inode->i_gid != fattr->gid)
7612 +           inode->i_uid != uid ||
7613 +           inode->i_gid != gid ||
7614 +           inode->i_tag != tag)
7615                 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
7616  
7617         inode->i_mode = fattr->mode;
7618         inode->i_nlink = fattr->nlink;
7619 -       inode->i_uid = fattr->uid;
7620 -       inode->i_gid = fattr->gid;
7621 +       inode->i_uid = uid;
7622 +       inode->i_gid = gid;
7623 +       inode->i_tag = tag;
7624  
7625         if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
7626                 /*
7627 diff -Nurp linux-2.6.22.15/fs/nfs/nfs3xdr.c linux-2.6.22.15-vs2.3.0.29.1/fs/nfs/nfs3xdr.c
7628 --- linux-2.6.22.15/fs/nfs/nfs3xdr.c    2007-07-21 18:00:17.000000000 -0400
7629 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/nfs/nfs3xdr.c       2007-12-09 06:44:21.000000000 -0500
7630 @@ -22,6 +22,7 @@
7631  #include <linux/nfs3.h>
7632  #include <linux/nfs_fs.h>
7633  #include <linux/nfsacl.h>
7634 +#include <linux/vs_tag.h>
7635  #include "internal.h"
7636  
7637  #define NFSDBG_FACILITY                NFSDBG_XDR
7638 @@ -178,7 +179,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
7639  }
7640  
7641  static inline __be32 *
7642 -xdr_encode_sattr(__be32 *p, struct iattr *attr)
7643 +xdr_encode_sattr(__be32 *p, struct iattr *attr, int tag)
7644  {
7645         if (attr->ia_valid & ATTR_MODE) {
7646                 *p++ = xdr_one;
7647 @@ -186,15 +187,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
7648         } else {
7649                 *p++ = xdr_zero;
7650         }
7651 -       if (attr->ia_valid & ATTR_UID) {
7652 +       if (attr->ia_valid & ATTR_UID ||
7653 +               (tag && (attr->ia_valid & ATTR_TAG))) {
7654                 *p++ = xdr_one;
7655 -               *p++ = htonl(attr->ia_uid);
7656 +               *p++ = htonl(TAGINO_UID(tag, attr->ia_uid, attr->ia_tag));
7657         } else {
7658                 *p++ = xdr_zero;
7659         }
7660 -       if (attr->ia_valid & ATTR_GID) {
7661 +       if (attr->ia_valid & ATTR_GID ||
7662 +               (tag && (attr->ia_valid & ATTR_TAG))) {
7663                 *p++ = xdr_one;
7664 -               *p++ = htonl(attr->ia_gid);
7665 +               *p++ = htonl(TAGINO_GID(tag, attr->ia_gid, attr->ia_tag));
7666         } else {
7667                 *p++ = xdr_zero;
7668         }
7669 @@ -279,7 +282,8 @@ static int
7670  nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args)
7671  {
7672         p = xdr_encode_fhandle(p, args->fh);
7673 -       p = xdr_encode_sattr(p, args->sattr);
7674 +       p = xdr_encode_sattr(p, args->sattr,
7675 +               req->rq_task->tk_client->cl_tag);
7676         *p++ = htonl(args->guard);
7677         if (args->guard)
7678                 p = xdr_encode_time3(p, &args->guardtime);
7679 @@ -370,7 +374,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
7680                 *p++ = args->verifier[0];
7681                 *p++ = args->verifier[1];
7682         } else
7683 -               p = xdr_encode_sattr(p, args->sattr);
7684 +               p = xdr_encode_sattr(p, args->sattr,
7685 +                       req->rq_task->tk_client->cl_tag);
7686  
7687         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
7688         return 0;
7689 @@ -384,7 +389,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
7690  {
7691         p = xdr_encode_fhandle(p, args->fh);
7692         p = xdr_encode_array(p, args->name, args->len);
7693 -       p = xdr_encode_sattr(p, args->sattr);
7694 +       p = xdr_encode_sattr(p, args->sattr,
7695 +               req->rq_task->tk_client->cl_tag);
7696         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
7697         return 0;
7698  }
7699 @@ -397,7 +403,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
7700  {
7701         p = xdr_encode_fhandle(p, args->fromfh);
7702         p = xdr_encode_array(p, args->fromname, args->fromlen);
7703 -       p = xdr_encode_sattr(p, args->sattr);
7704 +       p = xdr_encode_sattr(p, args->sattr,
7705 +               req->rq_task->tk_client->cl_tag);
7706         *p++ = htonl(args->pathlen);
7707         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
7708  
7709 @@ -415,7 +422,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
7710         p = xdr_encode_fhandle(p, args->fh);
7711         p = xdr_encode_array(p, args->name, args->len);
7712         *p++ = htonl(args->type);
7713 -       p = xdr_encode_sattr(p, args->sattr);
7714 +       p = xdr_encode_sattr(p, args->sattr,
7715 +               req->rq_task->tk_client->cl_tag);
7716         if (args->type == NF3CHR || args->type == NF3BLK) {
7717                 *p++ = htonl(MAJOR(args->rdev));
7718                 *p++ = htonl(MINOR(args->rdev));
7719 diff -Nurp linux-2.6.22.15/fs/nfs/nfsroot.c linux-2.6.22.15-vs2.3.0.29.1/fs/nfs/nfsroot.c
7720 --- linux-2.6.22.15/fs/nfs/nfsroot.c    2007-07-21 18:00:17.000000000 -0400
7721 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/nfs/nfsroot.c       2007-12-09 06:44:21.000000000 -0500
7722 @@ -118,12 +118,12 @@ static int mount_port __initdata = 0;             /
7723  enum {
7724         /* Options that take integer arguments */
7725         Opt_port, Opt_rsize, Opt_wsize, Opt_timeo, Opt_retrans, Opt_acregmin,
7726 -       Opt_acregmax, Opt_acdirmin, Opt_acdirmax,
7727 +       Opt_acregmax, Opt_acdirmin, Opt_acdirmax, Opt_tagid,
7728         /* Options that take no arguments */
7729         Opt_soft, Opt_hard, Opt_intr,
7730         Opt_nointr, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac, 
7731         Opt_noac, Opt_lock, Opt_nolock, Opt_v2, Opt_v3, Opt_udp, Opt_tcp,
7732 -       Opt_acl, Opt_noacl,
7733 +       Opt_acl, Opt_noacl, Opt_tag, Opt_notag,
7734         /* Error token */
7735         Opt_err
7736  };
7737 @@ -160,6 +160,9 @@ static match_table_t __initdata tokens =
7738         {Opt_tcp, "tcp"},
7739         {Opt_acl, "acl"},
7740         {Opt_noacl, "noacl"},
7741 +       {Opt_tag, "tag"},
7742 +       {Opt_notag, "notag"},
7743 +       {Opt_tagid, "tagid=%u"},
7744         {Opt_err, NULL}
7745         
7746  };
7747 @@ -274,6 +277,20 @@ static int __init root_nfs_parse(char *n
7748                         case Opt_noacl:
7749                                 nfs_data.flags |= NFS_MOUNT_NOACL;
7750                                 break;
7751 +#ifndef CONFIG_TAGGING_NONE
7752 +                       case Opt_tag:
7753 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
7754 +                               break;
7755 +                       case Opt_notag:
7756 +                               nfs_data.flags &= ~NFS_MOUNT_TAGGED;
7757 +                               break;
7758 +#endif
7759 +#ifdef CONFIG_PROPAGATE
7760 +                       case Opt_tagid:
7761 +                               /* use args[0] */
7762 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
7763 +                               break;
7764 +#endif
7765                         default:
7766                                 printk(KERN_WARNING "Root-NFS: unknown "
7767                                         "option: %s\n", p);
7768 diff -Nurp linux-2.6.22.15/fs/nfs/super.c linux-2.6.22.15-vs2.3.0.29.1/fs/nfs/super.c
7769 --- linux-2.6.22.15/fs/nfs/super.c      2007-09-29 08:11:49.000000000 -0400
7770 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/nfs/super.c 2007-12-09 06:44:21.000000000 -0500
7771 @@ -45,6 +45,7 @@
7772  #include <linux/nfs_xdr.h>
7773  #include <linux/magic.h>
7774  #include <linux/parser.h>
7775 +#include <linux/vs_tag.h>
7776  
7777  #include <asm/system.h>
7778  #include <asm/uaccess.h>
7779 @@ -291,6 +292,7 @@ static void nfs_show_mount_options(struc
7780                 { NFS_MOUNT_NOACL, ",noacl", "" },
7781                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
7782                 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
7783 +               { NFS_MOUNT_TAGGED, ",tag", "" },
7784                 { 0, NULL, NULL }
7785         };
7786         const struct proc_nfs_info *nfs_infop;
7787 diff -Nurp linux-2.6.22.15/fs/nfsd/auth.c linux-2.6.22.15-vs2.3.0.29.1/fs/nfsd/auth.c
7788 --- linux-2.6.22.15/fs/nfsd/auth.c      2006-06-17 21:49:35.000000000 -0400
7789 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/nfsd/auth.c 2007-12-09 06:44:21.000000000 -0500
7790 @@ -9,6 +9,7 @@
7791  #include <linux/sunrpc/svc.h>
7792  #include <linux/sunrpc/svcauth.h>
7793  #include <linux/nfsd/nfsd.h>
7794 +#include <linux/vs_tag.h>
7795  
7796  #define        CAP_NFSD_MASK (CAP_FS_MASK|CAP_TO_MASK(CAP_SYS_RESOURCE))
7797  
7798 @@ -41,19 +42,22 @@ int nfsd_setuser(struct svc_rqst *rqstp,
7799                 get_group_info(cred.cr_group_info);
7800  
7801         if (cred.cr_uid != (uid_t) -1)
7802 -               current->fsuid = cred.cr_uid;
7803 +               current->fsuid = INOTAG_UID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid);
7804         else
7805                 current->fsuid = exp->ex_anon_uid;
7806         if (cred.cr_gid != (gid_t) -1)
7807 -               current->fsgid = cred.cr_gid;
7808 +               current->fsgid = INOTAG_GID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid);
7809         else
7810                 current->fsgid = exp->ex_anon_gid;
7811  
7812 +       /* this desperately needs a tag :) */
7813 +       current->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
7814 +
7815         if (!cred.cr_group_info)
7816                 return -ENOMEM;
7817         ret = set_current_groups(cred.cr_group_info);
7818         put_group_info(cred.cr_group_info);
7819 -       if ((cred.cr_uid)) {
7820 +       if (INOTAG_UID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid)) {
7821                 cap_t(current->cap_effective) &= ~CAP_NFSD_MASK;
7822         } else {
7823                 cap_t(current->cap_effective) |= (CAP_NFSD_MASK &
7824 diff -Nurp linux-2.6.22.15/fs/nfsd/nfs3xdr.c linux-2.6.22.15-vs2.3.0.29.1/fs/nfsd/nfs3xdr.c
7825 --- linux-2.6.22.15/fs/nfsd/nfs3xdr.c   2007-07-21 18:00:17.000000000 -0400
7826 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/nfsd/nfs3xdr.c      2007-12-09 06:44:21.000000000 -0500
7827 @@ -21,6 +21,7 @@
7828  #include <linux/sunrpc/svc.h>
7829  #include <linux/nfsd/nfsd.h>
7830  #include <linux/nfsd/xdr3.h>
7831 +#include <linux/vs_tag.h>
7832  
7833  #define NFSDDBG_FACILITY               NFSDDBG_XDR
7834  
7835 @@ -107,6 +108,8 @@ static __be32 *
7836  decode_sattr3(__be32 *p, struct iattr *iap)
7837  {
7838         u32     tmp;
7839 +       uid_t   uid = 0;
7840 +       gid_t   gid = 0;
7841  
7842         iap->ia_valid = 0;
7843  
7844 @@ -116,12 +119,15 @@ decode_sattr3(__be32 *p, struct iattr *i
7845         }
7846         if (*p++) {
7847                 iap->ia_valid |= ATTR_UID;
7848 -               iap->ia_uid = ntohl(*p++);
7849 +               uid = ntohl(*p++);
7850         }
7851         if (*p++) {
7852                 iap->ia_valid |= ATTR_GID;
7853 -               iap->ia_gid = ntohl(*p++);
7854 +               gid = ntohl(*p++);
7855         }
7856 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
7857 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
7858 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
7859         if (*p++) {
7860                 u64     newsize;
7861  
7862 @@ -180,8 +186,10 @@ encode_fattr3(struct svc_rqst *rqstp, __
7863         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
7864         *p++ = htonl((u32) stat->mode);
7865         *p++ = htonl((u32) stat->nlink);
7866 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
7867 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
7868 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
7869 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
7870 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
7871 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
7872         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
7873                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
7874         } else {
7875 diff -Nurp linux-2.6.22.15/fs/nfsd/nfs4recover.c linux-2.6.22.15-vs2.3.0.29.1/fs/nfsd/nfs4recover.c
7876 --- linux-2.6.22.15/fs/nfsd/nfs4recover.c       2007-07-21 18:00:17.000000000 -0400
7877 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/nfsd/nfs4recover.c  2007-12-09 06:44:21.000000000 -0500
7878 @@ -156,7 +156,7 @@ nfsd4_create_clid_dir(struct nfs4_client
7879                 dprintk("NFSD: nfsd4_create_clid_dir: DIRECTORY EXISTS\n");
7880                 goto out_put;
7881         }
7882 -       status = vfs_mkdir(rec_dir.dentry->d_inode, dentry, S_IRWXU);
7883 +       status = vfs_mkdir(rec_dir.dentry->d_inode, dentry, S_IRWXU, NULL);
7884  out_put:
7885         dput(dentry);
7886  out_unlock:
7887 @@ -260,7 +260,7 @@ nfsd4_remove_clid_file(struct dentry *di
7888                 return -EINVAL;
7889         }
7890         mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
7891 -       status = vfs_unlink(dir->d_inode, dentry);
7892 +       status = vfs_unlink(dir->d_inode, dentry, NULL);
7893         mutex_unlock(&dir->d_inode->i_mutex);
7894         return status;
7895  }
7896 @@ -275,7 +275,7 @@ nfsd4_clear_clid_dir(struct dentry *dir,
7897          * a kernel from the future.... */
7898         nfsd4_list_rec_dir(dentry, nfsd4_remove_clid_file);
7899         mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
7900 -       status = vfs_rmdir(dir->d_inode, dentry);
7901 +       status = vfs_rmdir(dir->d_inode, dentry, NULL);
7902         mutex_unlock(&dir->d_inode->i_mutex);
7903         return status;
7904  }
7905 diff -Nurp linux-2.6.22.15/fs/nfsd/nfs4xdr.c linux-2.6.22.15-vs2.3.0.29.1/fs/nfsd/nfs4xdr.c
7906 --- linux-2.6.22.15/fs/nfsd/nfs4xdr.c   2007-07-21 18:00:17.000000000 -0400
7907 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/nfsd/nfs4xdr.c      2007-12-09 06:44:21.000000000 -0500
7908 @@ -56,6 +56,7 @@
7909  #include <linux/nfs4_acl.h>
7910  #include <linux/sunrpc/gss_api.h>
7911  #include <linux/sunrpc/svcauth_gss.h>
7912 +#include <linux/vs_tag.h>
7913  
7914  #define NFSDDBG_FACILITY               NFSDDBG_XDR
7915  
7916 @@ -1727,14 +1728,18 @@ out_acl:
7917                 WRITE32(stat.nlink);
7918         }
7919         if (bmval1 & FATTR4_WORD1_OWNER) {
7920 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
7921 +               status = nfsd4_encode_user(rqstp,
7922 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
7923 +                       stat.uid, stat.tag), &p, &buflen);
7924                 if (status == nfserr_resource)
7925                         goto out_resource;
7926                 if (status)
7927                         goto out;
7928         }
7929         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
7930 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
7931 +               status = nfsd4_encode_group(rqstp,
7932 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
7933 +                       stat.gid, stat.tag), &p, &buflen);
7934                 if (status == nfserr_resource)
7935                         goto out_resource;
7936                 if (status)
7937 diff -Nurp linux-2.6.22.15/fs/nfsd/nfsxdr.c linux-2.6.22.15-vs2.3.0.29.1/fs/nfsd/nfsxdr.c
7938 --- linux-2.6.22.15/fs/nfsd/nfsxdr.c    2007-07-21 18:00:17.000000000 -0400
7939 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/nfsd/nfsxdr.c       2007-12-09 06:44:21.000000000 -0500
7940 @@ -15,6 +15,7 @@
7941  #include <linux/nfsd/nfsd.h>
7942  #include <linux/nfsd/xdr.h>
7943  #include <linux/mm.h>
7944 +#include <linux/vs_tag.h>
7945  
7946  #define NFSDDBG_FACILITY               NFSDDBG_XDR
7947  
7948 @@ -97,6 +98,8 @@ static __be32 *
7949  decode_sattr(__be32 *p, struct iattr *iap)
7950  {
7951         u32     tmp, tmp1;
7952 +       uid_t   uid = 0;
7953 +       gid_t   gid = 0;
7954  
7955         iap->ia_valid = 0;
7956  
7957 @@ -110,12 +113,15 @@ decode_sattr(__be32 *p, struct iattr *ia
7958         }
7959         if ((tmp = ntohl(*p++)) != (u32)-1) {
7960                 iap->ia_valid |= ATTR_UID;
7961 -               iap->ia_uid = tmp;
7962 +               uid = tmp;
7963         }
7964         if ((tmp = ntohl(*p++)) != (u32)-1) {
7965                 iap->ia_valid |= ATTR_GID;
7966 -               iap->ia_gid = tmp;
7967 +               gid = tmp;
7968         }
7969 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
7970 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
7971 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
7972         if ((tmp = ntohl(*p++)) != (u32)-1) {
7973                 iap->ia_valid |= ATTR_SIZE;
7974                 iap->ia_size = tmp;
7975 @@ -160,8 +166,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
7976         *p++ = htonl(nfs_ftypes[type >> 12]);
7977         *p++ = htonl((u32) stat->mode);
7978         *p++ = htonl((u32) stat->nlink);
7979 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
7980 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
7981 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
7982 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
7983 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
7984 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
7985  
7986         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
7987                 *p++ = htonl(NFS_MAXPATHLEN);
7988 diff -Nurp linux-2.6.22.15/fs/nfsd/vfs.c linux-2.6.22.15-vs2.3.0.29.1/fs/nfsd/vfs.c
7989 --- linux-2.6.22.15/fs/nfsd/vfs.c       2007-08-11 21:54:36.000000000 -0400
7990 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/nfsd/vfs.c  2007-12-09 06:44:21.000000000 -0500
7991 @@ -1186,13 +1186,13 @@ nfsd_create(struct svc_rqst *rqstp, stru
7992                 host_err = vfs_create(dirp, dchild, iap->ia_mode, NULL);
7993                 break;
7994         case S_IFDIR:
7995 -               host_err = vfs_mkdir(dirp, dchild, iap->ia_mode);
7996 +               host_err = vfs_mkdir(dirp, dchild, iap->ia_mode, NULL);
7997                 break;
7998         case S_IFCHR:
7999         case S_IFBLK:
8000         case S_IFIFO:
8001         case S_IFSOCK:
8002 -               host_err = vfs_mknod(dirp, dchild, iap->ia_mode, rdev);
8003 +               host_err = vfs_mknod(dirp, dchild, iap->ia_mode, rdev, NULL);
8004                 break;
8005         default:
8006                 printk("nfsd: bad file type %o in nfsd_create\n", type);
8007 @@ -1466,11 +1466,13 @@ nfsd_symlink(struct svc_rqst *rqstp, str
8008                 else {
8009                         strncpy(path_alloced, path, plen);
8010                         path_alloced[plen] = 0;
8011 -                       host_err = vfs_symlink(dentry->d_inode, dnew, path_alloced, mode);
8012 +                       host_err = vfs_symlink(dentry->d_inode, dnew,
8013 +                               path_alloced, mode, NULL);
8014                         kfree(path_alloced);
8015                 }
8016         } else
8017 -               host_err = vfs_symlink(dentry->d_inode, dnew, path, mode);
8018 +               host_err = vfs_symlink(dentry->d_inode, dnew,
8019 +                       path, mode, NULL);
8020  
8021         if (!host_err) {
8022                 if (EX_ISSYNC(fhp->fh_export))
8023 @@ -1529,7 +1531,7 @@ nfsd_link(struct svc_rqst *rqstp, struct
8024         dold = tfhp->fh_dentry;
8025         dest = dold->d_inode;
8026  
8027 -       host_err = vfs_link(dold, dirp, dnew);
8028 +       host_err = vfs_link(dold, dirp, dnew, NULL);
8029         if (!host_err) {
8030                 if (EX_ISSYNC(ffhp->fh_export)) {
8031                         err = nfserrno(nfsd_sync_dir(ddir));
8032 @@ -1694,9 +1696,9 @@ nfsd_unlink(struct svc_rqst *rqstp, stru
8033                         host_err = -EPERM;
8034                 } else
8035  #endif
8036 -               host_err = vfs_unlink(dirp, rdentry);
8037 +               host_err = vfs_unlink(dirp, rdentry, NULL);
8038         } else { /* It's RMDIR */
8039 -               host_err = vfs_rmdir(dirp, rdentry);
8040 +               host_err = vfs_rmdir(dirp, rdentry, NULL);
8041         }
8042  
8043         dput(rdentry);
8044 @@ -1807,7 +1809,8 @@ nfsd_permission(struct svc_export *exp, 
8045          */
8046         if (!(acc & MAY_LOCAL_ACCESS))
8047                 if (acc & (MAY_WRITE | MAY_SATTR | MAY_TRUNC)) {
8048 -                       if (EX_RDONLY(exp, rqstp) || IS_RDONLY(inode))
8049 +                       if (EX_RDONLY(exp, rqstp) || IS_RDONLY(inode)
8050 +                               || MNT_IS_RDONLY(exp->ex_mnt))
8051                                 return nfserr_rofs;
8052                         if (/* (acc & MAY_WRITE) && */ IS_IMMUTABLE(inode))
8053                                 return nfserr_perm;
8054 diff -Nurp linux-2.6.22.15/fs/ocfs2/dlm/dlmfs.c linux-2.6.22.15-vs2.3.0.29.1/fs/ocfs2/dlm/dlmfs.c
8055 --- linux-2.6.22.15/fs/ocfs2/dlm/dlmfs.c        2007-07-21 18:00:17.000000000 -0400
8056 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ocfs2/dlm/dlmfs.c   2007-12-09 06:44:21.000000000 -0500
8057 @@ -43,6 +43,7 @@
8058  #include <linux/init.h>
8059  #include <linux/string.h>
8060  #include <linux/backing-dev.h>
8061 +#include <linux/vs_tag.h>
8062  
8063  #include <asm/uaccess.h>
8064  
8065 @@ -331,6 +332,7 @@ static struct inode *dlmfs_get_root_inod
8066                 inode->i_mode = mode;
8067                 inode->i_uid = current->fsuid;
8068                 inode->i_gid = current->fsgid;
8069 +               inode->i_tag = dx_current_fstag(sb);
8070                 inode->i_blocks = 0;
8071                 inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
8072                 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
8073 @@ -357,6 +359,7 @@ static struct inode *dlmfs_get_inode(str
8074         inode->i_mode = mode;
8075         inode->i_uid = current->fsuid;
8076         inode->i_gid = current->fsgid;
8077 +       inode->i_tag = dx_current_fstag(sb);
8078         inode->i_blocks = 0;
8079         inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
8080         inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
8081 diff -Nurp linux-2.6.22.15/fs/ocfs2/dlmglue.c linux-2.6.22.15-vs2.3.0.29.1/fs/ocfs2/dlmglue.c
8082 --- linux-2.6.22.15/fs/ocfs2/dlmglue.c  2007-07-21 18:00:18.000000000 -0400
8083 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ocfs2/dlmglue.c     2007-12-09 06:44:21.000000000 -0500
8084 @@ -1475,6 +1475,7 @@ static void __ocfs2_stuff_meta_lvb(struc
8085         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
8086         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
8087         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
8088 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
8089         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
8090         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
8091         lvb->lvb_iatime_packed  =
8092 @@ -1527,6 +1528,7 @@ static void ocfs2_refresh_inode_from_lvb
8093  
8094         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
8095         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
8096 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
8097         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
8098         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
8099         ocfs2_unpack_timespec(&inode->i_atime,
8100 diff -Nurp linux-2.6.22.15/fs/ocfs2/dlmglue.h linux-2.6.22.15-vs2.3.0.29.1/fs/ocfs2/dlmglue.h
8101 --- linux-2.6.22.15/fs/ocfs2/dlmglue.h  2007-07-21 18:00:18.000000000 -0400
8102 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ocfs2/dlmglue.h     2007-12-09 06:44:21.000000000 -0500
8103 @@ -34,7 +34,7 @@
8104  struct ocfs2_meta_lvb {
8105         __u8         lvb_version;
8106         __u8         lvb_reserved0;
8107 -       __be16       lvb_reserved1;
8108 +       __be16       lvb_itag;
8109         __be32       lvb_iclusters;
8110         __be32       lvb_iuid;
8111         __be32       lvb_igid;
8112 diff -Nurp linux-2.6.22.15/fs/ocfs2/file.c linux-2.6.22.15-vs2.3.0.29.1/fs/ocfs2/file.c
8113 --- linux-2.6.22.15/fs/ocfs2/file.c     2007-09-05 01:07:59.000000000 -0400
8114 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ocfs2/file.c        2007-12-09 06:44:21.000000000 -0500
8115 @@ -943,13 +943,15 @@ int ocfs2_setattr(struct dentry *dentry,
8116                 mlog(0, "uid change: %d\n", attr->ia_uid);
8117         if (attr->ia_valid & ATTR_GID)
8118                 mlog(0, "gid change: %d\n", attr->ia_gid);
8119 +       if (attr->ia_valid & ATTR_TAG)
8120 +               mlog(0, "tag change: %d\n", attr->ia_tag);
8121         if (attr->ia_valid & ATTR_SIZE)
8122                 mlog(0, "size change...\n");
8123         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
8124                 mlog(0, "time change...\n");
8125  
8126  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
8127 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
8128 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
8129         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
8130                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
8131                 return 0;
8132 @@ -1805,6 +1807,7 @@ bail:
8133  const struct inode_operations ocfs2_file_iops = {
8134         .setattr        = ocfs2_setattr,
8135         .getattr        = ocfs2_getattr,
8136 +       .sync_flags     = ocfs2_sync_flags,
8137         .permission     = ocfs2_permission,
8138  };
8139  
8140 diff -Nurp linux-2.6.22.15/fs/ocfs2/inode.c linux-2.6.22.15-vs2.3.0.29.1/fs/ocfs2/inode.c
8141 --- linux-2.6.22.15/fs/ocfs2/inode.c    2007-07-21 18:00:18.000000000 -0400
8142 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ocfs2/inode.c       2007-12-09 06:44:21.000000000 -0500
8143 @@ -28,6 +28,7 @@
8144  #include <linux/slab.h>
8145  #include <linux/highmem.h>
8146  #include <linux/pagemap.h>
8147 +#include <linux/vs_tag.h>
8148  
8149  #include <asm/byteorder.h>
8150  
8151 @@ -42,6 +43,7 @@
8152  #include "file.h"
8153  #include "heartbeat.h"
8154  #include "inode.h"
8155 +#include "ioctl.h"
8156  #include "journal.h"
8157  #include "namei.h"
8158  #include "suballoc.h"
8159 @@ -77,6 +79,10 @@ void ocfs2_set_inode_flags(struct inode 
8160  
8161         if (flags & OCFS2_IMMUTABLE_FL)
8162                 inode->i_flags |= S_IMMUTABLE;
8163 +       if (flags & OCFS2_IUNLINK_FL)
8164 +               inode->i_flags |= S_IUNLINK;
8165 +       if (flags & OCFS2_BARRIER_FL)
8166 +               inode->i_flags |= S_BARRIER;
8167  
8168         if (flags & OCFS2_SYNC_FL)
8169                 inode->i_flags |= S_SYNC;
8170 @@ -107,6 +113,27 @@ void ocfs2_get_inode_flags(struct ocfs2_
8171                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
8172  }
8173  
8174 +int ocfs2_sync_flags(struct inode *inode)
8175 +{
8176 +       unsigned int oldflags, newflags;
8177 +
8178 +       oldflags = OCFS2_I(inode)->ip_flags;
8179 +       newflags = oldflags & ~(OCFS2_IMMUTABLE_FL |
8180 +               OCFS2_IUNLINK_FL | OCFS2_BARRIER_FL);
8181 +
8182 +       if (IS_IMMUTABLE(inode))
8183 +               newflags |= OCFS2_IMMUTABLE_FL;
8184 +       if (IS_IUNLINK(inode))
8185 +               newflags |= OCFS2_IUNLINK_FL;
8186 +       if (IS_BARRIER(inode))
8187 +               newflags |= OCFS2_BARRIER_FL;
8188 +
8189 +       if (oldflags ^ newflags)
8190 +               return ocfs2_set_inode_attr(inode,
8191 +                       newflags, OCFS2_FL_MASK);
8192 +       return 0;
8193 +}
8194 +
8195  struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 blkno, int flags)
8196  {
8197         struct inode *inode = NULL;
8198 @@ -212,6 +239,8 @@ int ocfs2_populate_inode(struct inode *i
8199         struct super_block *sb;
8200         struct ocfs2_super *osb;
8201         int status = -EINVAL;
8202 +       uid_t uid;
8203 +       gid_t gid;
8204  
8205         mlog_entry("(0x%p, size:%llu)\n", inode,
8206                    (unsigned long long)le64_to_cpu(fe->i_size));
8207 @@ -246,8 +275,12 @@ int ocfs2_populate_inode(struct inode *i
8208         inode->i_generation = le32_to_cpu(fe->i_generation);
8209         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
8210         inode->i_mode = le16_to_cpu(fe->i_mode);
8211 -       inode->i_uid = le32_to_cpu(fe->i_uid);
8212 -       inode->i_gid = le32_to_cpu(fe->i_gid);
8213 +       uid = le32_to_cpu(fe->i_uid);
8214 +       gid = le32_to_cpu(fe->i_gid);
8215 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
8216 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
8217 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
8218 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
8219  
8220         /* Fast symlinks will have i_size but no allocated clusters. */
8221         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
8222 @@ -1224,8 +1257,11 @@ int ocfs2_mark_inode_dirty(handle_t *han
8223  
8224         fe->i_size = cpu_to_le64(i_size_read(inode));
8225         fe->i_links_count = cpu_to_le16(inode->i_nlink);
8226 -       fe->i_uid = cpu_to_le32(inode->i_uid);
8227 -       fe->i_gid = cpu_to_le32(inode->i_gid);
8228 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode),
8229 +               inode->i_uid, inode->i_tag));
8230 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode),
8231 +               inode->i_gid, inode->i_tag));
8232 +       /* i_tag = = cpu_to_le16(inode->i_tag); */
8233         fe->i_mode = cpu_to_le16(inode->i_mode);
8234         fe->i_atime = cpu_to_le64(inode->i_atime.tv_sec);
8235         fe->i_atime_nsec = cpu_to_le32(inode->i_atime.tv_nsec);
8236 @@ -1253,15 +1289,24 @@ leave:
8237  void ocfs2_refresh_inode(struct inode *inode,
8238                          struct ocfs2_dinode *fe)
8239  {
8240 +       uid_t uid;
8241 +       gid_t gid;
8242 +
8243         spin_lock(&OCFS2_I(inode)->ip_lock);
8244  
8245         OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters);
8246         OCFS2_I(inode)->ip_attr = le32_to_cpu(fe->i_attr);
8247 +       /* OCFS2_I(inode)->ip_flags &= ~OCFS2_FL_MASK;
8248 +          OCFS2_I(inode)->ip_flags |= le32_to_cpu(fe->i_flags) & OCFS2_FL_MASK; */
8249         ocfs2_set_inode_flags(inode);
8250         i_size_write(inode, le64_to_cpu(fe->i_size));
8251         inode->i_nlink = le16_to_cpu(fe->i_links_count);
8252 -       inode->i_uid = le32_to_cpu(fe->i_uid);
8253 -       inode->i_gid = le32_to_cpu(fe->i_gid);
8254 +       uid = le32_to_cpu(fe->i_uid);
8255 +       gid = le32_to_cpu(fe->i_gid);
8256 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
8257 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
8258 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
8259 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
8260         inode->i_mode = le16_to_cpu(fe->i_mode);
8261         if (S_ISLNK(inode->i_mode) && le32_to_cpu(fe->i_clusters) == 0)
8262                 inode->i_blocks = 0;
8263 diff -Nurp linux-2.6.22.15/fs/ocfs2/inode.h linux-2.6.22.15-vs2.3.0.29.1/fs/ocfs2/inode.h
8264 --- linux-2.6.22.15/fs/ocfs2/inode.h    2007-07-21 18:00:18.000000000 -0400
8265 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ocfs2/inode.h       2007-12-09 06:44:21.000000000 -0500
8266 @@ -142,6 +142,7 @@ int ocfs2_aio_write(struct file *file, s
8267  
8268  void ocfs2_set_inode_flags(struct inode *inode);
8269  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
8270 +int ocfs2_sync_flags(struct inode *inode);
8271  
8272  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
8273  {
8274 diff -Nurp linux-2.6.22.15/fs/ocfs2/ioctl.c linux-2.6.22.15-vs2.3.0.29.1/fs/ocfs2/ioctl.c
8275 --- linux-2.6.22.15/fs/ocfs2/ioctl.c    2007-07-21 18:00:18.000000000 -0400
8276 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ocfs2/ioctl.c       2007-12-09 06:44:21.000000000 -0500
8277 @@ -39,7 +39,7 @@ static int ocfs2_get_inode_attr(struct i
8278         return status;
8279  }
8280  
8281 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
8282 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
8283                                 unsigned mask)
8284  {
8285         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
8286 diff -Nurp linux-2.6.22.15/fs/ocfs2/ioctl.h linux-2.6.22.15-vs2.3.0.29.1/fs/ocfs2/ioctl.h
8287 --- linux-2.6.22.15/fs/ocfs2/ioctl.h    2007-07-21 18:00:18.000000000 -0400
8288 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ocfs2/ioctl.h       2007-12-09 06:44:21.000000000 -0500
8289 @@ -10,6 +10,9 @@
8290  #ifndef OCFS2_IOCTL_H
8291  #define OCFS2_IOCTL_H
8292  
8293 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
8294 +                               unsigned mask);
8295 +
8296  int ocfs2_ioctl(struct inode * inode, struct file * filp,
8297         unsigned int cmd, unsigned long arg);
8298  long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg);
8299 diff -Nurp linux-2.6.22.15/fs/ocfs2/namei.c linux-2.6.22.15-vs2.3.0.29.1/fs/ocfs2/namei.c
8300 --- linux-2.6.22.15/fs/ocfs2/namei.c    2007-07-21 18:00:18.000000000 -0400
8301 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ocfs2/namei.c       2007-12-09 06:44:21.000000000 -0500
8302 @@ -40,6 +40,7 @@
8303  #include <linux/types.h>
8304  #include <linux/slab.h>
8305  #include <linux/highmem.h>
8306 +#include <linux/vs_tag.h>
8307  
8308  #define MLOG_MASK_PREFIX ML_NAMEI
8309  #include <cluster/masklog.h>
8310 @@ -483,6 +484,9 @@ static int ocfs2_mknod_locked(struct ocf
8311         u64 fe_blkno = 0;
8312         u16 suballoc_bit;
8313         struct inode *inode = NULL;
8314 +       uid_t uid;
8315 +       gid_t gid;
8316 +       tag_t tag;
8317  
8318         mlog_entry("(0x%p, 0x%p, %d, %lu, '%.*s')\n", dir, dentry, mode,
8319                    (unsigned long)dev, dentry->d_name.len,
8320 @@ -542,13 +546,19 @@ static int ocfs2_mknod_locked(struct ocf
8321         fe->i_blkno = cpu_to_le64(fe_blkno);
8322         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
8323         fe->i_suballoc_slot = cpu_to_le16(osb->slot_num);
8324 -       fe->i_uid = cpu_to_le32(current->fsuid);
8325 +
8326 +       tag = dx_current_fstag(osb->sb);
8327 +       uid = current->fsuid;
8328         if (dir->i_mode & S_ISGID) {
8329 -               fe->i_gid = cpu_to_le32(dir->i_gid);
8330 +               gid = dir->i_gid;
8331                 if (S_ISDIR(mode))
8332                         mode |= S_ISGID;
8333         } else
8334 -               fe->i_gid = cpu_to_le32(current->fsgid);
8335 +               gid = current->fsgid;
8336 +
8337 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), uid, tag));
8338 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), gid, tag));
8339 +       inode->i_tag = tag;
8340         fe->i_mode = cpu_to_le16(mode);
8341         if (S_ISCHR(mode) || S_ISBLK(mode))
8342                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
8343 @@ -2316,5 +2326,6 @@ const struct inode_operations ocfs2_dir_
8344         .rename         = ocfs2_rename,
8345         .setattr        = ocfs2_setattr,
8346         .getattr        = ocfs2_getattr,
8347 +       .sync_flags     = ocfs2_sync_flags,
8348         .permission     = ocfs2_permission,
8349  };
8350 diff -Nurp linux-2.6.22.15/fs/ocfs2/ocfs2_fs.h linux-2.6.22.15-vs2.3.0.29.1/fs/ocfs2/ocfs2_fs.h
8351 --- linux-2.6.22.15/fs/ocfs2/ocfs2_fs.h 2007-07-21 18:00:18.000000000 -0400
8352 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ocfs2/ocfs2_fs.h    2007-12-09 06:44:21.000000000 -0500
8353 @@ -152,8 +152,12 @@
8354  #define OCFS2_NOATIME_FL       (0x00000080)    /* do not update atime */
8355  #define OCFS2_DIRSYNC_FL       (0x00010000)    /* dirsync behaviour (directories only) */
8356  
8357 +#define OCFS2_BARRIER_FL       (0x04000000)    /* Barrier for chroot() */
8358 +#define OCFS2_IUNLINK_FL       (0x08000000)    /* Immutable unlink */
8359 +
8360  #define OCFS2_FL_VISIBLE       (0x000100FF)    /* User visible flags */
8361  #define OCFS2_FL_MODIFIABLE    (0x000100FF)    /* User modifiable flags */
8362 +#define OCFS2_FL_MASK          (0x0F0100FF)
8363  
8364  /*
8365   * Extent record flags (e_node.leaf.flags)
8366 diff -Nurp linux-2.6.22.15/fs/ocfs2/ocfs2.h linux-2.6.22.15-vs2.3.0.29.1/fs/ocfs2/ocfs2.h
8367 --- linux-2.6.22.15/fs/ocfs2/ocfs2.h    2007-07-21 18:00:18.000000000 -0400
8368 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ocfs2/ocfs2.h       2007-12-09 06:44:21.000000000 -0500
8369 @@ -170,6 +170,7 @@ enum ocfs2_mount_options
8370         OCFS2_MOUNT_NOINTR  = 1 << 2,   /* Don't catch signals */
8371         OCFS2_MOUNT_ERRORS_PANIC = 1 << 3, /* Panic on errors */
8372         OCFS2_MOUNT_DATA_WRITEBACK = 1 << 4, /* No data ordering */
8373 +       OCFS2_MOUNT_TAGGED = 1 << 8, /* use tagging */
8374  };
8375  
8376  #define OCFS2_OSB_SOFT_RO      0x0001
8377 diff -Nurp linux-2.6.22.15/fs/ocfs2/super.c linux-2.6.22.15-vs2.3.0.29.1/fs/ocfs2/super.c
8378 --- linux-2.6.22.15/fs/ocfs2/super.c    2007-07-21 18:00:18.000000000 -0400
8379 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/ocfs2/super.c       2007-12-09 06:44:21.000000000 -0500
8380 @@ -140,6 +140,7 @@ enum {
8381         Opt_data_ordered,
8382         Opt_data_writeback,
8383         Opt_atime_quantum,
8384 +       Opt_tag, Opt_notag, Opt_tagid,
8385         Opt_err,
8386  };
8387  
8388 @@ -154,6 +155,9 @@ static match_table_t tokens = {
8389         {Opt_data_ordered, "data=ordered"},
8390         {Opt_data_writeback, "data=writeback"},
8391         {Opt_atime_quantum, "atime_quantum=%u"},
8392 +       {Opt_tag, "tag"},
8393 +       {Opt_notag, "notag"},
8394 +       {Opt_tagid, "tagid=%u"},
8395         {Opt_err, NULL}
8396  };
8397  
8398 @@ -362,6 +366,13 @@ static int ocfs2_remount(struct super_bl
8399                 goto out;
8400         }
8401  
8402 +       if ((parsed_options & OCFS2_MOUNT_TAGGED) &&
8403 +               !(sb->s_flags & MS_TAGGED)) {
8404 +               ret = -EINVAL;
8405 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
8406 +               goto out;
8407 +       }
8408 +
8409         if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
8410             (parsed_options & OCFS2_MOUNT_HB_LOCAL)) {
8411                 ret = -EINVAL;
8412 @@ -654,6 +665,9 @@ static int ocfs2_fill_super(struct super
8413  
8414         ocfs2_complete_mount_recovery(osb);
8415  
8416 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
8417 +               sb->s_flags |= MS_TAGGED;
8418 +
8419         if (ocfs2_mount_local(osb))
8420                 snprintf(nodestr, sizeof(nodestr), "local");
8421         else
8422 @@ -782,6 +796,20 @@ static int ocfs2_parse_options(struct su
8423                         else
8424                                 osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
8425                         break;
8426 +#ifndef CONFIG_TAGGING_NONE
8427 +               case Opt_tag:
8428 +                       *mount_opt |= OCFS2_MOUNT_TAGGED;
8429 +                       break;
8430 +               case Opt_notag:
8431 +                       *mount_opt &= ~OCFS2_MOUNT_TAGGED;
8432 +                       break;
8433 +#endif
8434 +#ifdef CONFIG_PROPAGATE
8435 +               case Opt_tagid:
8436 +                       /* use args[0] */
8437 +                       *mount_opt |= OCFS2_MOUNT_TAGGED;
8438 +                       break;
8439 +#endif
8440                 default:
8441                         mlog(ML_ERROR,
8442                              "Unrecognized mount option \"%s\" "
8443 diff -Nurp linux-2.6.22.15/fs/open.c linux-2.6.22.15-vs2.3.0.29.1/fs/open.c
8444 --- linux-2.6.22.15/fs/open.c   2007-07-21 18:00:18.000000000 -0400
8445 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/open.c      2007-12-09 06:44:21.000000000 -0500
8446 @@ -26,22 +26,31 @@
8447  #include <linux/syscalls.h>
8448  #include <linux/rcupdate.h>
8449  #include <linux/audit.h>
8450 +#include <linux/vs_base.h>
8451 +#include <linux/vs_limit.h>
8452 +#include <linux/vs_dlimit.h>
8453 +#include <linux/vs_tag.h>
8454 +#include <linux/vs_cowbl.h>
8455  
8456  int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
8457  {
8458         int retval = -ENODEV;
8459  
8460         if (dentry) {
8461 +               struct super_block *sb = dentry->d_sb;
8462 +
8463                 retval = -ENOSYS;
8464 -               if (dentry->d_sb->s_op->statfs) {
8465 +               if (sb->s_op->statfs) {
8466                         memset(buf, 0, sizeof(*buf));
8467                         retval = security_sb_statfs(dentry);
8468                         if (retval)
8469                                 return retval;
8470 -                       retval = dentry->d_sb->s_op->statfs(dentry, buf);
8471 +                       retval = sb->s_op->statfs(dentry, buf);
8472                         if (retval == 0 && buf->f_frsize == 0)
8473                                 buf->f_frsize = buf->f_bsize;
8474                 }
8475 +               if (!vx_check(0, VS_ADMIN|VS_WATCH))
8476 +                       vx_vsi_statfs(sb, buf);
8477         }
8478         return retval;
8479  }
8480 @@ -248,7 +257,7 @@ static long do_sys_truncate(const char _
8481                 goto dput_and_out;
8482  
8483         error = -EROFS;
8484 -       if (IS_RDONLY(inode))
8485 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(nd.mnt))
8486                 goto dput_and_out;
8487  
8488         error = -EPERM;
8489 @@ -397,7 +406,7 @@ asmlinkage long sys_faccessat(int dfd, c
8490            special_file(nd.dentry->d_inode->i_mode))
8491                 goto out_path_release;
8492  
8493 -       if(IS_RDONLY(nd.dentry->d_inode))
8494 +       if(IS_RDONLY(nd.dentry->d_inode) || MNT_IS_RDONLY(nd.mnt))
8495                 res = -EROFS;
8496  
8497  out_path_release:
8498 @@ -511,7 +520,7 @@ asmlinkage long sys_fchmod(unsigned int 
8499         audit_inode(NULL, inode);
8500  
8501         err = -EROFS;
8502 -       if (IS_RDONLY(inode))
8503 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(file->f_vfsmnt))
8504                 goto out_putf;
8505         err = -EPERM;
8506         if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
8507 @@ -541,11 +550,11 @@ asmlinkage long sys_fchmodat(int dfd, co
8508         error = __user_walk_fd(dfd, filename, LOOKUP_FOLLOW, &nd);
8509         if (error)
8510                 goto out;
8511 -       inode = nd.dentry->d_inode;
8512  
8513 -       error = -EROFS;
8514 -       if (IS_RDONLY(inode))
8515 +       error = cow_check_and_break(&nd);
8516 +       if (error)
8517                 goto dput_and_out;
8518 +       inode = nd.dentry->d_inode;
8519  
8520         error = -EPERM;
8521         if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
8522 @@ -570,7 +579,8 @@ asmlinkage long sys_chmod(const char __u
8523         return sys_fchmodat(AT_FDCWD, filename, mode);
8524  }
8525  
8526 -static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
8527 +static int chown_common(struct dentry *dentry, struct vfsmount *mnt,
8528 +       uid_t user, gid_t group)
8529  {
8530         struct inode * inode;
8531         int error;
8532 @@ -582,7 +592,7 @@ static int chown_common(struct dentry * 
8533                 goto out;
8534         }
8535         error = -EROFS;
8536 -       if (IS_RDONLY(inode))
8537 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(mnt))
8538                 goto out;
8539         error = -EPERM;
8540         if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
8541 @@ -590,11 +600,11 @@ static int chown_common(struct dentry * 
8542         newattrs.ia_valid =  ATTR_CTIME;
8543         if (user != (uid_t) -1) {
8544                 newattrs.ia_valid |= ATTR_UID;
8545 -               newattrs.ia_uid = user;
8546 +               newattrs.ia_uid = dx_map_uid(user);
8547         }
8548         if (group != (gid_t) -1) {
8549                 newattrs.ia_valid |= ATTR_GID;
8550 -               newattrs.ia_gid = group;
8551 +               newattrs.ia_gid = dx_map_gid(group);
8552         }
8553         if (!S_ISDIR(inode->i_mode))
8554                 newattrs.ia_valid |= ATTR_KILL_SUID|ATTR_KILL_SGID;
8555 @@ -613,7 +623,11 @@ asmlinkage long sys_chown(const char __u
8556         error = user_path_walk(filename, &nd);
8557         if (error)
8558                 goto out;
8559 -       error = chown_common(nd.dentry, user, group);
8560 +#ifdef CONFIG_VSERVER_COWBL
8561 +       error = cow_check_and_break(&nd);
8562 +       if (!error)
8563 +#endif
8564 +               error = chown_common(nd.dentry, nd.mnt, user, group);
8565         path_release(&nd);
8566  out:
8567         return error;
8568 @@ -633,7 +647,11 @@ asmlinkage long sys_fchownat(int dfd, co
8569         error = __user_walk_fd(dfd, filename, follow, &nd);
8570         if (error)
8571                 goto out;
8572 -       error = chown_common(nd.dentry, user, group);
8573 +#ifdef CONFIG_VSERVER_COWBL
8574 +       error = cow_check_and_break(&nd);
8575 +       if (!error)
8576 +#endif
8577 +               error = chown_common(nd.dentry, nd.mnt, user, group);
8578         path_release(&nd);
8579  out:
8580         return error;
8581 @@ -647,7 +665,11 @@ asmlinkage long sys_lchown(const char __
8582         error = user_path_walk_link(filename, &nd);
8583         if (error)
8584                 goto out;
8585 -       error = chown_common(nd.dentry, user, group);
8586 +#ifdef CONFIG_VSERVER_COWBL
8587 +       error = cow_check_and_break(&nd);
8588 +       if (!error)
8589 +#endif
8590 +               error = chown_common(nd.dentry, nd.mnt, user, group);
8591         path_release(&nd);
8592  out:
8593         return error;
8594 @@ -666,7 +688,7 @@ asmlinkage long sys_fchown(unsigned int 
8595  
8596         dentry = file->f_path.dentry;
8597         audit_inode(NULL, dentry->d_inode);
8598 -       error = chown_common(dentry, user, group);
8599 +       error = chown_common(dentry, file->f_vfsmnt, user, group);
8600         fput(file);
8601  out:
8602         return error;
8603 @@ -893,6 +915,7 @@ repeat:
8604         FD_SET(fd, fdt->open_fds);
8605         FD_CLR(fd, fdt->close_on_exec);
8606         files->next_fd = fd + 1;
8607 +       vx_openfd_inc(fd);
8608  #if 1
8609         /* Sanity check */
8610         if (fdt->fd[fd] != NULL) {
8611 @@ -915,6 +938,7 @@ static void __put_unused_fd(struct files
8612         __FD_CLR(fd, fdt->open_fds);
8613         if (fd < files->next_fd)
8614                 files->next_fd = fd;
8615 +       vx_openfd_dec(fd);
8616  }
8617  
8618  void fastcall put_unused_fd(unsigned int fd)
8619 diff -Nurp linux-2.6.22.15/fs/proc/array.c linux-2.6.22.15-vs2.3.0.29.1/fs/proc/array.c
8620 --- linux-2.6.22.15/fs/proc/array.c     2007-07-21 18:00:18.000000000 -0400
8621 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/proc/array.c        2007-12-09 06:44:21.000000000 -0500
8622 @@ -75,6 +75,8 @@
8623  #include <linux/cpuset.h>
8624  #include <linux/rcupdate.h>
8625  #include <linux/delayacct.h>
8626 +#include <linux/vs_context.h>
8627 +#include <linux/vs_network.h>
8628  
8629  #include <asm/uaccess.h>
8630  #include <asm/pgtable.h>
8631 @@ -134,8 +136,9 @@ static const char *task_state_array[] = 
8632         "D (disk sleep)",       /*  2 */
8633         "T (stopped)",          /*  4 */
8634         "T (tracing stop)",     /*  8 */
8635 -       "Z (zombie)",           /* 16 */
8636 -       "X (dead)"              /* 32 */
8637 +       "H (on hold)",          /* 16 */
8638 +       "Z (zombie)",           /* 32 */
8639 +       "X (dead)",             /* 64 */
8640  };
8641  
8642  static inline const char * get_task_state(struct task_struct *tsk)
8643 @@ -144,7 +147,8 @@ static inline const char * get_task_stat
8644                                             TASK_INTERRUPTIBLE |
8645                                             TASK_UNINTERRUPTIBLE |
8646                                             TASK_STOPPED |
8647 -                                           TASK_TRACED)) |
8648 +                                          TASK_TRACED |
8649 +                                          TASK_ONHOLD)) |
8650                         (tsk->exit_state & (EXIT_ZOMBIE |
8651                                             EXIT_DEAD));
8652         const char **p = &task_state_array[0];
8653 @@ -161,8 +165,16 @@ static inline char * task_state(struct t
8654         struct group_info *group_info;
8655         int g;
8656         struct fdtable *fdt = NULL;
8657 +       pid_t pid, ptgid, tppid, tgid;
8658  
8659         rcu_read_lock();
8660 +       tgid = vx_map_tgid(p->tgid);
8661 +       pid = vx_map_pid(p->pid);
8662 +       ptgid = vx_map_pid(pid_alive(p) ?
8663 +               rcu_dereference(p->real_parent)->tgid : 0);
8664 +       tppid = vx_map_pid(pid_alive(p) && p->ptrace ?
8665 +               rcu_dereference(p->parent)->pid : 0);
8666 +
8667         buffer += sprintf(buffer,
8668                 "State:\t%s\n"
8669                 "SleepAVG:\t%lu%%\n"
8670 @@ -174,9 +186,7 @@ static inline char * task_state(struct t
8671                 "Gid:\t%d\t%d\t%d\t%d\n",
8672                 get_task_state(p),
8673                 (p->sleep_avg/1024)*100/(1020000000/1024),
8674 -               p->tgid, p->pid,
8675 -               pid_alive(p) ? rcu_dereference(p->real_parent)->tgid : 0,
8676 -               pid_alive(p) && p->ptrace ? rcu_dereference(p->parent)->pid : 0,
8677 +               tgid, pid, (pid > 1) ? ptgid : 0, tppid,
8678                 p->uid, p->euid, p->suid, p->fsuid,
8679                 p->gid, p->egid, p->sgid, p->fsgid);
8680  
8681 @@ -283,12 +293,15 @@ static inline char * task_sig(struct tas
8682  
8683  static inline char *task_cap(struct task_struct *p, char *buffer)
8684  {
8685 -    return buffer + sprintf(buffer, "CapInh:\t%016x\n"
8686 -                           "CapPrm:\t%016x\n"
8687 -                           "CapEff:\t%016x\n",
8688 -                           cap_t(p->cap_inheritable),
8689 -                           cap_t(p->cap_permitted),
8690 -                           cap_t(p->cap_effective));
8691 +       struct vx_info *vxi = p->vx_info;
8692 +
8693 +       return buffer + sprintf(buffer,
8694 +               "CapInh:\t%016x\n"
8695 +               "CapPrm:\t%016x\n"
8696 +               "CapEff:\t%016x\n",
8697 +               (unsigned)vx_info_mbcap(vxi, p->cap_inheritable),
8698 +               (unsigned)vx_info_mbcap(vxi, p->cap_permitted),
8699 +               (unsigned)vx_info_mbcap(vxi, p->cap_effective));
8700  }
8701  
8702  int proc_pid_status(struct task_struct *task, char * buffer)
8703 @@ -306,6 +319,12 @@ int proc_pid_status(struct task_struct *
8704         buffer = task_sig(task, buffer);
8705         buffer = task_cap(task, buffer);
8706         buffer = cpuset_task_status_allowed(task, buffer);
8707 +
8708 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
8709 +               goto skip;
8710 +       buffer += sprintf (buffer,"VxID: %d\n", vx_task_xid(task));
8711 +       buffer += sprintf (buffer,"NxID: %d\n", nx_task_nid(task));
8712 +skip:
8713  #if defined(CONFIG_S390)
8714         buffer = task_show_regs(task, buffer);
8715  #endif
8716 @@ -320,7 +339,7 @@ static int do_task_stat(struct task_stru
8717         sigset_t sigign, sigcatch;
8718         char state;
8719         int res;
8720 -       pid_t ppid = 0, pgid = -1, sid = -1;
8721 +       pid_t pid = 0, ppid = 0, pgid = -1, sid = -1;
8722         int num_threads = 0;
8723         struct mm_struct *mm;
8724         unsigned long long start_time;
8725 @@ -382,8 +401,10 @@ static int do_task_stat(struct task_stru
8726                 }
8727  
8728                 sid = signal_session(sig);
8729 -               pgid = process_group(task);
8730 -               ppid = rcu_dereference(task->real_parent)->tgid;
8731 +               pid = vx_info_map_pid(task->vx_info, task->pid);
8732 +               pgid = vx_info_map_pid(task->vx_info, process_group(task));
8733 +               ppid = (pid > 1) ? vx_info_map_tgid(task->vx_info,
8734 +                       rcu_dereference(task->real_parent)->tgid) : 0;
8735  
8736                 unlock_task_sighand(task, &flags);
8737         }
8738 @@ -410,10 +431,21 @@ static int do_task_stat(struct task_stru
8739         /* convert nsec -> ticks */
8740         start_time = nsec_to_clock_t(start_time);
8741  
8742 +       /* fixup start time for virt uptime */
8743 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
8744 +               unsigned long long bias =
8745 +                       current->vx_info->cvirt.bias_clock;
8746 +
8747 +               if (start_time > bias)
8748 +                       start_time -= bias;
8749 +               else
8750 +                       start_time = 0;
8751 +       }
8752 +
8753         res = sprintf(buffer,"%d (%s) %c %d %d %d %d %d %u %lu \
8754  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
8755  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu\n",
8756 -               task->pid,
8757 +               pid,
8758                 tcomm,
8759                 state,
8760                 ppid,
8761 diff -Nurp linux-2.6.22.15/fs/proc/base.c linux-2.6.22.15-vs2.3.0.29.1/fs/proc/base.c
8762 --- linux-2.6.22.15/fs/proc/base.c      2007-07-21 18:00:18.000000000 -0400
8763 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/proc/base.c 2007-12-09 06:44:21.000000000 -0500
8764 @@ -73,6 +73,9 @@
8765  #include <linux/poll.h>
8766  #include <linux/nsproxy.h>
8767  #include <linux/oom.h>
8768 +#include <linux/vs_context.h>
8769 +#include <linux/vs_network.h>
8770 +
8771  #include "internal.h"
8772  
8773  /* NOTE:
8774 @@ -1049,6 +1052,8 @@ static struct inode *proc_pid_make_inode
8775                 inode->i_uid = task->euid;
8776                 inode->i_gid = task->egid;
8777         }
8778 +       /* procfs is xid tagged */
8779 +       inode->i_tag = (tag_t)vx_task_xid(task);
8780         security_task_to_inode(task, inode);
8781  
8782  out:
8783 @@ -1082,6 +1087,8 @@ static int pid_getattr(struct vfsmount *
8784  
8785  /* dentry stuff */
8786  
8787 +static unsigned name_to_int(struct dentry *dentry);
8788 +
8789  /*
8790   *     Exceptional case: normally we are not allowed to unhash a busy
8791   * directory. In this case, however, we can do it - no aliasing problems
8792 @@ -1102,6 +1109,12 @@ static int pid_revalidate(struct dentry 
8793         struct inode *inode = dentry->d_inode;
8794         struct task_struct *task = get_proc_task(inode);
8795         if (task) {
8796 +               unsigned pid = name_to_int(dentry);
8797 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
8798 +                       put_task_struct(task);
8799 +                       goto drop;
8800 +               }
8801 +
8802                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
8803                     task_dumpable(task)) {
8804                         inode->i_uid = task->euid;
8805 @@ -1115,6 +1128,7 @@ static int pid_revalidate(struct dentry 
8806                 put_task_struct(task);
8807                 return 1;
8808         }
8809 +drop:
8810         d_drop(dentry);
8811         return 0;
8812  }
8813 @@ -1595,6 +1609,13 @@ static struct dentry *proc_pident_lookup
8814         if (!task)
8815                 goto out_no_task;
8816  
8817 +       /* TODO: maybe we can come up with a generic approach? */
8818 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
8819 +               (dentry->d_name.len == 5) &&
8820 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
8821 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
8822 +               goto out;
8823 +
8824         /*
8825          * Yes, it does not scale. And it should not. Don't add
8826          * new entries into /proc/<tgid>/ without very good reasons.
8827 @@ -1790,14 +1811,14 @@ static int proc_self_readlink(struct den
8828                               int buflen)
8829  {
8830         char tmp[PROC_NUMBUF];
8831 -       sprintf(tmp, "%d", current->tgid);
8832 +       sprintf(tmp, "%d", vx_map_tgid(current->tgid));
8833         return vfs_readlink(dentry,buffer,buflen,tmp);
8834  }
8835  
8836  static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
8837  {
8838         char tmp[PROC_NUMBUF];
8839 -       sprintf(tmp, "%d", current->tgid);
8840 +       sprintf(tmp, "%d", vx_map_tgid(current->tgid));
8841         return ERR_PTR(vfs_follow_link(nd,tmp));
8842  }
8843  
8844 @@ -1891,7 +1912,7 @@ out_iput:
8845  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
8846  {
8847         struct dentry *error;
8848 -       struct task_struct *task = get_proc_task(dir);
8849 +       struct task_struct *task = get_proc_task_real(dir);
8850         const struct pid_entry *p, *last;
8851  
8852         error = ERR_PTR(-ENOENT);
8853 @@ -1956,6 +1977,9 @@ static int proc_pid_io_accounting(struct
8854  static const struct file_operations proc_task_operations;
8855  static const struct inode_operations proc_task_inode_operations;
8856  
8857 +extern int proc_pid_vx_info(struct task_struct *, char *);
8858 +extern int proc_pid_nx_info(struct task_struct *, char *);
8859 +
8860  static const struct pid_entry tgid_base_stuff[] = {
8861         DIR("task",       S_IRUGO|S_IXUGO, task),
8862         DIR("fd",         S_IRUSR|S_IXUSR, fd),
8863 @@ -1995,6 +2019,8 @@ static const struct pid_entry tgid_base_
8864  #ifdef CONFIG_CPUSETS
8865         REG("cpuset",     S_IRUGO, cpuset),
8866  #endif
8867 +       INF("vinfo",      S_IRUGO, pid_vx_info),
8868 +       INF("ninfo",      S_IRUGO, pid_nx_info),
8869         INF("oom_score",  S_IRUGO, oom_score),
8870         REG("oom_adj",    S_IRUGO|S_IWUSR, oom_adjust),
8871  #ifdef CONFIG_AUDITSYSCALL
8872 @@ -2141,9 +2167,11 @@ struct dentry *proc_pid_lookup(struct in
8873         tgid = name_to_int(dentry);
8874         if (tgid == ~0U)
8875                 goto out;
8876 +       if (vx_current_initpid(tgid))
8877 +               goto out;
8878  
8879         rcu_read_lock();
8880 -       task = find_task_by_pid(tgid);
8881 +       task = vx_find_proc_task_by_pid(tgid);
8882         if (task)
8883                 get_task_struct(task);
8884         rcu_read_unlock();
8885 @@ -2198,7 +2226,7 @@ static int proc_pid_fill_cache(struct fi
8886         struct task_struct *task, int tgid)
8887  {
8888         char name[PROC_NUMBUF];
8889 -       int len = snprintf(name, sizeof(name), "%d", tgid);
8890 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(tgid));
8891         return proc_fill_cache(filp, dirent, filldir, name, len,
8892                                 proc_pid_instantiate, task, NULL);
8893  }
8894 @@ -2207,7 +2235,7 @@ static int proc_pid_fill_cache(struct fi
8895  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
8896  {
8897         unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
8898 -       struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
8899 +       struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
8900         struct task_struct *task;
8901         int tgid;
8902  
8903 @@ -2226,6 +2254,8 @@ int proc_pid_readdir(struct file * filp,
8904              put_task_struct(task), task = next_tgid(tgid + 1)) {
8905                 tgid = task->pid;
8906                 filp->f_pos = tgid + TGID_OFFSET;
8907 +               if (!vx_proc_task_visible(task))
8908 +                       continue;
8909                 if (proc_pid_fill_cache(filp, dirent, filldir, task, tgid) < 0) {
8910                         put_task_struct(task);
8911                         goto out;
8912 @@ -2352,9 +2382,11 @@ static struct dentry *proc_task_lookup(s
8913         tid = name_to_int(dentry);
8914         if (tid == ~0U)
8915                 goto out;
8916 +       if (vx_current_initpid(tid))
8917 +               goto out;
8918  
8919         rcu_read_lock();
8920 -       task = find_task_by_pid(tid);
8921 +       task = vx_find_proc_task_by_pid(tid);
8922         if (task)
8923                 get_task_struct(task);
8924         rcu_read_unlock();
8925 @@ -2499,7 +2531,7 @@ static int proc_task_readdir(struct file
8926         for (task = first_tid(leader, tid, pos - 2);
8927              task;
8928              task = next_tid(task), pos++) {
8929 -               tid = task->pid;
8930 +               tid = vx_map_pid(task->pid);
8931                 if (proc_task_fill_cache(filp, dirent, filldir, task, tid) < 0) {
8932                         /* returning this tgid failed, save it as the first
8933                          * pid for the next readir call */
8934 diff -Nurp linux-2.6.22.15/fs/proc/generic.c linux-2.6.22.15-vs2.3.0.29.1/fs/proc/generic.c
8935 --- linux-2.6.22.15/fs/proc/generic.c   2007-07-21 18:00:18.000000000 -0400
8936 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/proc/generic.c      2007-12-09 06:44:21.000000000 -0500
8937 @@ -20,6 +20,7 @@
8938  #include <linux/namei.h>
8939  #include <linux/bitops.h>
8940  #include <linux/spinlock.h>
8941 +#include <linux/vserver/inode.h>
8942  #include <asm/uaccess.h>
8943  
8944  #include "internal.h"
8945 @@ -395,6 +396,8 @@ struct dentry *proc_lookup(struct inode 
8946                 for (de = de->subdir; de ; de = de->next) {
8947                         if (de->namelen != dentry->d_name.len)
8948                                 continue;
8949 +                       if (!vx_hide_check(0, de->vx_flags))
8950 +                               continue;
8951                         if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
8952                                 unsigned int ino = de->low_ino;
8953  
8954 @@ -402,6 +405,8 @@ struct dentry *proc_lookup(struct inode 
8955                                 spin_unlock(&proc_subdir_lock);
8956                                 error = -EINVAL;
8957                                 inode = proc_get_inode(dir->i_sb, ino, de);
8958 +                               /* generic proc entries belong to the host */
8959 +                               inode->i_tag = 0;
8960                                 spin_lock(&proc_subdir_lock);
8961                                 break;
8962                         }
8963 @@ -482,6 +487,8 @@ int proc_readdir(struct file * filp,
8964  
8965                                 /* filldir passes info to user space */
8966                                 de_get(de);
8967 +                               if (!vx_hide_check(0, de->vx_flags))
8968 +                                       goto skip;
8969                                 spin_unlock(&proc_subdir_lock);
8970                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
8971                                             de->low_ino, de->mode >> 12) < 0) {
8972 @@ -489,6 +496,7 @@ int proc_readdir(struct file * filp,
8973                                         goto out;
8974                                 }
8975                                 spin_lock(&proc_subdir_lock);
8976 +                       skip:
8977                                 filp->f_pos++;
8978                                 next = de->next;
8979                                 de_put(de);
8980 @@ -613,6 +621,7 @@ static struct proc_dir_entry *proc_creat
8981         ent->namelen = len;
8982         ent->mode = mode;
8983         ent->nlink = nlink;
8984 +       ent->vx_flags = IATTR_PROC_DEFAULT;
8985   out:
8986         return ent;
8987  }
8988 @@ -633,7 +642,8 @@ struct proc_dir_entry *proc_symlink(cons
8989                                 kfree(ent->data);
8990                                 kfree(ent);
8991                                 ent = NULL;
8992 -                       }
8993 +                       } else
8994 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
8995                 } else {
8996                         kfree(ent);
8997                         ent = NULL;
8998 diff -Nurp linux-2.6.22.15/fs/proc/inode.c linux-2.6.22.15-vs2.3.0.29.1/fs/proc/inode.c
8999 --- linux-2.6.22.15/fs/proc/inode.c     2007-07-21 18:00:18.000000000 -0400
9000 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/proc/inode.c        2007-12-09 06:44:21.000000000 -0500
9001 @@ -160,6 +160,8 @@ struct inode *proc_get_inode(struct supe
9002                         inode->i_uid = de->uid;
9003                         inode->i_gid = de->gid;
9004                 }
9005 +               if (de->vx_flags)
9006 +                       PROC_I(inode)->vx_flags = de->vx_flags;
9007                 if (de->size)
9008                         inode->i_size = de->size;
9009                 if (de->nlink)
9010 diff -Nurp linux-2.6.22.15/fs/proc/internal.h linux-2.6.22.15-vs2.3.0.29.1/fs/proc/internal.h
9011 --- linux-2.6.22.15/fs/proc/internal.h  2007-07-21 18:00:18.000000000 -0400
9012 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/proc/internal.h     2007-12-09 06:44:21.000000000 -0500
9013 @@ -10,6 +10,7 @@
9014   */
9015  
9016  #include <linux/proc_fs.h>
9017 +#include <linux/vs_pid.h>
9018  
9019  #ifdef CONFIG_PROC_SYSCTL
9020  extern int proc_sys_init(void);
9021 @@ -64,11 +65,16 @@ static inline struct pid *proc_pid(struc
9022         return PROC_I(inode)->pid;
9023  }
9024  
9025 -static inline struct task_struct *get_proc_task(struct inode *inode)
9026 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
9027  {
9028         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
9029  }
9030  
9031 +static inline struct task_struct *get_proc_task(struct inode *inode)
9032 +{
9033 +       return vx_get_proc_task(inode, proc_pid(inode));
9034 +}
9035 +
9036  static inline int proc_fd(struct inode *inode)
9037  {
9038         return PROC_I(inode)->fd;
9039 diff -Nurp linux-2.6.22.15/fs/proc/proc_misc.c linux-2.6.22.15-vs2.3.0.29.1/fs/proc/proc_misc.c
9040 --- linux-2.6.22.15/fs/proc/proc_misc.c 2007-07-21 18:00:18.000000000 -0400
9041 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/proc/proc_misc.c    2007-12-09 06:44:21.000000000 -0500
9042 @@ -53,6 +53,8 @@
9043  #include <asm/div64.h>
9044  #include "internal.h"
9045  
9046 +#include <linux/vs_cvirt.h>
9047 +
9048  #define LOAD_INT(x) ((x) >> FSHIFT)
9049  #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
9050  /*
9051 @@ -82,17 +84,32 @@ static int proc_calc_metrics(char *page,
9052  static int loadavg_read_proc(char *page, char **start, off_t off,
9053                                  int count, int *eof, void *data)
9054  {
9055 +       unsigned int running, threads;
9056         int a, b, c;
9057         int len;
9058  
9059 -       a = avenrun[0] + (FIXED_1/200);
9060 -       b = avenrun[1] + (FIXED_1/200);
9061 -       c = avenrun[2] + (FIXED_1/200);
9062 -       len = sprintf(page,"%d.%02d %d.%02d %d.%02d %ld/%d %d\n",
9063 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
9064 +               struct vx_info *vxi = current->vx_info;
9065 +
9066 +               a = vxi->cvirt.load[0] + (FIXED_1/200);
9067 +               b = vxi->cvirt.load[1] + (FIXED_1/200);
9068 +               c = vxi->cvirt.load[2] + (FIXED_1/200);
9069 +
9070 +               running = atomic_read(&vxi->cvirt.nr_running);
9071 +               threads = atomic_read(&vxi->cvirt.nr_threads);
9072 +       } else {
9073 +               a = avenrun[0] + (FIXED_1/200);
9074 +               b = avenrun[1] + (FIXED_1/200);
9075 +               c = avenrun[2] + (FIXED_1/200);
9076 +
9077 +               running = nr_running();
9078 +               threads = nr_threads;
9079 +       }
9080 +       len = sprintf(page,"%d.%02d %d.%02d %d.%02d %d/%d %d\n",
9081                 LOAD_INT(a), LOAD_FRAC(a),
9082                 LOAD_INT(b), LOAD_FRAC(b),
9083                 LOAD_INT(c), LOAD_FRAC(c),
9084 -               nr_running(), nr_threads, current->nsproxy->pid_ns->last_pid);
9085 +               running, threads, current->nsproxy->pid_ns->last_pid);
9086         return proc_calc_metrics(page, start, off, count, eof, len);
9087  }
9088  
9089 @@ -106,6 +123,9 @@ static int uptime_read_proc(char *page, 
9090  
9091         do_posix_clock_monotonic_gettime(&uptime);
9092         cputime_to_timespec(idletime, &idle);
9093 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
9094 +               vx_vsi_uptime(&uptime, &idle);
9095 +
9096         len = sprintf(page,"%lu.%02lu %lu.%02lu\n",
9097                         (unsigned long) uptime.tv_sec,
9098                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
9099 @@ -137,7 +157,7 @@ static int meminfo_read_proc(char *page,
9100  
9101         cached = global_page_state(NR_FILE_PAGES) -
9102                         total_swapcache_pages - i.bufferram;
9103 -       if (cached < 0)
9104 +       if (cached < 0 || vx_flags(VXF_VIRT_MEM, 0))
9105                 cached = 0;
9106  
9107         get_vmalloc_info(&vmi);
9108 diff -Nurp linux-2.6.22.15/fs/proc/root.c linux-2.6.22.15-vs2.3.0.29.1/fs/proc/root.c
9109 --- linux-2.6.22.15/fs/proc/root.c      2007-07-21 17:58:48.000000000 -0400
9110 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/proc/root.c 2007-12-09 06:44:21.000000000 -0500
9111 @@ -22,6 +22,9 @@
9112  #include "internal.h"
9113  
9114  struct proc_dir_entry *proc_net, *proc_net_stat, *proc_bus, *proc_root_fs, *proc_root_driver;
9115 +struct proc_dir_entry *proc_virtual;
9116 +
9117 +extern void proc_vx_init(void);
9118  
9119  static int proc_get_sb(struct file_system_type *fs_type,
9120         int flags, const char *dev_name, void *data, struct vfsmount *mnt)
9121 @@ -79,6 +82,7 @@ void __init proc_root_init(void)
9122         proc_device_tree_init();
9123  #endif
9124         proc_bus = proc_mkdir("bus", NULL);
9125 +       proc_vx_init();
9126         proc_sys_init();
9127  }
9128  
9129 diff -Nurp linux-2.6.22.15/fs/quota.c linux-2.6.22.15-vs2.3.0.29.1/fs/quota.c
9130 --- linux-2.6.22.15/fs/quota.c  2007-07-21 18:00:18.000000000 -0400
9131 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/quota.c     2007-12-09 06:44:21.000000000 -0500
9132 @@ -16,6 +16,7 @@
9133  #include <linux/buffer_head.h>
9134  #include <linux/capability.h>
9135  #include <linux/quotaops.h>
9136 +#include <linux/vs_context.h>
9137  
9138  /* Check validity of generic quotactl commands */
9139  static int generic_quotactl_valid(struct super_block *sb, int type, int cmd, qid_t id)
9140 @@ -80,11 +81,11 @@ static int generic_quotactl_valid(struct
9141         if (cmd == Q_GETQUOTA) {
9142                 if (((type == USRQUOTA && current->euid != id) ||
9143                      (type == GRPQUOTA && !in_egroup_p(id))) &&
9144 -                   !capable(CAP_SYS_ADMIN))
9145 +                   !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9146                         return -EPERM;
9147         }
9148         else if (cmd != Q_GETFMT && cmd != Q_SYNC && cmd != Q_GETINFO)
9149 -               if (!capable(CAP_SYS_ADMIN))
9150 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9151                         return -EPERM;
9152  
9153         return 0;
9154 @@ -131,10 +132,10 @@ static int xqm_quotactl_valid(struct sup
9155         if (cmd == Q_XGETQUOTA) {
9156                 if (((type == XQM_USRQUOTA && current->euid != id) ||
9157                      (type == XQM_GRPQUOTA && !in_egroup_p(id))) &&
9158 -                    !capable(CAP_SYS_ADMIN))
9159 +                    !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9160                         return -EPERM;
9161         } else if (cmd != Q_XGETQSTAT && cmd != Q_XQUOTASYNC) {
9162 -               if (!capable(CAP_SYS_ADMIN))
9163 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9164                         return -EPERM;
9165         }
9166  
9167 @@ -327,6 +328,46 @@ static int do_quotactl(struct super_bloc
9168         return 0;
9169  }
9170  
9171 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
9172 +
9173 +#include <linux/vroot.h>
9174 +#include <linux/major.h>
9175 +#include <linux/module.h>
9176 +#include <linux/kallsyms.h>
9177 +#include <linux/vserver/debug.h>
9178 +
9179 +static vroot_grb_func *vroot_get_real_bdev = NULL;
9180 +
9181 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
9182 +
9183 +int register_vroot_grb(vroot_grb_func *func) {
9184 +       int ret = -EBUSY;
9185 +
9186 +       spin_lock(&vroot_grb_lock);
9187 +       if (!vroot_get_real_bdev) {
9188 +               vroot_get_real_bdev = func;
9189 +               ret = 0;
9190 +       }
9191 +       spin_unlock(&vroot_grb_lock);
9192 +       return ret;
9193 +}
9194 +EXPORT_SYMBOL(register_vroot_grb);
9195 +
9196 +int unregister_vroot_grb(vroot_grb_func *func) {
9197 +       int ret = -EINVAL;
9198 +
9199 +       spin_lock(&vroot_grb_lock);
9200 +       if (vroot_get_real_bdev) {
9201 +               vroot_get_real_bdev = NULL;
9202 +               ret = 0;
9203 +       }
9204 +       spin_unlock(&vroot_grb_lock);
9205 +       return ret;
9206 +}
9207 +EXPORT_SYMBOL(unregister_vroot_grb);
9208 +
9209 +#endif
9210 +
9211  /*
9212   * look up a superblock on which quota ops will be performed
9213   * - use the name of a block device to find the superblock thereon
9214 @@ -344,6 +385,22 @@ static inline struct super_block *quotac
9215         putname(tmp);
9216         if (IS_ERR(bdev))
9217                 return ERR_PTR(PTR_ERR(bdev));
9218 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
9219 +       if (bdev && bdev->bd_inode &&
9220 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
9221 +               struct block_device *bdnew = (void *)-EINVAL;
9222 +
9223 +               if (vroot_get_real_bdev)
9224 +                       bdnew = vroot_get_real_bdev(bdev);
9225 +               else
9226 +                       vxdprintk(VXD_CBIT(misc, 0),
9227 +                                       "vroot_get_real_bdev not set");
9228 +               bdput(bdev);
9229 +               if (IS_ERR(bdnew))
9230 +                       return ERR_PTR(PTR_ERR(bdnew));
9231 +               bdev = bdnew;
9232 +       }
9233 +#endif
9234         sb = get_super(bdev);
9235         bdput(bdev);
9236         if (!sb)
9237 diff -Nurp linux-2.6.22.15/fs/reiserfs/bitmap.c linux-2.6.22.15-vs2.3.0.29.1/fs/reiserfs/bitmap.c
9238 --- linux-2.6.22.15/fs/reiserfs/bitmap.c        2007-05-04 09:58:22.000000000 -0400
9239 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/reiserfs/bitmap.c   2007-12-09 06:44:21.000000000 -0500
9240 @@ -13,6 +13,7 @@
9241  #include <linux/reiserfs_fs_sb.h>
9242  #include <linux/reiserfs_fs_i.h>
9243  #include <linux/quotaops.h>
9244 +#include <linux/vs_dlimit.h>
9245  
9246  #define PREALLOCATION_SIZE 9
9247  
9248 @@ -425,8 +426,10 @@ static void _reiserfs_free_block(struct 
9249         set_sb_free_blocks(rs, sb_free_blocks(rs) + 1);
9250  
9251         journal_mark_dirty(th, s, sbh);
9252 -       if (for_unformatted)
9253 +       if (for_unformatted) {
9254 +               DLIMIT_FREE_BLOCK(inode, 1);
9255                 DQUOT_FREE_BLOCK_NODIRTY(inode, 1);
9256 +       }
9257  }
9258  
9259  void reiserfs_free_block(struct reiserfs_transaction_handle *th,
9260 @@ -1034,6 +1037,7 @@ static inline int blocknrs_and_prealloc_
9261         b_blocknr_t finish = SB_BLOCK_COUNT(s) - 1;
9262         int passno = 0;
9263         int nr_allocated = 0;
9264 +       int blocks;
9265  
9266         determine_prealloc_size(hint);
9267         if (!hint->formatted_node) {
9268 @@ -1043,19 +1047,30 @@ static inline int blocknrs_and_prealloc_
9269                                "reiserquota: allocating %d blocks id=%u",
9270                                amount_needed, hint->inode->i_uid);
9271  #endif
9272 -               quota_ret =
9273 -                   DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode, amount_needed);
9274 -               if (quota_ret)  /* Quota exceeded? */
9275 +               quota_ret = DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode,
9276 +                       amount_needed);
9277 +               if (quota_ret)
9278                         return QUOTA_EXCEEDED;
9279 +               if (DLIMIT_ALLOC_BLOCK(hint->inode, amount_needed)) {
9280 +                       DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
9281 +                               amount_needed);
9282 +                       return NO_DISK_SPACE;
9283 +               }
9284 +
9285                 if (hint->preallocate && hint->prealloc_size) {
9286  #ifdef REISERQUOTA_DEBUG
9287                         reiserfs_debug(s, REISERFS_DEBUG_CODE,
9288                                        "reiserquota: allocating (prealloc) %d blocks id=%u",
9289                                        hint->prealloc_size, hint->inode->i_uid);
9290  #endif
9291 -                       quota_ret =
9292 -                           DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
9293 -                                                        hint->prealloc_size);
9294 +                       quota_ret = DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
9295 +                               hint->prealloc_size);
9296 +                       if (!quota_ret &&
9297 +                               DLIMIT_ALLOC_BLOCK(hint->inode, hint->prealloc_size)) {
9298 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
9299 +                                       hint->prealloc_size);
9300 +                               quota_ret = 1;
9301 +                       }
9302                         if (quota_ret)
9303                                 hint->preallocate = hint->prealloc_size = 0;
9304                 }
9305 @@ -1087,7 +1102,10 @@ static inline int blocknrs_and_prealloc_
9306                                                nr_allocated,
9307                                                hint->inode->i_uid);
9308  #endif
9309 -                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed + hint->prealloc_size - nr_allocated);      /* Free not allocated blocks */
9310 +                               /* Free not allocated blocks */
9311 +                               blocks = amount_needed + hint->prealloc_size - nr_allocated;
9312 +                               DLIMIT_FREE_BLOCK(hint->inode, blocks);
9313 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
9314                         }
9315                         while (nr_allocated--)
9316                                 reiserfs_free_block(hint->th, hint->inode,
9317 @@ -1118,10 +1136,10 @@ static inline int blocknrs_and_prealloc_
9318                                REISERFS_I(hint->inode)->i_prealloc_count,
9319                                hint->inode->i_uid);
9320  #endif
9321 -               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed +
9322 -                                        hint->prealloc_size - nr_allocated -
9323 -                                        REISERFS_I(hint->inode)->
9324 -                                        i_prealloc_count);
9325 +               blocks = amount_needed + hint->prealloc_size - nr_allocated -
9326 +                       REISERFS_I(hint->inode)->i_prealloc_count;
9327 +               DLIMIT_FREE_BLOCK(hint->inode, blocks);
9328 +               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
9329         }
9330  
9331         return CARRY_ON;
9332 diff -Nurp linux-2.6.22.15/fs/reiserfs/file.c linux-2.6.22.15-vs2.3.0.29.1/fs/reiserfs/file.c
9333 --- linux-2.6.22.15/fs/reiserfs/file.c  2007-07-21 18:00:18.000000000 -0400
9334 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/reiserfs/file.c     2007-12-09 06:44:21.000000000 -0500
9335 @@ -1546,4 +1546,5 @@ const struct inode_operations reiserfs_f
9336         .listxattr = reiserfs_listxattr,
9337         .removexattr = reiserfs_removexattr,
9338         .permission = reiserfs_permission,
9339 +       .sync_flags = reiserfs_sync_flags,
9340  };
9341 diff -Nurp linux-2.6.22.15/fs/reiserfs/inode.c linux-2.6.22.15-vs2.3.0.29.1/fs/reiserfs/inode.c
9342 --- linux-2.6.22.15/fs/reiserfs/inode.c 2007-07-21 18:00:18.000000000 -0400
9343 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/reiserfs/inode.c    2007-12-09 06:44:21.000000000 -0500
9344 @@ -16,6 +16,8 @@
9345  #include <linux/mpage.h>
9346  #include <linux/writeback.h>
9347  #include <linux/quotaops.h>
9348 +#include <linux/vs_dlimit.h>
9349 +#include <linux/vs_tag.h>
9350  
9351  static int reiserfs_commit_write(struct file *f, struct page *page,
9352                                  unsigned from, unsigned to);
9353 @@ -50,6 +52,7 @@ void reiserfs_delete_inode(struct inode 
9354                  * stat data deletion */
9355                 if (!err) 
9356                         DQUOT_FREE_INODE(inode);
9357 +               DLIMIT_FREE_INODE(inode);
9358  
9359                 if (journal_end(&th, inode->i_sb, jbegin_count))
9360                         goto out;
9361 @@ -1112,6 +1115,8 @@ static void init_inode(struct inode *ino
9362         struct buffer_head *bh;
9363         struct item_head *ih;
9364         __u32 rdev;
9365 +       uid_t uid;
9366 +       gid_t gid;
9367         //int version = ITEM_VERSION_1;
9368  
9369         bh = PATH_PLAST_BUFFER(path);
9370 @@ -1135,12 +1140,13 @@ static void init_inode(struct inode *ino
9371                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
9372                 unsigned long blocks;
9373  
9374 +               uid = sd_v1_uid(sd);
9375 +               gid = sd_v1_gid(sd);
9376 +
9377                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
9378                 set_inode_sd_version(inode, STAT_DATA_V1);
9379                 inode->i_mode = sd_v1_mode(sd);
9380                 inode->i_nlink = sd_v1_nlink(sd);
9381 -               inode->i_uid = sd_v1_uid(sd);
9382 -               inode->i_gid = sd_v1_gid(sd);
9383                 inode->i_size = sd_v1_size(sd);
9384                 inode->i_atime.tv_sec = sd_v1_atime(sd);
9385                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
9386 @@ -1182,11 +1188,12 @@ static void init_inode(struct inode *ino
9387                 // (directories and symlinks)
9388                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
9389  
9390 +               uid    = sd_v2_uid(sd);
9391 +               gid    = sd_v2_gid(sd);
9392 +
9393                 inode->i_mode = sd_v2_mode(sd);
9394                 inode->i_nlink = sd_v2_nlink(sd);
9395 -               inode->i_uid = sd_v2_uid(sd);
9396                 inode->i_size = sd_v2_size(sd);
9397 -               inode->i_gid = sd_v2_gid(sd);
9398                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
9399                 inode->i_atime.tv_sec = sd_v2_atime(sd);
9400                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
9401 @@ -1216,6 +1223,10 @@ static void init_inode(struct inode *ino
9402                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
9403         }
9404  
9405 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
9406 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
9407 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
9408 +
9409         pathrelse(path);
9410         if (S_ISREG(inode->i_mode)) {
9411                 inode->i_op = &reiserfs_file_inode_operations;
9412 @@ -1238,13 +1249,15 @@ static void init_inode(struct inode *ino
9413  static void inode2sd(void *sd, struct inode *inode, loff_t size)
9414  {
9415         struct stat_data *sd_v2 = (struct stat_data *)sd;
9416 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
9417 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
9418         __u16 flags;
9419  
9420 +       set_sd_v2_uid(sd_v2, uid);
9421 +       set_sd_v2_gid(sd_v2, gid);
9422         set_sd_v2_mode(sd_v2, inode->i_mode);
9423         set_sd_v2_nlink(sd_v2, inode->i_nlink);
9424 -       set_sd_v2_uid(sd_v2, inode->i_uid);
9425         set_sd_v2_size(sd_v2, size);
9426 -       set_sd_v2_gid(sd_v2, inode->i_gid);
9427         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
9428         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
9429         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
9430 @@ -1775,6 +1788,10 @@ int reiserfs_new_inode(struct reiserfs_t
9431  
9432         BUG_ON(!th->t_trans_id);
9433  
9434 +       if (DLIMIT_ALLOC_INODE(inode)) {
9435 +               err = -ENOSPC;
9436 +               goto out_bad_dlimit;
9437 +       }
9438         if (DQUOT_ALLOC_INODE(inode)) {
9439                 err = -EDQUOT;
9440                 goto out_end_trans;
9441 @@ -1960,6 +1977,9 @@ int reiserfs_new_inode(struct reiserfs_t
9442         DQUOT_FREE_INODE(inode);
9443  
9444        out_end_trans:
9445 +       DLIMIT_FREE_INODE(inode);
9446 +
9447 +      out_bad_dlimit:
9448         journal_end(th, th->t_super, th->t_blocks_allocated);
9449         /* Drop can be outside and it needs more credits so it's better to have it outside */
9450         DQUOT_DROP(inode);
9451 @@ -2690,6 +2710,14 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
9452                         inode->i_flags |= S_IMMUTABLE;
9453                 else
9454                         inode->i_flags &= ~S_IMMUTABLE;
9455 +               if (sd_attrs & REISERFS_IUNLINK_FL)
9456 +                       inode->i_flags |= S_IUNLINK;
9457 +               else
9458 +                       inode->i_flags &= ~S_IUNLINK;
9459 +               if (sd_attrs & REISERFS_BARRIER_FL)
9460 +                       inode->i_flags |= S_BARRIER;
9461 +               else
9462 +                       inode->i_flags &= ~S_BARRIER;
9463                 if (sd_attrs & REISERFS_APPEND_FL)
9464                         inode->i_flags |= S_APPEND;
9465                 else
9466 @@ -2712,6 +2740,14 @@ void i_attrs_to_sd_attrs(struct inode *i
9467                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
9468                 else
9469                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
9470 +               if (inode->i_flags & S_IUNLINK)
9471 +                       *sd_attrs |= REISERFS_IUNLINK_FL;
9472 +               else
9473 +                       *sd_attrs &= ~REISERFS_IUNLINK_FL;
9474 +               if (inode->i_flags & S_BARRIER)
9475 +                       *sd_attrs |= REISERFS_BARRIER_FL;
9476 +               else
9477 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
9478                 if (inode->i_flags & S_SYNC)
9479                         *sd_attrs |= REISERFS_SYNC_FL;
9480                 else
9481 @@ -2891,6 +2927,22 @@ static ssize_t reiserfs_direct_IO(int rw
9482                                   reiserfs_get_blocks_direct_io, NULL);
9483  }
9484  
9485 +int reiserfs_sync_flags(struct inode *inode)
9486 +{
9487 +       u16 oldflags, newflags;
9488 +
9489 +       oldflags = REISERFS_I(inode)->i_attrs;
9490 +       newflags = oldflags;
9491 +       i_attrs_to_sd_attrs(inode, &newflags);
9492 +
9493 +       if (oldflags ^ newflags) {
9494 +               REISERFS_I(inode)->i_attrs = newflags;
9495 +               inode->i_ctime = CURRENT_TIME_SEC;
9496 +               mark_inode_dirty(inode);
9497 +       }
9498 +       return 0;
9499 +}
9500 +
9501  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
9502  {
9503         struct inode *inode = dentry->d_inode;
9504 @@ -2940,9 +2992,11 @@ int reiserfs_setattr(struct dentry *dent
9505         }
9506  
9507         error = inode_change_ok(inode, attr);
9508 +
9509         if (!error) {
9510                 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
9511 -                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
9512 +                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
9513 +                   (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
9514                         error = reiserfs_chown_xattrs(inode, attr);
9515  
9516                         if (!error) {
9517 @@ -2972,6 +3026,9 @@ int reiserfs_setattr(struct dentry *dent
9518                                         inode->i_uid = attr->ia_uid;
9519                                 if (attr->ia_valid & ATTR_GID)
9520                                         inode->i_gid = attr->ia_gid;
9521 +                               if ((attr->ia_valid & ATTR_TAG) &&
9522 +                                       IS_TAGGED(inode))
9523 +                                       inode->i_tag = attr->ia_tag;
9524                                 mark_inode_dirty(inode);
9525                                 error =
9526                                     journal_end(&th, inode->i_sb, jbegin_count);
9527 diff -Nurp linux-2.6.22.15/fs/reiserfs/ioctl.c linux-2.6.22.15-vs2.3.0.29.1/fs/reiserfs/ioctl.c
9528 --- linux-2.6.22.15/fs/reiserfs/ioctl.c 2007-05-04 09:58:22.000000000 -0400
9529 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/reiserfs/ioctl.c    2007-12-09 06:44:21.000000000 -0500
9530 @@ -6,6 +6,7 @@
9531  #include <linux/fs.h>
9532  #include <linux/reiserfs_fs.h>
9533  #include <linux/time.h>
9534 +#include <linux/mount.h>
9535  #include <asm/uaccess.h>
9536  #include <linux/pagemap.h>
9537  #include <linux/smp_lock.h>
9538 @@ -24,7 +25,7 @@ static int reiserfs_unpack(struct inode 
9539  int reiserfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
9540                    unsigned long arg)
9541  {
9542 -       unsigned int flags;
9543 +       unsigned int flags, oldflags;
9544  
9545         switch (cmd) {
9546         case REISERFS_IOC_UNPACK:
9547 @@ -43,12 +44,14 @@ int reiserfs_ioctl(struct inode *inode, 
9548  
9549                 flags = REISERFS_I(inode)->i_attrs;
9550                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
9551 +               flags &= REISERFS_FL_USER_VISIBLE;
9552                 return put_user(flags, (int __user *)arg);
9553         case REISERFS_IOC_SETFLAGS:{
9554                         if (!reiserfs_attrs(inode->i_sb))
9555                                 return -ENOTTY;
9556  
9557 -                       if (IS_RDONLY(inode))
9558 +                       if (IS_RDONLY(inode) ||
9559 +                               (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
9560                                 return -EROFS;
9561  
9562                         if ((current->fsuid != inode->i_uid)
9563 @@ -58,10 +61,12 @@ int reiserfs_ioctl(struct inode *inode, 
9564                         if (get_user(flags, (int __user *)arg))
9565                                 return -EFAULT;
9566  
9567 -                       if (((flags ^ REISERFS_I(inode)->
9568 -                             i_attrs) & (REISERFS_IMMUTABLE_FL |
9569 -                                         REISERFS_APPEND_FL))
9570 -                           && !capable(CAP_LINUX_IMMUTABLE))
9571 +                       oldflags = REISERFS_I(inode) -> i_attrs;
9572 +                       if (((oldflags & REISERFS_IMMUTABLE_FL) ||
9573 +                               ((flags ^ oldflags) &
9574 +                               (REISERFS_IMMUTABLE_FL | REISERFS_IUNLINK_FL |
9575 +                                REISERFS_APPEND_FL))) &&
9576 +                               !capable(CAP_LINUX_IMMUTABLE))
9577                                 return -EPERM;
9578  
9579                         if ((flags & REISERFS_NOTAIL_FL) &&
9580 @@ -72,6 +77,9 @@ int reiserfs_ioctl(struct inode *inode, 
9581                                 if (result)
9582                                         return result;
9583                         }
9584 +
9585 +                       flags = flags & REISERFS_FL_USER_MODIFIABLE;
9586 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
9587                         sd_attrs_to_i_attrs(flags, inode);
9588                         REISERFS_I(inode)->i_attrs = flags;
9589                         inode->i_ctime = CURRENT_TIME_SEC;
9590 @@ -83,7 +91,8 @@ int reiserfs_ioctl(struct inode *inode, 
9591         case REISERFS_IOC_SETVERSION:
9592                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
9593                         return -EPERM;
9594 -               if (IS_RDONLY(inode))
9595 +               if (IS_RDONLY(inode) ||
9596 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
9597                         return -EROFS;
9598                 if (get_user(inode->i_generation, (int __user *)arg))
9599                         return -EFAULT;
9600 diff -Nurp linux-2.6.22.15/fs/reiserfs/namei.c linux-2.6.22.15-vs2.3.0.29.1/fs/reiserfs/namei.c
9601 --- linux-2.6.22.15/fs/reiserfs/namei.c 2007-07-21 18:00:18.000000000 -0400
9602 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/reiserfs/namei.c    2007-12-09 06:44:21.000000000 -0500
9603 @@ -17,6 +17,7 @@
9604  #include <linux/reiserfs_acl.h>
9605  #include <linux/reiserfs_xattr.h>
9606  #include <linux/quotaops.h>
9607 +#include <linux/vs_tag.h>
9608  
9609  #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; }
9610  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
9611 @@ -360,6 +361,7 @@ static struct dentry *reiserfs_lookup(st
9612                         reiserfs_write_unlock(dir->i_sb);
9613                         return ERR_PTR(-EACCES);
9614                 }
9615 +               dx_propagate_tag(nd, inode);
9616  
9617                 /* Propogate the priv_object flag so we know we're in the priv tree */
9618                 if (is_reiserfs_priv_object(dir))
9619 @@ -595,6 +597,7 @@ static int new_inode_init(struct inode *
9620         } else {
9621                 inode->i_gid = current->fsgid;
9622         }
9623 +       inode->i_tag = dx_current_fstag(inode->i_sb);
9624         DQUOT_INIT(inode);
9625         return 0;
9626  }
9627 @@ -1541,6 +1544,7 @@ const struct inode_operations reiserfs_d
9628         .listxattr = reiserfs_listxattr,
9629         .removexattr = reiserfs_removexattr,
9630         .permission = reiserfs_permission,
9631 +       .sync_flags = reiserfs_sync_flags,
9632  };
9633  
9634  /*
9635 @@ -1557,6 +1561,7 @@ const struct inode_operations reiserfs_s
9636         .listxattr = reiserfs_listxattr,
9637         .removexattr = reiserfs_removexattr,
9638         .permission = reiserfs_permission,
9639 +       .sync_flags = reiserfs_sync_flags,
9640  
9641  };
9642  
9643 @@ -1570,5 +1575,6 @@ const struct inode_operations reiserfs_s
9644         .listxattr = reiserfs_listxattr,
9645         .removexattr = reiserfs_removexattr,
9646         .permission = reiserfs_permission,
9647 +       .sync_flags = reiserfs_sync_flags,
9648  
9649  };
9650 diff -Nurp linux-2.6.22.15/fs/reiserfs/stree.c linux-2.6.22.15-vs2.3.0.29.1/fs/reiserfs/stree.c
9651 --- linux-2.6.22.15/fs/reiserfs/stree.c 2007-07-21 18:00:18.000000000 -0400
9652 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/reiserfs/stree.c    2007-12-09 06:44:21.000000000 -0500
9653 @@ -55,6 +55,7 @@
9654  #include <linux/reiserfs_fs.h>
9655  #include <linux/buffer_head.h>
9656  #include <linux/quotaops.h>
9657 +#include <linux/vs_dlimit.h>
9658  
9659  /* Does the buffer contain a disk block which is in the tree. */
9660  inline int B_IS_IN_TREE(const struct buffer_head *p_s_bh)
9661 @@ -1296,6 +1297,7 @@ int reiserfs_delete_item(struct reiserfs
9662                        "reiserquota delete_item(): freeing %u, id=%u type=%c",
9663                        quota_cut_bytes, p_s_inode->i_uid, head2type(&s_ih));
9664  #endif
9665 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
9666         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
9667  
9668         /* Return deleted body length */
9669 @@ -1384,6 +1386,7 @@ void reiserfs_delete_solid_item(struct r
9670  #endif
9671                                 DQUOT_FREE_SPACE_NODIRTY(inode,
9672                                                          quota_cut_bytes);
9673 +                               DLIMIT_FREE_SPACE(inode, quota_cut_bytes);
9674                         }
9675                         break;
9676                 }
9677 @@ -1737,6 +1740,7 @@ int reiserfs_cut_from_item(struct reiser
9678                        "reiserquota cut_from_item(): freeing %u id=%u type=%c",
9679                        quota_cut_bytes, p_s_inode->i_uid, '?');
9680  #endif
9681 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
9682         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
9683         return n_ret_value;
9684  }
9685 @@ -1978,6 +1982,11 @@ int reiserfs_paste_into_item(struct reis
9686                 pathrelse(p_s_search_path);
9687                 return -EDQUOT;
9688         }
9689 +       if (DLIMIT_ALLOC_SPACE(inode, n_pasted_size)) {
9690 +               DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
9691 +               pathrelse(p_s_search_path);
9692 +               return -ENOSPC;
9693 +       }
9694         init_tb_struct(th, &s_paste_balance, th->t_super, p_s_search_path,
9695                        n_pasted_size);
9696  #ifdef DISPLACE_NEW_PACKING_LOCALITIES
9697 @@ -2030,6 +2039,7 @@ int reiserfs_paste_into_item(struct reis
9698                        n_pasted_size, inode->i_uid,
9699                        key2type(&(p_s_key->on_disk_key)));
9700  #endif
9701 +       DLIMIT_FREE_SPACE(inode, n_pasted_size);
9702         DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
9703         return retval;
9704  }
9705 @@ -2067,6 +2077,11 @@ int reiserfs_insert_item(struct reiserfs
9706                         pathrelse(p_s_path);
9707                         return -EDQUOT;
9708                 }
9709 +               if (DLIMIT_ALLOC_SPACE(inode, quota_bytes)) {
9710 +                       DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
9711 +                       pathrelse(p_s_path);
9712 +                       return -ENOSPC;
9713 +               }
9714         }
9715         init_tb_struct(th, &s_ins_balance, th->t_super, p_s_path,
9716                        IH_SIZE + ih_item_len(p_s_ih));
9717 @@ -2114,7 +2129,9 @@ int reiserfs_insert_item(struct reiserfs
9718                        "reiserquota insert_item(): freeing %u id=%u type=%c",
9719                        quota_bytes, inode->i_uid, head2type(p_s_ih));
9720  #endif
9721 -       if (inode)
9722 +       if (inode) {
9723 +               DLIMIT_FREE_SPACE(inode, quota_bytes);
9724                 DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
9725 +       }
9726         return retval;
9727  }
9728 diff -Nurp linux-2.6.22.15/fs/reiserfs/super.c linux-2.6.22.15-vs2.3.0.29.1/fs/reiserfs/super.c
9729 --- linux-2.6.22.15/fs/reiserfs/super.c 2007-07-21 18:00:18.000000000 -0400
9730 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/reiserfs/super.c    2007-12-09 06:44:21.000000000 -0500
9731 @@ -882,6 +882,14 @@ static int reiserfs_parse_options(struct
9732                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
9733                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
9734  #endif
9735 +#ifndef CONFIG_TAGGING_NONE
9736 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
9737 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
9738 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
9739 +#endif
9740 +#ifdef CONFIG_PROPAGATE
9741 +               {"tag",.arg_required = 'T',.values = NULL},
9742 +#endif
9743  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
9744                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
9745                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
9746 @@ -1143,6 +1151,12 @@ static int reiserfs_remount(struct super
9747                 return -EINVAL;
9748         }
9749  
9750 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
9751 +               !(s->s_flags & MS_TAGGED)) {
9752 +               reiserfs_warning(s, "reiserfs: tagging not permitted on remount.");
9753 +               return -EINVAL;
9754 +       }
9755 +
9756         handle_attrs(s);
9757  
9758         /* Add options that are safe here */
9759 @@ -1591,6 +1605,10 @@ static int reiserfs_fill_super(struct su
9760                 goto error;
9761         }
9762  
9763 +       /* map mount option tagxid */
9764 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
9765 +               s->s_flags |= MS_TAGGED;
9766 +
9767         rs = SB_DISK_SUPER_BLOCK(s);
9768         /* Let's do basic sanity check to verify that underlying device is not
9769            smaller than the filesystem. If the check fails then abort and scream,
9770 diff -Nurp linux-2.6.22.15/fs/reiserfs/xattr.c linux-2.6.22.15-vs2.3.0.29.1/fs/reiserfs/xattr.c
9771 --- linux-2.6.22.15/fs/reiserfs/xattr.c 2007-07-21 18:00:18.000000000 -0400
9772 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/reiserfs/xattr.c    2007-12-09 06:44:21.000000000 -0500
9773 @@ -35,6 +35,7 @@
9774  #include <linux/namei.h>
9775  #include <linux/errno.h>
9776  #include <linux/fs.h>
9777 +#include <linux/mount.h>
9778  #include <linux/file.h>
9779  #include <linux/pagemap.h>
9780  #include <linux/xattr.h>
9781 @@ -775,7 +776,7 @@ int reiserfs_delete_xattrs(struct inode 
9782         if (dir->d_inode->i_nlink <= 2) {
9783                 root = get_xa_root(inode->i_sb, XATTR_REPLACE);
9784                 reiserfs_write_lock_xattrs(inode->i_sb);
9785 -               err = vfs_rmdir(root->d_inode, dir);
9786 +               err = vfs_rmdir(root->d_inode, dir, NULL);
9787                 reiserfs_write_unlock_xattrs(inode->i_sb);
9788                 dput(root);
9789         } else {
9790 diff -Nurp linux-2.6.22.15/fs/stat.c linux-2.6.22.15-vs2.3.0.29.1/fs/stat.c
9791 --- linux-2.6.22.15/fs/stat.c   2007-07-21 18:00:18.000000000 -0400
9792 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/stat.c      2007-12-09 06:44:21.000000000 -0500
9793 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
9794         stat->nlink = inode->i_nlink;
9795         stat->uid = inode->i_uid;
9796         stat->gid = inode->i_gid;
9797 +       stat->tag = inode->i_tag;
9798         stat->rdev = inode->i_rdev;
9799         stat->atime = inode->i_atime;
9800         stat->mtime = inode->i_mtime;
9801 diff -Nurp linux-2.6.22.15/fs/super.c linux-2.6.22.15-vs2.3.0.29.1/fs/super.c
9802 --- linux-2.6.22.15/fs/super.c  2007-07-21 18:00:18.000000000 -0400
9803 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/super.c     2007-12-09 06:44:21.000000000 -0500
9804 @@ -37,6 +37,9 @@
9805  #include <linux/idr.h>
9806  #include <linux/kobject.h>
9807  #include <linux/mutex.h>
9808 +#include <linux/devpts_fs.h>
9809 +#include <linux/proc_fs.h>
9810 +#include <linux/vs_context.h>
9811  #include <asm/uaccess.h>
9812  
9813  
9814 @@ -860,12 +863,18 @@ struct vfsmount *
9815  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
9816  {
9817         struct vfsmount *mnt;
9818 +       struct super_block *sb;
9819         char *secdata = NULL;
9820         int error;
9821  
9822         if (!type)
9823                 return ERR_PTR(-ENODEV);
9824  
9825 +       error = -EPERM;
9826 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
9827 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
9828 +               goto out;
9829 +
9830         error = -ENOMEM;
9831         mnt = alloc_vfsmnt(name);
9832         if (!mnt)
9833 @@ -885,7 +894,14 @@ vfs_kern_mount(struct file_system_type *
9834         if (error < 0)
9835                 goto out_free_secdata;
9836  
9837 -       error = security_sb_kern_mount(mnt->mnt_sb, secdata);
9838 +       sb = mnt->mnt_sb;
9839 +       error = -EPERM;
9840 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
9841 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
9842 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
9843 +               goto out_sb;
9844 +
9845 +       error = security_sb_kern_mount(sb, secdata);
9846         if (error)
9847                 goto out_sb;
9848  
9849 diff -Nurp linux-2.6.22.15/fs/sysfs/mount.c linux-2.6.22.15-vs2.3.0.29.1/fs/sysfs/mount.c
9850 --- linux-2.6.22.15/fs/sysfs/mount.c    2007-07-21 18:00:18.000000000 -0400
9851 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/sysfs/mount.c       2007-12-09 06:44:21.000000000 -0500
9852 @@ -12,8 +12,6 @@
9853  
9854  #include "sysfs.h"
9855  
9856 -/* Random magic number */
9857 -#define SYSFS_MAGIC 0x62656572
9858  
9859  struct vfsmount *sysfs_mount;
9860  struct super_block * sysfs_sb = NULL;
9861 @@ -48,7 +46,7 @@ static int sysfs_fill_super(struct super
9862  
9863         sb->s_blocksize = PAGE_CACHE_SIZE;
9864         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
9865 -       sb->s_magic = SYSFS_MAGIC;
9866 +       sb->s_magic = SYSFS_SUPER_MAGIC;
9867         sb->s_op = &sysfs_ops;
9868         sb->s_time_gran = 1;
9869         sysfs_sb = sb;
9870 diff -Nurp linux-2.6.22.15/fs/utimes.c linux-2.6.22.15-vs2.3.0.29.1/fs/utimes.c
9871 --- linux-2.6.22.15/fs/utimes.c 2007-07-21 18:00:18.000000000 -0400
9872 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/utimes.c    2007-12-09 06:44:21.000000000 -0500
9873 @@ -6,6 +6,8 @@
9874  #include <linux/sched.h>
9875  #include <linux/stat.h>
9876  #include <linux/utime.h>
9877 +#include <linux/mount.h>
9878 +#include <linux/vs_cowbl.h>
9879  #include <asm/uaccess.h>
9880  #include <asm/unistd.h>
9881  
9882 @@ -70,11 +72,13 @@ long do_utimes(int dfd, char __user *fil
9883                 if (error)
9884                         goto out;
9885  
9886 +               error = cow_check_and_break(&nd);
9887 +               if (error)
9888 +                       goto dput_and_out;
9889                 dentry = nd.dentry;
9890         }
9891  
9892         inode = dentry->d_inode;
9893 -
9894         error = -EROFS;
9895         if (IS_RDONLY(inode))
9896                 goto dput_and_out;
9897 diff -Nurp linux-2.6.22.15/fs/xattr.c linux-2.6.22.15-vs2.3.0.29.1/fs/xattr.c
9898 --- linux-2.6.22.15/fs/xattr.c  2007-07-21 18:00:18.000000000 -0400
9899 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/xattr.c     2007-12-09 06:44:21.000000000 -0500
9900 @@ -17,6 +17,7 @@
9901  #include <linux/module.h>
9902  #include <linux/fsnotify.h>
9903  #include <linux/audit.h>
9904 +#include <linux/mount.h>
9905  #include <asm/uaccess.h>
9906  
9907  
9908 @@ -194,7 +195,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
9909   */
9910  static long
9911  setxattr(struct dentry *d, char __user *name, void __user *value,
9912 -        size_t size, int flags)
9913 +        size_t size, int flags, struct vfsmount *mnt)
9914  {
9915         int error;
9916         void *kvalue = NULL;
9917 @@ -221,6 +222,9 @@ setxattr(struct dentry *d, char __user *
9918                 }
9919         }
9920  
9921 +       if (MNT_IS_RDONLY(mnt))
9922 +               return -EROFS;
9923 +
9924         error = vfs_setxattr(d, kname, kvalue, size, flags);
9925         kfree(kvalue);
9926         return error;
9927 @@ -236,7 +240,7 @@ sys_setxattr(char __user *path, char __u
9928         error = user_path_walk(path, &nd);
9929         if (error)
9930                 return error;
9931 -       error = setxattr(nd.dentry, name, value, size, flags);
9932 +       error = setxattr(nd.dentry, name, value, size, flags, nd.mnt);
9933         path_release(&nd);
9934         return error;
9935  }
9936 @@ -251,7 +255,7 @@ sys_lsetxattr(char __user *path, char __
9937         error = user_path_walk_link(path, &nd);
9938         if (error)
9939                 return error;
9940 -       error = setxattr(nd.dentry, name, value, size, flags);
9941 +       error = setxattr(nd.dentry, name, value, size, flags, nd.mnt);
9942         path_release(&nd);
9943         return error;
9944  }
9945 @@ -269,7 +273,7 @@ sys_fsetxattr(int fd, char __user *name,
9946                 return error;
9947         dentry = f->f_path.dentry;
9948         audit_inode(NULL, dentry->d_inode);
9949 -       error = setxattr(dentry, name, value, size, flags);
9950 +       error = setxattr(dentry, name, value, size, flags, f->f_vfsmnt);
9951         fput(f);
9952         return error;
9953  }
9954 @@ -433,7 +437,7 @@ sys_flistxattr(int fd, char __user *list
9955   * Extended attribute REMOVE operations
9956   */
9957  static long
9958 -removexattr(struct dentry *d, char __user *name)
9959 +removexattr(struct dentry *d, char __user *name, struct vfsmount *mnt)
9960  {
9961         int error;
9962         char kname[XATTR_NAME_MAX + 1];
9963 @@ -444,6 +448,9 @@ removexattr(struct dentry *d, char __use
9964         if (error < 0)
9965                 return error;
9966  
9967 +       if (MNT_IS_RDONLY(mnt))
9968 +               return -EROFS;
9969 +
9970         return vfs_removexattr(d, kname);
9971  }
9972  
9973 @@ -456,7 +463,7 @@ sys_removexattr(char __user *path, char 
9974         error = user_path_walk(path, &nd);
9975         if (error)
9976                 return error;
9977 -       error = removexattr(nd.dentry, name);
9978 +       error = removexattr(nd.dentry, name, nd.mnt);
9979         path_release(&nd);
9980         return error;
9981  }
9982 @@ -470,7 +477,7 @@ sys_lremovexattr(char __user *path, char
9983         error = user_path_walk_link(path, &nd);
9984         if (error)
9985                 return error;
9986 -       error = removexattr(nd.dentry, name);
9987 +       error = removexattr(nd.dentry, name, nd.mnt);
9988         path_release(&nd);
9989         return error;
9990  }
9991 @@ -487,7 +494,7 @@ sys_fremovexattr(int fd, char __user *na
9992                 return error;
9993         dentry = f->f_path.dentry;
9994         audit_inode(NULL, dentry->d_inode);
9995 -       error = removexattr(dentry, name);
9996 +       error = removexattr(dentry, name, f->f_vfsmnt);
9997         fput(f);
9998         return error;
9999  }
10000 diff -Nurp linux-2.6.22.15/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/linux-2.6/xfs_ioctl.c
10001 --- linux-2.6.22.15/fs/xfs/linux-2.6/xfs_ioctl.c        2007-07-21 17:58:49.000000000 -0400
10002 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/linux-2.6/xfs_ioctl.c   2007-12-09 06:44:21.000000000 -0500
10003 @@ -1128,6 +1128,10 @@ xfs_di2lxflags(
10004  
10005         if (di_flags & XFS_DIFLAG_IMMUTABLE)
10006                 flags |= FS_IMMUTABLE_FL;
10007 +       if (di_flags & XFS_DIFLAG_IUNLINK)
10008 +               flags |= FS_IUNLINK_FL;
10009 +       if (di_flags & XFS_DIFLAG_BARRIER)
10010 +               flags |= FS_BARRIER_FL;
10011         if (di_flags & XFS_DIFLAG_APPEND)
10012                 flags |= FS_APPEND_FL;
10013         if (di_flags & XFS_DIFLAG_SYNC)
10014 diff -Nurp linux-2.6.22.15/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/linux-2.6/xfs_iops.c
10015 --- linux-2.6.22.15/fs/xfs/linux-2.6/xfs_iops.c 2007-07-21 17:58:49.000000000 -0400
10016 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/linux-2.6/xfs_iops.c    2007-12-09 06:44:21.000000000 -0500
10017 @@ -51,6 +51,7 @@
10018  #include <linux/xattr.h>
10019  #include <linux/namei.h>
10020  #include <linux/security.h>
10021 +#include <linux/vs_tag.h>
10022  
10023  /*
10024   * Get a XFS inode from a given vnode.
10025 @@ -400,6 +401,7 @@ xfs_vn_lookup(
10026                 d_add(dentry, NULL);
10027                 return NULL;
10028         }
10029 +       dx_propagate_tag(nd, vn_to_inode(cvp));
10030  
10031         return d_splice_alias(vn_to_inode(cvp), dentry);
10032  }
10033 @@ -657,6 +659,10 @@ xfs_vn_setattr(
10034         int             flags = 0;
10035         int             error;
10036  
10037 +       error = inode_change_ok(inode, attr);
10038 +       if (error)
10039 +               return error;
10040 +
10041         if (ia_valid & ATTR_UID) {
10042                 vattr.va_mask |= XFS_AT_UID;
10043                 vattr.va_uid = attr->ia_uid;
10044 @@ -665,6 +671,10 @@ xfs_vn_setattr(
10045                 vattr.va_mask |= XFS_AT_GID;
10046                 vattr.va_gid = attr->ia_gid;
10047         }
10048 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode)) {
10049 +               vattr.va_mask |= XFS_AT_TAG;
10050 +               vattr.va_tag = attr->ia_tag;
10051 +       }
10052         if (ia_valid & ATTR_SIZE) {
10053                 vattr.va_mask |= XFS_AT_SIZE;
10054                 vattr.va_size = attr->ia_size;
10055 @@ -710,6 +720,42 @@ xfs_vn_truncate(
10056  }
10057  
10058  STATIC int
10059 +xfs_vn_sync_flags(struct inode *inode)
10060 +{
10061 +       unsigned int oldflags, newflags;
10062 +       int             flags = 0;
10063 +       int             error;
10064 +       bhv_vattr_t     vattr;
10065 +       bhv_vnode_t     *vp = vn_from_inode(inode);
10066 +
10067 +       memset(&vattr, 0, sizeof vattr);
10068 +
10069 +       vattr.va_mask = XFS_AT_XFLAGS;
10070 +       error = bhv_vop_getattr(vp, &vattr, 0, NULL);
10071 +
10072 +       if (error)
10073 +               return error;
10074 +       oldflags = vattr.va_xflags;
10075 +       newflags = oldflags & ~(XFS_XFLAG_IMMUTABLE |
10076 +               XFS_XFLAG_IUNLINK | XFS_XFLAG_BARRIER);
10077 +
10078 +       if (IS_IMMUTABLE(inode))
10079 +               newflags |= XFS_XFLAG_IMMUTABLE;
10080 +       if (IS_IUNLINK(inode))
10081 +               newflags |= XFS_XFLAG_IUNLINK;
10082 +       if (IS_BARRIER(inode))
10083 +               newflags |= XFS_XFLAG_BARRIER;
10084 +
10085 +       if (oldflags ^ newflags) {
10086 +               vattr.va_xflags = newflags;
10087 +               vattr.va_mask |= XFS_AT_XFLAGS;
10088 +               error = bhv_vop_setattr(vp, &vattr, flags, NULL);
10089 +       }
10090 +       vn_revalidate(vp);
10091 +       return error;
10092 +}
10093 +
10094 +STATIC int
10095  xfs_vn_setxattr(
10096         struct dentry   *dentry,
10097         const char      *name,
10098 @@ -822,6 +868,7 @@ const struct inode_operations xfs_inode_
10099         .getxattr               = xfs_vn_getxattr,
10100         .listxattr              = xfs_vn_listxattr,
10101         .removexattr            = xfs_vn_removexattr,
10102 +       .sync_flags             = xfs_vn_sync_flags,
10103  };
10104  
10105  const struct inode_operations xfs_dir_inode_operations = {
10106 @@ -841,6 +888,7 @@ const struct inode_operations xfs_dir_in
10107         .getxattr               = xfs_vn_getxattr,
10108         .listxattr              = xfs_vn_listxattr,
10109         .removexattr            = xfs_vn_removexattr,
10110 +       .sync_flags             = xfs_vn_sync_flags,
10111  };
10112  
10113  const struct inode_operations xfs_symlink_inode_operations = {
10114 @@ -854,4 +902,5 @@ const struct inode_operations xfs_symlin
10115         .getxattr               = xfs_vn_getxattr,
10116         .listxattr              = xfs_vn_listxattr,
10117         .removexattr            = xfs_vn_removexattr,
10118 +       .sync_flags             = xfs_vn_sync_flags,
10119  };
10120 diff -Nurp linux-2.6.22.15/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/linux-2.6/xfs_linux.h
10121 --- linux-2.6.22.15/fs/xfs/linux-2.6/xfs_linux.h        2007-07-21 17:58:49.000000000 -0400
10122 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/linux-2.6/xfs_linux.h   2007-12-09 06:44:21.000000000 -0500
10123 @@ -129,6 +129,7 @@
10124  #define current_pid()          (current->pid)
10125  #define current_fsuid(cred)    (current->fsuid)
10126  #define current_fsgid(cred)    (current->fsgid)
10127 +#define current_fstag(cred,vp) (dx_current_fstag(vn_to_inode(vp)->i_sb))
10128  #define current_test_flags(f)  (current->flags & (f))
10129  #define current_set_flags_nested(sp, f)                \
10130                 (*(sp) = current->flags, current->flags |= (f))
10131 diff -Nurp linux-2.6.22.15/fs/xfs/linux-2.6/xfs_super.c linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/linux-2.6/xfs_super.c
10132 --- linux-2.6.22.15/fs/xfs/linux-2.6/xfs_super.c        2007-07-21 18:00:18.000000000 -0400
10133 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/linux-2.6/xfs_super.c   2007-12-09 06:44:21.000000000 -0500
10134 @@ -157,6 +157,7 @@ xfs_revalidate_inode(
10135         inode->i_nlink  = ip->i_d.di_nlink;
10136         inode->i_uid    = ip->i_d.di_uid;
10137         inode->i_gid    = ip->i_d.di_gid;
10138 +       inode->i_tag    = ip->i_d.di_tag;
10139  
10140         switch (inode->i_mode & S_IFMT) {
10141         case S_IFBLK:
10142 @@ -184,6 +185,14 @@ xfs_revalidate_inode(
10143                 inode->i_flags |= S_IMMUTABLE;
10144         else
10145                 inode->i_flags &= ~S_IMMUTABLE;
10146 +       if (ip->i_d.di_flags & XFS_DIFLAG_IUNLINK)
10147 +               inode->i_flags |= S_IUNLINK;
10148 +       else
10149 +               inode->i_flags &= ~S_IUNLINK;
10150 +       if (ip->i_d.di_flags & XFS_DIFLAG_BARRIER)
10151 +               inode->i_flags |= S_BARRIER;
10152 +       else
10153 +               inode->i_flags &= ~S_BARRIER;
10154         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
10155                 inode->i_flags |= S_APPEND;
10156         else
10157 @@ -712,6 +721,12 @@ xfs_fs_remount(
10158         int                     error;
10159  
10160         error = bhv_vfs_parseargs(vfsp, options, args, 1);
10161 +       if ((args->flags2 & XFSMNT2_TAGGED) &&
10162 +               !(sb->s_flags & MS_TAGGED)) {
10163 +               printk("XFS: %s: tagging not permitted on remount.\n",
10164 +                       sb->s_id);
10165 +               error = EINVAL;
10166 +       }
10167         if (!error)
10168                 error = bhv_vfs_mntupdate(vfsp, flags, args);
10169         kmem_free(args, sizeof(*args));
10170 diff -Nurp linux-2.6.22.15/fs/xfs/linux-2.6/xfs_vnode.c linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/linux-2.6/xfs_vnode.c
10171 --- linux-2.6.22.15/fs/xfs/linux-2.6/xfs_vnode.c        2007-07-21 17:58:49.000000000 -0400
10172 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/linux-2.6/xfs_vnode.c   2007-12-09 06:44:21.000000000 -0500
10173 @@ -119,6 +119,7 @@ vn_revalidate_core(
10174         inode->i_nlink      = vap->va_nlink;
10175         inode->i_uid        = vap->va_uid;
10176         inode->i_gid        = vap->va_gid;
10177 +       inode->i_tag        = vap->va_tag;
10178         inode->i_blocks     = vap->va_nblocks;
10179         inode->i_mtime      = vap->va_mtime;
10180         inode->i_ctime      = vap->va_ctime;
10181 @@ -126,6 +127,14 @@ vn_revalidate_core(
10182                 inode->i_flags |= S_IMMUTABLE;
10183         else
10184                 inode->i_flags &= ~S_IMMUTABLE;
10185 +       if (vap->va_xflags & XFS_XFLAG_IUNLINK)
10186 +               inode->i_flags |= S_IUNLINK;
10187 +       else
10188 +               inode->i_flags &= ~S_IUNLINK;
10189 +       if (vap->va_xflags & XFS_XFLAG_BARRIER)
10190 +               inode->i_flags |= S_BARRIER;
10191 +       else
10192 +               inode->i_flags &= ~S_BARRIER;
10193         if (vap->va_xflags & XFS_XFLAG_APPEND)
10194                 inode->i_flags |= S_APPEND;
10195         else
10196 diff -Nurp linux-2.6.22.15/fs/xfs/linux-2.6/xfs_vnode.h linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/linux-2.6/xfs_vnode.h
10197 --- linux-2.6.22.15/fs/xfs/linux-2.6/xfs_vnode.h        2007-07-21 18:00:18.000000000 -0400
10198 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/linux-2.6/xfs_vnode.h   2007-12-09 06:44:21.000000000 -0500
10199 @@ -350,6 +350,7 @@ typedef struct bhv_vattr {
10200         xfs_nlink_t     va_nlink;       /* number of references to file */
10201         uid_t           va_uid;         /* owner user id */
10202         gid_t           va_gid;         /* owner group id */
10203 +       tag_t           va_tag;         /* owner group id */
10204         xfs_ino_t       va_nodeid;      /* file id */
10205         xfs_off_t       va_size;        /* file size in bytes */
10206         u_long          va_blocksize;   /* blocksize preferred for i/o */
10207 @@ -398,13 +399,15 @@ typedef struct bhv_vattr {
10208  #define XFS_AT_PROJID          0x04000000
10209  #define XFS_AT_SIZE_NOPERM     0x08000000
10210  #define XFS_AT_GENCOUNT                0x10000000
10211 +#define XFS_AT_TAG             0x20000000
10212  
10213  #define XFS_AT_ALL     (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
10214                 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
10215                 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
10216                 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|XFS_AT_MAC|\
10217                 XFS_AT_ACL|XFS_AT_CAP|XFS_AT_INF|XFS_AT_XFLAGS|XFS_AT_EXTSIZE|\
10218 -               XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_PROJID|XFS_AT_GENCOUNT)
10219 +               XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_PROJID|XFS_AT_GENCOUNT\
10220 +               XFS_AT_TAG)
10221  
10222  #define XFS_AT_STAT    (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
10223                 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
10224 diff -Nurp linux-2.6.22.15/fs/xfs/quota/xfs_qm_syscalls.c linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/quota/xfs_qm_syscalls.c
10225 --- linux-2.6.22.15/fs/xfs/quota/xfs_qm_syscalls.c      2007-07-21 18:00:18.000000000 -0400
10226 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/quota/xfs_qm_syscalls.c 2007-12-09 06:44:21.000000000 -0500
10227 @@ -17,6 +17,7 @@
10228   */
10229  
10230  #include <linux/capability.h>
10231 +#include <linux/vs_context.h>
10232  
10233  #include "xfs.h"
10234  #include "xfs_fs.h"
10235 @@ -211,7 +212,7 @@ xfs_qm_scall_quotaoff(
10236         xfs_qoff_logitem_t      *qoffstart;
10237         int                     nculprits;
10238  
10239 -       if (!force && !capable(CAP_SYS_ADMIN))
10240 +       if (!force && !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
10241                 return XFS_ERROR(EPERM);
10242         /*
10243          * No file system can have quotas enabled on disk but not in core.
10244 @@ -380,7 +381,7 @@ xfs_qm_scall_trunc_qfiles(
10245         int             error;
10246         xfs_inode_t     *qip;
10247  
10248 -       if (!capable(CAP_SYS_ADMIN))
10249 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
10250                 return XFS_ERROR(EPERM);
10251         error = 0;
10252         if (!XFS_SB_VERSION_HASQUOTA(&mp->m_sb) || flags == 0) {
10253 @@ -425,7 +426,7 @@ xfs_qm_scall_quotaon(
10254         uint            accflags;
10255         __int64_t       sbflags;
10256  
10257 -       if (!capable(CAP_SYS_ADMIN))
10258 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
10259                 return XFS_ERROR(EPERM);
10260  
10261         flags &= (XFS_ALL_QUOTA_ACCT | XFS_ALL_QUOTA_ENFD);
10262 @@ -594,7 +595,7 @@ xfs_qm_scall_setqlim(
10263         int                     error;
10264         xfs_qcnt_t              hard, soft;
10265  
10266 -       if (!capable(CAP_SYS_ADMIN))
10267 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
10268                 return XFS_ERROR(EPERM);
10269  
10270         if ((newlim->d_fieldmask &
10271 diff -Nurp linux-2.6.22.15/fs/xfs/xfs_clnt.h linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/xfs_clnt.h
10272 --- linux-2.6.22.15/fs/xfs/xfs_clnt.h   2006-06-17 21:49:35.000000000 -0400
10273 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/xfs_clnt.h      2007-12-09 06:44:21.000000000 -0500
10274 @@ -99,5 +99,7 @@ struct xfs_mount_args {
10275   */
10276  #define XFSMNT2_COMPAT_IOSIZE  0x00000001      /* don't report large preferred
10277                                                  * I/O size in stat(2) */
10278 +#define XFSMNT2_TAGGED         0x80000000      /* context tagging */
10279 +
10280  
10281  #endif /* __XFS_CLNT_H__ */
10282 diff -Nurp linux-2.6.22.15/fs/xfs/xfs_dinode.h linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/xfs_dinode.h
10283 --- linux-2.6.22.15/fs/xfs/xfs_dinode.h 2007-05-04 09:55:41.000000000 -0400
10284 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/xfs_dinode.h    2007-12-09 06:44:21.000000000 -0500
10285 @@ -53,7 +53,8 @@ typedef struct xfs_dinode_core
10286         __uint32_t      di_gid;         /* owner's group id */
10287         __uint32_t      di_nlink;       /* number of links to file */
10288         __uint16_t      di_projid;      /* owner's project id */
10289 -       __uint8_t       di_pad[8];      /* unused, zeroed space */
10290 +       __uint16_t      di_tag;         /* context tagging */
10291 +       __uint8_t       di_pad[6];      /* unused, zeroed space */
10292         __uint16_t      di_flushiter;   /* incremented on flush */
10293         xfs_timestamp_t di_atime;       /* time last accessed */
10294         xfs_timestamp_t di_mtime;       /* time last modified */
10295 @@ -257,6 +258,9 @@ typedef enum xfs_dinode_fmt
10296  #define XFS_DIFLAG_EXTSIZE_BIT      11 /* inode extent size allocator hint */
10297  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
10298  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
10299 +#define XFS_DIFLAG_BARRIER_BIT 14      /* chroot() barrier */
10300 +#define XFS_DIFLAG_IUNLINK_BIT 15      /* immutable unlink */
10301 +
10302  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
10303  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
10304  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
10305 @@ -271,12 +275,15 @@ typedef enum xfs_dinode_fmt
10306  #define XFS_DIFLAG_EXTSIZE       (1 << XFS_DIFLAG_EXTSIZE_BIT)
10307  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
10308  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
10309 +#define XFS_DIFLAG_BARRIER      (1 << XFS_DIFLAG_BARRIER_BIT)
10310 +#define XFS_DIFLAG_IUNLINK      (1 << XFS_DIFLAG_IUNLINK_BIT)
10311  
10312  #define XFS_DIFLAG_ANY \
10313         (XFS_DIFLAG_REALTIME | XFS_DIFLAG_PREALLOC | XFS_DIFLAG_NEWRTBM | \
10314          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
10315          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
10316          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
10317 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG)
10318 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_BARRIER | \
10319 +        XFS_DIFLAG_IUNLINK)
10320  
10321  #endif /* __XFS_DINODE_H__ */
10322 diff -Nurp linux-2.6.22.15/fs/xfs/xfs_fs.h linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/xfs_fs.h
10323 --- linux-2.6.22.15/fs/xfs/xfs_fs.h     2007-05-04 09:57:37.000000000 -0400
10324 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/xfs_fs.h        2007-12-09 06:44:21.000000000 -0500
10325 @@ -66,6 +66,8 @@ struct fsxattr {
10326  #define XFS_XFLAG_EXTSIZE      0x00000800      /* extent size allocator hint */
10327  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
10328  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
10329 +#define XFS_XFLAG_BARRIER      0x00004000      /* chroot() barrier */
10330 +#define XFS_XFLAG_IUNLINK      0x00008000      /* immutable unlink */
10331  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
10332  
10333  /*
10334 @@ -294,7 +296,8 @@ typedef struct xfs_bstat {
10335         __s32           bs_extents;     /* number of extents            */
10336         __u32           bs_gen;         /* generation count             */
10337         __u16           bs_projid;      /* project id                   */
10338 -       unsigned char   bs_pad[14];     /* pad space, unused            */
10339 +       __u16           bs_tag;         /* context tagging              */
10340 +       unsigned char   bs_pad[12];     /* pad space, unused            */
10341         __u32           bs_dmevmask;    /* DMIG event mask              */
10342         __u16           bs_dmstate;     /* DMIG state info              */
10343         __u16           bs_aextents;    /* attribute number of extents  */
10344 diff -Nurp linux-2.6.22.15/fs/xfs/xfs_inode.c linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/xfs_inode.c
10345 --- linux-2.6.22.15/fs/xfs/xfs_inode.c  2007-07-21 18:00:18.000000000 -0400
10346 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/xfs_inode.c     2007-12-09 06:44:22.000000000 -0500
10347 @@ -49,6 +49,7 @@
10348  #include "xfs_quota.h"
10349  #include "xfs_acl.h"
10350  
10351 +#include <linux/vs_tag.h>
10352  
10353  kmem_zone_t *xfs_ifork_zone;
10354  kmem_zone_t *xfs_inode_zone;
10355 @@ -736,20 +737,35 @@ xfs_xlate_dinode_core(
10356         xfs_dinode_core_t       *buf_core = (xfs_dinode_core_t *)buf;
10357         xfs_dinode_core_t       *mem_core = (xfs_dinode_core_t *)dip;
10358         xfs_arch_t              arch = ARCH_CONVERT;
10359 +       uint32_t                uid = 0, gid = 0;
10360 +       uint16_t                tag = 0;
10361  
10362         ASSERT(dir);
10363  
10364 +       if (dir < 0) {
10365 +               tag = mem_core->di_tag;
10366 +               /* FIXME: supposed to use superblock flag */
10367 +               uid = TAGINO_UID(1, mem_core->di_uid, tag);
10368 +               gid = TAGINO_GID(1, mem_core->di_gid, tag);
10369 +               tag = TAGINO_TAG(1, tag);
10370 +       }
10371 +
10372         INT_XLATE(buf_core->di_magic, mem_core->di_magic, dir, arch);
10373         INT_XLATE(buf_core->di_mode, mem_core->di_mode, dir, arch);
10374         INT_XLATE(buf_core->di_version, mem_core->di_version, dir, arch);
10375         INT_XLATE(buf_core->di_format, mem_core->di_format, dir, arch);
10376         INT_XLATE(buf_core->di_onlink, mem_core->di_onlink, dir, arch);
10377 -       INT_XLATE(buf_core->di_uid, mem_core->di_uid, dir, arch);
10378 -       INT_XLATE(buf_core->di_gid, mem_core->di_gid, dir, arch);
10379 +       INT_XLATE(buf_core->di_uid, uid, dir, arch);
10380 +       INT_XLATE(buf_core->di_gid, gid, dir, arch);
10381 +       INT_XLATE(buf_core->di_tag, tag, dir, arch);
10382         INT_XLATE(buf_core->di_nlink, mem_core->di_nlink, dir, arch);
10383         INT_XLATE(buf_core->di_projid, mem_core->di_projid, dir, arch);
10384  
10385         if (dir > 0) {
10386 +               /* FIXME: supposed to use superblock flag */
10387 +               mem_core->di_uid = INOTAG_UID(1, uid, gid);
10388 +               mem_core->di_gid = INOTAG_GID(1, uid, gid);
10389 +               mem_core->di_tag = INOTAG_TAG(1, uid, gid, tag);
10390                 memcpy(mem_core->di_pad, buf_core->di_pad,
10391                         sizeof(buf_core->di_pad));
10392         } else {
10393 @@ -797,6 +813,10 @@ _xfs_dic2xflags(
10394                         flags |= XFS_XFLAG_PREALLOC;
10395                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
10396                         flags |= XFS_XFLAG_IMMUTABLE;
10397 +               if (di_flags & XFS_DIFLAG_IUNLINK)
10398 +                       flags |= XFS_XFLAG_IUNLINK;
10399 +               if (di_flags & XFS_DIFLAG_BARRIER)
10400 +                       flags |= XFS_XFLAG_BARRIER;
10401                 if (di_flags & XFS_DIFLAG_APPEND)
10402                         flags |= XFS_XFLAG_APPEND;
10403                 if (di_flags & XFS_DIFLAG_SYNC)
10404 @@ -1129,6 +1149,7 @@ xfs_ialloc(
10405         ASSERT(ip->i_d.di_nlink == nlink);
10406         ip->i_d.di_uid = current_fsuid(cr);
10407         ip->i_d.di_gid = current_fsgid(cr);
10408 +       ip->i_d.di_tag = current_fstag(cr, vp);
10409         ip->i_d.di_projid = prid;
10410         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
10411  
10412 diff -Nurp linux-2.6.22.15/fs/xfs/xfs_itable.c linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/xfs_itable.c
10413 --- linux-2.6.22.15/fs/xfs/xfs_itable.c 2007-07-21 18:00:18.000000000 -0400
10414 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/xfs_itable.c    2007-12-09 06:44:22.000000000 -0500
10415 @@ -89,6 +89,7 @@ xfs_bulkstat_one_iget(
10416         buf->bs_mode = dic->di_mode;
10417         buf->bs_uid = dic->di_uid;
10418         buf->bs_gid = dic->di_gid;
10419 +       buf->bs_tag = dic->di_tag;
10420         buf->bs_size = dic->di_size;
10421         vn_atime_to_bstime(vp, &buf->bs_atime);
10422         buf->bs_mtime.tv_sec = dic->di_mtime.t_sec;
10423 @@ -163,6 +164,7 @@ xfs_bulkstat_one_dinode(
10424         buf->bs_mode = INT_GET(dic->di_mode, ARCH_CONVERT);
10425         buf->bs_uid = INT_GET(dic->di_uid, ARCH_CONVERT);
10426         buf->bs_gid = INT_GET(dic->di_gid, ARCH_CONVERT);
10427 +       buf->bs_tag = INT_GET(dic->di_tag, ARCH_CONVERT);
10428         buf->bs_size = INT_GET(dic->di_size, ARCH_CONVERT);
10429         buf->bs_atime.tv_sec = INT_GET(dic->di_atime.t_sec, ARCH_CONVERT);
10430         buf->bs_atime.tv_nsec = INT_GET(dic->di_atime.t_nsec, ARCH_CONVERT);
10431 diff -Nurp linux-2.6.22.15/fs/xfs/xfs_mount.h linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/xfs_mount.h
10432 --- linux-2.6.22.15/fs/xfs/xfs_mount.h  2007-07-21 17:58:49.000000000 -0400
10433 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/xfs_mount.h     2007-12-09 06:44:22.000000000 -0500
10434 @@ -464,6 +464,7 @@ typedef struct xfs_mount {
10435  #define XFS_MOUNT_NO_PERCPU_SB (1ULL << 23)    /* don't use per-cpu superblock
10436                                                    counters */
10437  
10438 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
10439  
10440  /*
10441   * Default minimum read and write sizes.
10442 diff -Nurp linux-2.6.22.15/fs/xfs/xfs_vfsops.c linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/xfs_vfsops.c
10443 --- linux-2.6.22.15/fs/xfs/xfs_vfsops.c 2007-07-21 18:00:18.000000000 -0400
10444 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/xfs_vfsops.c    2007-12-09 06:44:22.000000000 -0500
10445 @@ -300,6 +300,8 @@ xfs_start_flags(
10446  
10447         if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
10448                 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
10449 +       if (ap->flags2 & XFSMNT2_TAGGED)
10450 +               mp->m_flags |= XFS_MOUNT_TAGGED;
10451  
10452         /*
10453          * no recovery flag requires a read-only mount
10454 @@ -394,6 +396,8 @@ xfs_finish_flags(
10455                         return XFS_ERROR(EINVAL);
10456         }
10457  
10458 +       if (ap->flags2 & XFSMNT2_TAGGED)
10459 +               vfs->vfs_super->s_flags |= MS_TAGGED;
10460         return 0;
10461  }
10462  
10463 @@ -1645,6 +1649,9 @@ xfs_vget(
10464                                          * in stat(). */
10465  #define MNTOPT_ATTR2   "attr2"         /* do use attr2 attribute format */
10466  #define MNTOPT_NOATTR2 "noattr2"       /* do not use attr2 attribute format */
10467 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
10468 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
10469 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
10470  
10471  STATIC unsigned long
10472  suffix_strtoul(char *s, char **endp, unsigned int base)
10473 @@ -1831,6 +1838,19 @@ xfs_parseargs(
10474                         args->flags |= XFSMNT_ATTR2;
10475                 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
10476                         args->flags &= ~XFSMNT_ATTR2;
10477 +#ifndef CONFIG_TAGGING_NONE
10478 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
10479 +                       args->flags2 |= XFSMNT2_TAGGED;
10480 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
10481 +                       args->flags2 &= ~XFSMNT2_TAGGED;
10482 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
10483 +                       args->flags2 |= XFSMNT2_TAGGED;
10484 +#endif
10485 +#ifdef CONFIG_PROPAGATE
10486 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
10487 +                       /* use value */
10488 +                       args->flags2 |= XFSMNT2_TAGGED;
10489 +#endif
10490                 } else if (!strcmp(this_char, "osyncisdsync")) {
10491                         /* no-op, this is now the default */
10492                         cmn_err(CE_WARN,
10493 diff -Nurp linux-2.6.22.15/fs/xfs/xfs_vnodeops.c linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/xfs_vnodeops.c
10494 --- linux-2.6.22.15/fs/xfs/xfs_vnodeops.c       2007-07-21 18:00:18.000000000 -0400
10495 +++ linux-2.6.22.15-vs2.3.0.29.1/fs/xfs/xfs_vnodeops.c  2007-12-09 06:44:22.000000000 -0500
10496 @@ -159,6 +159,7 @@ xfs_getattr(
10497         vap->va_mode = ip->i_d.di_mode;
10498         vap->va_uid = ip->i_d.di_uid;
10499         vap->va_gid = ip->i_d.di_gid;
10500 +       vap->va_tag = ip->i_d.di_tag;
10501         vap->va_projid = ip->i_d.di_projid;
10502  
10503         /*
10504 @@ -259,6 +260,7 @@ xfs_setattr(
10505         uint                    commit_flags=0;
10506         uid_t                   uid=0, iuid=0;
10507         gid_t                   gid=0, igid=0;
10508 +       tag_t                   tag=0, itag=0;
10509         int                     timeflags = 0;
10510         bhv_vnode_t             *vp;
10511         xfs_prid_t              projid=0, iprojid=0;
10512 @@ -315,6 +317,7 @@ xfs_setattr(
10513             (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_PROJID))) {
10514                 uint    qflags = 0;
10515  
10516 +               /* TODO: handle tagging? */
10517                 if ((mask & XFS_AT_UID) && XFS_IS_UQUOTA_ON(mp)) {
10518                         uid = vap->va_uid;
10519                         qflags |= XFS_QMOPT_UQUOTA;
10520 @@ -394,6 +397,8 @@ xfs_setattr(
10521         if (mask &
10522             (XFS_AT_MODE|XFS_AT_XFLAGS|XFS_AT_EXTSIZE|XFS_AT_UID|
10523              XFS_AT_GID|XFS_AT_PROJID)) {
10524 +               /* TODO: handle tagging? */
10525 +
10526                 /*
10527                  * CAP_FOWNER overrides the following restrictions:
10528                  *
10529 @@ -442,7 +447,7 @@ xfs_setattr(
10530          * and can change the group id only to a group of which he
10531          * or she is a member.
10532          */
10533 -       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_PROJID)) {
10534 +       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_TAG|XFS_AT_PROJID)) {
10535                 /*
10536                  * These IDs could have changed since we last looked at them.
10537                  * But, we're assured that if the ownership did change
10538 @@ -450,10 +455,12 @@ xfs_setattr(
10539                  * would have changed also.
10540                  */
10541                 iuid = ip->i_d.di_uid;
10542 -               iprojid = ip->i_d.di_projid;
10543                 igid = ip->i_d.di_gid;
10544 -               gid = (mask & XFS_AT_GID) ? vap->va_gid : igid;
10545 +               itag = ip->i_d.di_tag;
10546 +               iprojid = ip->i_d.di_projid;
10547                 uid = (mask & XFS_AT_UID) ? vap->va_uid : iuid;
10548 +               gid = (mask & XFS_AT_GID) ? vap->va_gid : igid;
10549 +               tag = (mask & XFS_AT_TAG) ? vap->va_tag : itag;
10550                 projid = (mask & XFS_AT_PROJID) ? (xfs_prid_t)vap->va_projid :
10551                          iprojid;
10552  
10553 @@ -481,6 +488,7 @@ xfs_setattr(
10554                 if ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
10555                     (XFS_IS_PQUOTA_ON(mp) && iprojid != projid) ||
10556                     (XFS_IS_GQUOTA_ON(mp) && igid != gid)) {
10557 +                       /* TODO: handle tagging? */
10558                         ASSERT(tp);
10559                         code = XFS_QM_DQVOPCHOWNRESV(mp, tp, ip, udqp, gdqp,
10560                                                 capable(CAP_FOWNER) ?
10561 @@ -706,7 +714,7 @@ xfs_setattr(
10562          * and can change the group id only to a group of which he
10563          * or she is a member.
10564          */
10565 -       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_PROJID)) {
10566 +       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_TAG|XFS_AT_PROJID)) {
10567                 /*
10568                  * CAP_FSETID overrides the following restrictions:
10569                  *
10570 @@ -722,6 +730,9 @@ xfs_setattr(
10571                  * Change the ownerships and register quota modifications
10572                  * in the transaction.
10573                  */
10574 +               if (itag != tag) {
10575 +                       ip->i_d.di_tag = tag;
10576 +               }
10577                 if (iuid != uid) {
10578                         if (XFS_IS_UQUOTA_ON(mp)) {
10579                                 ASSERT(mask & XFS_AT_UID);
10580 @@ -802,6 +813,10 @@ xfs_setattr(
10581                         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
10582                         if (vap->va_xflags & XFS_XFLAG_IMMUTABLE)
10583                                 di_flags |= XFS_DIFLAG_IMMUTABLE;
10584 +                       if (vap->va_xflags & XFS_XFLAG_IUNLINK)
10585 +                               di_flags |= XFS_DIFLAG_IUNLINK;
10586 +                       if (vap->va_xflags & XFS_XFLAG_BARRIER)
10587 +                               di_flags |= XFS_DIFLAG_BARRIER;
10588                         if (vap->va_xflags & XFS_XFLAG_APPEND)
10589                                 di_flags |= XFS_DIFLAG_APPEND;
10590                         if (vap->va_xflags & XFS_XFLAG_SYNC)
10591 diff -Nurp linux-2.6.22.15/include/asm-alpha/socket.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-alpha/socket.h
10592 --- linux-2.6.22.15/include/asm-alpha/socket.h  2007-07-21 18:00:18.000000000 -0400
10593 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-alpha/socket.h     2007-12-09 06:44:22.000000000 -0500
10594 @@ -55,6 +55,8 @@
10595  #define SO_TIMESTAMPNS         35
10596  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10597  
10598 +#define SO_PEERTAG             36
10599 +
10600  /* Security levels - as per NRL IPv6 - don't actually do anything */
10601  #define SO_SECURITY_AUTHENTICATION             19
10602  #define SO_SECURITY_ENCRYPTION_TRANSPORT       20
10603 diff -Nurp linux-2.6.22.15/include/asm-arm/socket.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-arm/socket.h
10604 --- linux-2.6.22.15/include/asm-arm/socket.h    2007-07-21 18:00:19.000000000 -0400
10605 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-arm/socket.h       2007-12-09 06:44:22.000000000 -0500
10606 @@ -52,4 +52,6 @@
10607  #define SO_TIMESTAMPNS         35
10608  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10609  
10610 +#define SO_PEERTAG             36
10611 +
10612  #endif /* _ASM_SOCKET_H */
10613 diff -Nurp linux-2.6.22.15/include/asm-arm/tlb.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-arm/tlb.h
10614 --- linux-2.6.22.15/include/asm-arm/tlb.h       2006-06-17 21:49:35.000000000 -0400
10615 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-arm/tlb.h  2007-12-09 06:44:22.000000000 -0500
10616 @@ -28,6 +28,7 @@
10617  #else /* !CONFIG_MMU */
10618  
10619  #include <asm/pgalloc.h>
10620 +#include <linux/vs_memory.h>
10621  
10622  /*
10623   * TLB handling.  This allows us to remove pages from the page
10624 diff -Nurp linux-2.6.22.15/include/asm-arm26/tlb.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-arm26/tlb.h
10625 --- linux-2.6.22.15/include/asm-arm26/tlb.h     2006-06-17 21:49:35.000000000 -0400
10626 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-arm26/tlb.h        2007-12-09 06:44:22.000000000 -0500
10627 @@ -3,6 +3,7 @@
10628  
10629  #include <asm/pgalloc.h>
10630  #include <asm/tlbflush.h>
10631 +#include <linux/vs_memory.h>
10632  
10633  /*
10634   * TLB handling.  This allows us to remove pages from the page
10635 diff -Nurp linux-2.6.22.15/include/asm-arm26/unistd.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-arm26/unistd.h
10636 --- linux-2.6.22.15/include/asm-arm26/unistd.h  2007-05-04 09:58:22.000000000 -0400
10637 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-arm26/unistd.h     2007-12-09 06:44:22.000000000 -0500
10638 @@ -302,6 +302,8 @@
10639  #define __NR_mq_getsetattr             (__NR_SYSCALL_BASE+279)
10640  #define __NR_waitid                    (__NR_SYSCALL_BASE+280)
10641  
10642 +#define __NR_vserver                   (__NR_SYSCALL_BASE+313)
10643 +
10644  /*
10645   * The following SWIs are ARM private. FIXME - make appropriate for arm26
10646   */
10647 diff -Nurp linux-2.6.22.15/include/asm-cris/socket.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-cris/socket.h
10648 --- linux-2.6.22.15/include/asm-cris/socket.h   2007-07-21 18:00:19.000000000 -0400
10649 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-cris/socket.h      2007-12-09 06:44:22.000000000 -0500
10650 @@ -54,6 +54,8 @@
10651  #define SO_TIMESTAMPNS         35
10652  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10653  
10654 +#define SO_PEERTAG             36
10655 +
10656  #endif /* _ASM_SOCKET_H */
10657  
10658  
10659 diff -Nurp linux-2.6.22.15/include/asm-frv/socket.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-frv/socket.h
10660 --- linux-2.6.22.15/include/asm-frv/socket.h    2007-07-21 18:00:19.000000000 -0400
10661 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-frv/socket.h       2007-12-09 06:44:22.000000000 -0500
10662 @@ -52,5 +52,7 @@
10663  #define SO_TIMESTAMPNS         35
10664  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10665  
10666 +#define SO_PEERTAG             36
10667 +
10668  #endif /* _ASM_SOCKET_H */
10669  
10670 diff -Nurp linux-2.6.22.15/include/asm-generic/tlb.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-generic/tlb.h
10671 --- linux-2.6.22.15/include/asm-generic/tlb.h   2007-05-04 09:57:38.000000000 -0400
10672 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-generic/tlb.h      2007-12-09 06:44:22.000000000 -0500
10673 @@ -14,6 +14,7 @@
10674  #define _ASM_GENERIC__TLB_H
10675  
10676  #include <linux/swap.h>
10677 +#include <linux/vs_memory.h>
10678  #include <asm/pgalloc.h>
10679  #include <asm/tlbflush.h>
10680  
10681 diff -Nurp linux-2.6.22.15/include/asm-h8300/socket.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-h8300/socket.h
10682 --- linux-2.6.22.15/include/asm-h8300/socket.h  2007-07-21 18:00:19.000000000 -0400
10683 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-h8300/socket.h     2007-12-09 06:44:22.000000000 -0500
10684 @@ -52,4 +52,6 @@
10685  #define SO_TIMESTAMPNS         35
10686  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10687  
10688 +#define SO_PEERTAG             36
10689 +
10690  #endif /* _ASM_SOCKET_H */
10691 diff -Nurp linux-2.6.22.15/include/asm-i386/socket.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-i386/socket.h
10692 --- linux-2.6.22.15/include/asm-i386/socket.h   2007-07-21 18:00:19.000000000 -0400
10693 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-i386/socket.h      2007-12-09 06:44:22.000000000 -0500
10694 @@ -52,4 +52,6 @@
10695  #define SO_TIMESTAMPNS         35
10696  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10697  
10698 +#define SO_PEERTAG             36
10699 +
10700  #endif /* _ASM_SOCKET_H */
10701 diff -Nurp linux-2.6.22.15/include/asm-ia64/socket.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-ia64/socket.h
10702 --- linux-2.6.22.15/include/asm-ia64/socket.h   2007-07-21 18:00:19.000000000 -0400
10703 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-ia64/socket.h      2007-12-09 06:44:22.000000000 -0500
10704 @@ -61,4 +61,6 @@
10705  #define SO_TIMESTAMPNS         35
10706  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10707  
10708 +#define SO_PEERTAG             36
10709 +
10710  #endif /* _ASM_IA64_SOCKET_H */
10711 diff -Nurp linux-2.6.22.15/include/asm-ia64/tlb.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-ia64/tlb.h
10712 --- linux-2.6.22.15/include/asm-ia64/tlb.h      2007-05-04 09:55:44.000000000 -0400
10713 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-ia64/tlb.h 2007-12-09 06:44:22.000000000 -0500
10714 @@ -40,6 +40,7 @@
10715  #include <linux/mm.h>
10716  #include <linux/pagemap.h>
10717  #include <linux/swap.h>
10718 +#include <linux/vs_memory.h>
10719  
10720  #include <asm/pgalloc.h>
10721  #include <asm/processor.h>
10722 diff -Nurp linux-2.6.22.15/include/asm-m32r/socket.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-m32r/socket.h
10723 --- linux-2.6.22.15/include/asm-m32r/socket.h   2007-07-21 18:00:19.000000000 -0400
10724 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-m32r/socket.h      2007-12-09 06:44:22.000000000 -0500
10725 @@ -52,4 +52,6 @@
10726  #define SO_TIMESTAMPNS         35
10727  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10728  
10729 +#define SO_PEERTAG             36
10730 +
10731  #endif /* _ASM_M32R_SOCKET_H */
10732 diff -Nurp linux-2.6.22.15/include/asm-mips/socket.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-mips/socket.h
10733 --- linux-2.6.22.15/include/asm-mips/socket.h   2007-07-21 18:00:19.000000000 -0400
10734 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-mips/socket.h      2007-12-09 06:44:22.000000000 -0500
10735 @@ -73,6 +73,8 @@ To add: #define SO_REUSEPORT 0x0200   /* A
10736  #define SO_TIMESTAMPNS         35
10737  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10738  
10739 +#define SO_PEERTAG             36
10740 +
10741  #ifdef __KERNEL__
10742  
10743  /** sock_type - Socket types
10744 diff -Nurp linux-2.6.22.15/include/asm-parisc/socket.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-parisc/socket.h
10745 --- linux-2.6.22.15/include/asm-parisc/socket.h 2007-07-21 18:00:20.000000000 -0400
10746 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-parisc/socket.h    2007-12-09 06:44:22.000000000 -0500
10747 @@ -51,5 +51,6 @@
10748  
10749  #define SO_PEERSEC             0x401d
10750  #define SO_PASSSEC             0x401e
10751 +#define SO_PEERTAG             0x401f
10752  
10753  #endif /* _ASM_SOCKET_H */
10754 diff -Nurp linux-2.6.22.15/include/asm-powerpc/socket.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-powerpc/socket.h
10755 --- linux-2.6.22.15/include/asm-powerpc/socket.h        2007-07-21 18:00:20.000000000 -0400
10756 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-powerpc/socket.h   2007-12-09 06:44:22.000000000 -0500
10757 @@ -59,4 +59,6 @@
10758  #define SO_TIMESTAMPNS         35
10759  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10760  
10761 +#define SO_PEERTAG             36
10762 +
10763  #endif /* _ASM_POWERPC_SOCKET_H */
10764 diff -Nurp linux-2.6.22.15/include/asm-powerpc/systbl.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-powerpc/systbl.h
10765 --- linux-2.6.22.15/include/asm-powerpc/systbl.h        2007-07-21 18:00:20.000000000 -0400
10766 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-powerpc/systbl.h   2007-12-09 06:44:22.000000000 -0500
10767 @@ -260,7 +260,7 @@ COMPAT_SYS_SPU(fstatfs64)
10768  SYSX(sys_ni_syscall, ppc_fadvise64_64, ppc_fadvise64_64)
10769  PPC_SYS_SPU(rtas)
10770  OLDSYS(debug_setcontext)
10771 -SYSCALL(ni_syscall)
10772 +SYSX(sys_vserver, sys32_vserver, sys_vserver)
10773  COMPAT_SYS(migrate_pages)
10774  COMPAT_SYS(mbind)
10775  COMPAT_SYS(get_mempolicy)
10776 diff -Nurp linux-2.6.22.15/include/asm-powerpc/unistd.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-powerpc/unistd.h
10777 --- linux-2.6.22.15/include/asm-powerpc/unistd.h        2007-07-21 18:00:20.000000000 -0400
10778 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-powerpc/unistd.h   2007-12-09 06:44:22.000000000 -0500
10779 @@ -275,7 +275,7 @@
10780  #endif
10781  #define __NR_rtas              255
10782  #define __NR_sys_debug_setcontext 256
10783 -/* Number 257 is reserved for vserver */
10784 +#define __NR_vserver           257
10785  #define __NR_migrate_pages     258
10786  #define __NR_mbind             259
10787  #define __NR_get_mempolicy     260
10788 diff -Nurp linux-2.6.22.15/include/asm-s390/socket.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-s390/socket.h
10789 --- linux-2.6.22.15/include/asm-s390/socket.h   2007-07-21 18:00:20.000000000 -0400
10790 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-s390/socket.h      2007-12-09 06:44:22.000000000 -0500
10791 @@ -60,4 +60,6 @@
10792  #define SO_TIMESTAMPNS         35
10793  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10794  
10795 +#define SO_PEERTAG             36
10796 +
10797  #endif /* _ASM_SOCKET_H */
10798 diff -Nurp linux-2.6.22.15/include/asm-s390/unistd.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-s390/unistd.h
10799 --- linux-2.6.22.15/include/asm-s390/unistd.h   2007-07-21 18:00:20.000000000 -0400
10800 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-s390/unistd.h      2007-12-09 06:44:22.000000000 -0500
10801 @@ -202,7 +202,7 @@
10802  #define __NR_clock_gettime     (__NR_timer_create+6)
10803  #define __NR_clock_getres      (__NR_timer_create+7)
10804  #define __NR_clock_nanosleep   (__NR_timer_create+8)
10805 -/* Number 263 is reserved for vserver */
10806 +#define __NR_vserver           263
10807  #define __NR_statfs64          265
10808  #define __NR_fstatfs64         266
10809  #define __NR_remap_file_pages  267
10810 diff -Nurp linux-2.6.22.15/include/asm-sh/socket.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-sh/socket.h
10811 --- linux-2.6.22.15/include/asm-sh/socket.h     2007-07-21 18:00:20.000000000 -0400
10812 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-sh/socket.h        2007-12-09 06:44:22.000000000 -0500
10813 @@ -52,4 +52,6 @@
10814  #define SO_TIMESTAMPNS         35
10815  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10816  
10817 +#define SO_PEERTAG             36
10818 +
10819  #endif /* __ASM_SH_SOCKET_H */
10820 diff -Nurp linux-2.6.22.15/include/asm-sparc/socket.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-sparc/socket.h
10821 --- linux-2.6.22.15/include/asm-sparc/socket.h  2007-07-21 18:00:20.000000000 -0400
10822 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-sparc/socket.h     2007-12-09 06:44:22.000000000 -0500
10823 @@ -52,6 +52,8 @@
10824  #define SO_TIMESTAMPNS         0x0021
10825  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10826  
10827 +#define SO_PEERTAG             36
10828 +
10829  /* Security levels - as per NRL IPv6 - don't actually do anything */
10830  #define SO_SECURITY_AUTHENTICATION             0x5001
10831  #define SO_SECURITY_ENCRYPTION_TRANSPORT       0x5002
10832 diff -Nurp linux-2.6.22.15/include/asm-sparc/unistd.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-sparc/unistd.h
10833 --- linux-2.6.22.15/include/asm-sparc/unistd.h  2007-07-21 18:00:20.000000000 -0400
10834 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-sparc/unistd.h     2007-12-09 06:44:22.000000000 -0500
10835 @@ -283,7 +283,7 @@
10836  #define __NR_timer_getoverrun  264
10837  #define __NR_timer_delete      265
10838  #define __NR_timer_create      266
10839 -/* #define __NR_vserver                267 Reserved for VSERVER */
10840 +#define __NR_vserver           267
10841  #define __NR_io_setup          268
10842  #define __NR_io_destroy                269
10843  #define __NR_io_submit         270
10844 diff -Nurp linux-2.6.22.15/include/asm-sparc64/socket.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-sparc64/socket.h
10845 --- linux-2.6.22.15/include/asm-sparc64/socket.h        2007-07-21 18:00:20.000000000 -0400
10846 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-sparc64/socket.h   2007-12-09 06:44:22.000000000 -0500
10847 @@ -52,6 +52,8 @@
10848  #define SO_TIMESTAMPNS         0x0021
10849  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10850  
10851 +#define SO_PEERTAG             0x0022
10852 +
10853  /* Security levels - as per NRL IPv6 - don't actually do anything */
10854  #define SO_SECURITY_AUTHENTICATION             0x5001
10855  #define SO_SECURITY_ENCRYPTION_TRANSPORT       0x5002
10856 diff -Nurp linux-2.6.22.15/include/asm-sparc64/tlb.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-sparc64/tlb.h
10857 --- linux-2.6.22.15/include/asm-sparc64/tlb.h   2007-07-21 18:00:20.000000000 -0400
10858 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-sparc64/tlb.h      2007-12-09 06:44:22.000000000 -0500
10859 @@ -3,6 +3,7 @@
10860  
10861  #include <linux/swap.h>
10862  #include <linux/pagemap.h>
10863 +#include <linux/vs_memory.h>
10864  #include <asm/pgalloc.h>
10865  #include <asm/tlbflush.h>
10866  #include <asm/mmu_context.h>
10867 diff -Nurp linux-2.6.22.15/include/asm-sparc64/unistd.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-sparc64/unistd.h
10868 --- linux-2.6.22.15/include/asm-sparc64/unistd.h        2007-07-21 18:00:20.000000000 -0400
10869 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-sparc64/unistd.h   2007-12-09 06:44:22.000000000 -0500
10870 @@ -285,7 +285,7 @@
10871  #define __NR_timer_getoverrun  264
10872  #define __NR_timer_delete      265
10873  #define __NR_timer_create      266
10874 -/* #define __NR_vserver                267 Reserved for VSERVER */
10875 +#define __NR_vserver           267
10876  #define __NR_io_setup          268
10877  #define __NR_io_destroy                269
10878  #define __NR_io_submit         270
10879 diff -Nurp linux-2.6.22.15/include/asm-v850/socket.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-v850/socket.h
10880 --- linux-2.6.22.15/include/asm-v850/socket.h   2007-07-21 18:00:20.000000000 -0400
10881 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-v850/socket.h      2007-12-09 06:44:22.000000000 -0500
10882 @@ -52,4 +52,6 @@
10883  #define SO_TIMESTAMPNS         35
10884  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10885  
10886 +#define SO_PEERTAG             36
10887 +
10888  #endif /* __V850_SOCKET_H__ */
10889 diff -Nurp linux-2.6.22.15/include/asm-x86_64/socket.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-x86_64/socket.h
10890 --- linux-2.6.22.15/include/asm-x86_64/socket.h 2007-07-21 18:00:20.000000000 -0400
10891 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-x86_64/socket.h    2007-12-09 06:44:22.000000000 -0500
10892 @@ -52,4 +52,6 @@
10893  #define SO_TIMESTAMPNS         35
10894  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10895  
10896 +#define SO_PEERTAG             36
10897 +
10898  #endif /* _ASM_SOCKET_H */
10899 diff -Nurp linux-2.6.22.15/include/asm-x86_64/unistd.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-x86_64/unistd.h
10900 --- linux-2.6.22.15/include/asm-x86_64/unistd.h 2007-07-21 18:00:20.000000000 -0400
10901 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-x86_64/unistd.h    2007-12-09 06:44:22.000000000 -0500
10902 @@ -532,7 +532,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
10903  #define __NR_utimes            235
10904  __SYSCALL(__NR_utimes, sys_utimes)
10905  #define __NR_vserver           236
10906 -__SYSCALL(__NR_vserver, sys_ni_syscall)
10907 +__SYSCALL(__NR_vserver, sys_vserver)
10908  #define __NR_mbind             237
10909  __SYSCALL(__NR_mbind, sys_mbind)
10910  #define __NR_set_mempolicy     238
10911 diff -Nurp linux-2.6.22.15/include/asm-xtensa/socket.h linux-2.6.22.15-vs2.3.0.29.1/include/asm-xtensa/socket.h
10912 --- linux-2.6.22.15/include/asm-xtensa/socket.h 2007-07-21 18:00:20.000000000 -0400
10913 +++ linux-2.6.22.15-vs2.3.0.29.1/include/asm-xtensa/socket.h    2007-12-09 06:44:22.000000000 -0500
10914 @@ -63,4 +63,6 @@
10915  #define SO_TIMESTAMPNS         35
10916  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10917  
10918 +#define SO_PEERTAG             36
10919 +
10920  #endif /* _XTENSA_SOCKET_H */
10921 diff -Nurp linux-2.6.22.15/include/linux/capability.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/capability.h
10922 --- linux-2.6.22.15/include/linux/capability.h  2007-07-21 18:00:20.000000000 -0400
10923 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/capability.h     2007-12-09 06:44:22.000000000 -0500
10924 @@ -237,6 +237,7 @@ typedef __u32 kernel_cap_t;
10925     arbitrary SCSI commands */
10926  /* Allow setting encryption key on loopback filesystem */
10927  /* Allow setting zone reclaim policy */
10928 +/* Allow the selection of a security context */
10929  
10930  #define CAP_SYS_ADMIN        21
10931  
10932 @@ -290,6 +291,11 @@ typedef __u32 kernel_cap_t;
10933  
10934  #define CAP_AUDIT_CONTROL    30
10935  
10936 +/* Allow context manipulations */
10937 +/* Allow changing context info on files */
10938 +
10939 +#define CAP_CONTEXT         31
10940 +
10941  #ifdef __KERNEL__
10942  /* 
10943   * Bounding set
10944 diff -Nurp linux-2.6.22.15/include/linux/devpts_fs.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/devpts_fs.h
10945 --- linux-2.6.22.15/include/linux/devpts_fs.h   2006-06-17 21:49:35.000000000 -0400
10946 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/devpts_fs.h      2007-12-09 06:44:22.000000000 -0500
10947 @@ -30,5 +30,4 @@ static inline void devpts_pty_kill(int n
10948  
10949  #endif
10950  
10951 -
10952  #endif /* _LINUX_DEVPTS_FS_H */
10953 diff -Nurp linux-2.6.22.15/include/linux/ext2_fs.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/ext2_fs.h
10954 --- linux-2.6.22.15/include/linux/ext2_fs.h     2007-05-04 09:57:41.000000000 -0400
10955 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/ext2_fs.h        2007-12-09 06:44:22.000000000 -0500
10956 @@ -188,6 +188,8 @@ struct ext2_group_desc
10957  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
10958  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
10959  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
10960 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
10961 +#define EXT2_IUNLINK_FL                        FS_IUNLINK_FL   /* Immutable unlink */
10962  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
10963  
10964  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
10965 @@ -244,7 +246,7 @@ struct ext2_inode {
10966                 struct {
10967                         __u8    l_i_frag;       /* Fragment number */
10968                         __u8    l_i_fsize;      /* Fragment size */
10969 -                       __u16   i_pad1;
10970 +                       __u16   l_i_tag;        /* Context Tag */
10971                         __le16  l_i_uid_high;   /* these 2 fields    */
10972                         __le16  l_i_gid_high;   /* were reserved2[0] */
10973                         __u32   l_i_reserved2;
10974 @@ -276,6 +278,7 @@ struct ext2_inode {
10975  #define i_gid_low      i_gid
10976  #define i_uid_high     osd2.linux2.l_i_uid_high
10977  #define i_gid_high     osd2.linux2.l_i_gid_high
10978 +#define i_raw_tag      osd2.linux2.l_i_tag
10979  #define i_reserved2    osd2.linux2.l_i_reserved2
10980  #endif
10981  
10982 @@ -317,8 +320,9 @@ struct ext2_inode {
10983  #define EXT2_MOUNT_XATTR_USER          0x004000  /* Extended user attributes */
10984  #define EXT2_MOUNT_POSIX_ACL           0x008000  /* POSIX Access Control Lists */
10985  #define EXT2_MOUNT_XIP                 0x010000  /* Execute in place */
10986 -#define EXT2_MOUNT_USRQUOTA            0x020000 /* user quota */
10987 -#define EXT2_MOUNT_GRPQUOTA            0x040000 /* group quota */
10988 +#define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
10989 +#define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
10990 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
10991  
10992  
10993  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
10994 diff -Nurp linux-2.6.22.15/include/linux/ext3_fs.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/ext3_fs.h
10995 --- linux-2.6.22.15/include/linux/ext3_fs.h     2007-07-21 18:00:20.000000000 -0400
10996 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/ext3_fs.h        2007-12-09 06:44:22.000000000 -0500
10997 @@ -177,6 +177,8 @@ struct ext3_group_desc
10998  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
10999  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
11000  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
11001 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
11002 +#define EXT3_IUNLINK_FL                        0x08000000 /* Immutable unlink */
11003  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
11004  
11005  #define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
11006 @@ -296,7 +298,7 @@ struct ext3_inode {
11007                 struct {
11008                         __u8    l_i_frag;       /* Fragment number */
11009                         __u8    l_i_fsize;      /* Fragment size */
11010 -                       __u16   i_pad1;
11011 +                       __u16   l_i_tag;        /* Context Tag */
11012                         __le16  l_i_uid_high;   /* these 2 fields    */
11013                         __le16  l_i_gid_high;   /* were reserved2[0] */
11014                         __u32   l_i_reserved2;
11015 @@ -330,6 +332,7 @@ struct ext3_inode {
11016  #define i_gid_low      i_gid
11017  #define i_uid_high     osd2.linux2.l_i_uid_high
11018  #define i_gid_high     osd2.linux2.l_i_gid_high
11019 +#define i_raw_tag      osd2.linux2.l_i_tag
11020  #define i_reserved2    osd2.linux2.l_i_reserved2
11021  
11022  #elif defined(__GNU__)
11023 @@ -384,6 +387,7 @@ struct ext3_inode {
11024  #define EXT3_MOUNT_QUOTA               0x80000 /* Some quota option set */
11025  #define EXT3_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
11026  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
11027 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
11028  
11029  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
11030  #ifndef _LINUX_EXT2_FS_H
11031 @@ -812,6 +816,7 @@ struct buffer_head * ext3_bread (handle_
11032  int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
11033         sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result,
11034         int create, int extend_disksize);
11035 +extern int ext3_sync_flags(struct inode *inode);
11036  
11037  extern void ext3_read_inode (struct inode *);
11038  extern int  ext3_write_inode (struct inode *, int);
11039 diff -Nurp linux-2.6.22.15/include/linux/ext4_fs.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/ext4_fs.h
11040 --- linux-2.6.22.15/include/linux/ext4_fs.h     2007-07-21 18:00:22.000000000 -0400
11041 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/ext4_fs.h        2007-12-09 06:44:22.000000000 -0500
11042 @@ -189,8 +189,10 @@ struct ext4_group_desc
11043  #define EXT4_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
11044  #define EXT4_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
11045  #define EXT4_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
11046 -#define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
11047  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
11048 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
11049 +#define EXT4_IUNLINK_FL                        0x08000000 /* Immutable unlink */
11050 +#define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
11051  
11052  #define EXT4_FL_USER_VISIBLE           0x000BDFFF /* User visible flags */
11053  #define EXT4_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
11054 @@ -312,7 +314,8 @@ struct ext4_inode {
11055                         __le16  l_i_file_acl_high;
11056                         __le16  l_i_uid_high;   /* these 2 fields */
11057                         __le16  l_i_gid_high;   /* were reserved2[0] */
11058 -                       __u32   l_i_reserved2;
11059 +                       __u16   l_i_tag;        /* Context Tag */
11060 +                       __u16   l_i_reserved2;
11061                 } linux2;
11062                 struct {
11063                         __u8    h_i_frag;       /* Fragment number */
11064 @@ -344,6 +347,7 @@ struct ext4_inode {
11065  #define i_gid_low      i_gid
11066  #define i_uid_high     osd2.linux2.l_i_uid_high
11067  #define i_gid_high     osd2.linux2.l_i_gid_high
11068 +#define i_raw_tag      osd2.linux2.l_i_tag
11069  #define i_reserved2    osd2.linux2.l_i_reserved2
11070  
11071  #elif defined(__GNU__)
11072 @@ -400,6 +404,7 @@ struct ext4_inode {
11073  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
11074  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
11075  #define EXT4_MOUNT_EXTENTS             0x400000 /* Extents support */
11076 +#define EXT4_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
11077  
11078  /* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */
11079  #ifndef _LINUX_EXT2_FS_H
11080 @@ -850,6 +855,7 @@ struct buffer_head * ext4_bread (handle_
11081  int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,
11082         sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result,
11083         int create, int extend_disksize);
11084 +extern int ext4_sync_flags(struct inode *inode);
11085  
11086  extern void ext4_read_inode (struct inode *);
11087  extern int  ext4_write_inode (struct inode *, int);
11088 diff -Nurp linux-2.6.22.15/include/linux/fs.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/fs.h
11089 --- linux-2.6.22.15/include/linux/fs.h  2007-07-21 18:00:23.000000000 -0400
11090 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/fs.h     2007-12-09 06:44:22.000000000 -0500
11091 @@ -123,6 +123,8 @@ extern int dir_notify_enable;
11092  #define MS_SLAVE       (1<<19) /* change to slave */
11093  #define MS_SHARED      (1<<20) /* change to shared */
11094  #define MS_RELATIME    (1<<21) /* Update atime relative to mtime/ctime. */
11095 +#define MS_TAGGED      (1<<24) /* use generic inode tagging */
11096 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
11097  #define MS_ACTIVE      (1<<30)
11098  #define MS_NOUSER      (1<<31)
11099  
11100 @@ -149,6 +151,8 @@ extern int dir_notify_enable;
11101  #define S_NOCMTIME     128     /* Do not update file c/mtime */
11102  #define S_SWAPFILE     256     /* Do not truncate: swapon got its bmaps */
11103  #define S_PRIVATE      512     /* Inode is fs-internal */
11104 +#define S_BARRIER      1024    /* Barrier for chroot() */
11105 +#define S_IUNLINK      2048    /* Immutable unlink */
11106  
11107  /*
11108   * Note that nosuid etc flags are inode-specific: setting some file-system
11109 @@ -165,24 +169,36 @@ extern int dir_notify_enable;
11110   */
11111  #define __IS_FLG(inode,flg) ((inode)->i_sb->s_flags & (flg))
11112  
11113 -#define IS_RDONLY(inode) ((inode)->i_sb->s_flags & MS_RDONLY)
11114 +#define IS_RDONLY(inode)       __IS_FLG(inode, MS_RDONLY)
11115  #define IS_SYNC(inode)         (__IS_FLG(inode, MS_SYNCHRONOUS) || \
11116                                         ((inode)->i_flags & S_SYNC))
11117  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
11118                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
11119  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
11120 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
11121 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
11122 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
11123  
11124  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
11125  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
11126  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
11127 +#define IS_IUNLINK(inode)      ((inode)->i_flags & S_IUNLINK)
11128 +#define IS_IXORUNLINK(inode)   ((IS_IUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
11129  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
11130  
11131 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_flags & S_BARRIER))
11132  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
11133  #define IS_NOCMTIME(inode)     ((inode)->i_flags & S_NOCMTIME)
11134  #define IS_SWAPFILE(inode)     ((inode)->i_flags & S_SWAPFILE)
11135  #define IS_PRIVATE(inode)      ((inode)->i_flags & S_PRIVATE)
11136  
11137 +#ifdef CONFIG_VSERVER_COWBL
11138 +#  define IS_COW(inode)                (IS_IUNLINK(inode) && IS_IMMUTABLE(inode))
11139 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
11140 +#else
11141 +#  define IS_COW(inode)                (0)
11142 +#  define IS_COW_LINK(inode)   (0)
11143 +#endif
11144 +
11145  /* the read-only stuff doesn't really belong here, but any other place is
11146     probably as bad and I don't want to create yet another include file. */
11147  
11148 @@ -256,12 +272,13 @@ extern int dir_notify_enable;
11149  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
11150  #define FS_EXTENT_FL                   0x00080000 /* Extents */
11151  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
11152 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
11153 +#define FS_IUNLINK_FL                  0x08000000 /* Immutable unlink */
11154  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
11155  
11156  #define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
11157  #define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
11158  
11159 -
11160  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
11161  #define SYNC_FILE_RANGE_WRITE          2
11162  #define SYNC_FILE_RANGE_WAIT_AFTER     4
11163 @@ -327,6 +344,7 @@ typedef void (dio_iodone_t)(struct kiocb
11164  #define ATTR_KILL_SUID 2048
11165  #define ATTR_KILL_SGID 4096
11166  #define ATTR_FILE      8192
11167 +#define ATTR_TAG       16384
11168  
11169  /*
11170   * This is the Inode Attributes structure, used for notify_change().  It
11171 @@ -342,6 +360,7 @@ struct iattr {
11172         umode_t         ia_mode;
11173         uid_t           ia_uid;
11174         gid_t           ia_gid;
11175 +       tag_t           ia_tag;
11176         loff_t          ia_size;
11177         struct timespec ia_atime;
11178         struct timespec ia_mtime;
11179 @@ -355,6 +374,9 @@ struct iattr {
11180         struct file     *ia_file;
11181  };
11182  
11183 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
11184 +#define ATTR_FLAG_IUNLINK      1024    /* Immutable unlink */
11185 +
11186  /*
11187   * Includes for diskquotas.
11188   */
11189 @@ -537,7 +559,9 @@ struct inode {
11190         unsigned int            i_nlink;
11191         uid_t                   i_uid;
11192         gid_t                   i_gid;
11193 +       tag_t                   i_tag;
11194         dev_t                   i_rdev;
11195 +       dev_t                   i_mdev;
11196         unsigned long           i_version;
11197         loff_t                  i_size;
11198  #ifdef __NEED_I_SIZE_ORDERED
11199 @@ -672,12 +696,12 @@ static inline void i_size_write(struct i
11200  
11201  static inline unsigned iminor(const struct inode *inode)
11202  {
11203 -       return MINOR(inode->i_rdev);
11204 +       return MINOR(inode->i_mdev);
11205  }
11206  
11207  static inline unsigned imajor(const struct inode *inode)
11208  {
11209 -       return MAJOR(inode->i_rdev);
11210 +       return MAJOR(inode->i_mdev);
11211  }
11212  
11213  extern struct block_device *I_BDEV(struct inode *inode);
11214 @@ -728,6 +752,7 @@ struct file {
11215         loff_t                  f_pos;
11216         struct fown_struct      f_owner;
11217         unsigned int            f_uid, f_gid;
11218 +       xid_t                   f_xid;
11219         struct file_ra_state    f_ra;
11220  
11221         unsigned long           f_version;
11222 @@ -811,6 +836,7 @@ struct file_lock {
11223         unsigned char fl_type;
11224         loff_t fl_start;
11225         loff_t fl_end;
11226 +       xid_t fl_xid;
11227  
11228         struct fasync_struct *  fl_fasync; /* for lease break notifications */
11229         unsigned long fl_break_time;    /* for nonblocking lease breaks */
11230 @@ -993,12 +1019,12 @@ extern void unlock_super(struct super_bl
11231   */
11232  extern int vfs_permission(struct nameidata *, int);
11233  extern int vfs_create(struct inode *, struct dentry *, int, struct nameidata *);
11234 -extern int vfs_mkdir(struct inode *, struct dentry *, int);
11235 -extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t);
11236 -extern int vfs_symlink(struct inode *, struct dentry *, const char *, int);
11237 -extern int vfs_link(struct dentry *, struct inode *, struct dentry *);
11238 -extern int vfs_rmdir(struct inode *, struct dentry *);
11239 -extern int vfs_unlink(struct inode *, struct dentry *);
11240 +extern int vfs_mkdir(struct inode *, struct dentry *, int, struct nameidata *);
11241 +extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t, struct nameidata *);
11242 +extern int vfs_symlink(struct inode *, struct dentry *, const char *, int, struct nameidata *);
11243 +extern int vfs_link(struct dentry *, struct inode *, struct dentry *, struct nameidata *);
11244 +extern int vfs_rmdir(struct inode *, struct dentry *, struct nameidata *);
11245 +extern int vfs_unlink(struct inode *, struct dentry *, struct nameidata *);
11246  extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
11247  
11248  /*
11249 @@ -1138,6 +1164,7 @@ struct inode_operations {
11250         ssize_t (*listxattr) (struct dentry *, char *, size_t);
11251         int (*removexattr) (struct dentry *, const char *);
11252         void (*truncate_range)(struct inode *, loff_t, loff_t);
11253 +       int (*sync_flags) (struct inode *);
11254  };
11255  
11256  struct seq_file;
11257 @@ -1153,6 +1180,7 @@ extern ssize_t vfs_readv(struct file *, 
11258                 unsigned long, loff_t *);
11259  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
11260                 unsigned long, loff_t *);
11261 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
11262  
11263  /*
11264   * NOTE: write_inode, delete_inode, clear_inode, put_inode can be called
11265 @@ -1898,6 +1926,7 @@ extern int dcache_dir_open(struct inode 
11266  extern int dcache_dir_close(struct inode *, struct file *);
11267  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
11268  extern int dcache_readdir(struct file *, void *, filldir_t);
11269 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
11270  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
11271  extern int simple_statfs(struct dentry *, struct kstatfs *);
11272  extern int simple_link(struct dentry *, struct inode *, struct dentry *);
11273 diff -Nurp linux-2.6.22.15/include/linux/init_task.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/init_task.h
11274 --- linux-2.6.22.15/include/linux/init_task.h   2007-07-21 18:00:23.000000000 -0400
11275 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/init_task.h      2007-12-09 06:44:22.000000000 -0500
11276 @@ -169,6 +169,10 @@ extern struct group_info init_groups;
11277         },                                                              \
11278         INIT_TRACE_IRQFLAGS                                             \
11279         INIT_LOCKDEP                                                    \
11280 +       .xid            = 0,                                            \
11281 +       .vx_info        = NULL,                                         \
11282 +       .nid            = 0,                                            \
11283 +       .nx_info        = NULL,                                         \
11284  }
11285  
11286  
11287 diff -Nurp linux-2.6.22.15/include/linux/ipc.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/ipc.h
11288 --- linux-2.6.22.15/include/linux/ipc.h 2007-07-21 18:00:23.000000000 -0400
11289 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/ipc.h    2007-12-09 06:44:22.000000000 -0500
11290 @@ -63,6 +63,7 @@ struct kern_ipc_perm
11291         key_t           key;
11292         uid_t           uid;
11293         gid_t           gid;
11294 +       xid_t           xid;
11295         uid_t           cuid;
11296         gid_t           cgid;
11297         mode_t          mode; 
11298 diff -Nurp linux-2.6.22.15/include/linux/jffs2.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/jffs2.h
11299 --- linux-2.6.22.15/include/linux/jffs2.h       2007-05-04 09:57:43.000000000 -0400
11300 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/jffs2.h  2007-12-09 06:44:22.000000000 -0500
11301 @@ -82,12 +82,36 @@
11302  //#define JFFS2_NODETYPE_OPTIONS (JFFS2_FEATURE_RWCOMPAT_COPY | JFFS2_NODE_ACCURATE | 4)
11303  
11304  
11305 -#define JFFS2_INO_FLAG_PREREAD   1     /* Do read_inode() for this one at
11306 +#define JFFS2_INO_FLAG_PREREAD   0x01  /* Do read_inode() for this one at
11307                                            mount time, don't wait for it to
11308                                            happen later */
11309 -#define JFFS2_INO_FLAG_USERCOMPR  2    /* User has requested a specific
11310 +#define JFFS2_INO_FLAG_USERCOMPR 0x02  /* User has requested a specific
11311                                            compression type */
11312  
11313 +#define JFFS2_INO_FLAG_IMMUTABLE 0x10  /* immutable node */
11314 +#define JFFS2_INO_FLAG_IUNLINK   0x20  /* immutable unlink */
11315 +#define JFFS2_INO_FLAG_BARRIER   0x40  /* barrier */
11316 +
11317 +#define JFFS2_USER_VISIBLE       0x10
11318 +#define JFFS2_USER_MODIFIABLE    0x10
11319 +
11320 +/*
11321 + * Mount flags
11322 + */
11323 +#define JFFS2_MOUNT_TAGGED     (1<<24)   /* Enable Context Tags */
11324 +
11325 +#define clear_opt(o, opt)      o &= ~JFFS2_MOUNT_##opt
11326 +#define set_opt(o, opt)                o |= JFFS2_MOUNT_##opt
11327 +
11328 +/*
11329 + * Maximal mount counts between two filesystem checks
11330 + */
11331 +#define EXT2_DFL_MAX_MNT_COUNT         20      /* Allow 20 mounts */
11332 +#define EXT2_DFL_CHECKINTERVAL         0       /* Don't use interval check */
11333 +
11334 +/*
11335 + * Behaviour when detecting errors
11336 + */
11337  
11338  /* These can go once we've made sure we've caught all uses without
11339     byteswapping */
11340 @@ -97,7 +121,7 @@ typedef struct {
11341  } __attribute__((packed)) jint32_t;
11342  
11343  typedef struct {
11344 -       uint32_t m;
11345 +       uint16_t m;
11346  } __attribute__((packed)) jmode_t;
11347  
11348  typedef struct {
11349 @@ -145,7 +169,8 @@ struct jffs2_raw_inode
11350         jint32_t hdr_crc;
11351         jint32_t ino;        /* Inode number.  */
11352         jint32_t version;    /* Version number.  */
11353 -       jmode_t mode;       /* The file's type or mode.  */
11354 +       jmode_t mode;        /* The file's type or mode.  */
11355 +       jint16_t tag;        /* context tagging */
11356         jint16_t uid;        /* The file's owner.  */
11357         jint16_t gid;        /* The file's group.  */
11358         jint32_t isize;      /* Total resultant size of this inode (used for truncations)  */
11359 diff -Nurp linux-2.6.22.15/include/linux/Kbuild linux-2.6.22.15-vs2.3.0.29.1/include/linux/Kbuild
11360 --- linux-2.6.22.15/include/linux/Kbuild        2007-09-29 08:11:49.000000000 -0400
11361 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/Kbuild   2007-12-09 06:44:22.000000000 -0500
11362 @@ -351,3 +351,6 @@ unifdef-y += xattr.h
11363  unifdef-y += xfrm.h
11364  
11365  objhdr-y += version.h
11366 +
11367 +header-y += vserver/
11368 +
11369 diff -Nurp linux-2.6.22.15/include/linux/loop.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/loop.h
11370 --- linux-2.6.22.15/include/linux/loop.h        2007-07-21 18:00:24.000000000 -0400
11371 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/loop.h   2007-12-09 06:44:22.000000000 -0500
11372 @@ -45,6 +45,7 @@ struct loop_device {
11373         struct loop_func_table *lo_encryption;
11374         __u32           lo_init[2];
11375         uid_t           lo_key_owner;   /* Who set the key */
11376 +       xid_t           lo_xid;
11377         int             (*ioctl)(struct loop_device *, int cmd, 
11378                                  unsigned long arg); 
11379  
11380 diff -Nurp linux-2.6.22.15/include/linux/magic.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/magic.h
11381 --- linux-2.6.22.15/include/linux/magic.h       2007-07-21 18:00:24.000000000 -0400
11382 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/magic.h  2007-12-09 06:44:22.000000000 -0500
11383 @@ -3,7 +3,7 @@
11384  
11385  #define ADFS_SUPER_MAGIC       0xadf5
11386  #define AFFS_SUPER_MAGIC       0xadff
11387 -#define AFS_SUPER_MAGIC                0x5346414F
11388 +#define AFS_SUPER_MAGIC                0x5346414F
11389  #define AUTOFS_SUPER_MAGIC     0x0187
11390  #define CODA_SUPER_MAGIC       0x73757245
11391  #define EFS_SUPER_MAGIC                0x414A53
11392 @@ -27,6 +27,7 @@
11393  #define NFS_SUPER_MAGIC                0x6969
11394  #define OPENPROM_SUPER_MAGIC   0x9fa1
11395  #define PROC_SUPER_MAGIC       0x9fa0
11396 +#define DEVPTS_SUPER_MAGIC     0x1cd1
11397  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
11398  
11399  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
11400 diff -Nurp linux-2.6.22.15/include/linux/major.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/major.h
11401 --- linux-2.6.22.15/include/linux/major.h       2007-07-21 18:00:24.000000000 -0400
11402 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/major.h  2007-12-09 06:44:22.000000000 -0500
11403 @@ -15,6 +15,7 @@
11404  #define HD_MAJOR               IDE0_MAJOR
11405  #define PTY_SLAVE_MAJOR                3
11406  #define TTY_MAJOR              4
11407 +#define VROOT_MAJOR            4
11408  #define TTYAUX_MAJOR           5
11409  #define LP_MAJOR               6
11410  #define VCS_MAJOR              7
11411 diff -Nurp linux-2.6.22.15/include/linux/mount.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/mount.h
11412 --- linux-2.6.22.15/include/linux/mount.h       2007-07-21 18:00:24.000000000 -0400
11413 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/mount.h  2007-12-09 06:44:22.000000000 -0500
11414 @@ -28,6 +28,9 @@ struct mnt_namespace;
11415  #define MNT_NOATIME    0x08
11416  #define MNT_NODIRATIME 0x10
11417  #define MNT_RELATIME   0x20
11418 +#define MNT_RDONLY     0x40
11419 +
11420 +#define MNT_IS_RDONLY(m)       ((m) && ((m)->mnt_flags & MNT_RDONLY))
11421  
11422  #define MNT_SHRINKABLE 0x100
11423  
11424 @@ -35,6 +38,10 @@ struct mnt_namespace;
11425  #define MNT_UNBINDABLE 0x2000  /* if the vfsmount is a unbindable mount */
11426  #define MNT_PNODE_MASK 0x3000  /* propagation flag mask */
11427  
11428 +#define MNT_TAGID      0x10000
11429 +#define MNT_NOTAG      0x20000
11430 +#define MNT_NOTAGCHECK 0x40000
11431 +
11432  struct vfsmount {
11433         struct list_head mnt_hash;
11434         struct vfsmount *mnt_parent;    /* fs we are mounted on */
11435 @@ -61,6 +68,7 @@ struct vfsmount {
11436         atomic_t mnt_count;
11437         int mnt_expiry_mark;            /* true if marked for expiry */
11438         int mnt_pinned;
11439 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
11440  };
11441  
11442  static inline struct vfsmount *mntget(struct vfsmount *mnt)
11443 diff -Nurp linux-2.6.22.15/include/linux/net.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/net.h
11444 --- linux-2.6.22.15/include/linux/net.h 2007-07-21 18:00:24.000000000 -0400
11445 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/net.h    2007-12-09 06:44:22.000000000 -0500
11446 @@ -63,6 +63,7 @@ typedef enum {
11447  #define SOCK_NOSPACE           2
11448  #define SOCK_PASSCRED          3
11449  #define SOCK_PASSSEC           4
11450 +#define SOCK_USER_SOCKET       5
11451  
11452  #ifndef ARCH_HAS_SOCKET_TYPES
11453  /**
11454 diff -Nurp linux-2.6.22.15/include/linux/nfs_mount.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/nfs_mount.h
11455 --- linux-2.6.22.15/include/linux/nfs_mount.h   2007-07-21 18:00:24.000000000 -0400
11456 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/nfs_mount.h      2007-12-09 06:44:22.000000000 -0500
11457 @@ -63,6 +63,7 @@
11458  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
11459  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
11460  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
11461 -#define NFS_MOUNT_FLAGMASK     0xFFFF
11462 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
11463 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
11464  
11465  #endif
11466 diff -Nurp linux-2.6.22.15/include/linux/nsproxy.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/nsproxy.h
11467 --- linux-2.6.22.15/include/linux/nsproxy.h     2007-07-21 18:00:24.000000000 -0400
11468 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/nsproxy.h        2007-12-09 06:44:22.000000000 -0500
11469 @@ -3,6 +3,7 @@
11470  
11471  #include <linux/spinlock.h>
11472  #include <linux/sched.h>
11473 +#include <linux/vserver/debug.h>
11474  
11475  struct mnt_namespace;
11476  struct uts_namespace;
11477 @@ -32,26 +33,46 @@ struct nsproxy {
11478  extern struct nsproxy init_nsproxy;
11479  
11480  int copy_namespaces(int flags, struct task_struct *tsk);
11481 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
11482  void get_task_namespaces(struct task_struct *tsk);
11483  void free_nsproxy(struct nsproxy *ns);
11484  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
11485         struct fs_struct *);
11486  
11487 -static inline void put_nsproxy(struct nsproxy *ns)
11488 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
11489 +
11490 +static inline void __get_nsproxy(struct nsproxy *ns,
11491 +       const char *_file, int _line)
11492  {
11493 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
11494 +               ns, atomic_read(&ns->count), _file, _line);
11495 +       atomic_inc(&ns->count);
11496 +}
11497 +
11498 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
11499 +
11500 +static inline void __put_nsproxy(struct nsproxy *ns,
11501 +       const char *_file, int _line)
11502 +{
11503 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
11504 +               ns, atomic_read(&ns->count), _file, _line);
11505         if (atomic_dec_and_test(&ns->count)) {
11506                 free_nsproxy(ns);
11507         }
11508  }
11509  
11510 -static inline void exit_task_namespaces(struct task_struct *p)
11511 +#define        exit_task_namespaces(p) __exit_task_namespaces(p, __FILE__, __LINE__)
11512 +
11513 +static inline void __exit_task_namespaces(struct task_struct *p,
11514 +       const char *_file, int _line)
11515  {
11516         struct nsproxy *ns = p->nsproxy;
11517         if (ns) {
11518                 task_lock(p);
11519                 p->nsproxy = NULL;
11520                 task_unlock(p);
11521 -               put_nsproxy(ns);
11522 +               __put_nsproxy(ns, _file, _line);
11523         }
11524  }
11525 +
11526  #endif
11527 diff -Nurp linux-2.6.22.15/include/linux/pid.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/pid.h
11528 --- linux-2.6.22.15/include/linux/pid.h 2007-07-21 18:00:24.000000000 -0400
11529 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/pid.h    2007-12-09 06:44:22.000000000 -0500
11530 @@ -8,7 +8,8 @@ enum pid_type
11531         PIDTYPE_PID,
11532         PIDTYPE_PGID,
11533         PIDTYPE_SID,
11534 -       PIDTYPE_MAX
11535 +       PIDTYPE_MAX,
11536 +       PIDTYPE_REALPID
11537  };
11538  
11539  /*
11540 diff -Nurp linux-2.6.22.15/include/linux/proc_fs.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/proc_fs.h
11541 --- linux-2.6.22.15/include/linux/proc_fs.h     2007-07-21 18:00:24.000000000 -0400
11542 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/proc_fs.h        2007-12-09 06:44:22.000000000 -0500
11543 @@ -54,6 +54,7 @@ struct proc_dir_entry {
11544         nlink_t nlink;
11545         uid_t uid;
11546         gid_t gid;
11547 +       int vx_flags;
11548         loff_t size;
11549         const struct inode_operations *proc_iops;
11550         const struct file_operations *proc_fops;
11551 @@ -246,13 +247,20 @@ static inline void kclist_add(struct kco
11552  extern void kclist_add(struct kcore_list *, void *, size_t);
11553  #endif
11554  
11555 +struct vx_info;
11556 +struct nx_info;
11557 +
11558  union proc_op {
11559         int (*proc_get_link)(struct inode *, struct dentry **, struct vfsmount **);
11560         int (*proc_read)(struct task_struct *task, char *page);
11561 +       int (*proc_vs_read)(char *page);
11562 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
11563 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
11564  };
11565  
11566  struct proc_inode {
11567         struct pid *pid;
11568 +       int vx_flags;
11569         int fd;
11570         union proc_op op;
11571         struct proc_dir_entry *pde;
11572 diff -Nurp linux-2.6.22.15/include/linux/reiserfs_fs.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/reiserfs_fs.h
11573 --- linux-2.6.22.15/include/linux/reiserfs_fs.h 2007-07-21 17:58:53.000000000 -0400
11574 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/reiserfs_fs.h    2007-12-09 06:44:22.000000000 -0500
11575 @@ -821,6 +821,10 @@ struct stat_data_v1 {
11576  #define REISERFS_COMPR_FL     FS_COMPR_FL
11577  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
11578  
11579 +/* unfortunately reiserfs sdattr is only 16 bit */
11580 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
11581 +#define REISERFS_IUNLINK_FL   (FS_IUNLINK_FL >> 16)
11582 +
11583  /* persistent flags that file inherits from the parent directory */
11584  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
11585                                 REISERFS_SYNC_FL |      \
11586 @@ -830,6 +834,9 @@ struct stat_data_v1 {
11587                                 REISERFS_COMPR_FL |     \
11588                                 REISERFS_NOTAIL_FL )
11589  
11590 +#define REISERFS_FL_USER_VISIBLE       0x80FF
11591 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
11592 +
11593  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
11594     address blocks) */
11595  struct stat_data {
11596 @@ -1901,6 +1908,7 @@ static inline void reiserfs_update_sd(st
11597  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
11598  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
11599  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
11600 +int reiserfs_sync_flags(struct inode *inode);
11601  
11602  /* namei.c */
11603  void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
11604 diff -Nurp linux-2.6.22.15/include/linux/reiserfs_fs_sb.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/reiserfs_fs_sb.h
11605 --- linux-2.6.22.15/include/linux/reiserfs_fs_sb.h      2007-07-21 18:00:24.000000000 -0400
11606 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/reiserfs_fs_sb.h 2007-12-09 06:44:22.000000000 -0500
11607 @@ -458,6 +458,7 @@ enum reiserfs_mount_options {
11608         REISERFS_POSIXACL,
11609         REISERFS_BARRIER_NONE,
11610         REISERFS_BARRIER_FLUSH,
11611 +       REISERFS_TAGGED,
11612  
11613         /* Actions on error */
11614         REISERFS_ERROR_PANIC,
11615 diff -Nurp linux-2.6.22.15/include/linux/sched.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/sched.h
11616 --- linux-2.6.22.15/include/linux/sched.h       2007-07-21 18:00:24.000000000 -0400
11617 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/sched.h  2007-12-09 06:44:22.000000000 -0500
11618 @@ -26,6 +26,7 @@
11619  #define CLONE_STOPPED          0x02000000      /* Start in stopped state */
11620  #define CLONE_NEWUTS           0x04000000      /* New utsname group? */
11621  #define CLONE_NEWIPC           0x08000000      /* New ipcs */
11622 +#define CLONE_KTHREAD          0x10000000      /* clone a kernel thread */
11623  
11624  /*
11625   * Scheduling policies
11626 @@ -94,7 +95,7 @@ struct bio;
11627   * List of flags we want to share for kernel threads,
11628   * if only because they are not used by them anyway.
11629   */
11630 -#define CLONE_KERNEL   (CLONE_FS | CLONE_FILES | CLONE_SIGHAND)
11631 +#define CLONE_KERNEL   (CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_KTHREAD)
11632  
11633  /*
11634   * These are the constant used to fake the fixed-point load-average
11635 @@ -146,12 +147,13 @@ extern unsigned long weighted_cpuload(co
11636  #define TASK_UNINTERRUPTIBLE   2
11637  #define TASK_STOPPED           4
11638  #define TASK_TRACED            8
11639 +#define TASK_ONHOLD            16
11640  /* in tsk->exit_state */
11641 -#define EXIT_ZOMBIE            16
11642 -#define EXIT_DEAD              32
11643 +#define EXIT_ZOMBIE            32
11644 +#define EXIT_DEAD              64
11645  /* in tsk->state again */
11646 -#define TASK_NONINTERACTIVE    64
11647 -#define TASK_DEAD              128
11648 +#define TASK_NONINTERACTIVE    128
11649 +#define TASK_DEAD              256
11650  
11651  #define __set_task_state(tsk, state_value)             \
11652         do { (tsk)->state = (state_value); } while (0)
11653 @@ -287,27 +289,30 @@ extern void arch_unmap_area_topdown(stru
11654   * The mm counters are not protected by its page_table_lock,
11655   * so must be incremented atomically.
11656   */
11657 -#define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
11658 -#define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
11659 -#define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
11660 -#define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
11661 -#define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
11662  typedef atomic_long_t mm_counter_t;
11663 +#define __set_mm_counter(mm, member, value) \
11664 +       atomic_long_set(&(mm)->_##member, value)
11665 +#define get_mm_counter(mm, member) \
11666 +       ((unsigned long)atomic_long_read(&(mm)->_##member))
11667  
11668  #else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
11669  /*
11670   * The mm counters are protected by its page_table_lock,
11671   * so can be incremented directly.
11672   */
11673 -#define set_mm_counter(mm, member, value) (mm)->_##member = (value)
11674 -#define get_mm_counter(mm, member) ((mm)->_##member)
11675 -#define add_mm_counter(mm, member, value) (mm)->_##member += (value)
11676 -#define inc_mm_counter(mm, member) (mm)->_##member++
11677 -#define dec_mm_counter(mm, member) (mm)->_##member--
11678  typedef unsigned long mm_counter_t;
11679 +#define __set_mm_counter(mm, member, value) (mm)->_##member = (value)
11680 +#define get_mm_counter(mm, member) ((mm)->_##member)
11681  
11682  #endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
11683  
11684 +#define set_mm_counter(mm, member, value) \
11685 +       vx_ ## member ## pages_sub((mm), (get_mm_counter(mm, member) - value))
11686 +#define add_mm_counter(mm, member, value) \
11687 +       vx_ ## member ## pages_add((mm), (value))
11688 +#define inc_mm_counter(mm, member) vx_ ## member ## pages_inc((mm))
11689 +#define dec_mm_counter(mm, member) vx_ ## member ## pages_dec((mm))
11690 +
11691  #define get_mm_rss(mm)                                 \
11692         (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
11693  #define update_hiwater_rss(mm) do {                    \
11694 @@ -365,6 +370,7 @@ struct mm_struct {
11695  
11696         /* Architecture-specific MM context */
11697         mm_context_t context;
11698 +       struct vx_info *mm_vx_info;
11699  
11700         /* Swap token stuff */
11701         /*
11702 @@ -570,9 +576,10 @@ struct user_struct {
11703         /* Hash table maintenance information */
11704         struct list_head uidhash_list;
11705         uid_t uid;
11706 +       xid_t xid;
11707  };
11708  
11709 -extern struct user_struct *find_user(uid_t);
11710 +extern struct user_struct *find_user(xid_t, uid_t);
11711  
11712  extern struct user_struct root_user;
11713  #define INIT_USER (&root_user)
11714 @@ -969,6 +976,15 @@ struct task_struct {
11715         
11716         void *security;
11717         struct audit_context *audit_context;
11718 +
11719 +/* vserver context data */
11720 +       struct vx_info *vx_info;
11721 +       struct nx_info *nx_info;
11722 +
11723 +       xid_t xid;
11724 +       nid_t nid;
11725 +       tag_t tag;
11726 +
11727         seccomp_t seccomp;
11728  
11729  /* Thread group tracking */
11730 @@ -1290,12 +1306,16 @@ extern struct task_struct init_task;
11731  
11732  extern struct   mm_struct init_mm;
11733  
11734 -#define find_task_by_pid(nr)   find_task_by_pid_type(PIDTYPE_PID, nr)
11735 +#define find_task_by_real_pid(nr) \
11736 +       find_task_by_pid_type(PIDTYPE_REALPID, nr)
11737 +#define find_task_by_pid(nr) \
11738 +       find_task_by_pid_type(PIDTYPE_PID, nr)
11739 +
11740  extern struct task_struct *find_task_by_pid_type(int type, int pid);
11741  extern void __set_special_pids(pid_t session, pid_t pgrp);
11742  
11743  /* per-UID process charging. */
11744 -extern struct user_struct * alloc_uid(uid_t);
11745 +extern struct user_struct * alloc_uid(xid_t, uid_t);
11746  static inline struct user_struct *get_uid(struct user_struct *u)
11747  {
11748         atomic_inc(&u->__count);
11749 diff -Nurp linux-2.6.22.15/include/linux/shmem_fs.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/shmem_fs.h
11750 --- linux-2.6.22.15/include/linux/shmem_fs.h    2007-05-04 09:57:44.000000000 -0400
11751 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/shmem_fs.h       2007-12-09 06:44:22.000000000 -0500
11752 @@ -8,6 +8,9 @@
11753  
11754  #define SHMEM_NR_DIRECT 16
11755  
11756 +#define TMPFS_SUPER_MAGIC      0x01021994
11757 +
11758 +
11759  struct shmem_inode_info {
11760         spinlock_t              lock;
11761         unsigned long           flags;
11762 diff -Nurp linux-2.6.22.15/include/linux/stat.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/stat.h
11763 --- linux-2.6.22.15/include/linux/stat.h        2007-07-21 18:00:24.000000000 -0400
11764 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/stat.h   2007-12-09 06:44:22.000000000 -0500
11765 @@ -66,6 +66,7 @@ struct kstat {
11766         unsigned int    nlink;
11767         uid_t           uid;
11768         gid_t           gid;
11769 +       tag_t           tag;
11770         dev_t           rdev;
11771         loff_t          size;
11772         struct timespec  atime;
11773 diff -Nurp linux-2.6.22.15/include/linux/sunrpc/auth.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/sunrpc/auth.h
11774 --- linux-2.6.22.15/include/linux/sunrpc/auth.h 2007-05-04 09:57:44.000000000 -0400
11775 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/sunrpc/auth.h    2007-12-09 06:44:22.000000000 -0500
11776 @@ -24,6 +24,7 @@
11777  struct auth_cred {
11778         uid_t   uid;
11779         gid_t   gid;
11780 +       tag_t   tag;
11781         struct group_info *group_info;
11782  };
11783  
11784
11785 diff -Nurp linux-2.6.22.15/include/linux/sunrpc/clnt.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/sunrpc/clnt.h
11786 --- linux-2.6.22.15/include/linux/sunrpc/clnt.h 2007-07-21 18:00:24.000000000 -0400
11787 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/sunrpc/clnt.h    2007-12-09 06:44:22.000000000 -0500
11788 @@ -43,7 +43,8 @@ struct rpc_clnt {
11789         unsigned int            cl_softrtry : 1,/* soft timeouts */
11790                                 cl_intr     : 1,/* interruptible */
11791                                 cl_discrtry : 1,/* disconnect before retry */
11792 -                               cl_autobind : 1;/* use getport() */
11793 +                               cl_autobind : 1,/* use getport() */
11794 +                               cl_tag      : 1;/* context tagging */
11795  
11796         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
11797  
11798 diff -Nurp linux-2.6.22.15/include/linux/syscalls.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/syscalls.h
11799 --- linux-2.6.22.15/include/linux/syscalls.h    2007-07-21 18:00:24.000000000 -0400
11800 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/syscalls.h       2007-12-09 06:44:22.000000000 -0500
11801 @@ -294,6 +294,8 @@ asmlinkage long sys_symlink(const char _
11802  asmlinkage long sys_unlink(const char __user *pathname);
11803  asmlinkage long sys_rename(const char __user *oldname,
11804                                 const char __user *newname);
11805 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
11806 +                               umode_t mode);
11807  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
11808  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
11809  
11810 diff -Nurp linux-2.6.22.15/include/linux/sysctl.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/sysctl.h
11811 --- linux-2.6.22.15/include/linux/sysctl.h      2007-07-21 18:00:24.000000000 -0400
11812 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/sysctl.h 2007-12-09 06:44:22.000000000 -0500
11813 @@ -106,6 +106,7 @@ enum
11814         KERN_CAP_BSET=14,       /* int: capability bounding set */
11815         KERN_PANIC=15,          /* int: panic timeout */
11816         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
11817 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
11818  
11819         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
11820         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
11821 diff -Nurp linux-2.6.22.15/include/linux/sysfs.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/sysfs.h
11822 --- linux-2.6.22.15/include/linux/sysfs.h       2007-07-21 18:00:24.000000000 -0400
11823 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/sysfs.h  2007-12-09 06:44:22.000000000 -0500
11824 @@ -15,6 +15,8 @@
11825  #include <linux/list.h>
11826  #include <asm/atomic.h>
11827  
11828 +#define SYSFS_SUPER_MAGIC      0x62656572
11829 +
11830  struct kobject;
11831  struct module;
11832  struct nameidata;
11833 diff -Nurp linux-2.6.22.15/include/linux/time.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/time.h
11834 --- linux-2.6.22.15/include/linux/time.h        2007-07-21 18:00:24.000000000 -0400
11835 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/time.h   2007-12-09 06:44:22.000000000 -0500
11836 @@ -176,6 +176,9 @@ static inline void timespec_add_ns(struc
11837         }
11838         a->tv_nsec = ns;
11839  }
11840 +
11841 +#include <linux/vs_time.h>
11842 +
11843  #endif /* __KERNEL__ */
11844  
11845  #define NFDBITS                        __NFDBITS
11846 diff -Nurp linux-2.6.22.15/include/linux/types.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/types.h
11847 --- linux-2.6.22.15/include/linux/types.h       2007-05-04 09:58:24.000000000 -0400
11848 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/types.h  2007-12-09 06:44:22.000000000 -0500
11849 @@ -39,6 +39,9 @@ typedef __kernel_uid32_t      uid_t;
11850  typedef __kernel_gid32_t       gid_t;
11851  typedef __kernel_uid16_t        uid16_t;
11852  typedef __kernel_gid16_t        gid16_t;
11853 +typedef unsigned int           xid_t;
11854 +typedef unsigned int           nid_t;
11855 +typedef unsigned int           tag_t;
11856  
11857  #ifdef CONFIG_UID16
11858  /* This is defined by include/asm-{arch}/posix_types.h */
11859 diff -Nurp linux-2.6.22.15/include/linux/vroot.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vroot.h
11860 --- linux-2.6.22.15/include/linux/vroot.h       1969-12-31 19:00:00.000000000 -0500
11861 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vroot.h  2007-12-09 06:44:22.000000000 -0500
11862 @@ -0,0 +1,51 @@
11863 +
11864 +/*
11865 + * include/linux/vroot.h
11866 + *
11867 + * written by Herbert Pötzl, 9/11/2002
11868 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
11869 + *
11870 + * Copyright (C) 2002-2007 by Herbert Pötzl.
11871 + * Redistribution of this file is permitted under the
11872 + * GNU General Public License.
11873 + */
11874 +
11875 +#ifndef _LINUX_VROOT_H
11876 +#define _LINUX_VROOT_H
11877 +
11878 +
11879 +#ifdef __KERNEL__
11880 +
11881 +/* Possible states of device */
11882 +enum {
11883 +       Vr_unbound,
11884 +       Vr_bound,
11885 +};
11886 +
11887 +struct vroot_device {
11888 +       int             vr_number;
11889 +       int             vr_refcnt;
11890 +
11891 +       struct semaphore        vr_ctl_mutex;
11892 +       struct block_device    *vr_device;
11893 +       int                     vr_state;
11894 +};
11895 +
11896 +
11897 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
11898 +
11899 +extern int register_vroot_grb(vroot_grb_func *);
11900 +extern int unregister_vroot_grb(vroot_grb_func *);
11901 +
11902 +#endif /* __KERNEL__ */
11903 +
11904 +#define MAX_VROOT_DEFAULT      8
11905 +
11906 +/*
11907 + * IOCTL commands --- we will commandeer 0x56 ('V')
11908 + */
11909 +
11910 +#define VROOT_SET_DEV          0x5600
11911 +#define VROOT_CLR_DEV          0x5601
11912 +
11913 +#endif /* _LINUX_VROOT_H */
11914 diff -Nurp linux-2.6.22.15/include/linux/vs_base.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_base.h
11915 --- linux-2.6.22.15/include/linux/vs_base.h     1969-12-31 19:00:00.000000000 -0500
11916 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_base.h        2007-12-09 06:44:22.000000000 -0500
11917 @@ -0,0 +1,9 @@
11918 +#ifndef _VS_BASE_H
11919 +#define _VS_BASE_H
11920 +
11921 +#include "vserver/base.h"
11922 +#include "vserver/debug.h"
11923 +
11924 +#else
11925 +#warning duplicate inclusion
11926 +#endif
11927 diff -Nurp linux-2.6.22.15/include/linux/vs_context.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_context.h
11928 --- linux-2.6.22.15/include/linux/vs_context.h  1969-12-31 19:00:00.000000000 -0500
11929 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_context.h     2007-12-09 06:44:22.000000000 -0500
11930 @@ -0,0 +1,224 @@
11931 +#ifndef _VS_CONTEXT_H
11932 +#define _VS_CONTEXT_H
11933 +
11934 +#include "vserver/base.h"
11935 +#include "vserver/context.h"
11936 +#include "vserver/history.h"
11937 +#include "vserver/debug.h"
11938 +
11939 +
11940 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
11941 +
11942 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
11943 +       const char *_file, int _line, void *_here)
11944 +{
11945 +       if (!vxi)
11946 +               return NULL;
11947 +
11948 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
11949 +               vxi, vxi ? vxi->vx_id : 0,
11950 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
11951 +               _file, _line);
11952 +       __vxh_get_vx_info(vxi, _here);
11953 +
11954 +       atomic_inc(&vxi->vx_usecnt);
11955 +       return vxi;
11956 +}
11957 +
11958 +
11959 +extern void free_vx_info(struct vx_info *);
11960 +
11961 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
11962 +
11963 +static inline void __put_vx_info(struct vx_info *vxi,
11964 +       const char *_file, int _line, void *_here)
11965 +{
11966 +       if (!vxi)
11967 +               return;
11968 +
11969 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
11970 +               vxi, vxi ? vxi->vx_id : 0,
11971 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
11972 +               _file, _line);
11973 +       __vxh_put_vx_info(vxi, _here);
11974 +
11975 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
11976 +               free_vx_info(vxi);
11977 +}
11978 +
11979 +
11980 +#define init_vx_info(p, i) \
11981 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
11982 +
11983 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
11984 +       const char *_file, int _line, void *_here)
11985 +{
11986 +       if (vxi) {
11987 +               vxlprintk(VXD_CBIT(xid, 3),
11988 +                       "init_vx_info(%p[#%d.%d])",
11989 +                       vxi, vxi ? vxi->vx_id : 0,
11990 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
11991 +                       _file, _line);
11992 +               __vxh_init_vx_info(vxi, vxp, _here);
11993 +
11994 +               atomic_inc(&vxi->vx_usecnt);
11995 +       }
11996 +       *vxp = vxi;
11997 +}
11998 +
11999 +
12000 +#define set_vx_info(p, i) \
12001 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
12002 +
12003 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
12004 +       const char *_file, int _line, void *_here)
12005 +{
12006 +       struct vx_info *vxo;
12007 +
12008 +       if (!vxi)
12009 +               return;
12010 +
12011 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
12012 +               vxi, vxi ? vxi->vx_id : 0,
12013 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
12014 +               _file, _line);
12015 +       __vxh_set_vx_info(vxi, vxp, _here);
12016 +
12017 +       atomic_inc(&vxi->vx_usecnt);
12018 +       vxo = xchg(vxp, vxi);
12019 +       BUG_ON(vxo);
12020 +}
12021 +
12022 +
12023 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
12024 +
12025 +static inline void __clr_vx_info(struct vx_info **vxp,
12026 +       const char *_file, int _line, void *_here)
12027 +{
12028 +       struct vx_info *vxo;
12029 +
12030 +       vxo = xchg(vxp, NULL);
12031 +       if (!vxo)
12032 +               return;
12033 +
12034 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
12035 +               vxo, vxo ? vxo->vx_id : 0,
12036 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
12037 +               _file, _line);
12038 +       __vxh_clr_vx_info(vxo, vxp, _here);
12039 +
12040 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
12041 +               free_vx_info(vxo);
12042 +}
12043 +
12044 +
12045 +#define claim_vx_info(v, p) \
12046 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
12047 +
12048 +static inline void __claim_vx_info(struct vx_info *vxi,
12049 +       struct task_struct *task,
12050 +       const char *_file, int _line, void *_here)
12051 +{
12052 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
12053 +               vxi, vxi ? vxi->vx_id : 0,
12054 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
12055 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
12056 +               task, _file, _line);
12057 +       __vxh_claim_vx_info(vxi, task, _here);
12058 +
12059 +       atomic_inc(&vxi->vx_tasks);
12060 +}
12061 +
12062 +
12063 +extern void unhash_vx_info(struct vx_info *);
12064 +
12065 +#define release_vx_info(v, p) \
12066 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
12067 +
12068 +static inline void __release_vx_info(struct vx_info *vxi,
12069 +       struct task_struct *task,
12070 +       const char *_file, int _line, void *_here)
12071 +{
12072 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
12073 +               vxi, vxi ? vxi->vx_id : 0,
12074 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
12075 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
12076 +               task, _file, _line);
12077 +       __vxh_release_vx_info(vxi, task, _here);
12078 +
12079 +       might_sleep();
12080 +
12081 +       if (atomic_dec_and_test(&vxi->vx_tasks))
12082 +               unhash_vx_info(vxi);
12083 +}
12084 +
12085 +
12086 +#define task_get_vx_info(p) \
12087 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
12088 +
12089 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
12090 +       const char *_file, int _line, void *_here)
12091 +{
12092 +       struct vx_info *vxi;
12093 +
12094 +       task_lock(p);
12095 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
12096 +               p, _file, _line);
12097 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
12098 +       task_unlock(p);
12099 +       return vxi;
12100 +}
12101 +
12102 +
12103 +static inline void __wakeup_vx_info(struct vx_info *vxi)
12104 +{
12105 +       if (waitqueue_active(&vxi->vx_wait))
12106 +               wake_up_interruptible(&vxi->vx_wait);
12107 +}
12108 +
12109 +
12110 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
12111 +
12112 +static inline void __enter_vx_info(struct vx_info *vxi,
12113 +       struct vx_info_save *vxis, const char *_file, int _line)
12114 +{
12115 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
12116 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
12117 +               current->xid, current->vx_info, _file, _line);
12118 +       vxis->vxi = xchg(&current->vx_info, vxi);
12119 +       vxis->xid = current->xid;
12120 +       current->xid = vxi ? vxi->vx_id : 0;
12121 +}
12122 +
12123 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
12124 +
12125 +static inline void __leave_vx_info(struct vx_info_save *vxis,
12126 +       const char *_file, int _line)
12127 +{
12128 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
12129 +               vxis, vxis->xid, vxis->vxi, current,
12130 +               current->xid, current->vx_info, _file, _line);
12131 +       (void)xchg(&current->vx_info, vxis->vxi);
12132 +       current->xid = vxis->xid;
12133 +}
12134 +
12135 +
12136 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
12137 +{
12138 +       vxis->vxi = xchg(&current->vx_info, NULL);
12139 +       vxis->xid = xchg(&current->xid, (xid_t)0);
12140 +}
12141 +
12142 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
12143 +{
12144 +       (void)xchg(&current->xid, vxis->xid);
12145 +       (void)xchg(&current->vx_info, vxis->vxi);
12146 +}
12147 +
12148 +extern void exit_vx_info(struct task_struct *, int);
12149 +extern void exit_vx_info_early(struct task_struct *, int);
12150 +
12151 +
12152 +#else
12153 +#warning duplicate inclusion
12154 +#endif
12155 diff -Nurp linux-2.6.22.15/include/linux/vs_cowbl.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_cowbl.h
12156 --- linux-2.6.22.15/include/linux/vs_cowbl.h    1969-12-31 19:00:00.000000000 -0500
12157 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_cowbl.h       2007-12-09 06:44:22.000000000 -0500
12158 @@ -0,0 +1,44 @@
12159 +#ifndef _VS_COWBL_H
12160 +#define _VS_COWBL_H
12161 +
12162 +#include <linux/fs.h>
12163 +#include <linux/dcache.h>
12164 +#include <linux/namei.h>
12165 +
12166 +extern struct dentry *cow_break_link(const char *pathname);
12167 +
12168 +static inline int cow_check_and_break(struct nameidata *nd)
12169 +{
12170 +       struct inode *inode = nd->dentry->d_inode;
12171 +       int error = 0;
12172 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(nd->mnt))
12173 +               return -EROFS;
12174 +       if (IS_COW(inode)) {
12175 +               if (IS_COW_LINK(inode)) {
12176 +                       struct dentry *new_dentry, *old_dentry = nd->dentry;
12177 +                       char *path, *buf;
12178 +
12179 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
12180 +                       if (!buf) {
12181 +                               return -ENOMEM;
12182 +                       }
12183 +                       path = d_path(nd->dentry, nd->mnt, buf, PATH_MAX);
12184 +                       new_dentry = cow_break_link(path);
12185 +                       kfree(buf);
12186 +                       if (!IS_ERR(new_dentry)) {
12187 +                               nd->dentry = new_dentry;
12188 +                               dput(old_dentry);
12189 +                       } else
12190 +                               error = PTR_ERR(new_dentry);
12191 +               } else {
12192 +                       inode->i_flags &= ~(S_IUNLINK | S_IMMUTABLE);
12193 +                       inode->i_ctime = CURRENT_TIME;
12194 +                       mark_inode_dirty(inode);
12195 +               }
12196 +       }
12197 +       return error;
12198 +}
12199 +
12200 +#else
12201 +#warning duplicate inclusion
12202 +#endif
12203 diff -Nurp linux-2.6.22.15/include/linux/vs_cvirt.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_cvirt.h
12204 --- linux-2.6.22.15/include/linux/vs_cvirt.h    1969-12-31 19:00:00.000000000 -0500
12205 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_cvirt.h       2007-12-09 06:44:22.000000000 -0500
12206 @@ -0,0 +1,49 @@
12207 +#ifndef _VS_CVIRT_H
12208 +#define _VS_CVIRT_H
12209 +
12210 +#include "vserver/cvirt.h"
12211 +#include "vserver/context.h"
12212 +#include "vserver/base.h"
12213 +#include "vserver/debug.h"
12214 +
12215 +
12216 +static inline void vx_activate_task(struct task_struct *p)
12217 +{
12218 +       struct vx_info *vxi;
12219 +
12220 +       if ((vxi = p->vx_info)) {
12221 +               vx_update_load(vxi);
12222 +               atomic_inc(&vxi->cvirt.nr_running);
12223 +       }
12224 +}
12225 +
12226 +static inline void vx_deactivate_task(struct task_struct *p)
12227 +{
12228 +       struct vx_info *vxi;
12229 +
12230 +       if ((vxi = p->vx_info)) {
12231 +               vx_update_load(vxi);
12232 +               atomic_dec(&vxi->cvirt.nr_running);
12233 +       }
12234 +}
12235 +
12236 +static inline void vx_uninterruptible_inc(struct task_struct *p)
12237 +{
12238 +       struct vx_info *vxi;
12239 +
12240 +       if ((vxi = p->vx_info))
12241 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
12242 +}
12243 +
12244 +static inline void vx_uninterruptible_dec(struct task_struct *p)
12245 +{
12246 +       struct vx_info *vxi;
12247 +
12248 +       if ((vxi = p->vx_info))
12249 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
12250 +}
12251 +
12252 +
12253 +#else
12254 +#warning duplicate inclusion
12255 +#endif
12256 diff -Nurp linux-2.6.22.15/include/linux/vs_device.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_device.h
12257 --- linux-2.6.22.15/include/linux/vs_device.h   1969-12-31 19:00:00.000000000 -0500
12258 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_device.h      2007-12-09 06:44:22.000000000 -0500
12259 @@ -0,0 +1,45 @@
12260 +#ifndef _VS_DEVICE_H
12261 +#define _VS_DEVICE_H
12262 +
12263 +#include "vserver/base.h"
12264 +#include "vserver/device.h"
12265 +#include "vserver/debug.h"
12266 +
12267 +
12268 +#ifdef CONFIG_VSERVER_DEVICE
12269 +
12270 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
12271 +
12272 +#define vs_device_perm(v, d, m, p) \
12273 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
12274 +
12275 +#else
12276 +
12277 +static inline
12278 +int vs_map_device(struct vx_info *vxi,
12279 +       dev_t device, dev_t *target, umode_t mode)
12280 +{
12281 +       if (target)
12282 +               *target = device;
12283 +       return ~0;
12284 +}
12285 +
12286 +#define vs_device_perm(v, d, m, p) ((p) == (p))
12287 +
12288 +#endif
12289 +
12290 +
12291 +#define vs_map_chrdev(d, t, p) \
12292 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
12293 +#define vs_map_blkdev(d, t, p) \
12294 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
12295 +
12296 +#define vs_chrdev_perm(d, p) \
12297 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
12298 +#define vs_blkdev_perm(d, p) \
12299 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
12300 +
12301 +
12302 +#else
12303 +#warning duplicate inclusion
12304 +#endif
12305 diff -Nurp linux-2.6.22.15/include/linux/vs_dlimit.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_dlimit.h
12306 --- linux-2.6.22.15/include/linux/vs_dlimit.h   1969-12-31 19:00:00.000000000 -0500
12307 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_dlimit.h      2007-12-09 06:44:22.000000000 -0500
12308 @@ -0,0 +1,211 @@
12309 +#ifndef _VS_DLIMIT_H
12310 +#define _VS_DLIMIT_H
12311 +
12312 +#include <linux/fs.h>
12313 +
12314 +#include "vserver/dlimit.h"
12315 +#include "vserver/base.h"
12316 +#include "vserver/debug.h"
12317 +
12318 +
12319 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
12320 +
12321 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
12322 +       const char *_file, int _line)
12323 +{
12324 +       if (!dli)
12325 +               return NULL;
12326 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
12327 +               dli, dli ? dli->dl_tag : 0,
12328 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
12329 +               _file, _line);
12330 +       atomic_inc(&dli->dl_usecnt);
12331 +       return dli;
12332 +}
12333 +
12334 +
12335 +#define free_dl_info(i) \
12336 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
12337 +
12338 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
12339 +
12340 +static inline void __put_dl_info(struct dl_info *dli,
12341 +       const char *_file, int _line)
12342 +{
12343 +       if (!dli)
12344 +               return;
12345 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
12346 +               dli, dli ? dli->dl_tag : 0,
12347 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
12348 +               _file, _line);
12349 +       if (atomic_dec_and_test(&dli->dl_usecnt))
12350 +               free_dl_info(dli);
12351 +}
12352 +
12353 +
12354 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
12355 +
12356 +static inline int __dl_alloc_space(struct super_block *sb,
12357 +       tag_t tag, dlsize_t nr, const char *file, int line)
12358 +{
12359 +       struct dl_info *dli = NULL;
12360 +       int ret = 0;
12361 +
12362 +       if (nr == 0)
12363 +               goto out;
12364 +       dli = locate_dl_info(sb, tag);
12365 +       if (!dli)
12366 +               goto out;
12367 +
12368 +       spin_lock(&dli->dl_lock);
12369 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
12370 +       if (!ret)
12371 +               dli->dl_space_used += nr;
12372 +       spin_unlock(&dli->dl_lock);
12373 +       put_dl_info(dli);
12374 +out:
12375 +       vxlprintk(VXD_CBIT(dlim, 1),
12376 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
12377 +               sb, tag, __dlimit_char(dli), (long long)nr,
12378 +               ret, file, line);
12379 +       return ret;
12380 +}
12381 +
12382 +static inline void __dl_free_space(struct super_block *sb,
12383 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
12384 +{
12385 +       struct dl_info *dli = NULL;
12386 +
12387 +       if (nr == 0)
12388 +               goto out;
12389 +       dli = locate_dl_info(sb, tag);
12390 +       if (!dli)
12391 +               goto out;
12392 +
12393 +       spin_lock(&dli->dl_lock);
12394 +       if (dli->dl_space_used > nr)
12395 +               dli->dl_space_used -= nr;
12396 +       else
12397 +               dli->dl_space_used = 0;
12398 +       spin_unlock(&dli->dl_lock);
12399 +       put_dl_info(dli);
12400 +out:
12401 +       vxlprintk(VXD_CBIT(dlim, 1),
12402 +               "FREE  (%p,#%d)%c %lld bytes",
12403 +               sb, tag, __dlimit_char(dli), (long long)nr,
12404 +               _file, _line);
12405 +}
12406 +
12407 +static inline int __dl_alloc_inode(struct super_block *sb,
12408 +       tag_t tag, const char *_file, int _line)
12409 +{
12410 +       struct dl_info *dli;
12411 +       int ret = 0;
12412 +
12413 +       dli = locate_dl_info(sb, tag);
12414 +       if (!dli)
12415 +               goto out;
12416 +
12417 +       spin_lock(&dli->dl_lock);
12418 +       ret = (dli->dl_inodes_used >= dli->dl_inodes_total);
12419 +       if (!ret)
12420 +               dli->dl_inodes_used++;
12421 +       spin_unlock(&dli->dl_lock);
12422 +       put_dl_info(dli);
12423 +out:
12424 +       vxlprintk(VXD_CBIT(dlim, 0),
12425 +               "ALLOC (%p,#%d)%c inode (%d)",
12426 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
12427 +       return ret;
12428 +}
12429 +
12430 +static inline void __dl_free_inode(struct super_block *sb,
12431 +       tag_t tag, const char *_file, int _line)
12432 +{
12433 +       struct dl_info *dli;
12434 +
12435 +       dli = locate_dl_info(sb, tag);
12436 +       if (!dli)
12437 +               goto out;
12438 +
12439 +       spin_lock(&dli->dl_lock);
12440 +       if (dli->dl_inodes_used > 1)
12441 +               dli->dl_inodes_used--;
12442 +       else
12443 +               dli->dl_inodes_used = 0;
12444 +       spin_unlock(&dli->dl_lock);
12445 +       put_dl_info(dli);
12446 +out:
12447 +       vxlprintk(VXD_CBIT(dlim, 0),
12448 +               "FREE  (%p,#%d)%c inode",
12449 +               sb, tag, __dlimit_char(dli), _file, _line);
12450 +}
12451 +
12452 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
12453 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
12454 +       const char *_file, int _line)
12455 +{
12456 +       struct dl_info *dli;
12457 +       uint64_t broot, bfree;
12458 +
12459 +       dli = locate_dl_info(sb, tag);
12460 +       if (!dli)
12461 +               return;
12462 +
12463 +       spin_lock(&dli->dl_lock);
12464 +       broot = (dli->dl_space_total -
12465 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
12466 +               >> sb->s_blocksize_bits;
12467 +       bfree = (dli->dl_space_total - dli->dl_space_used)
12468 +                       >> sb->s_blocksize_bits;
12469 +       spin_unlock(&dli->dl_lock);
12470 +
12471 +       vxlprintk(VXD_CBIT(dlim, 2),
12472 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
12473 +               (long long)bfree, (long long)broot,
12474 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
12475 +               _file, _line);
12476 +       if (free_blocks) {
12477 +               if (*free_blocks > bfree)
12478 +                       *free_blocks = bfree;
12479 +       }
12480 +       if (root_blocks) {
12481 +               if (*root_blocks > broot)
12482 +                       *root_blocks = broot;
12483 +       }
12484 +       put_dl_info(dli);
12485 +}
12486 +
12487 +#define DLIMIT_ALLOC_SPACE(in, bytes) \
12488 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
12489 +               __FILE__, __LINE__ )
12490 +
12491 +#define DLIMIT_FREE_SPACE(in, bytes) \
12492 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
12493 +               __FILE__, __LINE__ )
12494 +
12495 +#define DLIMIT_ALLOC_BLOCK(in, nr) \
12496 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, \
12497 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
12498 +               __FILE__, __LINE__ )
12499 +
12500 +#define DLIMIT_FREE_BLOCK(in, nr) \
12501 +       __dl_free_space((in)->i_sb, (in)->i_tag, \
12502 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
12503 +               __FILE__, __LINE__ )
12504 +
12505 +
12506 +#define DLIMIT_ALLOC_INODE(in) \
12507 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
12508 +
12509 +#define DLIMIT_FREE_INODE(in) \
12510 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
12511 +
12512 +
12513 +#define DLIMIT_ADJUST_BLOCK(sb, tag, fb, rb) \
12514 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
12515 +
12516 +
12517 +#else
12518 +#warning duplicate inclusion
12519 +#endif
12520 diff -Nurp linux-2.6.22.15/include/linux/vserver/base.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/base.h
12521 --- linux-2.6.22.15/include/linux/vserver/base.h        1969-12-31 19:00:00.000000000 -0500
12522 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/base.h   2007-12-09 06:44:22.000000000 -0500
12523 @@ -0,0 +1,218 @@
12524 +#ifndef _VX_BASE_H
12525 +#define _VX_BASE_H
12526 +
12527 +
12528 +/* context state changes */
12529 +
12530 +enum {
12531 +       VSC_STARTUP = 1,
12532 +       VSC_SHUTDOWN,
12533 +
12534 +       VSC_NETUP,
12535 +       VSC_NETDOWN,
12536 +};
12537 +
12538 +
12539 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
12540 +
12541 +/* check conditions */
12542 +
12543 +#define VS_ADMIN       0x0001
12544 +#define VS_WATCH       0x0002
12545 +#define VS_HIDE                0x0004
12546 +#define VS_HOSTID      0x0008
12547 +
12548 +#define VS_IDENT       0x0010
12549 +#define VS_EQUIV       0x0020
12550 +#define VS_PARENT      0x0040
12551 +#define VS_CHILD       0x0080
12552 +
12553 +#define VS_ARG_MASK    0x00F0
12554 +
12555 +#ifdef CONFIG_VSERVER_PRIVACY
12556 +#define VS_ADMIN_P     (0)
12557 +#define VS_WATCH_P     (0)
12558 +#else
12559 +#define VS_ADMIN_P     VS_ADMIN
12560 +#define VS_WATCH_P     VS_WATCH
12561 +#endif
12562 +
12563 +#define VS_HARDIRQ     0x1000
12564 +#define VS_SOFTIRQ     0x2000
12565 +#define VS_IRQ         0x4000
12566 +
12567 +#define VS_IRQ_MASK    0xF000
12568 +
12569 +#include <linux/hardirq.h>
12570 +
12571 +/*
12572 + * check current context for ADMIN/WATCH and
12573 + * optionally against supplied argument
12574 + */
12575 +static inline int __vs_check(int cid, int id, unsigned int mode)
12576 +{
12577 +       if (mode & VS_ARG_MASK) {
12578 +               if ((mode & VS_IDENT) && (id == cid))
12579 +                       return 1;
12580 +       }
12581 +       if (mode & VS_IRQ_MASK) {
12582 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
12583 +                       return 1;
12584 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
12585 +                       return 1;
12586 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
12587 +                       return 1;
12588 +       }
12589 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
12590 +               ((mode & VS_WATCH) && (cid == 1)) ||
12591 +               ((mode & VS_HOSTID) && (id == 0)));
12592 +}
12593 +
12594 +#define vx_task_xid(t) ((t)->xid)
12595 +
12596 +#define vx_current_xid() vx_task_xid(current)
12597 +
12598 +#define current_vx_info() (current->vx_info)
12599 +
12600 +
12601 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
12602 +
12603 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
12604 +
12605 +
12606 +#define nx_task_nid(t) ((t)->nid)
12607 +
12608 +#define nx_current_nid() nx_task_nid(current)
12609 +
12610 +#define current_nx_info() (current->nx_info)
12611 +
12612 +
12613 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
12614 +
12615 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
12616 +
12617 +
12618 +
12619 +/* generic flag merging */
12620 +
12621 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
12622 +
12623 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
12624 +
12625 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
12626 +
12627 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
12628 +
12629 +
12630 +/* context flags */
12631 +
12632 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
12633 +
12634 +#define vx_current_flags()     __vx_flags(current->vx_info)
12635 +
12636 +#define vx_info_flags(v, m, f) \
12637 +       vs_check_flags(__vx_flags(v), m, f)
12638 +
12639 +#define task_vx_flags(t, m, f) \
12640 +       ((t) && vx_info_flags((t)->vx_info, m, f))
12641 +
12642 +#define vx_flags(m, f) vx_info_flags(current->vx_info, m, f)
12643 +
12644 +
12645 +/* context caps */
12646 +
12647 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
12648 +
12649 +#define vx_current_ccaps()     __vx_ccaps(current->vx_info)
12650 +
12651 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
12652 +
12653 +#define vx_ccaps(c)    vx_info_ccaps(current->vx_info, (c))
12654 +
12655 +
12656 +
12657 +/* network flags */
12658 +
12659 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
12660 +
12661 +#define nx_current_flags()     __nx_flags(current->nx_info)
12662 +
12663 +#define nx_info_flags(n, m, f) \
12664 +       vs_check_flags(__nx_flags(n), m, f)
12665 +
12666 +#define task_nx_flags(t, m, f) \
12667 +       ((t) && nx_info_flags((t)->nx_info, m, f))
12668 +
12669 +#define nx_flags(m, f) nx_info_flags(current->nx_info, m, f)
12670 +
12671 +
12672 +/* network caps */
12673 +
12674 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
12675 +
12676 +#define nx_current_ncaps()     __nx_ncaps(current->nx_info)
12677 +
12678 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
12679 +
12680 +#define nx_ncaps(c)    nx_info_ncaps(current->nx_info, c)
12681 +
12682 +
12683 +/* context mask capabilities */
12684 +
12685 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
12686 +
12687 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
12688 +
12689 +#define vx_mcaps(c)    vx_info_mcaps(current->vx_info, c)
12690 +
12691 +
12692 +/* context bcap mask */
12693 +
12694 +#define __vx_bcaps(v)  ((v) ? (v)->vx_bcaps : ~0 )
12695 +
12696 +#define vx_current_bcaps()     __vx_bcaps(current->vx_info)
12697 +
12698 +#define vx_info_bcaps(v, c)    (__vx_bcaps(v) & (c))
12699 +
12700 +#define vx_bcaps(c)    vx_info_bcaps(current->vx_info, c)
12701 +
12702 +
12703 +#define vx_info_cap_bset(v)    ((v) ? (v)->vx_cap_bset : cap_bset)
12704 +
12705 +#define vx_current_cap_bset()  vx_info_cap_bset(current->vx_info)
12706 +
12707 +
12708 +#define __vx_info_mbcap(v, b) \
12709 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
12710 +       vx_info_bcaps(v, b) : (b))
12711 +
12712 +#define vx_info_mbcap(v, b)    __vx_info_mbcap(v, cap_t(b))
12713 +
12714 +#define task_vx_mbcap(t, b) \
12715 +       vx_info_mbcap((t)->vx_info, (t)->b)
12716 +
12717 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
12718 +
12719 +#define vx_cap_raised(v, c, f) (vx_info_mbcap(v, c) & CAP_TO_MASK(f))
12720 +
12721 +#define vx_capable(b, c) (capable(b) || \
12722 +       (cap_raised(current->cap_effective, b) && vx_ccaps(c)))
12723 +
12724 +#define nx_capable(b, c) (capable(b) || \
12725 +       (cap_raised(current->cap_effective, b) && nx_ncaps(c)))
12726 +
12727 +#define vx_current_initpid(n) \
12728 +       (current->vx_info && \
12729 +       (current->vx_info->vx_initpid == (n)))
12730 +
12731 +
12732 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
12733 +
12734 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
12735 +
12736 +
12737 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
12738 +
12739 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
12740 +
12741 +#endif
12742 diff -Nurp linux-2.6.22.15/include/linux/vserver/cacct_cmd.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/cacct_cmd.h
12743 --- linux-2.6.22.15/include/linux/vserver/cacct_cmd.h   1969-12-31 19:00:00.000000000 -0500
12744 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/cacct_cmd.h      2007-12-09 06:44:22.000000000 -0500
12745 @@ -0,0 +1,23 @@
12746 +#ifndef _VX_CACCT_CMD_H
12747 +#define _VX_CACCT_CMD_H
12748 +
12749 +
12750 +/* virtual host info name commands */
12751 +
12752 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
12753 +
12754 +struct vcmd_sock_stat_v0 {
12755 +       uint32_t field;
12756 +       uint32_t count[3];
12757 +       uint64_t total[3];
12758 +};
12759 +
12760 +
12761 +#ifdef __KERNEL__
12762 +
12763 +#include <linux/compiler.h>
12764 +
12765 +extern int vc_sock_stat(struct vx_info *, void __user *);
12766 +
12767 +#endif /* __KERNEL__ */
12768 +#endif /* _VX_CACCT_CMD_H */
12769 diff -Nurp linux-2.6.22.15/include/linux/vserver/cacct_def.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/cacct_def.h
12770 --- linux-2.6.22.15/include/linux/vserver/cacct_def.h   1969-12-31 19:00:00.000000000 -0500
12771 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/cacct_def.h      2007-12-09 06:44:22.000000000 -0500
12772 @@ -0,0 +1,43 @@
12773 +#ifndef _VX_CACCT_DEF_H
12774 +#define _VX_CACCT_DEF_H
12775 +
12776 +#include <asm/atomic.h>
12777 +#include <linux/vserver/cacct.h>
12778 +
12779 +
12780 +struct _vx_sock_acc {
12781 +       atomic_long_t count;
12782 +       atomic_long_t total;
12783 +};
12784 +
12785 +/* context sub struct */
12786 +
12787 +struct _vx_cacct {
12788 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
12789 +       atomic_t slab[8];
12790 +       atomic_t page[6][8];
12791 +};
12792 +
12793 +#ifdef CONFIG_VSERVER_DEBUG
12794 +
12795 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
12796 +{
12797 +       int i, j;
12798 +
12799 +       printk("\t_vx_cacct:");
12800 +       for (i = 0; i < 6; i++) {
12801 +               struct _vx_sock_acc *ptr = cacct->sock[i];
12802 +
12803 +               printk("\t [%d] =", i);
12804 +               for (j = 0; j < 3; j++) {
12805 +                       printk(" [%d] = %8lu, %8lu", j,
12806 +                               atomic_long_read(&ptr[j].count),
12807 +                               atomic_long_read(&ptr[j].total));
12808 +               }
12809 +               printk("\n");
12810 +       }
12811 +}
12812 +
12813 +#endif
12814 +
12815 +#endif /* _VX_CACCT_DEF_H */
12816 diff -Nurp linux-2.6.22.15/include/linux/vserver/cacct.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/cacct.h
12817 --- linux-2.6.22.15/include/linux/vserver/cacct.h       1969-12-31 19:00:00.000000000 -0500
12818 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/cacct.h  2007-12-09 06:44:22.000000000 -0500
12819 @@ -0,0 +1,15 @@
12820 +#ifndef _VX_CACCT_H
12821 +#define _VX_CACCT_H
12822 +
12823 +
12824 +enum sock_acc_field {
12825 +       VXA_SOCK_UNSPEC = 0,
12826 +       VXA_SOCK_UNIX,
12827 +       VXA_SOCK_INET,
12828 +       VXA_SOCK_INET6,
12829 +       VXA_SOCK_PACKET,
12830 +       VXA_SOCK_OTHER,
12831 +       VXA_SOCK_SIZE   /* array size */
12832 +};
12833 +
12834 +#endif /* _VX_CACCT_H */
12835 diff -Nurp linux-2.6.22.15/include/linux/vserver/cacct_int.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/cacct_int.h
12836 --- linux-2.6.22.15/include/linux/vserver/cacct_int.h   1969-12-31 19:00:00.000000000 -0500
12837 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/cacct_int.h      2007-12-09 06:44:22.000000000 -0500
12838 @@ -0,0 +1,21 @@
12839 +#ifndef _VX_CACCT_INT_H
12840 +#define _VX_CACCT_INT_H
12841 +
12842 +
12843 +#ifdef __KERNEL__
12844 +
12845 +static inline
12846 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
12847 +{
12848 +       return atomic_long_read(&cacct->sock[type][pos].count);
12849 +}
12850 +
12851 +
12852 +static inline
12853 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
12854 +{
12855 +       return atomic_long_read(&cacct->sock[type][pos].total);
12856 +}
12857 +
12858 +#endif /* __KERNEL__ */
12859 +#endif /* _VX_CACCT_INT_H */
12860 diff -Nurp linux-2.6.22.15/include/linux/vserver/context_cmd.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/context_cmd.h
12861 --- linux-2.6.22.15/include/linux/vserver/context_cmd.h 1969-12-31 19:00:00.000000000 -0500
12862 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/context_cmd.h    2007-12-09 06:44:22.000000000 -0500
12863 @@ -0,0 +1,128 @@
12864 +#ifndef _VX_CONTEXT_CMD_H
12865 +#define _VX_CONTEXT_CMD_H
12866 +
12867 +
12868 +/* vinfo commands */
12869 +
12870 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
12871 +
12872 +#ifdef __KERNEL__
12873 +extern int vc_task_xid(uint32_t);
12874 +
12875 +#endif /* __KERNEL__ */
12876 +
12877 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
12878 +
12879 +struct vcmd_vx_info_v0 {
12880 +       uint32_t xid;
12881 +       uint32_t initpid;
12882 +       /* more to come */
12883 +};
12884 +
12885 +#ifdef __KERNEL__
12886 +extern int vc_vx_info(struct vx_info *, void __user *);
12887 +
12888 +#endif /* __KERNEL__ */
12889 +
12890 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
12891 +
12892 +struct vcmd_ctx_stat_v0 {
12893 +       uint32_t usecnt;
12894 +       uint32_t tasks;
12895 +       /* more to come */
12896 +};
12897 +
12898 +#ifdef __KERNEL__
12899 +extern int vc_ctx_stat(struct vx_info *, void __user *);
12900 +
12901 +#endif /* __KERNEL__ */
12902 +
12903 +/* context commands */
12904 +
12905 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
12906 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
12907 +
12908 +struct vcmd_ctx_create {
12909 +       uint64_t flagword;
12910 +};
12911 +
12912 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
12913 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
12914 +
12915 +struct vcmd_ctx_migrate {
12916 +       uint64_t flagword;
12917 +};
12918 +
12919 +#ifdef __KERNEL__
12920 +extern int vc_ctx_create(uint32_t, void __user *);
12921 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
12922 +
12923 +#endif /* __KERNEL__ */
12924 +
12925 +
12926 +/* flag commands */
12927 +
12928 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
12929 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
12930 +
12931 +struct vcmd_ctx_flags_v0 {
12932 +       uint64_t flagword;
12933 +       uint64_t mask;
12934 +};
12935 +
12936 +#ifdef __KERNEL__
12937 +extern int vc_get_cflags(struct vx_info *, void __user *);
12938 +extern int vc_set_cflags(struct vx_info *, void __user *);
12939 +
12940 +#endif /* __KERNEL__ */
12941 +
12942 +
12943 +/* context caps commands */
12944 +
12945 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
12946 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
12947 +
12948 +struct vcmd_ctx_caps_v1 {
12949 +       uint64_t ccaps;
12950 +       uint64_t cmask;
12951 +};
12952 +
12953 +#ifdef __KERNEL__
12954 +extern int vc_get_ccaps(struct vx_info *, void __user *);
12955 +extern int vc_set_ccaps(struct vx_info *, void __user *);
12956 +
12957 +#endif /* __KERNEL__ */
12958 +
12959 +
12960 +/* bcaps commands */
12961 +
12962 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
12963 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
12964 +
12965 +struct vcmd_bcaps {
12966 +       uint64_t bcaps;
12967 +       uint64_t bmask;
12968 +};
12969 +
12970 +#ifdef __KERNEL__
12971 +extern int vc_get_bcaps(struct vx_info *, void __user *);
12972 +extern int vc_set_bcaps(struct vx_info *, void __user *);
12973 +
12974 +#endif /* __KERNEL__ */
12975 +
12976 +
12977 +/* OOM badness */
12978 +
12979 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
12980 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
12981 +
12982 +struct vcmd_badness_v0 {
12983 +       int64_t bias;
12984 +};
12985 +
12986 +#ifdef __KERNEL__
12987 +extern int vc_get_badness(struct vx_info *, void __user *);
12988 +extern int vc_set_badness(struct vx_info *, void __user *);
12989 +
12990 +#endif /* __KERNEL__ */
12991 +#endif /* _VX_CONTEXT_CMD_H */
12992 diff -Nurp linux-2.6.22.15/include/linux/vserver/context.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/context.h
12993 --- linux-2.6.22.15/include/linux/vserver/context.h     1969-12-31 19:00:00.000000000 -0500
12994 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/context.h        2007-12-09 06:44:22.000000000 -0500
12995 @@ -0,0 +1,176 @@
12996 +#ifndef _VX_CONTEXT_H
12997 +#define _VX_CONTEXT_H
12998 +
12999 +#include <linux/types.h>
13000 +#include <linux/capability.h>
13001 +
13002 +
13003 +/* context flags */
13004 +
13005 +#define VXF_INFO_SCHED         0x00000002
13006 +#define VXF_INFO_NPROC         0x00000004
13007 +#define VXF_INFO_PRIVATE       0x00000008
13008 +
13009 +#define VXF_INFO_INIT          0x00000010
13010 +#define VXF_INFO_HIDE          0x00000020
13011 +#define VXF_INFO_ULIMIT                0x00000040
13012 +#define VXF_INFO_NSPACE                0x00000080
13013 +
13014 +#define VXF_SCHED_HARD         0x00000100
13015 +#define VXF_SCHED_PRIO         0x00000200
13016 +#define VXF_SCHED_PAUSE                0x00000400
13017 +
13018 +#define VXF_VIRT_MEM           0x00010000
13019 +#define VXF_VIRT_UPTIME                0x00020000
13020 +#define VXF_VIRT_CPU           0x00040000
13021 +#define VXF_VIRT_LOAD          0x00080000
13022 +#define VXF_VIRT_TIME          0x00100000
13023 +
13024 +#define VXF_HIDE_MOUNT         0x01000000
13025 +/* was VXF_HIDE_NETIF          0x02000000 */
13026 +#define VXF_HIDE_VINFO         0x04000000
13027 +
13028 +#define VXF_STATE_SETUP                (1ULL << 32)
13029 +#define VXF_STATE_INIT         (1ULL << 33)
13030 +#define VXF_STATE_ADMIN                (1ULL << 34)
13031 +
13032 +#define VXF_SC_HELPER          (1ULL << 36)
13033 +#define VXF_REBOOT_KILL                (1ULL << 37)
13034 +#define VXF_PERSISTENT         (1ULL << 38)
13035 +
13036 +#define VXF_FORK_RSS           (1ULL << 48)
13037 +#define VXF_PROLIFIC           (1ULL << 49)
13038 +
13039 +#define VXF_IGNEG_NICE         (1ULL << 52)
13040 +
13041 +#define VXF_ONE_TIME           (0x0007ULL << 32)
13042 +
13043 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
13044 +
13045 +
13046 +/* context migration */
13047 +
13048 +#define VXM_SET_INIT           0x00000001
13049 +#define VXM_SET_REAPER         0x00000002
13050 +
13051 +/* context caps */
13052 +
13053 +#define VXC_CAP_MASK           0x00000000
13054 +
13055 +#define VXC_SET_UTSNAME                0x00000001
13056 +#define VXC_SET_RLIMIT         0x00000002
13057 +
13058 +/* was VXC_RAW_ICMP            0x00000100 */
13059 +#define VXC_SYSLOG             0x00001000
13060 +
13061 +#define VXC_SECURE_MOUNT       0x00010000
13062 +#define VXC_SECURE_REMOUNT     0x00020000
13063 +#define VXC_BINARY_MOUNT       0x00040000
13064 +
13065 +#define VXC_QUOTA_CTL          0x00100000
13066 +#define VXC_ADMIN_MAPPER       0x00200000
13067 +#define VXC_ADMIN_CLOOP                0x00400000
13068 +
13069 +#define VXC_KTHREAD            0x01000000
13070 +
13071 +
13072 +#ifdef __KERNEL__
13073 +
13074 +#include <linux/list.h>
13075 +#include <linux/spinlock.h>
13076 +#include <linux/rcupdate.h>
13077 +
13078 +#include "limit_def.h"
13079 +#include "sched_def.h"
13080 +#include "cvirt_def.h"
13081 +#include "cacct_def.h"
13082 +#include "device_def.h"
13083 +
13084 +struct _vx_info_pc {
13085 +       struct _vx_sched_pc sched_pc;
13086 +       struct _vx_cvirt_pc cvirt_pc;
13087 +};
13088 +
13089 +struct vx_info {
13090 +       struct hlist_node vx_hlist;             /* linked list of contexts */
13091 +       xid_t vx_id;                            /* context id */
13092 +       atomic_t vx_usecnt;                     /* usage count */
13093 +       atomic_t vx_tasks;                      /* tasks count */
13094 +       struct vx_info *vx_parent;              /* parent context */
13095 +       int vx_state;                           /* context state */
13096 +
13097 +       unsigned long vx_nsmask;                /* assignment mask */
13098 +       struct nsproxy *vx_nsproxy;             /* private namespace */
13099 +       struct fs_struct *vx_fs;                /* private namespace fs */
13100 +
13101 +       uint64_t vx_flags;                      /* context flags */
13102 +       uint64_t vx_bcaps;                      /* bounding caps (system) */
13103 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
13104 +       kernel_cap_t vx_cap_bset;               /* the guest's bset */
13105 +
13106 +       struct task_struct *vx_reaper;          /* guest reaper process */
13107 +       pid_t vx_initpid;                       /* PID of guest init */
13108 +       int64_t vx_badness_bias;                /* OOM points bias */
13109 +
13110 +       struct _vx_limit limit;                 /* vserver limits */
13111 +       struct _vx_sched sched;                 /* vserver scheduler */
13112 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
13113 +       struct _vx_cacct cacct;                 /* context accounting */
13114 +
13115 +       struct _vx_device dmap;                 /* default device map targets */
13116 +
13117 +#ifndef CONFIG_SMP
13118 +       struct _vx_info_pc info_pc;             /* per cpu data */
13119 +#else
13120 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
13121 +#endif
13122 +
13123 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
13124 +       int reboot_cmd;                         /* last sys_reboot() cmd */
13125 +       int exit_code;                          /* last process exit code */
13126 +
13127 +       char vx_name[65];                       /* vserver name */
13128 +};
13129 +
13130 +#ifndef CONFIG_SMP
13131 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
13132 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
13133 +#else
13134 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
13135 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
13136 +#endif
13137 +
13138 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
13139 +
13140 +
13141 +struct vx_info_save {
13142 +       struct vx_info *vxi;
13143 +       xid_t xid;
13144 +};
13145 +
13146 +
13147 +/* status flags */
13148 +
13149 +#define VXS_HASHED     0x0001
13150 +#define VXS_PAUSED     0x0010
13151 +#define VXS_SHUTDOWN   0x0100
13152 +#define VXS_HELPER     0x1000
13153 +#define VXS_RELEASED   0x8000
13154 +
13155 +
13156 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
13157 +extern void release_vx_info(struct vx_info *, struct task_struct *);
13158 +
13159 +extern struct vx_info *lookup_vx_info(int);
13160 +extern struct vx_info *lookup_or_create_vx_info(int);
13161 +
13162 +extern int get_xid_list(int, unsigned int *, int);
13163 +extern int xid_is_hashed(xid_t);
13164 +
13165 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
13166 +
13167 +extern long vs_state_change(struct vx_info *, unsigned int);
13168 +
13169 +
13170 +#endif /* __KERNEL__ */
13171 +#endif /* _VX_CONTEXT_H */
13172 diff -Nurp linux-2.6.22.15/include/linux/vserver/cvirt_cmd.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/cvirt_cmd.h
13173 --- linux-2.6.22.15/include/linux/vserver/cvirt_cmd.h   1969-12-31 19:00:00.000000000 -0500
13174 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/cvirt_cmd.h      2007-12-09 06:44:22.000000000 -0500
13175 @@ -0,0 +1,53 @@
13176 +#ifndef _VX_CVIRT_CMD_H
13177 +#define _VX_CVIRT_CMD_H
13178 +
13179 +
13180 +/* virtual host info name commands */
13181 +
13182 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
13183 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
13184 +
13185 +struct vcmd_vhi_name_v0 {
13186 +       uint32_t field;
13187 +       char name[65];
13188 +};
13189 +
13190 +
13191 +enum vhi_name_field {
13192 +       VHIN_CONTEXT = 0,
13193 +       VHIN_SYSNAME,
13194 +       VHIN_NODENAME,
13195 +       VHIN_RELEASE,
13196 +       VHIN_VERSION,
13197 +       VHIN_MACHINE,
13198 +       VHIN_DOMAINNAME,
13199 +};
13200 +
13201 +
13202 +#ifdef __KERNEL__
13203 +
13204 +#include <linux/compiler.h>
13205 +
13206 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
13207 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
13208 +
13209 +#endif /* __KERNEL__ */
13210 +
13211 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
13212 +
13213 +struct vcmd_virt_stat_v0 {
13214 +       uint64_t offset;
13215 +       uint64_t uptime;
13216 +       uint32_t nr_threads;
13217 +       uint32_t nr_running;
13218 +       uint32_t nr_uninterruptible;
13219 +       uint32_t nr_onhold;
13220 +       uint32_t nr_forks;
13221 +       uint32_t load[3];
13222 +};
13223 +
13224 +#ifdef __KERNEL__
13225 +extern int vc_virt_stat(struct vx_info *, void __user *);
13226 +
13227 +#endif /* __KERNEL__ */
13228 +#endif /* _VX_CVIRT_CMD_H */
13229 diff -Nurp linux-2.6.22.15/include/linux/vserver/cvirt_def.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/cvirt_def.h
13230 --- linux-2.6.22.15/include/linux/vserver/cvirt_def.h   1969-12-31 19:00:00.000000000 -0500
13231 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/cvirt_def.h      2007-12-09 06:44:22.000000000 -0500
13232 @@ -0,0 +1,81 @@
13233 +#ifndef _VX_CVIRT_DEF_H
13234 +#define _VX_CVIRT_DEF_H
13235 +
13236 +#include <linux/jiffies.h>
13237 +#include <linux/spinlock.h>
13238 +#include <linux/wait.h>
13239 +#include <linux/time.h>
13240 +#include <linux/utsname.h>
13241 +#include <asm/atomic.h>
13242 +
13243 +
13244 +struct _vx_usage_stat {
13245 +       uint64_t user;
13246 +       uint64_t nice;
13247 +       uint64_t system;
13248 +       uint64_t softirq;
13249 +       uint64_t irq;
13250 +       uint64_t idle;
13251 +       uint64_t iowait;
13252 +};
13253 +
13254 +struct _vx_syslog {
13255 +       wait_queue_head_t log_wait;
13256 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
13257 +
13258 +       unsigned long log_start;        /* next char to be read by syslog() */
13259 +       unsigned long con_start;        /* next char to be sent to consoles */
13260 +       unsigned long log_end;  /* most-recently-written-char + 1 */
13261 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
13262 +
13263 +       char log_buf[1024];
13264 +};
13265 +
13266 +
13267 +/* context sub struct */
13268 +
13269 +struct _vx_cvirt {
13270 +       atomic_t nr_threads;            /* number of current threads */
13271 +       atomic_t nr_running;            /* number of running threads */
13272 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
13273 +
13274 +       atomic_t nr_onhold;             /* processes on hold */
13275 +       uint32_t onhold_last;           /* jiffies when put on hold */
13276 +
13277 +       struct timeval bias_tv;         /* time offset to the host */
13278 +       struct timespec bias_idle;
13279 +       struct timespec bias_uptime;    /* context creation point */
13280 +       uint64_t bias_clock;            /* offset in clock_t */
13281 +
13282 +       spinlock_t load_lock;           /* lock for the load averages */
13283 +       atomic_t load_updates;          /* nr of load updates done so far */
13284 +       uint32_t load_last;             /* last time load was calculated */
13285 +       uint32_t load[3];               /* load averages 1,5,15 */
13286 +
13287 +       atomic_t total_forks;           /* number of forks so far */
13288 +
13289 +       struct _vx_syslog syslog;
13290 +};
13291 +
13292 +struct _vx_cvirt_pc {
13293 +       struct _vx_usage_stat cpustat;
13294 +};
13295 +
13296 +
13297 +#ifdef CONFIG_VSERVER_DEBUG
13298 +
13299 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
13300 +{
13301 +       printk("\t_vx_cvirt:\n");
13302 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
13303 +               atomic_read(&cvirt->nr_threads),
13304 +               atomic_read(&cvirt->nr_running),
13305 +               atomic_read(&cvirt->nr_uninterruptible),
13306 +               atomic_read(&cvirt->nr_onhold));
13307 +       /* add rest here */
13308 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
13309 +}
13310 +
13311 +#endif
13312 +
13313 +#endif /* _VX_CVIRT_DEF_H */
13314 diff -Nurp linux-2.6.22.15/include/linux/vserver/cvirt.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/cvirt.h
13315 --- linux-2.6.22.15/include/linux/vserver/cvirt.h       1969-12-31 19:00:00.000000000 -0500
13316 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/cvirt.h  2007-12-09 06:44:22.000000000 -0500
13317 @@ -0,0 +1,20 @@
13318 +#ifndef _VX_CVIRT_H
13319 +#define _VX_CVIRT_H
13320 +
13321 +
13322 +#ifdef __KERNEL__
13323 +
13324 +struct timespec;
13325 +
13326 +void vx_vsi_uptime(struct timespec *, struct timespec *);
13327 +
13328 +
13329 +struct vx_info;
13330 +
13331 +void vx_update_load(struct vx_info *);
13332 +
13333 +
13334 +int vx_do_syslog(int, char __user *, int);
13335 +
13336 +#endif /* __KERNEL__ */
13337 +#endif /* _VX_CVIRT_H */
13338 diff -Nurp linux-2.6.22.15/include/linux/vserver/debug_cmd.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/debug_cmd.h
13339 --- linux-2.6.22.15/include/linux/vserver/debug_cmd.h   1969-12-31 19:00:00.000000000 -0500
13340 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/debug_cmd.h      2007-12-09 06:44:22.000000000 -0500
13341 @@ -0,0 +1,58 @@
13342 +#ifndef _VX_DEBUG_CMD_H
13343 +#define _VX_DEBUG_CMD_H
13344 +
13345 +
13346 +/* debug commands */
13347 +
13348 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
13349 +
13350 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
13351 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
13352 +
13353 +struct  vcmd_read_history_v0 {
13354 +       uint32_t index;
13355 +       uint32_t count;
13356 +       char __user *data;
13357 +};
13358 +
13359 +struct  vcmd_read_monitor_v0 {
13360 +       uint32_t index;
13361 +       uint32_t count;
13362 +       char __user *data;
13363 +};
13364 +
13365 +
13366 +#ifdef __KERNEL__
13367 +
13368 +#ifdef CONFIG_COMPAT
13369 +
13370 +#include <asm/compat.h>
13371 +
13372 +struct vcmd_read_history_v0_x32 {
13373 +       uint32_t index;
13374 +       uint32_t count;
13375 +       compat_uptr_t data_ptr;
13376 +};
13377 +
13378 +struct vcmd_read_monitor_v0_x32 {
13379 +       uint32_t index;
13380 +       uint32_t count;
13381 +       compat_uptr_t data_ptr;
13382 +};
13383 +
13384 +#endif  /* CONFIG_COMPAT */
13385 +
13386 +extern int vc_dump_history(uint32_t);
13387 +
13388 +extern int vc_read_history(uint32_t, void __user *);
13389 +extern int vc_read_monitor(uint32_t, void __user *);
13390 +
13391 +#ifdef CONFIG_COMPAT
13392 +
13393 +extern int vc_read_history_x32(uint32_t, void __user *);
13394 +extern int vc_read_monitor_x32(uint32_t, void __user *);
13395 +
13396 +#endif  /* CONFIG_COMPAT */
13397 +
13398 +#endif /* __KERNEL__ */
13399 +#endif /* _VX_DEBUG_CMD_H */
13400 diff -Nurp linux-2.6.22.15/include/linux/vserver/debug.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/debug.h
13401 --- linux-2.6.22.15/include/linux/vserver/debug.h       1969-12-31 19:00:00.000000000 -0500
13402 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/debug.h  2007-12-09 06:44:22.000000000 -0500
13403 @@ -0,0 +1,130 @@
13404 +#ifndef _VX_DEBUG_H
13405 +#define _VX_DEBUG_H
13406 +
13407 +
13408 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
13409 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
13410 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
13411 +
13412 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
13413 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
13414 +#define VXF_DEV                "%p[%lu,%d:%d]"
13415 +
13416 +
13417 +#define __FUNC__       __func__
13418 +
13419 +
13420 +#define vxd_path(d, m)                                         \
13421 +       ({ static char _buffer[PATH_MAX];                       \
13422 +          d_path(d, m, _buffer, sizeof(_buffer)); })
13423 +
13424 +#define vxd_cond_path(n)                                       \
13425 +       ((n) ? vxd_path((n)->dentry, (n)->mnt) : "<null>" )
13426 +
13427 +
13428 +#ifdef CONFIG_VSERVER_DEBUG
13429 +
13430 +extern unsigned int vx_debug_switch;
13431 +extern unsigned int vx_debug_xid;
13432 +extern unsigned int vx_debug_nid;
13433 +extern unsigned int vx_debug_tag;
13434 +extern unsigned int vx_debug_net;
13435 +extern unsigned int vx_debug_limit;
13436 +extern unsigned int vx_debug_cres;
13437 +extern unsigned int vx_debug_dlim;
13438 +extern unsigned int vx_debug_quota;
13439 +extern unsigned int vx_debug_cvirt;
13440 +extern unsigned int vx_debug_space;
13441 +extern unsigned int vx_debug_misc;
13442 +
13443 +
13444 +#define VX_LOGLEVEL    "vxD: "
13445 +#define VX_PROC_FMT    "%p: "
13446 +#define VX_PROCESS     current
13447 +
13448 +#define vxdprintk(c, f, x...)                                  \
13449 +       do {                                                    \
13450 +               if (c)                                          \
13451 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
13452 +                               VX_PROCESS , ##x);              \
13453 +       } while (0)
13454 +
13455 +#define vxlprintk(c, f, x...)                                  \
13456 +       do {                                                    \
13457 +               if (c)                                          \
13458 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
13459 +       } while (0)
13460 +
13461 +#define vxfprintk(c, f, x...)                                  \
13462 +       do {                                                    \
13463 +               if (c)                                          \
13464 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
13465 +       } while (0)
13466 +
13467 +
13468 +struct vx_info;
13469 +
13470 +void dump_vx_info(struct vx_info *, int);
13471 +void dump_vx_info_inactive(int);
13472 +
13473 +#else  /* CONFIG_VSERVER_DEBUG */
13474 +
13475 +#define vx_debug_switch 0
13476 +#define vx_debug_xid   0
13477 +#define vx_debug_nid   0
13478 +#define vx_debug_tag   0
13479 +#define vx_debug_net   0
13480 +#define vx_debug_limit 0
13481 +#define vx_debug_cres  0
13482 +#define vx_debug_dlim  0
13483 +#define vx_debug_cvirt 0
13484 +
13485 +#define vxdprintk(x...) do { } while (0)
13486 +#define vxlprintk(x...) do { } while (0)
13487 +#define vxfprintk(x...) do { } while (0)
13488 +
13489 +#endif /* CONFIG_VSERVER_DEBUG */
13490 +
13491 +
13492 +#ifdef CONFIG_VSERVER_WARN
13493 +
13494 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
13495 +#define VX_WARN_TASK   "[»%s«,%u:#%u|%u|%u] "
13496 +#define VX_WARN_XID    "[xid #%u] "
13497 +#define VX_WARN_NID    "[nid #%u] "
13498 +#define VX_WARN_TAG    "[tag #%u] "
13499 +
13500 +#define vxwprintk(c, f, x...)                                  \
13501 +       do {                                                    \
13502 +               if (c)                                          \
13503 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
13504 +       } while (0)
13505 +
13506 +#else  /* CONFIG_VSERVER_WARN */
13507 +
13508 +#define vxwprintk(x...) do { } while (0)
13509 +
13510 +#endif /* CONFIG_VSERVER_WARN */
13511 +
13512 +#define vxwprintk_task(c, f, x...)                             \
13513 +       vxwprintk(c, VX_WARN_TASK f,                            \
13514 +               current->comm, current->pid,                    \
13515 +               current->xid, current->nid, current->tag, ##x)
13516 +#define vxwprintk_xid(c, f, x...)                              \
13517 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
13518 +#define vxwprintk_nid(c, f, x...)                              \
13519 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
13520 +#define vxwprintk_tag(c, f, x...)                              \
13521 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
13522 +
13523 +#ifdef CONFIG_VSERVER_DEBUG
13524 +#define vxd_assert_lock(l)     assert_spin_locked(l)
13525 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
13526 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
13527 +#else
13528 +#define vxd_assert_lock(l)     do { } while (0)
13529 +#define vxd_assert(c, f, x...) do { } while (0)
13530 +#endif
13531 +
13532 +
13533 +#endif /* _VX_DEBUG_H */
13534 diff -Nurp linux-2.6.22.15/include/linux/vserver/device_cmd.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/device_cmd.h
13535 --- linux-2.6.22.15/include/linux/vserver/device_cmd.h  1969-12-31 19:00:00.000000000 -0500
13536 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/device_cmd.h     2007-12-09 06:44:22.000000000 -0500
13537 @@ -0,0 +1,44 @@
13538 +#ifndef _VX_DEVICE_CMD_H
13539 +#define _VX_DEVICE_CMD_H
13540 +
13541 +
13542 +/*  device vserver commands */
13543 +
13544 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
13545 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
13546 +
13547 +struct vcmd_set_mapping_v0 {
13548 +       const char __user *device;
13549 +       const char __user *target;
13550 +       uint32_t flags;
13551 +};
13552 +
13553 +
13554 +#ifdef __KERNEL__
13555 +
13556 +#ifdef CONFIG_COMPAT
13557 +
13558 +#include <asm/compat.h>
13559 +
13560 +struct vcmd_set_mapping_v0_x32 {
13561 +       compat_uptr_t device_ptr;
13562 +       compat_uptr_t target_ptr;
13563 +       uint32_t flags;
13564 +};
13565 +
13566 +#endif /* CONFIG_COMPAT */
13567 +
13568 +#include <linux/compiler.h>
13569 +
13570 +extern int vc_set_mapping(struct vx_info *, void __user *);
13571 +extern int vc_unset_mapping(struct vx_info *, void __user *);
13572 +
13573 +#ifdef CONFIG_COMPAT
13574 +
13575 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
13576 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
13577 +
13578 +#endif /* CONFIG_COMPAT */
13579 +
13580 +#endif /* __KERNEL__ */
13581 +#endif /* _VX_DEVICE_CMD_H */
13582 diff -Nurp linux-2.6.22.15/include/linux/vserver/device_def.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/device_def.h
13583 --- linux-2.6.22.15/include/linux/vserver/device_def.h  1969-12-31 19:00:00.000000000 -0500
13584 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/device_def.h     2007-12-09 06:44:22.000000000 -0500
13585 @@ -0,0 +1,17 @@
13586 +#ifndef _VX_DEVICE_DEF_H
13587 +#define _VX_DEVICE_DEF_H
13588 +
13589 +#include <linux/types.h>
13590 +
13591 +struct vx_dmap_target {
13592 +       dev_t target;
13593 +       uint32_t flags;
13594 +};
13595 +
13596 +struct _vx_device {
13597 +#ifdef CONFIG_VSERVER_DEVICE
13598 +       struct vx_dmap_target targets[2];
13599 +#endif
13600 +};
13601 +
13602 +#endif /* _VX_DEVICE_DEF_H */
13603 diff -Nurp linux-2.6.22.15/include/linux/vserver/device.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/device.h
13604 --- linux-2.6.22.15/include/linux/vserver/device.h      1969-12-31 19:00:00.000000000 -0500
13605 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/device.h 2007-12-09 06:44:22.000000000 -0500
13606 @@ -0,0 +1,15 @@
13607 +#ifndef _VX_DEVICE_H
13608 +#define _VX_DEVICE_H
13609 +
13610 +
13611 +#define DATTR_CREATE   0x00000001
13612 +#define DATTR_OPEN     0x00000002
13613 +
13614 +#define DATTR_REMAP    0x00000010
13615 +
13616 +#define DATTR_MASK     0x00000013
13617 +
13618 +
13619 +#else  /* _VX_DEVICE_H */
13620 +#warning duplicate inclusion
13621 +#endif /* _VX_DEVICE_H */
13622 diff -Nurp linux-2.6.22.15/include/linux/vserver/dlimit_cmd.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/dlimit_cmd.h
13623 --- linux-2.6.22.15/include/linux/vserver/dlimit_cmd.h  1969-12-31 19:00:00.000000000 -0500
13624 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/dlimit_cmd.h     2007-12-09 06:44:22.000000000 -0500
13625 @@ -0,0 +1,74 @@
13626 +#ifndef _VX_DLIMIT_CMD_H
13627 +#define _VX_DLIMIT_CMD_H
13628 +
13629 +
13630 +/*  dlimit vserver commands */
13631 +
13632 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
13633 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
13634 +
13635 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
13636 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
13637 +
13638 +struct vcmd_ctx_dlimit_base_v0 {
13639 +       const char __user *name;
13640 +       uint32_t flags;
13641 +};
13642 +
13643 +struct vcmd_ctx_dlimit_v0 {
13644 +       const char __user *name;
13645 +       uint32_t space_used;                    /* used space in kbytes */
13646 +       uint32_t space_total;                   /* maximum space in kbytes */
13647 +       uint32_t inodes_used;                   /* used inodes */
13648 +       uint32_t inodes_total;                  /* maximum inodes */
13649 +       uint32_t reserved;                      /* reserved for root in % */
13650 +       uint32_t flags;
13651 +};
13652 +
13653 +#define CDLIM_UNSET            ((uint32_t)0UL)
13654 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
13655 +#define CDLIM_KEEP             ((uint32_t)~1UL)
13656 +
13657 +#ifdef __KERNEL__
13658 +
13659 +#ifdef CONFIG_COMPAT
13660 +
13661 +#include <asm/compat.h>
13662 +
13663 +struct vcmd_ctx_dlimit_base_v0_x32 {
13664 +       compat_uptr_t name_ptr;
13665 +       uint32_t flags;
13666 +};
13667 +
13668 +struct vcmd_ctx_dlimit_v0_x32 {
13669 +       compat_uptr_t name_ptr;
13670 +       uint32_t space_used;                    /* used space in kbytes */
13671 +       uint32_t space_total;                   /* maximum space in kbytes */
13672 +       uint32_t inodes_used;                   /* used inodes */
13673 +       uint32_t inodes_total;                  /* maximum inodes */
13674 +       uint32_t reserved;                      /* reserved for root in % */
13675 +       uint32_t flags;
13676 +};
13677 +
13678 +#endif /* CONFIG_COMPAT */
13679 +
13680 +#include <linux/compiler.h>
13681 +
13682 +extern int vc_add_dlimit(uint32_t, void __user *);
13683 +extern int vc_rem_dlimit(uint32_t, void __user *);
13684 +
13685 +extern int vc_set_dlimit(uint32_t, void __user *);
13686 +extern int vc_get_dlimit(uint32_t, void __user *);
13687 +
13688 +#ifdef CONFIG_COMPAT
13689 +
13690 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
13691 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
13692 +
13693 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
13694 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
13695 +
13696 +#endif /* CONFIG_COMPAT */
13697 +
13698 +#endif /* __KERNEL__ */
13699 +#endif /* _VX_DLIMIT_CMD_H */
13700 diff -Nurp linux-2.6.22.15/include/linux/vserver/dlimit.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/dlimit.h
13701 --- linux-2.6.22.15/include/linux/vserver/dlimit.h      1969-12-31 19:00:00.000000000 -0500
13702 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/dlimit.h 2007-12-09 06:44:22.000000000 -0500
13703 @@ -0,0 +1,54 @@
13704 +#ifndef _VX_DLIMIT_H
13705 +#define _VX_DLIMIT_H
13706 +
13707 +#include "switch.h"
13708 +
13709 +
13710 +#ifdef __KERNEL__
13711 +
13712 +/*      keep in sync with CDLIM_INFINITY       */
13713 +
13714 +#define DLIM_INFINITY          (~0ULL)
13715 +
13716 +#include <linux/spinlock.h>
13717 +#include <linux/rcupdate.h>
13718 +
13719 +struct super_block;
13720 +
13721 +struct dl_info {
13722 +       struct hlist_node dl_hlist;             /* linked list of contexts */
13723 +       struct rcu_head dl_rcu;                 /* the rcu head */
13724 +       tag_t dl_tag;                           /* context tag */
13725 +       atomic_t dl_usecnt;                     /* usage count */
13726 +       atomic_t dl_refcnt;                     /* reference count */
13727 +
13728 +       struct super_block *dl_sb;              /* associated superblock */
13729 +
13730 +       spinlock_t dl_lock;                     /* protect the values */
13731 +
13732 +       unsigned long long dl_space_used;       /* used space in bytes */
13733 +       unsigned long long dl_space_total;      /* maximum space in bytes */
13734 +       unsigned long dl_inodes_used;           /* used inodes */
13735 +       unsigned long dl_inodes_total;          /* maximum inodes */
13736 +
13737 +       unsigned int dl_nrlmult;                /* non root limit mult */
13738 +};
13739 +
13740 +struct rcu_head;
13741 +
13742 +extern void rcu_free_dl_info(struct rcu_head *);
13743 +extern void unhash_dl_info(struct dl_info *);
13744 +
13745 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
13746 +
13747 +
13748 +struct kstatfs;
13749 +
13750 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
13751 +
13752 +typedef uint64_t dlsize_t;
13753 +
13754 +#endif /* __KERNEL__ */
13755 +#else  /* _VX_DLIMIT_H */
13756 +#warning duplicate inclusion
13757 +#endif /* _VX_DLIMIT_H */
13758 diff -Nurp linux-2.6.22.15/include/linux/vserver/global.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/global.h
13759 --- linux-2.6.22.15/include/linux/vserver/global.h      1969-12-31 19:00:00.000000000 -0500
13760 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/global.h 2007-12-09 06:44:22.000000000 -0500
13761 @@ -0,0 +1,18 @@
13762 +#ifndef _VX_GLOBAL_H
13763 +#define _VX_GLOBAL_H
13764 +
13765 +
13766 +extern atomic_t vx_global_ctotal;
13767 +extern atomic_t vx_global_cactive;
13768 +
13769 +extern atomic_t nx_global_ctotal;
13770 +extern atomic_t nx_global_cactive;
13771 +
13772 +extern atomic_t vs_global_nsproxy;
13773 +extern atomic_t vs_global_fs;
13774 +extern atomic_t vs_global_mnt_ns;
13775 +extern atomic_t vs_global_uts_ns;
13776 +extern atomic_t vs_global_ipc_ns;
13777 +
13778 +
13779 +#endif /* _VX_GLOBAL_H */
13780 diff -Nurp linux-2.6.22.15/include/linux/vserver/history.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/history.h
13781 --- linux-2.6.22.15/include/linux/vserver/history.h     1969-12-31 19:00:00.000000000 -0500
13782 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/history.h        2007-12-09 06:44:22.000000000 -0500
13783 @@ -0,0 +1,197 @@
13784 +#ifndef _VX_HISTORY_H
13785 +#define _VX_HISTORY_H
13786 +
13787 +
13788 +enum {
13789 +       VXH_UNUSED = 0,
13790 +       VXH_THROW_OOPS = 1,
13791 +
13792 +       VXH_GET_VX_INFO,
13793 +       VXH_PUT_VX_INFO,
13794 +       VXH_INIT_VX_INFO,
13795 +       VXH_SET_VX_INFO,
13796 +       VXH_CLR_VX_INFO,
13797 +       VXH_CLAIM_VX_INFO,
13798 +       VXH_RELEASE_VX_INFO,
13799 +       VXH_ALLOC_VX_INFO,
13800 +       VXH_DEALLOC_VX_INFO,
13801 +       VXH_HASH_VX_INFO,
13802 +       VXH_UNHASH_VX_INFO,
13803 +       VXH_LOC_VX_INFO,
13804 +       VXH_LOOKUP_VX_INFO,
13805 +       VXH_CREATE_VX_INFO,
13806 +};
13807 +
13808 +struct _vxhe_vxi {
13809 +       struct vx_info *ptr;
13810 +       unsigned xid;
13811 +       unsigned usecnt;
13812 +       unsigned tasks;
13813 +};
13814 +
13815 +struct _vxhe_set_clr {
13816 +       void *data;
13817 +};
13818 +
13819 +struct _vxhe_loc_lookup {
13820 +       unsigned arg;
13821 +};
13822 +
13823 +struct _vx_hist_entry {
13824 +       void *loc;
13825 +       unsigned short seq;
13826 +       unsigned short type;
13827 +       struct _vxhe_vxi vxi;
13828 +       union {
13829 +               struct _vxhe_set_clr sc;
13830 +               struct _vxhe_loc_lookup ll;
13831 +       };
13832 +};
13833 +
13834 +#ifdef CONFIG_VSERVER_HISTORY
13835 +
13836 +extern unsigned volatile int vxh_active;
13837 +
13838 +struct _vx_hist_entry *vxh_advance(void *loc);
13839 +
13840 +
13841 +static inline
13842 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
13843 +{
13844 +       entry->vxi.ptr = vxi;
13845 +       if (vxi) {
13846 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
13847 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
13848 +               entry->vxi.xid = vxi->vx_id;
13849 +       }
13850 +}
13851 +
13852 +
13853 +#define        __HERE__ current_text_addr()
13854 +
13855 +#define __VXH_BODY(__type, __data, __here)     \
13856 +       struct _vx_hist_entry *entry;           \
13857 +                                               \
13858 +       preempt_disable();                      \
13859 +       entry = vxh_advance(__here);            \
13860 +       __data;                                 \
13861 +       entry->type = __type;                   \
13862 +       preempt_enable();
13863 +
13864 +
13865 +       /* pass vxi only */
13866 +
13867 +#define __VXH_SMPL                             \
13868 +       __vxh_copy_vxi(entry, vxi)
13869 +
13870 +static inline
13871 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
13872 +{
13873 +       __VXH_BODY(__type, __VXH_SMPL, __here)
13874 +}
13875 +
13876 +       /* pass vxi and data (void *) */
13877 +
13878 +#define __VXH_DATA                             \
13879 +       __vxh_copy_vxi(entry, vxi);             \
13880 +       entry->sc.data = data
13881 +
13882 +static inline
13883 +void   __vxh_data(struct vx_info *vxi, void *data,
13884 +                       int __type, void *__here)
13885 +{
13886 +       __VXH_BODY(__type, __VXH_DATA, __here)
13887 +}
13888 +
13889 +       /* pass vxi and arg (long) */
13890 +
13891 +#define __VXH_LONG                             \
13892 +       __vxh_copy_vxi(entry, vxi);             \
13893 +       entry->ll.arg = arg
13894 +
13895 +static inline
13896 +void   __vxh_long(struct vx_info *vxi, long arg,
13897 +                       int __type, void *__here)
13898 +{
13899 +       __VXH_BODY(__type, __VXH_LONG, __here)
13900 +}
13901 +
13902 +
13903 +static inline
13904 +void   __vxh_throw_oops(void *__here)
13905 +{
13906 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
13907 +       /* prevent further acquisition */
13908 +       vxh_active = 0;
13909 +}
13910 +
13911 +
13912 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
13913 +
13914 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
13915 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
13916 +
13917 +#define __vxh_init_vx_info(v, d, h) \
13918 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
13919 +#define __vxh_set_vx_info(v, d, h) \
13920 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
13921 +#define __vxh_clr_vx_info(v, d, h) \
13922 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
13923 +
13924 +#define __vxh_claim_vx_info(v, d, h) \
13925 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
13926 +#define __vxh_release_vx_info(v, d, h) \
13927 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
13928 +
13929 +#define vxh_alloc_vx_info(v) \
13930 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
13931 +#define vxh_dealloc_vx_info(v) \
13932 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
13933 +
13934 +#define vxh_hash_vx_info(v) \
13935 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
13936 +#define vxh_unhash_vx_info(v) \
13937 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
13938 +
13939 +#define vxh_loc_vx_info(v, l) \
13940 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
13941 +#define vxh_lookup_vx_info(v, l) \
13942 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
13943 +#define vxh_create_vx_info(v, l) \
13944 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
13945 +
13946 +extern void vxh_dump_history(void);
13947 +
13948 +
13949 +#else  /* CONFIG_VSERVER_HISTORY */
13950 +
13951 +#define        __HERE__        0
13952 +
13953 +#define vxh_throw_oops()               do { } while (0)
13954 +
13955 +#define __vxh_get_vx_info(v, h)                do { } while (0)
13956 +#define __vxh_put_vx_info(v, h)                do { } while (0)
13957 +
13958 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
13959 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
13960 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
13961 +
13962 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
13963 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
13964 +
13965 +#define vxh_alloc_vx_info(v)           do { } while (0)
13966 +#define vxh_dealloc_vx_info(v)         do { } while (0)
13967 +
13968 +#define vxh_hash_vx_info(v)            do { } while (0)
13969 +#define vxh_unhash_vx_info(v)          do { } while (0)
13970 +
13971 +#define vxh_loc_vx_info(v, l)          do { } while (0)
13972 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
13973 +#define vxh_create_vx_info(v, l)       do { } while (0)
13974 +
13975 +#define vxh_dump_history()             do { } while (0)
13976 +
13977 +
13978 +#endif /* CONFIG_VSERVER_HISTORY */
13979 +
13980 +#endif /* _VX_HISTORY_H */
13981 diff -Nurp linux-2.6.22.15/include/linux/vserver/inode_cmd.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/inode_cmd.h
13982 --- linux-2.6.22.15/include/linux/vserver/inode_cmd.h   1969-12-31 19:00:00.000000000 -0500
13983 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/inode_cmd.h      2007-12-09 06:44:22.000000000 -0500
13984 @@ -0,0 +1,59 @@
13985 +#ifndef _VX_INODE_CMD_H
13986 +#define _VX_INODE_CMD_H
13987 +
13988 +
13989 +/*  inode vserver commands */
13990 +
13991 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
13992 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
13993 +
13994 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
13995 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
13996 +
13997 +struct vcmd_ctx_iattr_v1 {
13998 +       const char __user *name;
13999 +       uint32_t tag;
14000 +       uint32_t flags;
14001 +       uint32_t mask;
14002 +};
14003 +
14004 +struct vcmd_ctx_fiattr_v0 {
14005 +       uint32_t tag;
14006 +       uint32_t flags;
14007 +       uint32_t mask;
14008 +};
14009 +
14010 +
14011 +#ifdef __KERNEL__
14012 +
14013 +
14014 +#ifdef CONFIG_COMPAT
14015 +
14016 +#include <asm/compat.h>
14017 +
14018 +struct vcmd_ctx_iattr_v1_x32 {
14019 +       compat_uptr_t name_ptr;
14020 +       uint32_t tag;
14021 +       uint32_t flags;
14022 +       uint32_t mask;
14023 +};
14024 +
14025 +#endif /* CONFIG_COMPAT */
14026 +
14027 +#include <linux/compiler.h>
14028 +
14029 +extern int vc_get_iattr(void __user *);
14030 +extern int vc_set_iattr(void __user *);
14031 +
14032 +extern int vc_fget_iattr(uint32_t, void __user *);
14033 +extern int vc_fset_iattr(uint32_t, void __user *);
14034 +
14035 +#ifdef CONFIG_COMPAT
14036 +
14037 +extern int vc_get_iattr_x32(void __user *);
14038 +extern int vc_set_iattr_x32(void __user *);
14039 +
14040 +#endif /* CONFIG_COMPAT */
14041 +
14042 +#endif /* __KERNEL__ */
14043 +#endif /* _VX_INODE_CMD_H */
14044 diff -Nurp linux-2.6.22.15/include/linux/vserver/inode.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/inode.h
14045 --- linux-2.6.22.15/include/linux/vserver/inode.h       1969-12-31 19:00:00.000000000 -0500
14046 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/inode.h  2007-12-09 06:44:22.000000000 -0500
14047 @@ -0,0 +1,38 @@
14048 +#ifndef _VX_INODE_H
14049 +#define _VX_INODE_H
14050 +
14051 +
14052 +#define IATTR_TAG      0x01000000
14053 +
14054 +#define IATTR_ADMIN    0x00000001
14055 +#define IATTR_WATCH    0x00000002
14056 +#define IATTR_HIDE     0x00000004
14057 +#define IATTR_FLAGS    0x00000007
14058 +
14059 +#define IATTR_BARRIER  0x00010000
14060 +#define IATTR_IUNLINK  0x00020000
14061 +#define IATTR_IMMUTABLE 0x00040000
14062 +
14063 +#ifdef __KERNEL__
14064 +
14065 +
14066 +#ifdef CONFIG_VSERVER_PROC_SECURE
14067 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
14068 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
14069 +#else
14070 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
14071 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
14072 +#endif
14073 +
14074 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
14075 +
14076 +#endif /* __KERNEL__ */
14077 +
14078 +/* inode ioctls */
14079 +
14080 +#define FIOC_GETXFLG   _IOR('x', 5, long)
14081 +#define FIOC_SETXFLG   _IOW('x', 6, long)
14082 +
14083 +#else  /* _VX_INODE_H */
14084 +#warning duplicate inclusion
14085 +#endif /* _VX_INODE_H */
14086 diff -Nurp linux-2.6.22.15/include/linux/vserver/Kbuild linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/Kbuild
14087 --- linux-2.6.22.15/include/linux/vserver/Kbuild        1969-12-31 19:00:00.000000000 -0500
14088 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/Kbuild   2007-12-09 06:44:22.000000000 -0500
14089 @@ -0,0 +1,8 @@
14090 +
14091 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
14092 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
14093 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
14094 +       debug_cmd.h device_cmd.h
14095 +
14096 +unifdef-y += switch.h network.h monitor.h inode.h device.h
14097 +
14098 diff -Nurp linux-2.6.22.15/include/linux/vserver/limit_cmd.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/limit_cmd.h
14099 --- linux-2.6.22.15/include/linux/vserver/limit_cmd.h   1969-12-31 19:00:00.000000000 -0500
14100 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/limit_cmd.h      2007-12-09 06:44:22.000000000 -0500
14101 @@ -0,0 +1,69 @@
14102 +#ifndef _VX_LIMIT_CMD_H
14103 +#define _VX_LIMIT_CMD_H
14104 +
14105 +
14106 +/*  rlimit vserver commands */
14107 +
14108 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
14109 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
14110 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
14111 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
14112 +
14113 +struct vcmd_ctx_rlimit_v0 {
14114 +       uint32_t id;
14115 +       uint64_t minimum;
14116 +       uint64_t softlimit;
14117 +       uint64_t maximum;
14118 +};
14119 +
14120 +struct vcmd_ctx_rlimit_mask_v0 {
14121 +       uint32_t minimum;
14122 +       uint32_t softlimit;
14123 +       uint32_t maximum;
14124 +};
14125 +
14126 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
14127 +
14128 +struct vcmd_rlimit_stat_v0 {
14129 +       uint32_t id;
14130 +       uint32_t hits;
14131 +       uint64_t value;
14132 +       uint64_t minimum;
14133 +       uint64_t maximum;
14134 +};
14135 +
14136 +#define CRLIM_UNSET            (0ULL)
14137 +#define CRLIM_INFINITY         (~0ULL)
14138 +#define CRLIM_KEEP             (~1ULL)
14139 +
14140 +#ifdef __KERNEL__
14141 +
14142 +#ifdef CONFIG_IA32_EMULATION
14143 +
14144 +struct vcmd_ctx_rlimit_v0_x32 {
14145 +       uint32_t id;
14146 +       uint64_t minimum;
14147 +       uint64_t softlimit;
14148 +       uint64_t maximum;
14149 +} __attribute__ ((aligned (4)));
14150 +
14151 +#endif /* CONFIG_IA32_EMULATION */
14152 +
14153 +#include <linux/compiler.h>
14154 +
14155 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
14156 +extern int vc_get_rlimit(struct vx_info *, void __user *);
14157 +extern int vc_set_rlimit(struct vx_info *, void __user *);
14158 +extern int vc_reset_minmax(struct vx_info *, void __user *);
14159 +
14160 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
14161 +
14162 +#ifdef CONFIG_IA32_EMULATION
14163 +
14164 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
14165 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
14166 +
14167 +#endif /* CONFIG_IA32_EMULATION */
14168 +
14169 +#endif /* __KERNEL__ */
14170 +#endif /* _VX_LIMIT_CMD_H */
14171 diff -Nurp linux-2.6.22.15/include/linux/vserver/limit_def.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/limit_def.h
14172 --- linux-2.6.22.15/include/linux/vserver/limit_def.h   1969-12-31 19:00:00.000000000 -0500
14173 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/limit_def.h      2007-12-09 06:44:22.000000000 -0500
14174 @@ -0,0 +1,47 @@
14175 +#ifndef _VX_LIMIT_DEF_H
14176 +#define _VX_LIMIT_DEF_H
14177 +
14178 +#include <asm/atomic.h>
14179 +#include <asm/resource.h>
14180 +
14181 +#include "limit.h"
14182 +
14183 +
14184 +struct _vx_res_limit {
14185 +       rlim_t soft;            /* Context soft limit */
14186 +       rlim_t hard;            /* Context hard limit */
14187 +
14188 +       rlim_atomic_t rcur;     /* Current value */
14189 +       rlim_t rmin;            /* Context minimum */
14190 +       rlim_t rmax;            /* Context maximum */
14191 +
14192 +       atomic_t lhit;          /* Limit hits */
14193 +};
14194 +
14195 +/* context sub struct */
14196 +
14197 +struct _vx_limit {
14198 +       struct _vx_res_limit res[NUM_LIMITS];
14199 +};
14200 +
14201 +#ifdef CONFIG_VSERVER_DEBUG
14202 +
14203 +static inline void __dump_vx_limit(struct _vx_limit *limit)
14204 +{
14205 +       int i;
14206 +
14207 +       printk("\t_vx_limit:");
14208 +       for (i = 0; i < NUM_LIMITS; i++) {
14209 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
14210 +                       i, (unsigned long)__rlim_get(limit, i),
14211 +                       (unsigned long)__rlim_rmin(limit, i),
14212 +                       (unsigned long)__rlim_rmax(limit, i),
14213 +                       (long)__rlim_soft(limit, i),
14214 +                       (long)__rlim_hard(limit, i),
14215 +                       atomic_read(&__rlim_lhit(limit, i)));
14216 +       }
14217 +}
14218 +
14219 +#endif
14220 +
14221 +#endif /* _VX_LIMIT_DEF_H */
14222 diff -Nurp linux-2.6.22.15/include/linux/vserver/limit.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/limit.h
14223 --- linux-2.6.22.15/include/linux/vserver/limit.h       1969-12-31 19:00:00.000000000 -0500
14224 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/limit.h  2007-12-09 06:44:22.000000000 -0500
14225 @@ -0,0 +1,70 @@
14226 +#ifndef _VX_LIMIT_H
14227 +#define _VX_LIMIT_H
14228 +
14229 +#define VLIMIT_NSOCK   16
14230 +#define VLIMIT_OPENFD  17
14231 +#define VLIMIT_ANON    18
14232 +#define VLIMIT_SHMEM   19
14233 +#define VLIMIT_SEMARY  20
14234 +#define VLIMIT_NSEMS   21
14235 +#define VLIMIT_DENTRY  22
14236 +#define VLIMIT_MAPPED  23
14237 +
14238 +
14239 +#ifdef __KERNEL__
14240 +
14241 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
14242 +
14243 +/*     keep in sync with CRLIM_INFINITY */
14244 +
14245 +#define        VLIM_INFINITY   (~0ULL)
14246 +
14247 +#include <asm/atomic.h>
14248 +#include <asm/resource.h>
14249 +
14250 +#ifndef RLIM_INFINITY
14251 +#warning RLIM_INFINITY is undefined
14252 +#endif
14253 +
14254 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
14255 +
14256 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
14257 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
14258 +
14259 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
14260 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
14261 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
14262 +
14263 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
14264 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
14265 +
14266 +typedef atomic_long_t rlim_atomic_t;
14267 +typedef unsigned long rlim_t;
14268 +
14269 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
14270 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
14271 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
14272 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
14273 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
14274 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
14275 +
14276 +
14277 +#if    (RLIM_INFINITY == VLIM_INFINITY)
14278 +#define        VX_VLIM(r) ((long long)(long)(r))
14279 +#define        VX_RLIM(v) ((rlim_t)(v))
14280 +#else
14281 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
14282 +               ? VLIM_INFINITY : (long long)(r))
14283 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
14284 +               ? RLIM_INFINITY : (rlim_t)(v))
14285 +#endif
14286 +
14287 +struct sysinfo;
14288 +
14289 +void vx_vsi_meminfo(struct sysinfo *);
14290 +void vx_vsi_swapinfo(struct sysinfo *);
14291 +
14292 +#define NUM_LIMITS     24
14293 +
14294 +#endif /* __KERNEL__ */
14295 +#endif /* _VX_LIMIT_H */
14296 diff -Nurp linux-2.6.22.15/include/linux/vserver/limit_int.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/limit_int.h
14297 --- linux-2.6.22.15/include/linux/vserver/limit_int.h   1969-12-31 19:00:00.000000000 -0500
14298 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/limit_int.h      2007-12-09 06:44:22.000000000 -0500
14299 @@ -0,0 +1,198 @@
14300 +#ifndef _VX_LIMIT_INT_H
14301 +#define _VX_LIMIT_INT_H
14302 +
14303 +#include "context.h"
14304 +
14305 +#ifdef __KERNEL__
14306 +
14307 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
14308 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
14309 +
14310 +extern const char *vlimit_name[NUM_LIMITS];
14311 +
14312 +static inline void __vx_acc_cres(struct vx_info *vxi,
14313 +       int res, int dir, void *_data, char *_file, int _line)
14314 +{
14315 +       if (VXD_RCRES_COND(res))
14316 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
14317 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
14318 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
14319 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
14320 +       if (!vxi)
14321 +               return;
14322 +
14323 +       if (dir > 0)
14324 +               __rlim_inc(&vxi->limit, res);
14325 +       else
14326 +               __rlim_dec(&vxi->limit, res);
14327 +}
14328 +
14329 +static inline void __vx_add_cres(struct vx_info *vxi,
14330 +       int res, int amount, void *_data, char *_file, int _line)
14331 +{
14332 +       if (VXD_RCRES_COND(res))
14333 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
14334 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
14335 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
14336 +                       amount, _data, _file, _line);
14337 +       if (amount == 0)
14338 +               return;
14339 +       if (!vxi)
14340 +               return;
14341 +       __rlim_add(&vxi->limit, res, amount);
14342 +}
14343 +
14344 +static inline
14345 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
14346 +{
14347 +       int cond = (value > __rlim_rmax(limit, res));
14348 +
14349 +       if (cond)
14350 +               __rlim_rmax(limit, res) = value;
14351 +       return cond;
14352 +}
14353 +
14354 +static inline
14355 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
14356 +{
14357 +       int cond = (value < __rlim_rmin(limit, res));
14358 +
14359 +       if (cond)
14360 +               __rlim_rmin(limit, res) = value;
14361 +       return cond;
14362 +}
14363 +
14364 +static inline
14365 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
14366 +{
14367 +       if (!__vx_cres_adjust_max(limit, res, value))
14368 +               __vx_cres_adjust_min(limit, res, value);
14369 +}
14370 +
14371 +
14372 +/*     return values:
14373 +        +1 ... no limit hit
14374 +        -1 ... over soft limit
14375 +         0 ... over hard limit         */
14376 +
14377 +static inline int __vx_cres_avail(struct vx_info *vxi,
14378 +       int res, int num, char *_file, int _line)
14379 +{
14380 +       struct _vx_limit *limit;
14381 +       rlim_t value;
14382 +
14383 +       if (VXD_RLIMIT_COND(res))
14384 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
14385 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
14386 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
14387 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
14388 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
14389 +                       num, _file, _line);
14390 +       if (!vxi)
14391 +               return 1;
14392 +
14393 +       limit = &vxi->limit;
14394 +       value = __rlim_get(limit, res);
14395 +
14396 +       if (!__vx_cres_adjust_max(limit, res, value))
14397 +               __vx_cres_adjust_min(limit, res, value);
14398 +
14399 +       if (num == 0)
14400 +               return 1;
14401 +
14402 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
14403 +               return -1;
14404 +       if (value + num <= __rlim_soft(limit, res))
14405 +               return -1;
14406 +
14407 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
14408 +               return 1;
14409 +       if (value + num <= __rlim_hard(limit, res))
14410 +               return 1;
14411 +
14412 +       __rlim_hit(limit, res);
14413 +       return 0;
14414 +}
14415 +
14416 +
14417 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
14418 +
14419 +static inline
14420 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
14421 +{
14422 +       rlim_t value, sum = 0;
14423 +       int res;
14424 +
14425 +       while ((res = *array++)) {
14426 +               value = __rlim_get(limit, res);
14427 +               __vx_cres_fixup(limit, res, value);
14428 +               sum += value;
14429 +       }
14430 +       return sum;
14431 +}
14432 +
14433 +static inline
14434 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
14435 +{
14436 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
14437 +       int res = *array;
14438 +
14439 +       if (value == __rlim_get(limit, res))
14440 +               return value;
14441 +
14442 +       __rlim_set(limit, res, value);
14443 +       /* now adjust min/max */
14444 +       if (!__vx_cres_adjust_max(limit, res, value))
14445 +               __vx_cres_adjust_min(limit, res, value);
14446 +
14447 +       return value;
14448 +}
14449 +
14450 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
14451 +       const int *array, int num, char *_file, int _line)
14452 +{
14453 +       struct _vx_limit *limit;
14454 +       rlim_t value = 0;
14455 +       int res;
14456 +
14457 +       if (num == 0)
14458 +               return 1;
14459 +       if (!vxi)
14460 +               return 1;
14461 +
14462 +       limit = &vxi->limit;
14463 +       res = *array;
14464 +       value = __vx_cres_array_sum(limit, array + 1);
14465 +
14466 +       __rlim_set(limit, res, value);
14467 +       __vx_cres_fixup(limit, res, value);
14468 +
14469 +       return __vx_cres_avail(vxi, res, num, _file, _line);
14470 +}
14471 +
14472 +
14473 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
14474 +{
14475 +       rlim_t value;
14476 +       int res;
14477 +
14478 +       /* complex resources first */
14479 +       if ((id < 0) || (id == RLIMIT_RSS))
14480 +               __vx_cres_array_fixup(limit, VLA_RSS);
14481 +
14482 +       for (res = 0; res < NUM_LIMITS; res++) {
14483 +               if ((id > 0) && (res != id))
14484 +                       continue;
14485 +
14486 +               value = __rlim_get(limit, res);
14487 +               __vx_cres_fixup(limit, res, value);
14488 +
14489 +               /* not supposed to happen, maybe warn? */
14490 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
14491 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
14492 +       }
14493 +}
14494 +
14495 +
14496 +#endif /* __KERNEL__ */
14497 +#endif /* _VX_LIMIT_INT_H */
14498 diff -Nurp linux-2.6.22.15/include/linux/vserver/monitor.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/monitor.h
14499 --- linux-2.6.22.15/include/linux/vserver/monitor.h     1969-12-31 19:00:00.000000000 -0500
14500 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/monitor.h        2007-12-09 06:44:22.000000000 -0500
14501 @@ -0,0 +1,96 @@
14502 +#ifndef _VX_MONITOR_H
14503 +#define _VX_MONITOR_H
14504 +
14505 +#include <linux/types.h>
14506 +
14507 +enum {
14508 +       VXM_UNUSED = 0,
14509 +
14510 +       VXM_SYNC = 0x10,
14511 +
14512 +       VXM_UPDATE = 0x20,
14513 +       VXM_UPDATE_1,
14514 +       VXM_UPDATE_2,
14515 +
14516 +       VXM_RQINFO_1 = 0x24,
14517 +       VXM_RQINFO_2,
14518 +
14519 +       VXM_ACTIVATE = 0x40,
14520 +       VXM_DEACTIVATE,
14521 +       VXM_IDLE,
14522 +
14523 +       VXM_HOLD = 0x44,
14524 +       VXM_UNHOLD,
14525 +
14526 +       VXM_MIGRATE = 0x48,
14527 +       VXM_RESCHED,
14528 +
14529 +       /* all other bits are flags */
14530 +       VXM_SCHED = 0x80,
14531 +};
14532 +
14533 +struct _vxm_update_1 {
14534 +       uint32_t tokens_max;
14535 +       uint32_t fill_rate;
14536 +       uint32_t interval;
14537 +};
14538 +
14539 +struct _vxm_update_2 {
14540 +       uint32_t tokens_min;
14541 +       uint32_t fill_rate;
14542 +       uint32_t interval;
14543 +};
14544 +
14545 +struct _vxm_rqinfo_1 {
14546 +       uint16_t running;
14547 +       uint16_t onhold;
14548 +       uint16_t iowait;
14549 +       uint16_t uintr;
14550 +       uint32_t idle_tokens;
14551 +};
14552 +
14553 +struct _vxm_rqinfo_2 {
14554 +       uint32_t norm_time;
14555 +       uint32_t idle_time;
14556 +       uint32_t idle_skip;
14557 +};
14558 +
14559 +struct _vxm_sched {
14560 +       uint32_t tokens;
14561 +       uint32_t norm_time;
14562 +       uint32_t idle_time;
14563 +};
14564 +
14565 +struct _vxm_task {
14566 +       uint16_t pid;
14567 +       uint16_t state;
14568 +};
14569 +
14570 +struct _vxm_event {
14571 +       uint32_t jif;
14572 +       union {
14573 +               uint32_t seq;
14574 +               uint32_t sec;
14575 +       };
14576 +       union {
14577 +               uint32_t tokens;
14578 +               uint32_t nsec;
14579 +               struct _vxm_task tsk;
14580 +       };
14581 +};
14582 +
14583 +struct _vx_mon_entry {
14584 +       uint16_t type;
14585 +       uint16_t xid;
14586 +       union {
14587 +               struct _vxm_event ev;
14588 +               struct _vxm_sched sd;
14589 +               struct _vxm_update_1 u1;
14590 +               struct _vxm_update_2 u2;
14591 +               struct _vxm_rqinfo_1 q1;
14592 +               struct _vxm_rqinfo_2 q2;
14593 +       };
14594 +};
14595 +
14596 +
14597 +#endif /* _VX_MONITOR_H */
14598 diff -Nurp linux-2.6.22.15/include/linux/vserver/network_cmd.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/network_cmd.h
14599 --- linux-2.6.22.15/include/linux/vserver/network_cmd.h 1969-12-31 19:00:00.000000000 -0500
14600 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/network_cmd.h    2007-12-09 06:44:22.000000000 -0500
14601 @@ -0,0 +1,150 @@
14602 +#ifndef _VX_NETWORK_CMD_H
14603 +#define _VX_NETWORK_CMD_H
14604 +
14605 +
14606 +/* vinfo commands */
14607 +
14608 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
14609 +
14610 +#ifdef __KERNEL__
14611 +extern int vc_task_nid(uint32_t);
14612 +
14613 +#endif /* __KERNEL__ */
14614 +
14615 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
14616 +
14617 +struct vcmd_nx_info_v0 {
14618 +       uint32_t nid;
14619 +       /* more to come */
14620 +};
14621 +
14622 +#ifdef __KERNEL__
14623 +extern int vc_nx_info(struct nx_info *, void __user *);
14624 +
14625 +#endif /* __KERNEL__ */
14626 +
14627 +#include <linux/in.h>
14628 +#include <linux/in6.h>
14629 +
14630 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
14631 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
14632 +
14633 +struct  vcmd_net_create {
14634 +       uint64_t flagword;
14635 +};
14636 +
14637 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
14638 +
14639 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
14640 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
14641 +
14642 +struct vcmd_net_addr_v0 {
14643 +       uint16_t type;
14644 +       uint16_t count;
14645 +       struct in_addr ip[4];
14646 +       struct in_addr mask[4];
14647 +};
14648 +
14649 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
14650 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
14651 +
14652 +struct vcmd_net_addr_ipv4_v1 {
14653 +       uint16_t type;
14654 +       uint16_t flags;
14655 +       struct in_addr ip;
14656 +       struct in_addr mask;
14657 +};
14658 +
14659 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
14660 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
14661 +
14662 +struct vcmd_net_addr_ipv6_v1 {
14663 +       uint16_t type;
14664 +       uint16_t flags;
14665 +       uint32_t prefix;
14666 +       struct in6_addr ip;
14667 +       struct in6_addr mask;
14668 +};
14669 +
14670 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
14671 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
14672 +
14673 +struct vcmd_match_ipv4_v0 {
14674 +       uint16_t type;
14675 +       uint16_t flags;
14676 +       uint16_t parent;
14677 +       uint16_t prefix;
14678 +       struct in_addr ip;
14679 +       struct in_addr ip2;
14680 +       struct in_addr mask;
14681 +};
14682 +
14683 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
14684 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
14685 +
14686 +struct vcmd_match_ipv6_v0 {
14687 +       uint16_t type;
14688 +       uint16_t flags;
14689 +       uint16_t parent;
14690 +       uint16_t prefix;
14691 +       struct in6_addr ip;
14692 +       struct in6_addr ip2;
14693 +       struct in6_addr mask;
14694 +};
14695 +
14696 +
14697 +#ifdef __KERNEL__
14698 +extern int vc_net_create(uint32_t, void __user *);
14699 +extern int vc_net_migrate(struct nx_info *, void __user *);
14700 +
14701 +extern int vc_net_add(struct nx_info *, void __user *);
14702 +extern int vc_net_remove(struct nx_info *, void __user *);
14703 +
14704 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
14705 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
14706 +
14707 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
14708 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
14709 +
14710 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
14711 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
14712 +
14713 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
14714 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
14715 +
14716 +#endif /* __KERNEL__ */
14717 +
14718 +
14719 +/* flag commands */
14720 +
14721 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
14722 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
14723 +
14724 +struct vcmd_net_flags_v0 {
14725 +       uint64_t flagword;
14726 +       uint64_t mask;
14727 +};
14728 +
14729 +#ifdef __KERNEL__
14730 +extern int vc_get_nflags(struct nx_info *, void __user *);
14731 +extern int vc_set_nflags(struct nx_info *, void __user *);
14732 +
14733 +#endif /* __KERNEL__ */
14734 +
14735 +
14736 +/* network caps commands */
14737 +
14738 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
14739 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
14740 +
14741 +struct vcmd_net_caps_v0 {
14742 +       uint64_t ncaps;
14743 +       uint64_t cmask;
14744 +};
14745 +
14746 +#ifdef __KERNEL__
14747 +extern int vc_get_ncaps(struct nx_info *, void __user *);
14748 +extern int vc_set_ncaps(struct nx_info *, void __user *);
14749 +
14750 +#endif /* __KERNEL__ */
14751 +#endif /* _VX_CONTEXT_CMD_H */
14752 diff -Nurp linux-2.6.22.15/include/linux/vserver/network.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/network.h
14753 --- linux-2.6.22.15/include/linux/vserver/network.h     1969-12-31 19:00:00.000000000 -0500
14754 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/network.h        2007-12-09 06:44:22.000000000 -0500
14755 @@ -0,0 +1,143 @@
14756 +#ifndef _VX_NETWORK_H
14757 +#define _VX_NETWORK_H
14758 +
14759 +#include <linux/types.h>
14760 +
14761 +
14762 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
14763 +
14764 +
14765 +/* network flags */
14766 +
14767 +#define NXF_INFO_PRIVATE       0x00000008
14768 +
14769 +#define NXF_SINGLE_IP          0x00000100
14770 +#define NXF_LBACK_REMAP                0x00000200
14771 +
14772 +#define NXF_HIDE_NETIF         0x02000000
14773 +#define NXF_HIDE_LBACK         0x04000000
14774 +
14775 +#define NXF_STATE_SETUP                (1ULL << 32)
14776 +#define NXF_STATE_ADMIN                (1ULL << 34)
14777 +
14778 +#define NXF_SC_HELPER          (1ULL << 36)
14779 +#define NXF_PERSISTENT         (1ULL << 38)
14780 +
14781 +#define NXF_ONE_TIME           (0x0005ULL << 32)
14782 +
14783 +
14784 +#define        NXF_INIT_SET            (__nxf_init_set())
14785 +
14786 +static inline uint64_t __nxf_init_set(void) {
14787 +       return    NXF_STATE_ADMIN
14788 +#ifdef CONFIG_VSERVER_AUTO_LBACK
14789 +               | NXF_LBACK_REMAP
14790 +               | NXF_HIDE_LBACK
14791 +#endif
14792 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
14793 +               | NXF_SINGLE_IP
14794 +#endif
14795 +               | NXF_HIDE_NETIF;
14796 +}
14797 +
14798 +
14799 +/* network caps */
14800 +
14801 +#define NXC_RAW_ICMP           0x00000100
14802 +
14803 +
14804 +/* address types */
14805 +
14806 +#define NXA_TYPE_IPV4          0x0001
14807 +#define NXA_TYPE_IPV6          0x0002
14808 +
14809 +#define NXA_TYPE_NONE          0x0000
14810 +#define NXA_TYPE_ANY           0x00FF
14811 +
14812 +#define NXA_TYPE_ADDR          0x0010
14813 +#define NXA_TYPE_MASK          0x0020
14814 +#define NXA_TYPE_RANGE         0x0040
14815 +
14816 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
14817 +
14818 +#define NXA_MOD_BCAST          0x0100
14819 +#define NXA_MOD_LBACK          0x0200
14820 +
14821 +#define NXA_LOOPBACK           0x1000
14822 +
14823 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
14824 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
14825 +
14826 +#ifdef __KERNEL__
14827 +
14828 +#include <linux/list.h>
14829 +#include <linux/spinlock.h>
14830 +#include <linux/rcupdate.h>
14831 +#include <linux/in.h>
14832 +#include <linux/in6.h>
14833 +#include <asm/atomic.h>
14834 +
14835 +struct nx_addr_v4 {
14836 +       struct nx_addr_v4 *next;
14837 +       struct in_addr ip[2];
14838 +       struct in_addr mask;
14839 +       uint16_t type;
14840 +       uint16_t flags;
14841 +};
14842 +
14843 +struct nx_addr_v6 {
14844 +       struct nx_addr_v6 *next;
14845 +       struct in6_addr ip;
14846 +       struct in6_addr mask;
14847 +       uint32_t prefix;
14848 +       uint16_t type;
14849 +       uint16_t flags;
14850 +};
14851 +
14852 +struct nx_info {
14853 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
14854 +       nid_t nx_id;                    /* vnet id */
14855 +       atomic_t nx_usecnt;             /* usage count */
14856 +       atomic_t nx_tasks;              /* tasks count */
14857 +       int nx_state;                   /* context state */
14858 +
14859 +       uint64_t nx_flags;              /* network flag word */
14860 +       uint64_t nx_ncaps;              /* network capabilities */
14861 +
14862 +       struct in_addr v4_lback;        /* Loopback address */
14863 +       struct in_addr v4_bcast;        /* Broadcast address */
14864 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
14865 +#ifdef CONFIG_IPV6
14866 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
14867 +#endif
14868 +       char nx_name[65];               /* network context name */
14869 +};
14870 +
14871 +
14872 +/* status flags */
14873 +
14874 +#define NXS_HASHED      0x0001
14875 +#define NXS_SHUTDOWN    0x0100
14876 +#define NXS_RELEASED    0x8000
14877 +
14878 +extern struct nx_info *lookup_nx_info(int);
14879 +
14880 +extern int get_nid_list(int, unsigned int *, int);
14881 +extern int nid_is_hashed(nid_t);
14882 +
14883 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
14884 +
14885 +extern long vs_net_change(struct nx_info *, unsigned int);
14886 +
14887 +struct sock;
14888 +
14889 +
14890 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
14891 +#ifdef  CONFIG_IPV6
14892 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
14893 +#else
14894 +#define NX_IPV6(n)     (0)
14895 +#endif
14896 +
14897 +#endif /* __KERNEL__ */
14898 +#endif /* _VX_NETWORK_H */
14899 diff -Nurp linux-2.6.22.15/include/linux/vserver/percpu.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/percpu.h
14900 --- linux-2.6.22.15/include/linux/vserver/percpu.h      1969-12-31 19:00:00.000000000 -0500
14901 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/percpu.h 2007-12-09 06:44:22.000000000 -0500
14902 @@ -0,0 +1,14 @@
14903 +#ifndef _VX_PERCPU_H
14904 +#define _VX_PERCPU_H
14905 +
14906 +#include "cvirt_def.h"
14907 +#include "sched_def.h"
14908 +
14909 +struct _vx_percpu {
14910 +       struct _vx_cvirt_pc cvirt;
14911 +       struct _vx_sched_pc sched;
14912 +};
14913 +
14914 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
14915 +
14916 +#endif /* _VX_PERCPU_H */
14917 diff -Nurp linux-2.6.22.15/include/linux/vserver/sched_cmd.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/sched_cmd.h
14918 --- linux-2.6.22.15/include/linux/vserver/sched_cmd.h   1969-12-31 19:00:00.000000000 -0500
14919 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/sched_cmd.h      2007-12-09 06:44:22.000000000 -0500
14920 @@ -0,0 +1,108 @@
14921 +#ifndef _VX_SCHED_CMD_H
14922 +#define _VX_SCHED_CMD_H
14923 +
14924 +
14925 +/*  sched vserver commands */
14926 +
14927 +#define VCMD_set_sched_v2      VC_CMD(SCHED, 1, 2)
14928 +#define VCMD_set_sched_v3      VC_CMD(SCHED, 1, 3)
14929 +#define VCMD_set_sched_v4      VC_CMD(SCHED, 1, 4)
14930 +
14931 +struct vcmd_set_sched_v2 {
14932 +       int32_t fill_rate;
14933 +       int32_t interval;
14934 +       int32_t tokens;
14935 +       int32_t tokens_min;
14936 +       int32_t tokens_max;
14937 +       uint64_t cpu_mask;
14938 +};
14939 +
14940 +struct vcmd_set_sched_v3 {
14941 +       uint32_t set_mask;
14942 +       int32_t fill_rate;
14943 +       int32_t interval;
14944 +       int32_t tokens;
14945 +       int32_t tokens_min;
14946 +       int32_t tokens_max;
14947 +       int32_t priority_bias;
14948 +};
14949 +
14950 +struct vcmd_set_sched_v4 {
14951 +       uint32_t set_mask;
14952 +       int32_t fill_rate;
14953 +       int32_t interval;
14954 +       int32_t tokens;
14955 +       int32_t tokens_min;
14956 +       int32_t tokens_max;
14957 +       int32_t prio_bias;
14958 +       int32_t cpu_id;
14959 +       int32_t bucket_id;
14960 +};
14961 +
14962 +#define VCMD_set_sched         VC_CMD(SCHED, 1, 5)
14963 +#define VCMD_get_sched         VC_CMD(SCHED, 2, 5)
14964 +
14965 +struct vcmd_sched_v5 {
14966 +       uint32_t mask;
14967 +       int32_t cpu_id;
14968 +       int32_t bucket_id;
14969 +       int32_t fill_rate[2];
14970 +       int32_t interval[2];
14971 +       int32_t tokens;
14972 +       int32_t tokens_min;
14973 +       int32_t tokens_max;
14974 +       int32_t prio_bias;
14975 +};
14976 +
14977 +#define VXSM_FILL_RATE         0x0001
14978 +#define VXSM_INTERVAL          0x0002
14979 +#define VXSM_FILL_RATE2                0x0004
14980 +#define VXSM_INTERVAL2         0x0008
14981 +#define VXSM_TOKENS            0x0010
14982 +#define VXSM_TOKENS_MIN                0x0020
14983 +#define VXSM_TOKENS_MAX                0x0040
14984 +#define VXSM_PRIO_BIAS         0x0100
14985 +
14986 +#define VXSM_IDLE_TIME         0x0200
14987 +#define VXSM_FORCE             0x0400
14988 +
14989 +#define        VXSM_V3_MASK            0x0173
14990 +#define        VXSM_SET_MASK           0x01FF
14991 +
14992 +#define VXSM_CPU_ID            0x1000
14993 +#define VXSM_BUCKET_ID         0x2000
14994 +
14995 +#define VXSM_MSEC              0x4000
14996 +
14997 +#define SCHED_KEEP             (-2)    /* only for v2 */
14998 +
14999 +#ifdef __KERNEL__
15000 +
15001 +#include <linux/compiler.h>
15002 +
15003 +extern int vc_set_sched_v2(struct vx_info *, void __user *);
15004 +extern int vc_set_sched_v3(struct vx_info *, void __user *);
15005 +extern int vc_set_sched_v4(struct vx_info *, void __user *);
15006 +extern int vc_set_sched(struct vx_info *, void __user *);
15007 +extern int vc_get_sched(struct vx_info *, void __user *);
15008 +
15009 +#endif /* __KERNEL__ */
15010 +
15011 +#define VCMD_sched_info                VC_CMD(SCHED, 3, 0)
15012 +
15013 +struct vcmd_sched_info {
15014 +       int32_t cpu_id;
15015 +       int32_t bucket_id;
15016 +       uint64_t user_msec;
15017 +       uint64_t sys_msec;
15018 +       uint64_t hold_msec;
15019 +       uint32_t token_usec;
15020 +       int32_t vavavoom;
15021 +};
15022 +
15023 +#ifdef __KERNEL__
15024 +
15025 +extern int vc_sched_info(struct vx_info *, void __user *);
15026 +
15027 +#endif /* __KERNEL__ */
15028 +#endif /* _VX_SCHED_CMD_H */
15029 diff -Nurp linux-2.6.22.15/include/linux/vserver/sched_def.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/sched_def.h
15030 --- linux-2.6.22.15/include/linux/vserver/sched_def.h   1969-12-31 19:00:00.000000000 -0500
15031 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/sched_def.h      2007-12-09 06:44:22.000000000 -0500
15032 @@ -0,0 +1,68 @@
15033 +#ifndef _VX_SCHED_DEF_H
15034 +#define _VX_SCHED_DEF_H
15035 +
15036 +#include <linux/spinlock.h>
15037 +#include <linux/jiffies.h>
15038 +#include <linux/cpumask.h>
15039 +#include <asm/atomic.h>
15040 +#include <asm/param.h>
15041 +
15042 +
15043 +/* context sub struct */
15044 +
15045 +struct _vx_sched {
15046 +       spinlock_t tokens_lock;         /* lock for token bucket */
15047 +
15048 +       int tokens;                     /* number of CPU tokens */
15049 +       int fill_rate[2];               /* Fill rate: add X tokens... */
15050 +       int interval[2];                /* Divisor:   per Y jiffies   */
15051 +       int tokens_min;                 /* Limit:     minimum for unhold */
15052 +       int tokens_max;                 /* Limit:     no more than N tokens */
15053 +
15054 +       int prio_bias;                  /* bias offset for priority */
15055 +
15056 +       unsigned update_mask;           /* which features should be updated */
15057 +       cpumask_t update;               /* CPUs which should update */
15058 +};
15059 +
15060 +struct _vx_sched_pc {
15061 +       int tokens;                     /* number of CPU tokens */
15062 +       int flags;                      /* bucket flags */
15063 +
15064 +       int fill_rate[2];               /* Fill rate: add X tokens... */
15065 +       int interval[2];                /* Divisor:   per Y jiffies   */
15066 +       int tokens_min;                 /* Limit:     minimum for unhold */
15067 +       int tokens_max;                 /* Limit:     no more than N tokens */
15068 +
15069 +       int prio_bias;                  /* bias offset for priority */
15070 +       int vavavoom;                   /* last calculated vavavoom */
15071 +
15072 +       unsigned long norm_time;        /* last time accounted */
15073 +       unsigned long idle_time;        /* non linear time for fair sched */
15074 +       unsigned long token_time;       /* token time for accounting */
15075 +       unsigned long onhold;           /* jiffies when put on hold */
15076 +
15077 +       uint64_t user_ticks;            /* token tick events */
15078 +       uint64_t sys_ticks;             /* token tick events */
15079 +       uint64_t hold_ticks;            /* token ticks paused */
15080 +};
15081 +
15082 +
15083 +#define VXSF_ONHOLD    0x0001
15084 +#define VXSF_IDLE_TIME 0x0100
15085 +
15086 +#ifdef CONFIG_VSERVER_DEBUG
15087 +
15088 +static inline void __dump_vx_sched(struct _vx_sched *sched)
15089 +{
15090 +       printk("\t_vx_sched:\n");
15091 +       printk("\t tokens: %4d/%4d, %4d/%4d, %4d, %4d\n",
15092 +               sched->fill_rate[0], sched->interval[0],
15093 +               sched->fill_rate[1], sched->interval[1],
15094 +               sched->tokens_min, sched->tokens_max);
15095 +       printk("\t priority = %4d\n", sched->prio_bias);
15096 +}
15097 +
15098 +#endif
15099 +
15100 +#endif /* _VX_SCHED_DEF_H */
15101 diff -Nurp linux-2.6.22.15/include/linux/vserver/sched.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/sched.h
15102 --- linux-2.6.22.15/include/linux/vserver/sched.h       1969-12-31 19:00:00.000000000 -0500
15103 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/sched.h  2007-12-09 06:44:22.000000000 -0500
15104 @@ -0,0 +1,26 @@
15105 +#ifndef _VX_SCHED_H
15106 +#define _VX_SCHED_H
15107 +
15108 +
15109 +#ifdef __KERNEL__
15110 +
15111 +struct timespec;
15112 +
15113 +void vx_vsi_uptime(struct timespec *, struct timespec *);
15114 +
15115 +
15116 +struct vx_info;
15117 +
15118 +void vx_update_load(struct vx_info *);
15119 +
15120 +
15121 +int vx_tokens_recalc(struct _vx_sched_pc *,
15122 +       unsigned long *, unsigned long *, int [2]);
15123 +
15124 +void vx_update_sched_param(struct _vx_sched *sched,
15125 +       struct _vx_sched_pc *sched_pc);
15126 +
15127 +#endif /* __KERNEL__ */
15128 +#else  /* _VX_SCHED_H */
15129 +#warning duplicate inclusion
15130 +#endif /* _VX_SCHED_H */
15131 diff -Nurp linux-2.6.22.15/include/linux/vserver/signal_cmd.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/signal_cmd.h
15132 --- linux-2.6.22.15/include/linux/vserver/signal_cmd.h  1969-12-31 19:00:00.000000000 -0500
15133 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/signal_cmd.h     2007-12-09 06:44:22.000000000 -0500
15134 @@ -0,0 +1,43 @@
15135 +#ifndef _VX_SIGNAL_CMD_H
15136 +#define _VX_SIGNAL_CMD_H
15137 +
15138 +
15139 +/*  signalling vserver commands */
15140 +
15141 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
15142 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
15143 +
15144 +struct vcmd_ctx_kill_v0 {
15145 +       int32_t pid;
15146 +       int32_t sig;
15147 +};
15148 +
15149 +struct vcmd_wait_exit_v0 {
15150 +       int32_t reboot_cmd;
15151 +       int32_t exit_code;
15152 +};
15153 +
15154 +#ifdef __KERNEL__
15155 +
15156 +extern int vc_ctx_kill(struct vx_info *, void __user *);
15157 +extern int vc_wait_exit(struct vx_info *, void __user *);
15158 +
15159 +#endif /* __KERNEL__ */
15160 +
15161 +/*  process alteration commands */
15162 +
15163 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
15164 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
15165 +
15166 +struct vcmd_pflags_v0 {
15167 +       uint32_t flagword;
15168 +       uint32_t mask;
15169 +};
15170 +
15171 +#ifdef __KERNEL__
15172 +
15173 +extern int vc_get_pflags(uint32_t pid, void __user *);
15174 +extern int vc_set_pflags(uint32_t pid, void __user *);
15175 +
15176 +#endif /* __KERNEL__ */
15177 +#endif /* _VX_SIGNAL_CMD_H */
15178 diff -Nurp linux-2.6.22.15/include/linux/vserver/signal.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/signal.h
15179 --- linux-2.6.22.15/include/linux/vserver/signal.h      1969-12-31 19:00:00.000000000 -0500
15180 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/signal.h 2007-12-09 06:44:22.000000000 -0500
15181 @@ -0,0 +1,14 @@
15182 +#ifndef _VX_SIGNAL_H
15183 +#define _VX_SIGNAL_H
15184 +
15185 +
15186 +#ifdef __KERNEL__
15187 +
15188 +struct vx_info;
15189 +
15190 +int vx_info_kill(struct vx_info *, int, int);
15191 +
15192 +#endif /* __KERNEL__ */
15193 +#else  /* _VX_SIGNAL_H */
15194 +#warning duplicate inclusion
15195 +#endif /* _VX_SIGNAL_H */
15196 diff -Nurp linux-2.6.22.15/include/linux/vserver/space_cmd.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/space_cmd.h
15197 --- linux-2.6.22.15/include/linux/vserver/space_cmd.h   1969-12-31 19:00:00.000000000 -0500
15198 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/space_cmd.h      2007-12-09 06:44:22.000000000 -0500
15199 @@ -0,0 +1,26 @@
15200 +#ifndef _VX_SPACE_CMD_H
15201 +#define _VX_SPACE_CMD_H
15202 +
15203 +
15204 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
15205 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 1)
15206 +
15207 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
15208 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 1)
15209 +
15210 +#define VCMD_get_space_mask    VC_CMD(PROCALT, 4, 0)
15211 +
15212 +
15213 +struct vcmd_space_mask {
15214 +       uint64_t mask;
15215 +};
15216 +
15217 +
15218 +#ifdef __KERNEL__
15219 +
15220 +extern int vc_enter_space(struct vx_info *, void __user *);
15221 +extern int vc_set_space(struct vx_info *, void __user *);
15222 +extern int vc_get_space_mask(struct vx_info *, void __user *);
15223 +
15224 +#endif /* __KERNEL__ */
15225 +#endif /* _VX_SPACE_CMD_H */
15226 diff -Nurp linux-2.6.22.15/include/linux/vserver/space.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/space.h
15227 --- linux-2.6.22.15/include/linux/vserver/space.h       1969-12-31 19:00:00.000000000 -0500
15228 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/space.h  2007-12-09 06:44:22.000000000 -0500
15229 @@ -0,0 +1,13 @@
15230 +#ifndef _VX_SPACE_H
15231 +#define _VX_SPACE_H
15232 +
15233 +
15234 +#include <linux/types.h>
15235 +
15236 +struct vx_info;
15237 +
15238 +int vx_set_space(struct vx_info *vxi, unsigned long mask);
15239 +
15240 +#else  /* _VX_SPACE_H */
15241 +#warning duplicate inclusion
15242 +#endif /* _VX_SPACE_H */
15243 diff -Nurp linux-2.6.22.15/include/linux/vserver/switch.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/switch.h
15244 --- linux-2.6.22.15/include/linux/vserver/switch.h      1969-12-31 19:00:00.000000000 -0500
15245 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/switch.h 2007-12-09 06:44:22.000000000 -0500
15246 @@ -0,0 +1,99 @@
15247 +#ifndef _VX_SWITCH_H
15248 +#define _VX_SWITCH_H
15249 +
15250 +#include <linux/types.h>
15251 +
15252 +
15253 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
15254 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
15255 +#define VC_VERSION(c)          ((c) & 0xFFF)
15256 +
15257 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
15258 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
15259 +
15260 +/*
15261 +
15262 +  Syscall Matrix V2.8
15263 +
15264 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
15265 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
15266 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
15267 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15268 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
15269 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
15270 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15271 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
15272 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
15273 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15274 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
15275 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
15276 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15277 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
15278 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
15279 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15280 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
15281 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
15282 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15283 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
15284 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
15285 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
15286 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |       |       |
15287 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
15288 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15289 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
15290 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
15291 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15292 +
15293 +*/
15294 +
15295 +#define VC_CAT_VERSION         0
15296 +
15297 +#define VC_CAT_VSETUP          1
15298 +#define VC_CAT_VHOST           2
15299 +
15300 +#define VC_CAT_DEVICE          6
15301 +
15302 +#define VC_CAT_VPROC           9
15303 +#define VC_CAT_PROCALT         10
15304 +#define VC_CAT_PROCMIG         11
15305 +#define VC_CAT_PROCTRL         12
15306 +
15307 +#define VC_CAT_SCHED           14
15308 +#define VC_CAT_MEMCTRL         20
15309 +
15310 +#define VC_CAT_VNET            25
15311 +#define VC_CAT_NETALT          26
15312 +#define VC_CAT_NETMIG          27
15313 +#define VC_CAT_NETCTRL         28
15314 +
15315 +#define VC_CAT_TAGMIG          35
15316 +#define VC_CAT_DLIMIT          36
15317 +#define VC_CAT_INODE           38
15318 +
15319 +#define VC_CAT_VSTAT           40
15320 +#define VC_CAT_VINFO           46
15321 +#define VC_CAT_EVENT           48
15322 +
15323 +#define VC_CAT_FLAGS           52
15324 +#define VC_CAT_DEBUG           56
15325 +#define VC_CAT_RLIMIT          60
15326 +
15327 +#define VC_CAT_SYSTEST         61
15328 +#define VC_CAT_COMPAT          63
15329 +
15330 +/*  query version */
15331 +
15332 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
15333 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
15334 +
15335 +
15336 +#ifdef __KERNEL__
15337 +
15338 +#include <linux/errno.h>
15339 +
15340 +
15341 +#else  /* __KERNEL__ */
15342 +#define __user
15343 +#endif /* __KERNEL__ */
15344 +
15345 +#endif /* _VX_SWITCH_H */
15346 diff -Nurp linux-2.6.22.15/include/linux/vserver/tag_cmd.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/tag_cmd.h
15347 --- linux-2.6.22.15/include/linux/vserver/tag_cmd.h     1969-12-31 19:00:00.000000000 -0500
15348 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/tag_cmd.h        2007-12-09 06:44:22.000000000 -0500
15349 @@ -0,0 +1,22 @@
15350 +#ifndef _VX_TAG_CMD_H
15351 +#define _VX_TAG_CMD_H
15352 +
15353 +
15354 +/* vinfo commands */
15355 +
15356 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
15357 +
15358 +#ifdef __KERNEL__
15359 +extern int vc_task_tag(uint32_t);
15360 +
15361 +#endif /* __KERNEL__ */
15362 +
15363 +/* context commands */
15364 +
15365 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
15366 +
15367 +#ifdef __KERNEL__
15368 +extern int vc_tag_migrate(uint32_t);
15369 +
15370 +#endif /* __KERNEL__ */
15371 +#endif /* _VX_TAG_CMD_H */
15372 diff -Nurp linux-2.6.22.15/include/linux/vserver/tag.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/tag.h
15373 --- linux-2.6.22.15/include/linux/vserver/tag.h 1969-12-31 19:00:00.000000000 -0500
15374 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vserver/tag.h    2007-12-09 06:44:22.000000000 -0500
15375 @@ -0,0 +1,143 @@
15376 +#ifndef _DX_TAG_H
15377 +#define _DX_TAG_H
15378 +
15379 +#include <linux/types.h>
15380 +
15381 +
15382 +#define DX_TAG(in)     (IS_TAGGED(in))
15383 +
15384 +
15385 +#ifdef CONFIG_DX_TAG_NFSD
15386 +#define DX_TAG_NFSD    1
15387 +#else
15388 +#define DX_TAG_NFSD    0
15389 +#endif
15390 +
15391 +
15392 +#ifdef CONFIG_TAGGING_NONE
15393 +
15394 +#define MAX_UID                0xFFFFFFFF
15395 +#define MAX_GID                0xFFFFFFFF
15396 +
15397 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
15398 +
15399 +#define TAGINO_UID(cond, uid, tag)     (uid)
15400 +#define TAGINO_GID(cond, gid, tag)     (gid)
15401 +
15402 +#endif
15403 +
15404 +
15405 +#ifdef CONFIG_TAGGING_GID16
15406 +
15407 +#define MAX_UID                0xFFFFFFFF
15408 +#define MAX_GID                0x0000FFFF
15409 +
15410 +#define INOTAG_TAG(cond, uid, gid, tag)        \
15411 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
15412 +
15413 +#define TAGINO_UID(cond, uid, tag)     (uid)
15414 +#define TAGINO_GID(cond, gid, tag)     \
15415 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
15416 +
15417 +#endif
15418 +
15419 +
15420 +#ifdef CONFIG_TAGGING_ID24
15421 +
15422 +#define MAX_UID                0x00FFFFFF
15423 +#define MAX_GID                0x00FFFFFF
15424 +
15425 +#define INOTAG_TAG(cond, uid, gid, tag)        \
15426 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
15427 +
15428 +#define TAGINO_UID(cond, uid, tag)     \
15429 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
15430 +#define TAGINO_GID(cond, gid, tag)     \
15431 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
15432 +
15433 +#endif
15434 +
15435 +
15436 +#ifdef CONFIG_TAGGING_UID16
15437 +
15438 +#define MAX_UID                0x0000FFFF
15439 +#define MAX_GID                0xFFFFFFFF
15440 +
15441 +#define INOTAG_TAG(cond, uid, gid, tag)        \
15442 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
15443 +
15444 +#define TAGINO_UID(cond, uid, tag)     \
15445 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
15446 +#define TAGINO_GID(cond, gid, tag)     (gid)
15447 +
15448 +#endif
15449 +
15450 +
15451 +#ifdef CONFIG_TAGGING_INTERN
15452 +
15453 +#define MAX_UID                0xFFFFFFFF
15454 +#define MAX_GID                0xFFFFFFFF
15455 +
15456 +#define INOTAG_TAG(cond, uid, gid, tag)        \
15457 +       ((cond) ? (tag) : 0)
15458 +
15459 +#define TAGINO_UID(cond, uid, tag)     (uid)
15460 +#define TAGINO_GID(cond, gid, tag)     (gid)
15461 +
15462 +#endif
15463 +
15464 +
15465 +#ifndef CONFIG_TAGGING_NONE
15466 +#define dx_current_fstag(sb)   \
15467 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
15468 +#else
15469 +#define dx_current_fstag(sb)   (0)
15470 +#endif
15471 +
15472 +#ifndef CONFIG_TAGGING_INTERN
15473 +#define TAGINO_TAG(cond, tag)  (0)
15474 +#else
15475 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
15476 +#endif
15477 +
15478 +#define INOTAG_UID(cond, uid, gid)     \
15479 +       ((cond) ? ((uid) & MAX_UID) : (uid))
15480 +#define INOTAG_GID(cond, uid, gid)     \
15481 +       ((cond) ? ((gid) & MAX_GID) : (gid))
15482 +
15483 +
15484 +static inline uid_t dx_map_uid(uid_t uid)
15485 +{
15486 +       if ((uid > MAX_UID) && (uid != -1))
15487 +               uid = -2;
15488 +       return (uid & MAX_UID);
15489 +}
15490 +
15491 +static inline gid_t dx_map_gid(gid_t gid)
15492 +{
15493 +       if ((gid > MAX_GID) && (gid != -1))
15494 +               gid = -2;
15495 +       return (gid & MAX_GID);
15496 +}
15497 +
15498 +struct peer_tag {
15499 +       int32_t xid;
15500 +       int32_t nid;
15501 +};
15502 +
15503 +#define dx_notagcheck(nd) \
15504 +       ((nd) && (nd)->mnt && ((nd)->mnt->mnt_flags & MNT_NOTAGCHECK))
15505 +
15506 +int dx_parse_tag(char *string, tag_t *tag, int remove);
15507 +
15508 +#ifdef CONFIG_PROPAGATE
15509 +
15510 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
15511 +
15512 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
15513 +
15514 +#else
15515 +#define dx_propagate_tag(n, i) do { } while (0)
15516 +#endif
15517 +
15518 +#endif /* _DX_TAG_H */
15519 diff -Nurp linux-2.6.22.15/include/linux/vs_inet6.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_inet6.h
15520 --- linux-2.6.22.15/include/linux/vs_inet6.h    1969-12-31 19:00:00.000000000 -0500
15521 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_inet6.h       2007-12-09 06:44:22.000000000 -0500
15522 @@ -0,0 +1,228 @@
15523 +#ifndef _VS_INET6_H
15524 +#define _VS_INET6_H
15525 +
15526 +#include <net/ipv6.h>
15527 +#include "vserver/base.h"
15528 +#include "vserver/network.h"
15529 +#include "vserver/debug.h"
15530 +
15531 +#define NXAV6(a)       NIP6((a)->ip), NIP6((a)->mask), (a)->prefix, (a)->type
15532 +#define NXAV6_FMT      "[" NIP6_FMT "/" NIP6_FMT "/%d:%04x]"
15533 +
15534 +
15535 +#ifdef CONFIG_IPV6
15536 +
15537 +static inline
15538 +int v6_addr_match(struct nx_addr_v6 *nxa,
15539 +       const struct in6_addr *addr, uint16_t mask)
15540 +{
15541 +       switch (nxa->type & mask) {
15542 +       case NXA_TYPE_MASK:
15543 +               return ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
15544 +       case NXA_TYPE_ADDR:
15545 +               return ipv6_addr_equal(&nxa->ip, addr);
15546 +       case NXA_TYPE_ANY:
15547 +               return 1;
15548 +       default:
15549 +               return 0;
15550 +       }
15551 +}
15552 +
15553 +static inline
15554 +int v6_addr_in_nx_info(struct nx_info *nxi,
15555 +       const struct in6_addr *addr, uint16_t mask)
15556 +{
15557 +       struct nx_addr_v6 *nxa;
15558 +
15559 +       if (!nxi)
15560 +               return 1;
15561 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
15562 +               if (v6_addr_match(nxa, addr, mask))
15563 +                       return 1;
15564 +       return 0;
15565 +}
15566 +
15567 +static inline
15568 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
15569 +{
15570 +       /* FIXME: needs full range checks */
15571 +       return v6_addr_match(nxa, &addr->ip, mask);
15572 +}
15573 +
15574 +static inline
15575 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
15576 +{
15577 +       struct nx_addr_v6 *ptr;
15578 +
15579 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
15580 +               if (v6_nx_addr_match(ptr, nxa, mask))
15581 +                       return 1;
15582 +       return 0;
15583 +}
15584 +
15585 +
15586 +/*
15587 + *     Check if a given address matches for a socket
15588 + *
15589 + *     nxi:            the socket's nx_info if any
15590 + *     addr:           to be verified address
15591 + */
15592 +static inline
15593 +int v6_sock_addr_match (
15594 +       struct nx_info *nxi,
15595 +       struct inet_sock *inet,
15596 +       struct in6_addr *addr)
15597 +{
15598 +       struct sock *sk = &inet->sk;
15599 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
15600 +
15601 +       if (!ipv6_addr_any(addr) &&
15602 +               ipv6_addr_equal(saddr, addr))
15603 +               return 1;
15604 +       if (ipv6_addr_any(saddr))
15605 +               return v6_addr_in_nx_info(nxi, addr, -1);
15606 +       return 0;
15607 +}
15608 +
15609 +/*
15610 + *     check if address is covered by socket
15611 + *
15612 + *     sk:     the socket to check against
15613 + *     addr:   the address in question (must be != 0)
15614 + */
15615 +
15616 +static inline
15617 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
15618 +{
15619 +       struct nx_info *nxi = sk->sk_nx_info;
15620 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
15621 +
15622 +       vxdprintk(VXD_CBIT(net, 5),
15623 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:" NIP6_FMT " %p;%lx",
15624 +               sk, NXAV6(nxa), nxi, NIP6(*saddr), sk->sk_socket,
15625 +               (sk->sk_socket?sk->sk_socket->flags:0));
15626 +
15627 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
15628 +               return v6_addr_match(nxa, saddr, -1);
15629 +       } else if (nxi) {               /* match against nx_info */
15630 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
15631 +       } else {                        /* unrestricted any socket */
15632 +               return 1;
15633 +       }
15634 +}
15635 +
15636 +
15637 +/* inet related checks and helpers */
15638 +
15639 +
15640 +struct in_ifaddr;
15641 +struct net_device;
15642 +struct sock;
15643 +
15644 +
15645 +#include <linux/netdevice.h>
15646 +#include <linux/inetdevice.h>
15647 +#include <net/inet_timewait_sock.h>
15648 +
15649 +
15650 +int dev_in_nx_info(struct net_device *, struct nx_info *);
15651 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
15652 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
15653 +
15654 +
15655 +
15656 +static inline
15657 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
15658 +{
15659 +       if (!nxi)
15660 +               return 1;
15661 +       if (!ifa)
15662 +               return 0;
15663 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
15664 +}
15665 +
15666 +static inline
15667 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
15668 +{
15669 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
15670 +               return 1;
15671 +       if (v6_ifa_in_nx_info(ifa, nxi))
15672 +               return 1;
15673 +       return 0;
15674 +}
15675 +
15676 +
15677 +struct nx_v6_sock_addr {
15678 +       struct in6_addr saddr;  /* Address used for validation */
15679 +       struct in6_addr baddr;  /* Address used for socket bind */
15680 +};
15681 +
15682 +static inline
15683 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
15684 +       struct nx_v6_sock_addr *nsa)
15685 +{
15686 +       // struct sock *sk = &inet->sk;
15687 +       // struct nx_info *nxi = sk->sk_nx_info;
15688 +       struct in6_addr saddr = addr->sin6_addr;
15689 +       struct in6_addr baddr = saddr;
15690 +
15691 +       nsa->saddr = saddr;
15692 +       nsa->baddr = baddr;
15693 +       return 0;
15694 +}
15695 +
15696 +static inline
15697 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
15698 +{
15699 +       // struct sock *sk = &inet->sk;
15700 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
15701 +
15702 +       // *saddr = nsa->baddr;
15703 +       // inet->saddr = nsa->baddr;
15704 +}
15705 +
15706 +static inline
15707 +int nx_info_has_v6(struct nx_info *nxi)
15708 +{
15709 +       if (!nxi)
15710 +               return 1;
15711 +       if (NX_IPV6(nxi))
15712 +               return 1;
15713 +       return 0;
15714 +}
15715 +
15716 +#else /* CONFIG_IPV6 */
15717 +
15718 +static inline
15719 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
15720 +{
15721 +       return 1;
15722 +}
15723 +
15724 +
15725 +static inline
15726 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
15727 +{
15728 +       return 1;
15729 +}
15730 +
15731 +static inline
15732 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
15733 +{
15734 +       return 1;
15735 +}
15736 +
15737 +static inline
15738 +int nx_info_has_v6(struct nx_info *nxi)
15739 +{
15740 +       return 0;
15741 +}
15742 +
15743 +#endif /* CONFIG_IPV6 */
15744 +
15745 +#define current_nx_info_has_v6() \
15746 +       nx_info_has_v6(current_nx_info())
15747 +
15748 +#else
15749 +#warning duplicate inclusion
15750 +#endif
15751 diff -Nurp linux-2.6.22.15/include/linux/vs_inet.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_inet.h
15752 --- linux-2.6.22.15/include/linux/vs_inet.h     1969-12-31 19:00:00.000000000 -0500
15753 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_inet.h        2007-12-09 06:44:22.000000000 -0500
15754 @@ -0,0 +1,341 @@
15755 +#ifndef _VS_INET_H
15756 +#define _VS_INET_H
15757 +
15758 +#include "vserver/base.h"
15759 +#include "vserver/network.h"
15760 +#include "vserver/debug.h"
15761 +
15762 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
15763 +
15764 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
15765 +                       NIPQUAD((a)->mask), (a)->type
15766 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
15767 +
15768 +
15769 +static inline
15770 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
15771 +{
15772 +       __be32 ip = nxa->ip[0].s_addr;
15773 +       __be32 mask = nxa->mask.s_addr;
15774 +       __be32 bcast = ip | ~mask;
15775 +       int ret = 0;
15776 +
15777 +       switch (nxa->type & tmask) {
15778 +       case NXA_TYPE_MASK:
15779 +               ret = (ip == (addr & mask));
15780 +               break;
15781 +       case NXA_TYPE_ADDR:
15782 +               ret = 3;
15783 +               if (addr == ip)
15784 +                       break;
15785 +               /* fall through to broadcast */
15786 +       case NXA_MOD_BCAST:
15787 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
15788 +               break;
15789 +       case NXA_TYPE_RANGE:
15790 +               ret = ((nxa->ip[0].s_addr <= addr) &&
15791 +                       (nxa->ip[1].s_addr > addr));
15792 +               break;
15793 +       case NXA_TYPE_ANY:
15794 +               ret = 2;
15795 +               break;
15796 +       }
15797 +
15798 +       vxdprintk(VXD_CBIT(net, 0),
15799 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
15800 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
15801 +       return ret;
15802 +}
15803 +
15804 +static inline
15805 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
15806 +{
15807 +       struct nx_addr_v4 *nxa;
15808 +       int ret = 1;
15809 +
15810 +       if (!nxi)
15811 +               goto out;
15812 +
15813 +       ret = 2;
15814 +       /* allow 127.0.0.1 when remapping lback */
15815 +       if ((tmask & NXA_LOOPBACK) &&
15816 +               (addr == IPI_LOOPBACK) &&
15817 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
15818 +               goto out;
15819 +       ret = 3;
15820 +       /* check for lback address */
15821 +       if ((tmask & NXA_MOD_LBACK) &&
15822 +               (nxi->v4_lback.s_addr == addr))
15823 +               goto out;
15824 +       ret = 4;
15825 +       /* check for broadcast address */
15826 +       if ((tmask & NXA_MOD_BCAST) &&
15827 +               (nxi->v4_bcast.s_addr == addr))
15828 +               goto out;
15829 +       ret = 5;
15830 +       /* check for v4 addresses */
15831 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
15832 +               if (v4_addr_match(nxa, addr, tmask))
15833 +                       goto out;
15834 +       ret = 0;
15835 +out:
15836 +       vxdprintk(VXD_CBIT(net, 0),
15837 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
15838 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
15839 +       return ret;
15840 +}
15841 +
15842 +static inline
15843 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
15844 +{
15845 +       /* FIXME: needs full range checks */
15846 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
15847 +}
15848 +
15849 +static inline
15850 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
15851 +{
15852 +       struct nx_addr_v4 *ptr;
15853 +
15854 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
15855 +               if (v4_nx_addr_match(ptr, nxa, mask))
15856 +                       return 1;
15857 +       return 0;
15858 +}
15859 +
15860 +#include <net/inet_sock.h>
15861 +
15862 +/*
15863 + *     Check if a given address matches for a socket
15864 + *
15865 + *     nxi:            the socket's nx_info if any
15866 + *     addr:           to be verified address
15867 + */
15868 +static inline
15869 +int v4_sock_addr_match (
15870 +       struct nx_info *nxi,
15871 +       struct inet_sock *inet,
15872 +       __be32 addr)
15873 +{
15874 +       __be32 saddr = inet->rcv_saddr;
15875 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
15876 +
15877 +       if (addr && (saddr == addr || bcast == addr))
15878 +               return 1;
15879 +       if (!saddr)
15880 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
15881 +       return 0;
15882 +}
15883 +
15884 +
15885 +/* inet related checks and helpers */
15886 +
15887 +
15888 +struct in_ifaddr;
15889 +struct net_device;
15890 +struct sock;
15891 +
15892 +#ifdef CONFIG_INET
15893 +
15894 +#include <linux/netdevice.h>
15895 +#include <linux/inetdevice.h>
15896 +#include <net/inet_timewait_sock.h>
15897 +
15898 +
15899 +int dev_in_nx_info(struct net_device *, struct nx_info *);
15900 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
15901 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
15902 +
15903 +
15904 +/*
15905 + *     check if address is covered by socket
15906 + *
15907 + *     sk:     the socket to check against
15908 + *     addr:   the address in question (must be != 0)
15909 + */
15910 +
15911 +static inline
15912 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
15913 +{
15914 +       struct nx_info *nxi = sk->sk_nx_info;
15915 +       __be32 saddr = inet_rcv_saddr(sk);
15916 +
15917 +       vxdprintk(VXD_CBIT(net, 5),
15918 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
15919 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
15920 +               (sk->sk_socket?sk->sk_socket->flags:0));
15921 +
15922 +       if (saddr) {            /* direct address match */
15923 +               return v4_addr_match(nxa, saddr, -1);
15924 +       } else if (nxi) {       /* match against nx_info */
15925 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
15926 +       } else {                /* unrestricted any socket */
15927 +               return 1;
15928 +       }
15929 +}
15930 +
15931 +
15932 +
15933 +static inline
15934 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
15935 +{
15936 +       vxdprintk(VXD_CBIT(net, 1), "nx_dev_visible(%p[#%u],%p Â»%s«) %d",
15937 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
15938 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
15939 +
15940 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
15941 +               return 1;
15942 +       if (dev_in_nx_info(dev, nxi))
15943 +               return 1;
15944 +       return 0;
15945 +}
15946 +
15947 +
15948 +static inline
15949 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
15950 +{
15951 +       if (!nxi)
15952 +               return 1;
15953 +       if (!ifa)
15954 +               return 0;
15955 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
15956 +}
15957 +
15958 +static inline
15959 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
15960 +{
15961 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
15962 +               nxi, nxi ? nxi->nx_id : 0, ifa,
15963 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
15964 +
15965 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
15966 +               return 1;
15967 +       if (v4_ifa_in_nx_info(ifa, nxi))
15968 +               return 1;
15969 +       return 0;
15970 +}
15971 +
15972 +
15973 +struct nx_v4_sock_addr {
15974 +       __be32 saddr;   /* Address used for validation */
15975 +       __be32 baddr;   /* Address used for socket bind */
15976 +};
15977 +
15978 +static inline
15979 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
15980 +       struct nx_v4_sock_addr *nsa)
15981 +{
15982 +       struct sock *sk = &inet->sk;
15983 +       struct nx_info *nxi = sk->sk_nx_info;
15984 +       __be32 saddr = addr->sin_addr.s_addr;
15985 +       __be32 baddr = saddr;
15986 +
15987 +       vxdprintk(VXD_CBIT(net, 3),
15988 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
15989 +               sk, sk->sk_nx_info, sk->sk_socket,
15990 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
15991 +               NIPQUAD(saddr));
15992 +
15993 +       if (nxi) {
15994 +               if (saddr == INADDR_ANY) {
15995 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
15996 +                               baddr = nxi->v4.ip[0].s_addr;
15997 +               } else if (saddr == IPI_LOOPBACK) {
15998 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
15999 +                               baddr = nxi->v4_lback.s_addr;
16000 +               } else {        /* normal address bind */
16001 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
16002 +                               return -EADDRNOTAVAIL;
16003 +               }
16004 +       }
16005 +
16006 +       vxdprintk(VXD_CBIT(net, 3),
16007 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
16008 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
16009 +
16010 +       nsa->saddr = saddr;
16011 +       nsa->baddr = baddr;
16012 +       return 0;
16013 +}
16014 +
16015 +static inline
16016 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
16017 +{
16018 +       inet->saddr = nsa->baddr;
16019 +       inet->rcv_saddr = nsa->baddr;
16020 +}
16021 +
16022 +
16023 +/*
16024 + *      helper to simplify inet_lookup_listener
16025 + *
16026 + *      nxi:   the socket's nx_info if any
16027 + *      addr:  to be verified address
16028 + *      saddr: socket address
16029 + */
16030 +static inline int v4_inet_addr_match (
16031 +       struct nx_info *nxi,
16032 +       __be32 addr,
16033 +       __be32 saddr)
16034 +{
16035 +       if (addr && (saddr == addr))
16036 +               return 1;
16037 +       if (!saddr)
16038 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
16039 +       return 0;
16040 +}
16041 +
16042 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
16043 +{
16044 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
16045 +               (addr == nxi->v4_lback.s_addr))
16046 +               return IPI_LOOPBACK;
16047 +       return addr;
16048 +}
16049 +
16050 +static inline
16051 +int nx_info_has_v4(struct nx_info *nxi)
16052 +{
16053 +       if (!nxi)
16054 +               return 1;
16055 +       if (NX_IPV4(nxi))
16056 +               return 1;
16057 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
16058 +               return 1;
16059 +       return 0;
16060 +}
16061 +
16062 +#else /* CONFIG_INET */
16063 +
16064 +static inline
16065 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
16066 +{
16067 +       return 1;
16068 +}
16069 +
16070 +static inline
16071 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
16072 +{
16073 +       return 1;
16074 +}
16075 +
16076 +static inline
16077 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
16078 +{
16079 +       return 1;
16080 +}
16081 +
16082 +static inline
16083 +int nx_info_has_v4(struct nx_info *nxi)
16084 +{
16085 +       return 0;
16086 +}
16087 +
16088 +#endif /* CONFIG_INET */
16089 +
16090 +#define current_nx_info_has_v4() \
16091 +       nx_info_has_v4(current_nx_info())
16092 +
16093 +#else
16094 +#warning duplicate inclusion
16095 +#endif
16096 diff -Nurp linux-2.6.22.15/include/linux/vs_limit.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_limit.h
16097 --- linux-2.6.22.15/include/linux/vs_limit.h    1969-12-31 19:00:00.000000000 -0500
16098 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_limit.h       2007-12-09 06:44:22.000000000 -0500
16099 @@ -0,0 +1,140 @@
16100 +#ifndef _VS_LIMIT_H
16101 +#define _VS_LIMIT_H
16102 +
16103 +#include "vserver/limit.h"
16104 +#include "vserver/base.h"
16105 +#include "vserver/context.h"
16106 +#include "vserver/debug.h"
16107 +#include "vserver/context.h"
16108 +#include "vserver/limit_int.h"
16109 +
16110 +
16111 +#define vx_acc_cres(v, d, p, r) \
16112 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
16113 +
16114 +#define vx_acc_cres_cond(x, d, p, r) \
16115 +       __vx_acc_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
16116 +       r, d, p, __FILE__, __LINE__)
16117 +
16118 +
16119 +#define vx_add_cres(v, a, p, r) \
16120 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
16121 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
16122 +
16123 +#define vx_add_cres_cond(x, a, p, r) \
16124 +       __vx_add_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
16125 +       r, a, p, __FILE__, __LINE__)
16126 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
16127 +
16128 +
16129 +/* process and file limits */
16130 +
16131 +#define vx_nproc_inc(p) \
16132 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
16133 +
16134 +#define vx_nproc_dec(p) \
16135 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
16136 +
16137 +#define vx_files_inc(f) \
16138 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
16139 +
16140 +#define vx_files_dec(f) \
16141 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
16142 +
16143 +#define vx_locks_inc(l) \
16144 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
16145 +
16146 +#define vx_locks_dec(l) \
16147 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
16148 +
16149 +#define vx_openfd_inc(f) \
16150 +       vx_acc_cres(current->vx_info, 1, (void *)(long)(f), VLIMIT_OPENFD)
16151 +
16152 +#define vx_openfd_dec(f) \
16153 +       vx_acc_cres(current->vx_info,-1, (void *)(long)(f), VLIMIT_OPENFD)
16154 +
16155 +
16156 +#define vx_cres_avail(v, n, r) \
16157 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
16158 +
16159 +
16160 +#define vx_nproc_avail(n) \
16161 +       vx_cres_avail(current->vx_info, n, RLIMIT_NPROC)
16162 +
16163 +#define vx_files_avail(n) \
16164 +       vx_cres_avail(current->vx_info, n, RLIMIT_NOFILE)
16165 +
16166 +#define vx_locks_avail(n) \
16167 +       vx_cres_avail(current->vx_info, n, RLIMIT_LOCKS)
16168 +
16169 +#define vx_openfd_avail(n) \
16170 +       vx_cres_avail(current->vx_info, n, VLIMIT_OPENFD)
16171 +
16172 +
16173 +/* dentry limits */
16174 +
16175 +#define vx_dentry_inc(d) do {                                          \
16176 +       if (atomic_read(&d->d_count) == 1)                              \
16177 +               vx_acc_cres(current->vx_info, 1, d, VLIMIT_DENTRY);     \
16178 +       } while (0)
16179 +
16180 +#define vx_dentry_dec(d) do {                                          \
16181 +       if (atomic_read(&d->d_count) == 0)                              \
16182 +               vx_acc_cres(current->vx_info,-1, d, VLIMIT_DENTRY);     \
16183 +       } while (0)
16184 +
16185 +#define vx_dentry_avail(n) \
16186 +       vx_cres_avail(current->vx_info, n, VLIMIT_DENTRY)
16187 +
16188 +
16189 +/* socket limits */
16190 +
16191 +#define vx_sock_inc(s) \
16192 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
16193 +
16194 +#define vx_sock_dec(s) \
16195 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
16196 +
16197 +#define vx_sock_avail(n) \
16198 +       vx_cres_avail(current->vx_info, n, VLIMIT_NSOCK)
16199 +
16200 +
16201 +/* ipc resource limits */
16202 +
16203 +#define vx_ipcmsg_add(v, u, a) \
16204 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
16205 +
16206 +#define vx_ipcmsg_sub(v, u, a) \
16207 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
16208 +
16209 +#define vx_ipcmsg_avail(v, a) \
16210 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
16211 +
16212 +
16213 +#define vx_ipcshm_add(v, k, a) \
16214 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
16215 +
16216 +#define vx_ipcshm_sub(v, k, a) \
16217 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
16218 +
16219 +#define vx_ipcshm_avail(v, a) \
16220 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
16221 +
16222 +
16223 +#define vx_semary_inc(a) \
16224 +       vx_acc_cres(current->vx_info, 1, a, VLIMIT_SEMARY)
16225 +
16226 +#define vx_semary_dec(a) \
16227 +       vx_acc_cres(current->vx_info, -1, a, VLIMIT_SEMARY)
16228 +
16229 +
16230 +#define vx_nsems_add(a,n) \
16231 +       vx_add_cres(current->vx_info, n, a, VLIMIT_NSEMS)
16232 +
16233 +#define vx_nsems_sub(a,n) \
16234 +       vx_sub_cres(current->vx_info, n, a, VLIMIT_NSEMS)
16235 +
16236 +
16237 +#else
16238 +#warning duplicate inclusion
16239 +#endif
16240 diff -Nurp linux-2.6.22.15/include/linux/vs_memory.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_memory.h
16241 --- linux-2.6.22.15/include/linux/vs_memory.h   1969-12-31 19:00:00.000000000 -0500
16242 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_memory.h      2007-12-09 06:44:22.000000000 -0500
16243 @@ -0,0 +1,159 @@
16244 +#ifndef _VS_MEMORY_H
16245 +#define _VS_MEMORY_H
16246 +
16247 +#include "vserver/limit.h"
16248 +#include "vserver/base.h"
16249 +#include "vserver/context.h"
16250 +#include "vserver/debug.h"
16251 +#include "vserver/context.h"
16252 +#include "vserver/limit_int.h"
16253 +
16254 +
16255 +#define __acc_add_long(a, v)   (*(v) += (a))
16256 +#define __acc_inc_long(v)      (++*(v))
16257 +#define __acc_dec_long(v)      (--*(v))
16258 +
16259 +#if    NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
16260 +#define __acc_add_atomic(a, v) atomic_long_add(a, v)
16261 +#define __acc_inc_atomic(v)    atomic_long_inc(v)
16262 +#define __acc_dec_atomic(v)    atomic_long_dec(v)
16263 +#else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
16264 +#define __acc_add_atomic(a, v) __acc_add_long(a, v)
16265 +#define __acc_inc_atomic(v)    __acc_inc_long(v)
16266 +#define __acc_dec_atomic(v)    __acc_dec_long(v)
16267 +#endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
16268 +
16269 +
16270 +#define vx_acc_page(m, d, v, r) do {                                   \
16271 +       if ((d) > 0)                                                    \
16272 +               __acc_inc_long(&(m)->v);                                \
16273 +       else                                                            \
16274 +               __acc_dec_long(&(m)->v);                                \
16275 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
16276 +} while (0)
16277 +
16278 +#define vx_acc_page_atomic(m, d, v, r) do {                            \
16279 +       if ((d) > 0)                                                    \
16280 +               __acc_inc_atomic(&(m)->v);                              \
16281 +       else                                                            \
16282 +               __acc_dec_atomic(&(m)->v);                              \
16283 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
16284 +} while (0)
16285 +
16286 +
16287 +#define vx_acc_pages(m, p, v, r) do {                                  \
16288 +       unsigned long __p = (p);                                        \
16289 +       __acc_add_long(__p, &(m)->v);                                   \
16290 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
16291 +} while (0)
16292 +
16293 +#define vx_acc_pages_atomic(m, p, v, r) do {                           \
16294 +       unsigned long __p = (p);                                        \
16295 +       __acc_add_atomic(__p, &(m)->v);                                 \
16296 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
16297 +} while (0)
16298 +
16299 +
16300 +
16301 +#define vx_acc_vmpage(m, d) \
16302 +       vx_acc_page(m, d, total_vm,  RLIMIT_AS)
16303 +#define vx_acc_vmlpage(m, d) \
16304 +       vx_acc_page(m, d, locked_vm, RLIMIT_MEMLOCK)
16305 +#define vx_acc_file_rsspage(m, d) \
16306 +       vx_acc_page_atomic(m, d, _file_rss, VLIMIT_MAPPED)
16307 +#define vx_acc_anon_rsspage(m, d) \
16308 +       vx_acc_page_atomic(m, d, _anon_rss, VLIMIT_ANON)
16309 +
16310 +#define vx_acc_vmpages(m, p) \
16311 +       vx_acc_pages(m, p, total_vm,  RLIMIT_AS)
16312 +#define vx_acc_vmlpages(m, p) \
16313 +       vx_acc_pages(m, p, locked_vm, RLIMIT_MEMLOCK)
16314 +#define vx_acc_file_rsspages(m, p) \
16315 +       vx_acc_pages_atomic(m, p, _file_rss, VLIMIT_MAPPED)
16316 +#define vx_acc_anon_rsspages(m, p) \
16317 +       vx_acc_pages_atomic(m, p, _anon_rss, VLIMIT_ANON)
16318 +
16319 +#define vx_pages_add(s, r, p)  __vx_add_cres(s, r, p, 0, __FILE__, __LINE__)
16320 +#define vx_pages_sub(s, r, p)  vx_pages_add(s, r, -(p))
16321 +
16322 +#define vx_vmpages_inc(m)              vx_acc_vmpage(m, 1)
16323 +#define vx_vmpages_dec(m)              vx_acc_vmpage(m, -1)
16324 +#define vx_vmpages_add(m, p)           vx_acc_vmpages(m, p)
16325 +#define vx_vmpages_sub(m, p)           vx_acc_vmpages(m, -(p))
16326 +
16327 +#define vx_vmlocked_inc(m)             vx_acc_vmlpage(m, 1)
16328 +#define vx_vmlocked_dec(m)             vx_acc_vmlpage(m, -1)
16329 +#define vx_vmlocked_add(m, p)          vx_acc_vmlpages(m, p)
16330 +#define vx_vmlocked_sub(m, p)          vx_acc_vmlpages(m, -(p))
16331 +
16332 +#define vx_file_rsspages_inc(m)                vx_acc_file_rsspage(m, 1)
16333 +#define vx_file_rsspages_dec(m)                vx_acc_file_rsspage(m, -1)
16334 +#define vx_file_rsspages_add(m, p)     vx_acc_file_rsspages(m, p)
16335 +#define vx_file_rsspages_sub(m, p)     vx_acc_file_rsspages(m, -(p))
16336 +
16337 +#define vx_anon_rsspages_inc(m)                vx_acc_anon_rsspage(m, 1)
16338 +#define vx_anon_rsspages_dec(m)                vx_acc_anon_rsspage(m, -1)
16339 +#define vx_anon_rsspages_add(m, p)     vx_acc_anon_rsspages(m, p)
16340 +#define vx_anon_rsspages_sub(m, p)     vx_acc_anon_rsspages(m, -(p))
16341 +
16342 +
16343 +#define vx_pages_avail(m, p, r) \
16344 +       __vx_cres_avail((m)->mm_vx_info, r, p, __FILE__, __LINE__)
16345 +
16346 +#define vx_vmpages_avail(m, p) vx_pages_avail(m, p, RLIMIT_AS)
16347 +#define vx_vmlocked_avail(m, p)        vx_pages_avail(m, p, RLIMIT_MEMLOCK)
16348 +#define vx_anon_avail(m, p)    vx_pages_avail(m, p, VLIMIT_ANON)
16349 +#define vx_mapped_avail(m, p)  vx_pages_avail(m, p, VLIMIT_MAPPED)
16350 +
16351 +#define vx_rss_avail(m, p) \
16352 +       __vx_cres_array_avail((m)->mm_vx_info, VLA_RSS, p, __FILE__, __LINE__)
16353 +
16354 +
16355 +enum {
16356 +       VXPT_UNKNOWN = 0,
16357 +       VXPT_ANON,
16358 +       VXPT_NONE,
16359 +       VXPT_FILE,
16360 +       VXPT_SWAP,
16361 +       VXPT_WRITE
16362 +};
16363 +
16364 +#if 0
16365 +#define        vx_page_fault(mm, vma, type, ret)
16366 +#else
16367 +
16368 +static inline
16369 +void __vx_page_fault(struct mm_struct *mm,
16370 +       struct vm_area_struct *vma, int type, int ret)
16371 +{
16372 +       struct vx_info *vxi = mm->mm_vx_info;
16373 +       int what;
16374 +/*
16375 +       static char *page_type[6] =
16376 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
16377 +       static char *page_what[4] =
16378 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
16379 +*/
16380 +
16381 +       if (!vxi)
16382 +               return;
16383 +
16384 +       what = (ret & 0x3);
16385 +
16386 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
16387 +               type, what, ret, page_type[type], page_what[what]);
16388 +*/
16389 +       if (ret & VM_FAULT_WRITE)
16390 +               what |= 0x4;
16391 +       atomic_inc(&vxi->cacct.page[type][what]);
16392 +}
16393 +
16394 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
16395 +#endif
16396 +
16397 +
16398 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
16399 +
16400 +#else
16401 +#warning duplicate inclusion
16402 +#endif
16403 diff -Nurp linux-2.6.22.15/include/linux/vs_network.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_network.h
16404 --- linux-2.6.22.15/include/linux/vs_network.h  1969-12-31 19:00:00.000000000 -0500
16405 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_network.h     2007-12-09 06:44:22.000000000 -0500
16406 @@ -0,0 +1,166 @@
16407 +#ifndef _NX_VS_NETWORK_H
16408 +#define _NX_VS_NETWORK_H
16409 +
16410 +#include "vserver/context.h"
16411 +#include "vserver/network.h"
16412 +#include "vserver/base.h"
16413 +#include "vserver/debug.h"
16414 +
16415 +
16416 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
16417 +
16418 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
16419 +       const char *_file, int _line)
16420 +{
16421 +       if (!nxi)
16422 +               return NULL;
16423 +
16424 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
16425 +               nxi, nxi ? nxi->nx_id : 0,
16426 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
16427 +               _file, _line);
16428 +
16429 +       atomic_inc(&nxi->nx_usecnt);
16430 +       return nxi;
16431 +}
16432 +
16433 +
16434 +extern void free_nx_info(struct nx_info *);
16435 +
16436 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
16437 +
16438 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
16439 +{
16440 +       if (!nxi)
16441 +               return;
16442 +
16443 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
16444 +               nxi, nxi ? nxi->nx_id : 0,
16445 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
16446 +               _file, _line);
16447 +
16448 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
16449 +               free_nx_info(nxi);
16450 +}
16451 +
16452 +
16453 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
16454 +
16455 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
16456 +               const char *_file, int _line)
16457 +{
16458 +       if (nxi) {
16459 +               vxlprintk(VXD_CBIT(nid, 3),
16460 +                       "init_nx_info(%p[#%d.%d])",
16461 +                       nxi, nxi ? nxi->nx_id : 0,
16462 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
16463 +                       _file, _line);
16464 +
16465 +               atomic_inc(&nxi->nx_usecnt);
16466 +       }
16467 +       *nxp = nxi;
16468 +}
16469 +
16470 +
16471 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
16472 +
16473 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
16474 +       const char *_file, int _line)
16475 +{
16476 +       struct nx_info *nxo;
16477 +
16478 +       if (!nxi)
16479 +               return;
16480 +
16481 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
16482 +               nxi, nxi ? nxi->nx_id : 0,
16483 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
16484 +               _file, _line);
16485 +
16486 +       atomic_inc(&nxi->nx_usecnt);
16487 +       nxo = xchg(nxp, nxi);
16488 +       BUG_ON(nxo);
16489 +}
16490 +
16491 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
16492 +
16493 +static inline void __clr_nx_info(struct nx_info **nxp,
16494 +       const char *_file, int _line)
16495 +{
16496 +       struct nx_info *nxo;
16497 +
16498 +       nxo = xchg(nxp, NULL);
16499 +       if (!nxo)
16500 +               return;
16501 +
16502 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
16503 +               nxo, nxo ? nxo->nx_id : 0,
16504 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
16505 +               _file, _line);
16506 +
16507 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
16508 +               free_nx_info(nxo);
16509 +}
16510 +
16511 +
16512 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
16513 +
16514 +static inline void __claim_nx_info(struct nx_info *nxi,
16515 +       struct task_struct *task, const char *_file, int _line)
16516 +{
16517 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
16518 +               nxi, nxi ? nxi->nx_id : 0,
16519 +               nxi?atomic_read(&nxi->nx_usecnt):0,
16520 +               nxi?atomic_read(&nxi->nx_tasks):0,
16521 +               task, _file, _line);
16522 +
16523 +       atomic_inc(&nxi->nx_tasks);
16524 +}
16525 +
16526 +
16527 +extern void unhash_nx_info(struct nx_info *);
16528 +
16529 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
16530 +
16531 +static inline void __release_nx_info(struct nx_info *nxi,
16532 +       struct task_struct *task, const char *_file, int _line)
16533 +{
16534 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
16535 +               nxi, nxi ? nxi->nx_id : 0,
16536 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
16537 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
16538 +               task, _file, _line);
16539 +
16540 +       might_sleep();
16541 +
16542 +       if (atomic_dec_and_test(&nxi->nx_tasks))
16543 +               unhash_nx_info(nxi);
16544 +}
16545 +
16546 +
16547 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
16548 +
16549 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
16550 +       const char *_file, int _line)
16551 +{
16552 +       struct nx_info *nxi;
16553 +
16554 +       task_lock(p);
16555 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
16556 +               p, _file, _line);
16557 +       nxi = __get_nx_info(p->nx_info, _file, _line);
16558 +       task_unlock(p);
16559 +       return nxi;
16560 +}
16561 +
16562 +
16563 +static inline void exit_nx_info(struct task_struct *p)
16564 +{
16565 +       if (p->nx_info)
16566 +               release_nx_info(p->nx_info, p);
16567 +}
16568 +
16569 +
16570 +#else
16571 +#warning duplicate inclusion
16572 +#endif
16573 diff -Nurp linux-2.6.22.15/include/linux/vs_pid.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_pid.h
16574 --- linux-2.6.22.15/include/linux/vs_pid.h      1969-12-31 19:00:00.000000000 -0500
16575 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_pid.h 2007-12-09 06:44:22.000000000 -0500
16576 @@ -0,0 +1,133 @@
16577 +#ifndef _VS_PID_H
16578 +#define _VS_PID_H
16579 +
16580 +#include "vserver/base.h"
16581 +#include "vserver/context.h"
16582 +#include "vserver/debug.h"
16583 +#include <linux/pid_namespace.h>
16584 +
16585 +
16586 +/* pid faking stuff */
16587 +
16588 +
16589 +#define vx_info_map_pid(v, p) \
16590 +       __vx_info_map_pid((v), (p), __FUNC__, __FILE__, __LINE__)
16591 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
16592 +#define vx_map_pid(p) vx_info_map_pid(current->vx_info, p)
16593 +#define vx_map_tgid(p) vx_map_pid(p)
16594 +
16595 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
16596 +       const char *func, const char *file, int line)
16597 +{
16598 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
16599 +               vxfprintk(VXD_CBIT(cvirt, 2),
16600 +                       "vx_map_tgid: %p/%llx: %d -> %d",
16601 +                       vxi, (long long)vxi->vx_flags, pid,
16602 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
16603 +                       func, file, line);
16604 +               if (pid == 0)
16605 +                       return 0;
16606 +               if (pid == vxi->vx_initpid)
16607 +                       return 1;
16608 +       }
16609 +       return pid;
16610 +}
16611 +
16612 +#define vx_info_rmap_pid(v, p) \
16613 +       __vx_info_rmap_pid((v), (p), __FUNC__, __FILE__, __LINE__)
16614 +#define vx_rmap_pid(p) vx_info_rmap_pid(current->vx_info, p)
16615 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
16616 +
16617 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
16618 +       const char *func, const char *file, int line)
16619 +{
16620 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
16621 +               vxfprintk(VXD_CBIT(cvirt, 2),
16622 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
16623 +                       vxi, (long long)vxi->vx_flags, pid,
16624 +                       (pid == 1) ? vxi->vx_initpid : pid,
16625 +                       func, file, line);
16626 +               if ((pid == 1) && vxi->vx_initpid)
16627 +                       return vxi->vx_initpid;
16628 +               if (pid == vxi->vx_initpid)
16629 +                       return ~0U;
16630 +       }
16631 +       return pid;
16632 +}
16633 +
16634 +
16635 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
16636 +
16637 +static inline
16638 +int vx_proc_task_visible(struct task_struct *task)
16639 +{
16640 +       if ((task->pid == 1) &&
16641 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
16642 +               /* show a blend through init */
16643 +               goto visible;
16644 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
16645 +               goto visible;
16646 +       return 0;
16647 +visible:
16648 +       return 1;
16649 +}
16650 +
16651 +static inline
16652 +struct task_struct *vx_find_proc_task_by_pid(int pid)
16653 +{
16654 +       struct task_struct *task = find_task_by_pid(pid);
16655 +
16656 +       if (task && !vx_proc_task_visible(task)) {
16657 +               vxdprintk(VXD_CBIT(misc, 6),
16658 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
16659 +                       task, task->xid, task->pid,
16660 +                       current, current->xid, current->pid);
16661 +               task = NULL;
16662 +       }
16663 +       return task;
16664 +}
16665 +
16666 +static inline
16667 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
16668 +{
16669 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
16670 +
16671 +       if (task && !vx_proc_task_visible(task)) {
16672 +               vxdprintk(VXD_CBIT(misc, 6),
16673 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
16674 +                       task, task->xid, task->pid,
16675 +                       current, current->xid, current->pid);
16676 +               put_task_struct(task);
16677 +               task = NULL;
16678 +       }
16679 +       return task;
16680 +}
16681 +
16682 +
16683 +static inline
16684 +struct task_struct *vx_child_reaper(struct task_struct *p)
16685 +{
16686 +       struct vx_info *vxi = p->vx_info;
16687 +       struct task_struct *reaper = child_reaper(p);
16688 +
16689 +       if (!vxi)
16690 +               goto out;
16691 +
16692 +       BUG_ON(!p->vx_info->vx_reaper);
16693 +
16694 +       /* child reaper for the guest reaper */
16695 +       if (vxi->vx_reaper == p)
16696 +               goto out;
16697 +
16698 +       reaper = vxi->vx_reaper;
16699 +out:
16700 +       vxdprintk(VXD_CBIT(xid, 7),
16701 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
16702 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
16703 +       return reaper;
16704 +}
16705 +
16706 +
16707 +#else
16708 +#warning duplicate inclusion
16709 +#endif
16710 diff -Nurp linux-2.6.22.15/include/linux/vs_sched.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_sched.h
16711 --- linux-2.6.22.15/include/linux/vs_sched.h    1969-12-31 19:00:00.000000000 -0500
16712 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_sched.h       2007-12-09 06:44:22.000000000 -0500
16713 @@ -0,0 +1,110 @@
16714 +#ifndef _VS_SCHED_H
16715 +#define _VS_SCHED_H
16716 +
16717 +#include "vserver/base.h"
16718 +#include "vserver/context.h"
16719 +#include "vserver/sched.h"
16720 +
16721 +
16722 +#define VAVAVOOM_RATIO          50
16723 +
16724 +#define MAX_PRIO_BIAS           20
16725 +#define MIN_PRIO_BIAS          -20
16726 +
16727 +
16728 +#ifdef CONFIG_VSERVER_HARDCPU
16729 +
16730 +/*
16731 + * effective_prio - return the priority that is based on the static
16732 + * priority but is modified by bonuses/penalties.
16733 + *
16734 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
16735 + * into a -4 ... 0 ... +4 bonus/penalty range.
16736 + *
16737 + * Additionally, we scale another amount based on the number of
16738 + * CPU tokens currently held by the context, if the process is
16739 + * part of a context (and the appropriate SCHED flag is set).
16740 + * This ranges from -5 ... 0 ... +15, quadratically.
16741 + *
16742 + * So, the total bonus is -9 .. 0 .. +19
16743 + * We use ~50% of the full 0...39 priority range so that:
16744 + *
16745 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
16746 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
16747 + *    unless that context is far exceeding its CPU allocation.
16748 + *
16749 + * Both properties are important to certain workloads.
16750 + */
16751 +static inline
16752 +int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
16753 +{
16754 +       int vavavoom, max;
16755 +
16756 +       /* lots of tokens = lots of vavavoom
16757 +        *      no tokens = no vavavoom      */
16758 +       if ((vavavoom = sched_pc->tokens) >= 0) {
16759 +               max = sched_pc->tokens_max;
16760 +               vavavoom = max - vavavoom;
16761 +               max = max * max;
16762 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
16763 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
16764 +               return vavavoom;
16765 +       }
16766 +       return 0;
16767 +}
16768 +
16769 +
16770 +static inline
16771 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
16772 +{
16773 +       struct vx_info *vxi = p->vx_info;
16774 +       struct _vx_sched_pc *sched_pc;
16775 +
16776 +       if (!vxi)
16777 +               return prio;
16778 +
16779 +       sched_pc = &vx_cpu(vxi, sched_pc);
16780 +       if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
16781 +               int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
16782 +
16783 +               sched_pc->vavavoom = vavavoom;
16784 +               prio += vavavoom;
16785 +       }
16786 +       prio += sched_pc->prio_bias;
16787 +       return prio;
16788 +}
16789 +
16790 +#else /* !CONFIG_VSERVER_HARDCPU */
16791 +
16792 +static inline
16793 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
16794 +{
16795 +       struct vx_info *vxi = p->vx_info;
16796 +
16797 +       if (vxi)
16798 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
16799 +       return prio;
16800 +}
16801 +
16802 +#endif /* CONFIG_VSERVER_HARDCPU */
16803 +
16804 +
16805 +static inline void vx_account_user(struct vx_info *vxi,
16806 +       cputime_t cputime, int nice)
16807 +{
16808 +       if (!vxi)
16809 +               return;
16810 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
16811 +}
16812 +
16813 +static inline void vx_account_system(struct vx_info *vxi,
16814 +       cputime_t cputime, int idle)
16815 +{
16816 +       if (!vxi)
16817 +               return;
16818 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
16819 +}
16820 +
16821 +#else
16822 +#warning duplicate inclusion
16823 +#endif
16824 diff -Nurp linux-2.6.22.15/include/linux/vs_socket.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_socket.h
16825 --- linux-2.6.22.15/include/linux/vs_socket.h   1969-12-31 19:00:00.000000000 -0500
16826 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_socket.h      2007-12-09 06:44:22.000000000 -0500
16827 @@ -0,0 +1,80 @@
16828 +#ifndef _VS_SOCKET_H
16829 +#define _VS_SOCKET_H
16830 +
16831 +#include "vserver/debug.h"
16832 +#include "vserver/base.h"
16833 +#include "vserver/cacct.h"
16834 +#include "vserver/context.h"
16835 +#include "vserver/tag.h"
16836 +
16837 +
16838 +/* socket accounting */
16839 +
16840 +#include <linux/socket.h>
16841 +
16842 +static inline int vx_sock_type(int family)
16843 +{
16844 +       switch (family) {
16845 +       case PF_UNSPEC:
16846 +               return VXA_SOCK_UNSPEC;
16847 +       case PF_UNIX:
16848 +               return VXA_SOCK_UNIX;
16849 +       case PF_INET:
16850 +               return VXA_SOCK_INET;
16851 +       case PF_INET6:
16852 +               return VXA_SOCK_INET6;
16853 +       case PF_PACKET:
16854 +               return VXA_SOCK_PACKET;
16855 +       default:
16856 +               return VXA_SOCK_OTHER;
16857 +       }
16858 +}
16859 +
16860 +#define vx_acc_sock(v, f, p, s) \
16861 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
16862 +
16863 +static inline void __vx_acc_sock(struct vx_info *vxi,
16864 +       int family, int pos, int size, char *file, int line)
16865 +{
16866 +       if (vxi) {
16867 +               int type = vx_sock_type(family);
16868 +
16869 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
16870 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
16871 +       }
16872 +}
16873 +
16874 +#define vx_sock_recv(sk, s) \
16875 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
16876 +#define vx_sock_send(sk, s) \
16877 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
16878 +#define vx_sock_fail(sk, s) \
16879 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
16880 +
16881 +
16882 +#define sock_vx_init(s) do {           \
16883 +       (s)->sk_xid = 0;                \
16884 +       (s)->sk_vx_info = NULL;         \
16885 +       } while (0)
16886 +
16887 +#define sock_nx_init(s) do {           \
16888 +       (s)->sk_nid = 0;                \
16889 +       (s)->sk_nx_info = NULL;         \
16890 +       } while (0)
16891 +
16892 +static inline
16893 +int vx_socket_peer_tag(struct socket *sock, int level,
16894 +       char __user *optval, int __user *optlen, int len)
16895 +{
16896 +       struct peer_tag tag;
16897 +
16898 +       tag.xid = sock->sk->sk_xid;
16899 +       tag.nid = sock->sk->sk_nid;
16900 +       if (copy_to_user(optval, &tag, sizeof(tag)))
16901 +               return -EFAULT;
16902 +       return 0;
16903 +}
16904 +
16905 +#else
16906 +#warning duplicate inclusion
16907 +#endif
16908 diff -Nurp linux-2.6.22.15/include/linux/vs_tag.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_tag.h
16909 --- linux-2.6.22.15/include/linux/vs_tag.h      1969-12-31 19:00:00.000000000 -0500
16910 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_tag.h 2007-12-09 06:44:22.000000000 -0500
16911 @@ -0,0 +1,43 @@
16912 +#ifndef _VS_TAG_H
16913 +#define _VS_TAG_H
16914 +
16915 +#include <linux/vserver/tag.h>
16916 +
16917 +/* check conditions */
16918 +
16919 +#define DX_ADMIN       0x0001
16920 +#define DX_WATCH       0x0002
16921 +#define DX_HOSTID      0x0008
16922 +
16923 +#define DX_IDENT       0x0010
16924 +
16925 +#define DX_ARG_MASK    0x0010
16926 +
16927 +
16928 +#define dx_task_tag(t) ((t)->tag)
16929 +
16930 +#define dx_current_tag() dx_task_tag(current)
16931 +
16932 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
16933 +
16934 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
16935 +
16936 +
16937 +/*
16938 + * check current context for ADMIN/WATCH and
16939 + * optionally against supplied argument
16940 + */
16941 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
16942 +{
16943 +       if (mode & DX_ARG_MASK) {
16944 +               if ((mode & DX_IDENT) && (id == cid))
16945 +                       return 1;
16946 +       }
16947 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
16948 +               ((mode & DX_WATCH) && (cid == 1)) ||
16949 +               ((mode & DX_HOSTID) && (id == 0)));
16950 +}
16951 +
16952 +#else
16953 +#warning duplicate inclusion
16954 +#endif
16955 diff -Nurp linux-2.6.22.15/include/linux/vs_time.h linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_time.h
16956 --- linux-2.6.22.15/include/linux/vs_time.h     1969-12-31 19:00:00.000000000 -0500
16957 +++ linux-2.6.22.15-vs2.3.0.29.1/include/linux/vs_time.h        2007-12-09 06:44:22.000000000 -0500
16958 @@ -0,0 +1,19 @@
16959 +#ifndef _VS_TIME_H
16960 +#define _VS_TIME_H
16961 +
16962 +
16963 +/* time faking stuff */
16964 +
16965 +#ifdef CONFIG_VSERVER_VTIME
16966 +
16967 +extern void vx_gettimeofday(struct timeval *tv);
16968 +extern int vx_settimeofday(struct timespec *ts);
16969 +
16970 +#else
16971 +#define        vx_gettimeofday(t)      do_gettimeofday(t)
16972 +#define        vx_settimeofday(t)      do_settimeofday(t)
16973 +#endif
16974 +
16975 +#else
16976 +#warning duplicate inclusion
16977 +#endif
16978 diff -Nurp linux-2.6.22.15/include/net/addrconf.h linux-2.6.22.15-vs2.3.0.29.1/include/net/addrconf.h
16979 --- linux-2.6.22.15/include/net/addrconf.h      2007-07-21 18:00:24.000000000 -0400
16980 +++ linux-2.6.22.15-vs2.3.0.29.1/include/net/addrconf.h 2007-12-09 06:44:22.000000000 -0500
16981 @@ -69,10 +69,12 @@ extern struct inet6_ifaddr *        ipv6_get_if
16982                                                 int strict);
16983  extern int                     ipv6_get_saddr(struct dst_entry *dst, 
16984                                                struct in6_addr *daddr,
16985 -                                              struct in6_addr *saddr);
16986 +                                              struct in6_addr *saddr,
16987 +                                              struct nx_info *nxi);
16988  extern int                     ipv6_dev_get_saddr(struct net_device *dev, 
16989                                                struct in6_addr *daddr,
16990 -                                              struct in6_addr *saddr);
16991 +                                              struct in6_addr *saddr,
16992 +                                              struct nx_info *nxi);
16993  extern int                     ipv6_get_lladdr(struct net_device *dev,
16994                                                 struct in6_addr *addr,
16995                                                 unsigned char banned_flags);
16996 diff -Nurp linux-2.6.22.15/include/net/af_unix.h linux-2.6.22.15-vs2.3.0.29.1/include/net/af_unix.h
16997 --- linux-2.6.22.15/include/net/af_unix.h       2007-07-21 18:00:24.000000000 -0400
16998 +++ linux-2.6.22.15-vs2.3.0.29.1/include/net/af_unix.h  2007-12-09 06:44:22.000000000 -0500
16999 @@ -4,6 +4,7 @@
17000  #include <linux/socket.h>
17001  #include <linux/un.h>
17002  #include <linux/mutex.h>
17003 +#include <linux/vs_base.h>
17004  #include <net/sock.h>
17005  
17006  extern void unix_inflight(struct file *fp);
17007 @@ -17,9 +18,9 @@ extern spinlock_t unix_table_lock;
17008  
17009  extern atomic_t unix_tot_inflight;
17010  
17011 -static inline struct sock *first_unix_socket(int *i)
17012 +static inline struct sock *next_unix_socket_table(int *i)
17013  {
17014 -       for (*i = 0; *i <= UNIX_HASH_SIZE; (*i)++) {
17015 +       for ((*i)++; *i <= UNIX_HASH_SIZE; (*i)++) {
17016                 if (!hlist_empty(&unix_socket_table[*i]))
17017                         return __sk_head(&unix_socket_table[*i]);
17018         }
17019 @@ -28,16 +29,19 @@ static inline struct sock *first_unix_so
17020  
17021  static inline struct sock *next_unix_socket(int *i, struct sock *s)
17022  {
17023 -       struct sock *next = sk_next(s);
17024 -       /* More in this chain? */
17025 -       if (next)
17026 -               return next;
17027 -       /* Look for next non-empty chain. */
17028 -       for ((*i)++; *i <= UNIX_HASH_SIZE; (*i)++) {
17029 -               if (!hlist_empty(&unix_socket_table[*i]))
17030 -                       return __sk_head(&unix_socket_table[*i]);
17031 -       }
17032 -       return NULL;
17033 +       do {
17034 +               if (s)
17035 +                       s = sk_next(s);
17036 +               if (!s)
17037 +                       s = next_unix_socket_table(i);
17038 +       } while (s && !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT));
17039 +       return s;
17040 +}
17041 +
17042 +static inline struct sock *first_unix_socket(int *i)
17043 +{
17044 +       *i = 0;
17045 +       return next_unix_socket(i, NULL);
17046  }
17047  
17048  #define forall_unix_sockets(i, s) \
17049 diff -Nurp linux-2.6.22.15/include/net/inet_timewait_sock.h linux-2.6.22.15-vs2.3.0.29.1/include/net/inet_timewait_sock.h
17050 --- linux-2.6.22.15/include/net/inet_timewait_sock.h    2007-07-21 17:58:53.000000000 -0400
17051 +++ linux-2.6.22.15-vs2.3.0.29.1/include/net/inet_timewait_sock.h       2007-12-09 06:44:22.000000000 -0500
17052 @@ -115,6 +115,10 @@ struct inet_timewait_sock {
17053  #define tw_refcnt              __tw_common.skc_refcnt
17054  #define tw_hash                        __tw_common.skc_hash
17055  #define tw_prot                        __tw_common.skc_prot
17056 +#define tw_xid         __tw_common.skc_xid
17057 +#define tw_vx_info             __tw_common.skc_vx_info
17058 +#define tw_nid         __tw_common.skc_nid
17059 +#define tw_nx_info             __tw_common.skc_nx_info
17060         volatile unsigned char  tw_substate;
17061         /* 3 bits hole, try to pack */
17062         unsigned char           tw_rcv_wscale;
17063 diff -Nurp linux-2.6.22.15/include/net/route.h linux-2.6.22.15-vs2.3.0.29.1/include/net/route.h
17064 --- linux-2.6.22.15/include/net/route.h 2007-07-21 17:58:53.000000000 -0400
17065 +++ linux-2.6.22.15-vs2.3.0.29.1/include/net/route.h    2007-12-09 06:44:22.000000000 -0500
17066 @@ -27,12 +27,16 @@
17067  #include <net/dst.h>
17068  #include <net/inetpeer.h>
17069  #include <net/flow.h>
17070 +#include <net/inet_sock.h>
17071  #include <linux/in_route.h>
17072  #include <linux/rtnetlink.h>
17073  #include <linux/route.h>
17074  #include <linux/ip.h>
17075  #include <linux/cache.h>
17076  #include <linux/security.h>
17077 +#include <linux/vs_base.h>
17078 +#include <linux/vs_inet.h>
17079 +#include <linux/in.h>
17080  
17081  #ifndef __KERNEL__
17082  #warning This file is not supposed to be used outside of kernel.
17083 @@ -143,6 +147,8 @@ static inline char rt_tos2priority(u8 to
17084         return ip_tos2prio[IPTOS_TOS(tos)>>1];
17085  }
17086  
17087 +extern int ip_v4_find_src(struct nx_info *, struct rtable **, struct flowi *);
17088 +
17089  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
17090                                    __be32 src, u32 tos, int oif, u8 protocol,
17091                                    __be16 sport, __be16 dport, struct sock *sk,
17092 @@ -158,7 +164,21 @@ static inline int ip_route_connect(struc
17093                                          .dport = dport } } };
17094  
17095         int err;
17096 -       if (!dst || !src) {
17097 +       struct nx_info *nx_info = current->nx_info;
17098 +
17099 +       if (sk)
17100 +               nx_info = sk->sk_nx_info;
17101 +
17102 +       vxdprintk(VXD_CBIT(net, 4),
17103 +               "ip_route_connect(%p) %p,%p;%lx",
17104 +               sk, nx_info, sk->sk_socket,
17105 +               (sk->sk_socket?sk->sk_socket->flags:0));
17106 +
17107 +       err = ip_v4_find_src(nx_info, rp, &fl);
17108 +       if (err)
17109 +               return err;
17110 +
17111 +       if (!fl.fl4_dst || !fl.fl4_src) {
17112                 err = __ip_route_output_key(rp, &fl);
17113                 if (err)
17114                         return err;
17115 diff -Nurp linux-2.6.22.15/include/net/sock.h linux-2.6.22.15-vs2.3.0.29.1/include/net/sock.h
17116 --- linux-2.6.22.15/include/net/sock.h  2007-07-21 18:00:24.000000000 -0400
17117 +++ linux-2.6.22.15-vs2.3.0.29.1/include/net/sock.h     2007-12-09 06:44:22.000000000 -0500
17118 @@ -119,6 +119,10 @@ struct sock_common {
17119         atomic_t                skc_refcnt;
17120         unsigned int            skc_hash;
17121         struct proto            *skc_prot;
17122 +       xid_t                   skc_xid;
17123 +       struct vx_info          *skc_vx_info;
17124 +       nid_t                   skc_nid;
17125 +       struct nx_info          *skc_nx_info;
17126  };
17127  
17128  /**
17129 @@ -195,6 +199,10 @@ struct sock {
17130  #define sk_refcnt              __sk_common.skc_refcnt
17131  #define sk_hash                        __sk_common.skc_hash
17132  #define sk_prot                        __sk_common.skc_prot
17133 +#define sk_xid                 __sk_common.skc_xid
17134 +#define sk_vx_info             __sk_common.skc_vx_info
17135 +#define sk_nid                 __sk_common.skc_nid
17136 +#define sk_nx_info             __sk_common.skc_nx_info
17137         unsigned char           sk_shutdown : 2,
17138                                 sk_no_check : 2,
17139                                 sk_userlocks : 4;
17140 diff -Nurp linux-2.6.22.15/init/main.c linux-2.6.22.15-vs2.3.0.29.1/init/main.c
17141 --- linux-2.6.22.15/init/main.c 2007-07-21 18:00:24.000000000 -0400
17142 +++ linux-2.6.22.15-vs2.3.0.29.1/init/main.c    2007-12-09 06:44:22.000000000 -0500
17143 @@ -55,6 +55,7 @@
17144  #include <linux/pid_namespace.h>
17145  #include <linux/device.h>
17146  #include <linux/kthread.h>
17147 +#include <linux/vserver/percpu.h>
17148  
17149  #include <asm/io.h>
17150  #include <asm/bugs.h>
17151 @@ -364,12 +365,14 @@ EXPORT_SYMBOL(__per_cpu_offset);
17152  
17153  static void __init setup_per_cpu_areas(void)
17154  {
17155 -       unsigned long size, i;
17156 +       unsigned long size, vspc, i;
17157         char *ptr;
17158         unsigned long nr_possible_cpus = num_possible_cpus();
17159  
17160 +       vspc = PERCPU_PERCTX * CONFIG_VSERVER_CONTEXTS;
17161 +
17162         /* Copy section for each CPU (we discard the original) */
17163 -       size = ALIGN(PERCPU_ENOUGH_ROOM, PAGE_SIZE);
17164 +       size = ALIGN(PERCPU_ENOUGH_ROOM + vspc, PAGE_SIZE);
17165         ptr = alloc_bootmem_pages(size * nr_possible_cpus);
17166  
17167         for_each_possible_cpu(i) {
17168 diff -Nurp linux-2.6.22.15/ipc/mqueue.c linux-2.6.22.15-vs2.3.0.29.1/ipc/mqueue.c
17169 --- linux-2.6.22.15/ipc/mqueue.c        2007-12-09 06:43:53.000000000 -0500
17170 +++ linux-2.6.22.15-vs2.3.0.29.1/ipc/mqueue.c   2007-12-09 06:44:22.000000000 -0500
17171 @@ -29,6 +29,8 @@
17172  #include <linux/audit.h>
17173  #include <linux/signal.h>
17174  #include <linux/mutex.h>
17175 +#include <linux/vs_context.h>
17176 +#include <linux/vs_limit.h>
17177  
17178  #include <net/sock.h>
17179  #include "util.h"
17180 @@ -151,17 +153,20 @@ static struct inode *mqueue_get_inode(st
17181                         spin_lock(&mq_lock);
17182                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
17183                             u->mq_bytes + mq_bytes >
17184 -                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur) {
17185 +                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur ||
17186 +                           !vx_ipcmsg_avail(p->vx_info, mq_bytes)) {
17187                                 spin_unlock(&mq_lock);
17188                                 goto out_inode;
17189                         }
17190                         u->mq_bytes += mq_bytes;
17191 +                       vx_ipcmsg_add(p->vx_info, u, mq_bytes);
17192                         spin_unlock(&mq_lock);
17193  
17194                         info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
17195                         if (!info->messages) {
17196                                 spin_lock(&mq_lock);
17197                                 u->mq_bytes -= mq_bytes;
17198 +                               vx_ipcmsg_sub(p->vx_info, u, mq_bytes);
17199                                 spin_unlock(&mq_lock);
17200                                 goto out_inode;
17201                         }
17202 @@ -257,10 +262,14 @@ static void mqueue_delete_inode(struct i
17203                    (info->attr.mq_maxmsg * info->attr.mq_msgsize));
17204         user = info->user;
17205         if (user) {
17206 +               struct vx_info *vxi = lookup_vx_info(user->xid);
17207 +
17208                 spin_lock(&mq_lock);
17209                 user->mq_bytes -= mq_bytes;
17210 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
17211                 queues_count--;
17212                 spin_unlock(&mq_lock);
17213 +               put_vx_info(vxi);
17214                 free_uid(user);
17215         }
17216  }
17217 @@ -748,7 +757,7 @@ asmlinkage long sys_mq_unlink(const char
17218         if (inode)
17219                 atomic_inc(&inode->i_count);
17220  
17221 -       err = vfs_unlink(dentry->d_parent->d_inode, dentry);
17222 +       err = vfs_unlink(dentry->d_parent->d_inode, dentry, NULL);
17223  out_err:
17224         dput(dentry);
17225  
17226 diff -Nurp linux-2.6.22.15/ipc/msg.c linux-2.6.22.15-vs2.3.0.29.1/ipc/msg.c
17227 --- linux-2.6.22.15/ipc/msg.c   2007-05-04 09:58:24.000000000 -0400
17228 +++ linux-2.6.22.15-vs2.3.0.29.1/ipc/msg.c      2007-12-09 06:44:22.000000000 -0500
17229 @@ -36,6 +36,7 @@
17230  #include <linux/seq_file.h>
17231  #include <linux/mutex.h>
17232  #include <linux/nsproxy.h>
17233 +#include <linux/vs_base.h>
17234  
17235  #include <asm/current.h>
17236  #include <asm/uaccess.h>
17237 @@ -149,6 +150,7 @@ static int newque (struct ipc_namespace 
17238  
17239         msq->q_perm.mode = msgflg & S_IRWXUGO;
17240         msq->q_perm.key = key;
17241 +       msq->q_perm.xid = vx_current_xid();
17242  
17243         msq->q_perm.security = NULL;
17244         retval = security_msg_queue_alloc(msq);
17245 diff -Nurp linux-2.6.22.15/ipc/sem.c linux-2.6.22.15-vs2.3.0.29.1/ipc/sem.c
17246 --- linux-2.6.22.15/ipc/sem.c   2007-07-21 18:00:24.000000000 -0400
17247 +++ linux-2.6.22.15-vs2.3.0.29.1/ipc/sem.c      2007-12-09 06:44:22.000000000 -0500
17248 @@ -82,6 +82,8 @@
17249  #include <linux/seq_file.h>
17250  #include <linux/mutex.h>
17251  #include <linux/nsproxy.h>
17252 +#include <linux/vs_base.h>
17253 +#include <linux/vs_limit.h>
17254  
17255  #include <asm/uaccess.h>
17256  #include "util.h"
17257 @@ -229,6 +231,7 @@ static int newary (struct ipc_namespace 
17258  
17259         sma->sem_perm.mode = (semflg & S_IRWXUGO);
17260         sma->sem_perm.key = key;
17261 +       sma->sem_perm.xid = vx_current_xid();
17262  
17263         sma->sem_perm.security = NULL;
17264         retval = security_sem_alloc(sma);
17265 @@ -244,6 +247,9 @@ static int newary (struct ipc_namespace 
17266                 return -ENOSPC;
17267         }
17268         ns->used_sems += nsems;
17269 +       /* FIXME: obsoleted? */
17270 +       vx_semary_inc(sma);
17271 +       vx_nsems_add(sma, nsems);
17272  
17273         sma->sem_id = sem_buildid(ns, id, sma->sem_perm.seq);
17274         sma->sem_base = (struct sem *) &sma[1];
17275 @@ -525,6 +531,9 @@ static void freeary (struct ipc_namespac
17276         sem_unlock(sma);
17277  
17278         ns->used_sems -= sma->sem_nsems;
17279 +       /* FIXME: obsoleted? */
17280 +       vx_nsems_sub(sma, sma->sem_nsems);
17281 +       vx_semary_dec(sma);
17282         size = sizeof (*sma) + sma->sem_nsems * sizeof (struct sem);
17283         security_sem_free(sma);
17284         ipc_rcu_putref(sma);
17285 diff -Nurp linux-2.6.22.15/ipc/shm.c linux-2.6.22.15-vs2.3.0.29.1/ipc/shm.c
17286 --- linux-2.6.22.15/ipc/shm.c   2007-08-11 21:54:37.000000000 -0400
17287 +++ linux-2.6.22.15-vs2.3.0.29.1/ipc/shm.c      2007-12-09 06:44:22.000000000 -0500
17288 @@ -38,6 +38,8 @@
17289  #include <linux/mutex.h>
17290  #include <linux/nsproxy.h>
17291  #include <linux/mount.h>
17292 +#include <linux/vs_context.h>
17293 +#include <linux/vs_limit.h>
17294  
17295  #include <asm/uaccess.h>
17296  
17297 @@ -185,7 +187,12 @@ static void shm_open(struct vm_area_stru
17298   */
17299  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
17300  {
17301 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
17302 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
17303 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
17304 +
17305 +       vx_ipcshm_sub(vxi, shp, numpages);
17306 +       ns->shm_tot -= numpages;
17307 +
17308         shm_rmid(ns, shp->id);
17309         shm_unlock(shp);
17310         if (!is_file_hugepages(shp->shm_file))
17311 @@ -195,6 +202,7 @@ static void shm_destroy(struct ipc_names
17312                                                 shp->mlock_user);
17313         fput (shp->shm_file);
17314         security_shm_free(shp);
17315 +       put_vx_info(vxi);
17316         ipc_rcu_putref(shp);
17317  }
17318  
17319 @@ -351,11 +359,15 @@ static int newseg (struct ipc_namespace 
17320         if (ns->shm_tot + numpages > ns->shm_ctlall)
17321                 return -ENOSPC;
17322  
17323 +       if (!vx_ipcshm_avail(current->vx_info, numpages))
17324 +               return -ENOSPC;
17325 +
17326         shp = ipc_rcu_alloc(sizeof(*shp));
17327         if (!shp)
17328                 return -ENOMEM;
17329  
17330         shp->shm_perm.key = key;
17331 +       shp->shm_perm.xid = vx_current_xid();
17332         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
17333         shp->mlock_user = NULL;
17334  
17335 @@ -406,6 +418,7 @@ static int newseg (struct ipc_namespace 
17336         file->f_dentry->d_inode->i_ino = shp->id;
17337  
17338         ns->shm_tot += numpages;
17339 +       vx_ipcshm_add(current->vx_info, key, numpages);
17340         shm_unlock(shp);
17341         return shp->id;
17342  
17343 diff -Nurp linux-2.6.22.15/ipc/util.c linux-2.6.22.15-vs2.3.0.29.1/ipc/util.c
17344 --- linux-2.6.22.15/ipc/util.c  2007-07-21 18:00:24.000000000 -0400
17345 +++ linux-2.6.22.15-vs2.3.0.29.1/ipc/util.c     2007-12-09 06:44:22.000000000 -0500
17346 @@ -32,6 +32,8 @@
17347  #include <linux/proc_fs.h>
17348  #include <linux/audit.h>
17349  #include <linux/nsproxy.h>
17350 +#include <linux/vs_base.h>
17351 +#include <linux/vserver/global.h>
17352  
17353  #include <asm/unistd.h>
17354  
17355 @@ -72,6 +74,7 @@ static struct ipc_namespace *clone_ipc_n
17356                 goto err_shm;
17357  
17358         kref_init(&ns->kref);
17359 +       atomic_inc(&vs_global_ipc_ns);
17360         return ns;
17361  
17362  err_shm:
17363 @@ -108,6 +111,7 @@ void free_ipc_ns(struct kref *kref)
17364         sem_exit_ns(ns);
17365         msg_exit_ns(ns);
17366         shm_exit_ns(ns);
17367 +       atomic_dec(&vs_global_ipc_ns);
17368         kfree(ns);
17369  }
17370  #else
17371 diff -Nurp linux-2.6.22.15/kernel/capability.c linux-2.6.22.15-vs2.3.0.29.1/kernel/capability.c
17372 --- linux-2.6.22.15/kernel/capability.c 2007-07-21 17:58:53.000000000 -0400
17373 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/capability.c    2007-12-09 06:44:22.000000000 -0500
17374 @@ -12,6 +12,7 @@
17375  #include <linux/module.h>
17376  #include <linux/security.h>
17377  #include <linux/syscalls.h>
17378 +#include <linux/vs_context.h>
17379  #include <asm/uaccess.h>
17380  
17381  unsigned securebits = SECUREBITS_DEFAULT; /* systemwide security settings */
17382 @@ -103,6 +104,8 @@ static inline int cap_set_pg(int pgrp_nr
17383  
17384         pgrp = find_pid(pgrp_nr);
17385         do_each_pid_task(pgrp, PIDTYPE_PGID, g) {
17386 +               if (!vx_check(g->xid, VS_ADMIN_P | VS_IDENT))
17387 +                       continue;
17388                 target = g;
17389                 while_each_thread(g, target) {
17390                         if (!security_capset_check(target, effective,
17391 @@ -246,8 +249,12 @@ int __capable(struct task_struct *t, int
17392  }
17393  EXPORT_SYMBOL(__capable);
17394  
17395 +#include <linux/vserver/base.h>
17396  int capable(int cap)
17397  {
17398 +       /* here for now so we don't require task locking */
17399 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
17400 +               return 0;
17401         return __capable(current, cap);
17402  }
17403  EXPORT_SYMBOL(capable);
17404 diff -Nurp linux-2.6.22.15/kernel/compat.c linux-2.6.22.15-vs2.3.0.29.1/kernel/compat.c
17405 --- linux-2.6.22.15/kernel/compat.c     2007-07-21 18:00:24.000000000 -0400
17406 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/compat.c        2007-12-09 06:44:22.000000000 -0500
17407 @@ -846,7 +846,7 @@ asmlinkage long compat_sys_time(compat_t
17408         compat_time_t i;
17409         struct timeval tv;
17410  
17411 -       do_gettimeofday(&tv);
17412 +       vx_gettimeofday(&tv);
17413         i = tv.tv_sec;
17414  
17415         if (tloc) {
17416 @@ -870,7 +870,7 @@ asmlinkage long compat_sys_stime(compat_
17417         if (err)
17418                 return err;
17419  
17420 -       do_settimeofday(&tv);
17421 +       vx_settimeofday(&tv);
17422         return 0;
17423  }
17424  
17425 diff -Nurp linux-2.6.22.15/kernel/exit.c linux-2.6.22.15-vs2.3.0.29.1/kernel/exit.c
17426 --- linux-2.6.22.15/kernel/exit.c       2007-12-09 06:43:49.000000000 -0500
17427 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/exit.c  2007-12-09 06:44:23.000000000 -0500
17428 @@ -44,6 +44,11 @@
17429  #include <linux/resource.h>
17430  #include <linux/blkdev.h>
17431  #include <linux/task_io_accounting_ops.h>
17432 +#include <linux/vs_limit.h>
17433 +#include <linux/vs_context.h>
17434 +#include <linux/vs_network.h>
17435 +#include <linux/vs_pid.h>
17436 +#include <linux/vserver/global.h>
17437  
17438  #include <asm/uaccess.h>
17439  #include <asm/unistd.h>
17440 @@ -443,9 +448,11 @@ static void close_files(struct files_str
17441                                         filp_close(file, files);
17442                                         cond_resched();
17443                                 }
17444 +                               vx_openfd_dec(i);
17445                         }
17446                         i++;
17447                         set >>= 1;
17448 +                       cond_resched();
17449                 }
17450         }
17451  }
17452 @@ -525,6 +532,7 @@ static inline void __put_fs_struct(struc
17453                         dput(fs->altroot);
17454                         mntput(fs->altrootmnt);
17455                 }
17456 +               atomic_dec(&vs_global_fs);
17457                 kmem_cache_free(fs_cachep, fs);
17458         }
17459  }
17460 @@ -596,6 +604,14 @@ static void exit_mm(struct task_struct *
17461  static inline void
17462  choose_new_parent(struct task_struct *p, struct task_struct *reaper)
17463  {
17464 +       /* check for reaper context */
17465 +       vxwprintk((p->xid != reaper->xid) && (reaper != child_reaper(p)),
17466 +               "rogue reaper: %p[%d,#%u] <> %p[%d,#%u]",
17467 +               p, p->pid, p->xid, reaper, reaper->pid, reaper->xid);
17468 +
17469 +       if (p == reaper)
17470 +               reaper = vx_child_reaper(p);
17471 +
17472         /*
17473          * Make sure we're not reparenting to ourselves and that
17474          * the parent is not a zombie.
17475 @@ -687,7 +703,7 @@ forget_original_parent(struct task_struc
17476         do {
17477                 reaper = next_thread(reaper);
17478                 if (reaper == father) {
17479 -                       reaper = child_reaper(father);
17480 +                       reaper = vx_child_reaper(father);
17481                         break;
17482                 }
17483         } while (reaper->exit_state);
17484 @@ -964,6 +980,8 @@ fastcall NORET_TYPE void do_exit(long co
17485         tsk->exit_code = code;
17486         proc_exit_connector(tsk);
17487         exit_task_namespaces(tsk);
17488 +       /* needs to stay before exit_notify() */
17489 +       exit_vx_info_early(tsk, code);
17490         exit_notify(tsk);
17491  #ifdef CONFIG_NUMA
17492         mpol_free(tsk->mempolicy);
17493 @@ -994,6 +1012,10 @@ fastcall NORET_TYPE void do_exit(long co
17494         if (tsk->splice_pipe)
17495                 __free_pipe_info(tsk->splice_pipe);
17496  
17497 +       /* needs to stay after exit_notify() */
17498 +       exit_vx_info(tsk, code);
17499 +       exit_nx_info(tsk);
17500 +
17501         preempt_disable();
17502         /* causes final put_task_struct in finish_task_switch(). */
17503         tsk->state = TASK_DEAD;
17504 diff -Nurp linux-2.6.22.15/kernel/fork.c linux-2.6.22.15-vs2.3.0.29.1/kernel/fork.c
17505 --- linux-2.6.22.15/kernel/fork.c       2007-07-21 18:00:24.000000000 -0400
17506 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/fork.c  2007-12-09 06:44:23.000000000 -0500
17507 @@ -49,6 +49,11 @@
17508  #include <linux/delayacct.h>
17509  #include <linux/taskstats_kern.h>
17510  #include <linux/random.h>
17511 +#include <linux/vs_context.h>
17512 +#include <linux/vs_network.h>
17513 +#include <linux/vs_limit.h>
17514 +#include <linux/vs_memory.h>
17515 +#include <linux/vserver/global.h>
17516  
17517  #include <asm/pgtable.h>
17518  #include <asm/pgalloc.h>
17519 @@ -108,6 +113,8 @@ void free_task(struct task_struct *tsk)
17520  {
17521         free_thread_info(tsk->stack);
17522         rt_mutex_debug_task_free(tsk);
17523 +       clr_vx_info(&tsk->vx_info);
17524 +       clr_nx_info(&tsk->nx_info);
17525         free_task_struct(tsk);
17526  }
17527  EXPORT_SYMBOL(free_task);
17528 @@ -215,6 +222,8 @@ static inline int dup_mmap(struct mm_str
17529         mm->free_area_cache = oldmm->mmap_base;
17530         mm->cached_hole_size = ~0UL;
17531         mm->map_count = 0;
17532 +       __set_mm_counter(mm, file_rss, 0);
17533 +       __set_mm_counter(mm, anon_rss, 0);
17534         cpus_clear(mm->cpu_vm_mask);
17535         mm->mm_rb = RB_ROOT;
17536         rb_link = &mm->mm_rb.rb_node;
17537 @@ -226,7 +235,7 @@ static inline int dup_mmap(struct mm_str
17538  
17539                 if (mpnt->vm_flags & VM_DONTCOPY) {
17540                         long pages = vma_pages(mpnt);
17541 -                       mm->total_vm -= pages;
17542 +                       vx_vmpages_sub(mm, pages);
17543                         vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
17544                                                                 -pages);
17545                         continue;
17546 @@ -327,7 +336,7 @@ static inline void mm_free_pgd(struct mm
17547  
17548  #include <linux/init_task.h>
17549  
17550 -static struct mm_struct * mm_init(struct mm_struct * mm)
17551 +static struct mm_struct * mm_init(struct mm_struct * mm, struct vx_info *vxi)
17552  {
17553         atomic_set(&mm->mm_users, 1);
17554         atomic_set(&mm->mm_count, 1);
17555 @@ -335,8 +344,8 @@ static struct mm_struct * mm_init(struct
17556         INIT_LIST_HEAD(&mm->mmlist);
17557         mm->core_waiters = 0;
17558         mm->nr_ptes = 0;
17559 -       set_mm_counter(mm, file_rss, 0);
17560 -       set_mm_counter(mm, anon_rss, 0);
17561 +       __set_mm_counter(mm, file_rss, 0);
17562 +       __set_mm_counter(mm, anon_rss, 0);
17563         spin_lock_init(&mm->page_table_lock);
17564         rwlock_init(&mm->ioctx_list_lock);
17565         mm->ioctx_list = NULL;
17566 @@ -345,6 +354,7 @@ static struct mm_struct * mm_init(struct
17567  
17568         if (likely(!mm_alloc_pgd(mm))) {
17569                 mm->def_flags = 0;
17570 +               set_vx_info(&mm->mm_vx_info, vxi);
17571                 return mm;
17572         }
17573         free_mm(mm);
17574 @@ -361,7 +371,7 @@ struct mm_struct * mm_alloc(void)
17575         mm = allocate_mm();
17576         if (mm) {
17577                 memset(mm, 0, sizeof(*mm));
17578 -               mm = mm_init(mm);
17579 +               mm = mm_init(mm, current->vx_info);
17580         }
17581         return mm;
17582  }
17583 @@ -376,6 +386,7 @@ void fastcall __mmdrop(struct mm_struct 
17584         BUG_ON(mm == &init_mm);
17585         mm_free_pgd(mm);
17586         destroy_context(mm);
17587 +       clr_vx_info(&mm->mm_vx_info);
17588         free_mm(mm);
17589  }
17590  
17591 @@ -490,12 +501,13 @@ static struct mm_struct *dup_mm(struct t
17592                 goto fail_nomem;
17593  
17594         memcpy(mm, oldmm, sizeof(*mm));
17595 +       mm->mm_vx_info = NULL;
17596  
17597         /* Initializing for Swap token stuff */
17598         mm->token_priority = 0;
17599         mm->last_interval = 0;
17600  
17601 -       if (!mm_init(mm))
17602 +       if (!mm_init(mm, oldmm->mm_vx_info))
17603                 goto fail_nomem;
17604  
17605         if (init_new_context(tsk, mm))
17606 @@ -521,6 +533,7 @@ fail_nocontext:
17607          * If init_new_context() failed, we cannot use mmput() to free the mm
17608          * because it calls destroy_context()
17609          */
17610 +       clr_vx_info(&mm->mm_vx_info);
17611         mm_free_pgd(mm);
17612         free_mm(mm);
17613         return NULL;
17614 @@ -591,6 +604,7 @@ static inline struct fs_struct *__copy_f
17615                         fs->altroot = NULL;
17616                 }
17617                 read_unlock(&old->lock);
17618 +               atomic_inc(&vs_global_fs);
17619         }
17620         return fs;
17621  }
17622 @@ -709,6 +723,8 @@ static struct files_struct *dup_fd(struc
17623                 struct file *f = *old_fds++;
17624                 if (f) {
17625                         get_file(f);
17626 +                       /* TODO: sum it first for check and performance */
17627 +                       vx_openfd_inc(open_files - i);
17628                 } else {
17629                         /*
17630                          * The fd may be claimed in the fd bitmap but not yet
17631 @@ -961,6 +977,8 @@ static struct task_struct *copy_process(
17632  {
17633         int retval;
17634         struct task_struct *p = NULL;
17635 +       struct vx_info *vxi;
17636 +       struct nx_info *nxi;
17637  
17638         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
17639                 return ERR_PTR(-EINVAL);
17640 @@ -995,12 +1013,30 @@ static struct task_struct *copy_process(
17641         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
17642         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
17643  #endif
17644 +       init_vx_info(&p->vx_info, current->vx_info);
17645 +       init_nx_info(&p->nx_info, current->nx_info);
17646 +
17647 +       /* check vserver memory */
17648 +       if (p->mm && !(clone_flags & CLONE_VM)) {
17649 +               if (vx_vmpages_avail(p->mm, p->mm->total_vm))
17650 +                       vx_pages_add(p->vx_info, RLIMIT_AS, p->mm->total_vm);
17651 +               else
17652 +                       goto bad_fork_free;
17653 +       }
17654 +       if (p->mm && vx_flags(VXF_FORK_RSS, 0)) {
17655 +               if (!vx_rss_avail(p->mm, get_mm_counter(p->mm, file_rss)))
17656 +                       goto bad_fork_cleanup_vm;
17657 +       }
17658 +
17659         retval = -EAGAIN;
17660 +       if (!vx_nproc_avail(1))
17661 +               goto bad_fork_cleanup_vm;
17662 +
17663         if (atomic_read(&p->user->processes) >=
17664                         p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
17665                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
17666                                 p->user != &root_user)
17667 -                       goto bad_fork_free;
17668 +                       goto bad_fork_cleanup_vm;
17669         }
17670  
17671         atomic_inc(&p->user->__count);
17672 @@ -1265,6 +1301,18 @@ static struct task_struct *copy_process(
17673  
17674         total_forks++;
17675         spin_unlock(&current->sighand->siglock);
17676 +
17677 +       /* p is copy of current */
17678 +       vxi = p->vx_info;
17679 +       if (vxi) {
17680 +               claim_vx_info(vxi, p);
17681 +               atomic_inc(&vxi->cvirt.nr_threads);
17682 +               atomic_inc(&vxi->cvirt.total_forks);
17683 +               vx_nproc_inc(p);
17684 +       }
17685 +       nxi = p->nx_info;
17686 +       if (nxi)
17687 +               claim_nx_info(nxi, p);
17688         write_unlock_irq(&tasklist_lock);
17689         proc_fork_connector(p);
17690         return p;
17691 @@ -1306,6 +1354,9 @@ bad_fork_cleanup_count:
17692         put_group_info(p->group_info);
17693         atomic_dec(&p->user->processes);
17694         free_uid(p->user);
17695 +bad_fork_cleanup_vm:
17696 +       if (p->mm && !(clone_flags & CLONE_VM))
17697 +               vx_pages_sub(p->vx_info, RLIMIT_AS, p->mm->total_vm);
17698  bad_fork_free:
17699         free_task(p);
17700  fork_out:
17701 @@ -1367,6 +1418,15 @@ long do_fork(unsigned long clone_flags,
17702  
17703         if (!pid)
17704                 return -EAGAIN;
17705 +
17706 +       /* kernel threads are host only */
17707 +       if ((clone_flags & CLONE_KTHREAD) &&
17708 +               !vx_capable(CAP_SYS_ADMIN, VXC_KTHREAD)) {
17709 +               vxwprintk_task(1, "tried to spawn a kernel thread.");
17710 +               free_pid(pid);
17711 +               return -EPERM;
17712 +       }
17713 +
17714         nr = pid->nr;
17715         if (unlikely(current->ptrace)) {
17716                 trace = fork_traceflag (clone_flags);
17717 diff -Nurp linux-2.6.22.15/kernel/kthread.c linux-2.6.22.15-vs2.3.0.29.1/kernel/kthread.c
17718 --- linux-2.6.22.15/kernel/kthread.c    2007-07-21 18:00:24.000000000 -0400
17719 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/kthread.c       2007-12-09 06:44:23.000000000 -0500
17720 @@ -96,7 +96,7 @@ static void create_kthread(struct kthrea
17721         } else {
17722                 wait_for_completion(&create->started);
17723                 read_lock(&tasklist_lock);
17724 -               create->result = find_task_by_pid(pid);
17725 +               create->result = find_task_by_real_pid(pid);
17726                 read_unlock(&tasklist_lock);
17727         }
17728         complete(&create->done);
17729 diff -Nurp linux-2.6.22.15/kernel/Makefile linux-2.6.22.15-vs2.3.0.29.1/kernel/Makefile
17730 --- linux-2.6.22.15/kernel/Makefile     2007-07-21 18:00:24.000000000 -0400
17731 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/Makefile        2007-12-09 06:44:22.000000000 -0500
17732 @@ -10,6 +10,8 @@ obj-y     = sched.o fork.o exec_domain.o
17733             kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \
17734             hrtimer.o rwsem.o latency.o nsproxy.o srcu.o die_notifier.o
17735  
17736 +obj-y    += vserver/
17737 +
17738  obj-$(CONFIG_STACKTRACE) += stacktrace.o
17739  obj-y += time/
17740  obj-$(CONFIG_DEBUG_MUTEXES) += mutex-debug.o
17741 diff -Nurp linux-2.6.22.15/kernel/nsproxy.c linux-2.6.22.15-vs2.3.0.29.1/kernel/nsproxy.c
17742 --- linux-2.6.22.15/kernel/nsproxy.c    2007-07-21 18:00:25.000000000 -0400
17743 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/nsproxy.c       2007-12-09 06:44:23.000000000 -0500
17744 @@ -20,14 +20,11 @@
17745  #include <linux/mnt_namespace.h>
17746  #include <linux/utsname.h>
17747  #include <linux/pid_namespace.h>
17748 +#include <linux/vserver/global.h>
17749 +#include <linux/vserver/debug.h>
17750  
17751  struct nsproxy init_nsproxy = INIT_NSPROXY(init_nsproxy);
17752  
17753 -static inline void get_nsproxy(struct nsproxy *ns)
17754 -{
17755 -       atomic_inc(&ns->count);
17756 -}
17757 -
17758  void get_task_namespaces(struct task_struct *tsk)
17759  {
17760         struct nsproxy *ns = tsk->nsproxy;
17761 @@ -46,6 +43,9 @@ static inline struct nsproxy *clone_nspr
17762         ns = kmemdup(orig, sizeof(struct nsproxy), GFP_KERNEL);
17763         if (ns)
17764                 atomic_set(&ns->count, 1);
17765 +       vxdprintk(VXD_CBIT(space, 2), "clone_nsproxy(%p[%u] = %p[1]",
17766 +               orig, atomic_read(&orig->count), ns);
17767 +       atomic_inc(&vs_global_nsproxy);
17768         return ns;
17769  }
17770  
17771 @@ -54,28 +54,32 @@ static inline struct nsproxy *clone_nspr
17772   * Return the newly created nsproxy.  Do not attach this to the task,
17773   * leave it to the caller to do proper locking and attach it to task.
17774   */
17775 -static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
17776 +static struct nsproxy *unshare_namespaces(int flags, struct nsproxy *orig,
17777                         struct fs_struct *new_fs)
17778  {
17779         struct nsproxy *new_nsp;
17780  
17781 -       new_nsp = clone_nsproxy(tsk->nsproxy);
17782 +       vxdprintk(VXD_CBIT(space, 4),
17783 +               "unshare_namespaces(0x%08x,%p,%p)",
17784 +               flags, orig, new_fs);
17785 +
17786 +       new_nsp = clone_nsproxy(orig);
17787         if (!new_nsp)
17788                 return ERR_PTR(-ENOMEM);
17789  
17790 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
17791 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
17792         if (IS_ERR(new_nsp->mnt_ns))
17793                 goto out_ns;
17794  
17795 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
17796 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
17797         if (IS_ERR(new_nsp->uts_ns))
17798                 goto out_uts;
17799  
17800 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
17801 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
17802         if (IS_ERR(new_nsp->ipc_ns))
17803                 goto out_ipc;
17804  
17805 -       new_nsp->pid_ns = copy_pid_ns(flags, tsk->nsproxy->pid_ns);
17806 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
17807         if (IS_ERR(new_nsp->pid_ns))
17808                 goto out_pid;
17809  
17810 @@ -95,6 +99,33 @@ out_ns:
17811         return ERR_PTR(-ENOMEM);
17812  }
17813  
17814 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
17815 +                       struct fs_struct *new_fs)
17816 +{
17817 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
17818 +}
17819 +
17820 +/*
17821 + * copies the nsproxy, setting refcount to 1, and grabbing a
17822 + * reference to all contained namespaces.
17823 + */
17824 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
17825 +{
17826 +       struct nsproxy *ns = clone_nsproxy(orig);
17827 +
17828 +       if (ns) {
17829 +               if (ns->mnt_ns)
17830 +                       get_mnt_ns(ns->mnt_ns);
17831 +               if (ns->uts_ns)
17832 +                       get_uts_ns(ns->uts_ns);
17833 +               if (ns->ipc_ns)
17834 +                       get_ipc_ns(ns->ipc_ns);
17835 +               if (ns->pid_ns)
17836 +                       get_pid_ns(ns->pid_ns);
17837 +       }
17838 +       return ns;
17839 +}
17840 +
17841  /*
17842   * called from clone.  This now handles copy for nsproxy and all
17843   * namespaces therein.
17844 @@ -102,9 +133,12 @@ out_ns:
17845  int copy_namespaces(int flags, struct task_struct *tsk)
17846  {
17847         struct nsproxy *old_ns = tsk->nsproxy;
17848 -       struct nsproxy *new_ns;
17849 +       struct nsproxy *new_ns = NULL;
17850         int err = 0;
17851  
17852 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08x,%p[%p])",
17853 +               flags, tsk, old_ns);
17854 +
17855         if (!old_ns)
17856                 return 0;
17857  
17858 @@ -127,6 +161,9 @@ int copy_namespaces(int flags, struct ta
17859         tsk->nsproxy = new_ns;
17860  out:
17861         put_nsproxy(old_ns);
17862 +       vxdprintk(VXD_CBIT(space, 3),
17863 +               "copy_namespaces(0x%08x,%p[%p]) = %d [%p]",
17864 +               flags, tsk, old_ns, err, new_ns);
17865         return err;
17866  }
17867  
17868 @@ -140,6 +177,7 @@ void free_nsproxy(struct nsproxy *ns)
17869                 put_ipc_ns(ns->ipc_ns);
17870         if (ns->pid_ns)
17871                 put_pid_ns(ns->pid_ns);
17872 +       atomic_dec(&vs_global_nsproxy);
17873         kfree(ns);
17874  }
17875  
17876 @@ -152,6 +190,10 @@ int unshare_nsproxy_namespaces(unsigned 
17877  {
17878         int err = 0;
17879  
17880 +       vxdprintk(VXD_CBIT(space, 4),
17881 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
17882 +               unshare_flags, current->nsproxy);
17883 +
17884         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC)))
17885                 return 0;
17886  
17887 diff -Nurp linux-2.6.22.15/kernel/pid.c linux-2.6.22.15-vs2.3.0.29.1/kernel/pid.c
17888 --- linux-2.6.22.15/kernel/pid.c        2007-07-21 18:00:25.000000000 -0400
17889 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/pid.c   2007-12-09 06:44:23.000000000 -0500
17890 @@ -28,6 +28,7 @@
17891  #include <linux/hash.h>
17892  #include <linux/pid_namespace.h>
17893  #include <linux/init_task.h>
17894 +#include <linux/vs_pid.h>
17895  
17896  #define pid_hashfn(nr) hash_long((unsigned long)nr, pidhash_shift)
17897  static struct hlist_head *pid_hash;
17898 @@ -295,6 +296,9 @@ void fastcall transfer_pid(struct task_s
17899  struct task_struct * fastcall pid_task(struct pid *pid, enum pid_type type)
17900  {
17901         struct task_struct *result = NULL;
17902 +
17903 +       if (type == PIDTYPE_REALPID)
17904 +               type = PIDTYPE_PID;
17905         if (pid) {
17906                 struct hlist_node *first;
17907                 first = rcu_dereference(pid->tasks[type].first);
17908 @@ -309,7 +313,17 @@ struct task_struct * fastcall pid_task(s
17909   */
17910  struct task_struct *find_task_by_pid_type(int type, int nr)
17911  {
17912 -       return pid_task(find_pid(nr), type);
17913 +       struct task_struct *task;
17914 +
17915 +       if (type == PIDTYPE_PID)
17916 +               nr = vx_rmap_pid(nr);
17917 +
17918 +       task = pid_task(find_pid(nr), type);
17919 +       if (task && (type != PIDTYPE_REALPID) &&
17920 +               /* maybe VS_WATCH_P in the future? */
17921 +               !vx_check(task->xid, VS_WATCH|VS_IDENT))
17922 +               return NULL;
17923 +       return task;
17924  }
17925  
17926  EXPORT_SYMBOL(find_task_by_pid_type);
17927 diff -Nurp linux-2.6.22.15/kernel/posix-timers.c linux-2.6.22.15-vs2.3.0.29.1/kernel/posix-timers.c
17928 --- linux-2.6.22.15/kernel/posix-timers.c       2007-07-21 18:00:25.000000000 -0400
17929 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/posix-timers.c  2007-12-09 06:44:23.000000000 -0500
17930 @@ -47,6 +47,7 @@
17931  #include <linux/wait.h>
17932  #include <linux/workqueue.h>
17933  #include <linux/module.h>
17934 +#include <linux/vs_context.h>
17935  
17936  /*
17937   * Management arrays for POSIX timers.  Timers are kept in slab memory
17938 @@ -297,6 +298,12 @@ void do_schedule_next_timer(struct sigin
17939  
17940  int posix_timer_event(struct k_itimer *timr,int si_private)
17941  {
17942 +       struct vx_info_save vxis;
17943 +       struct vx_info *vxi;
17944 +       int ret;
17945 +
17946 +       vxi = task_get_vx_info(timr->it_process);
17947 +       enter_vx_info(vxi, &vxis);
17948         memset(&timr->sigq->info, 0, sizeof(siginfo_t));
17949         timr->sigq->info.si_sys_private = si_private;
17950         /* Send signal to the process that owns this timer.*/
17951 @@ -309,11 +316,11 @@ int posix_timer_event(struct k_itimer *t
17952  
17953         if (timr->it_sigev_notify & SIGEV_THREAD_ID) {
17954                 struct task_struct *leader;
17955 -               int ret = send_sigqueue(timr->it_sigev_signo, timr->sigq,
17956 -                                       timr->it_process);
17957  
17958 +               ret = send_sigqueue(timr->it_sigev_signo, timr->sigq,
17959 +                                   timr->it_process);
17960                 if (likely(ret >= 0))
17961 -                       return ret;
17962 +                       goto out;
17963  
17964                 timr->it_sigev_notify = SIGEV_SIGNAL;
17965                 leader = timr->it_process->group_leader;
17966 @@ -321,8 +328,12 @@ int posix_timer_event(struct k_itimer *t
17967                 timr->it_process = leader;
17968         }
17969  
17970 -       return send_group_sigqueue(timr->it_sigev_signo, timr->sigq,
17971 +       ret = send_group_sigqueue(timr->it_sigev_signo, timr->sigq,
17972                                    timr->it_process);
17973 +out:
17974 +       leave_vx_info(&vxis);
17975 +       put_vx_info(vxi);
17976 +       return ret;
17977  }
17978  EXPORT_SYMBOL_GPL(posix_timer_event);
17979  
17980 @@ -402,7 +413,7 @@ static struct task_struct * good_sigeven
17981         struct task_struct *rtn = current->group_leader;
17982  
17983         if ((event->sigev_notify & SIGEV_THREAD_ID ) &&
17984 -               (!(rtn = find_task_by_pid(event->sigev_notify_thread_id)) ||
17985 +               (!(rtn = find_task_by_real_pid(event->sigev_notify_thread_id)) ||
17986                  rtn->tgid != current->tgid ||
17987                  (event->sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_SIGNAL))
17988                 return NULL;
17989 diff -Nurp linux-2.6.22.15/kernel/printk.c linux-2.6.22.15-vs2.3.0.29.1/kernel/printk.c
17990 --- linux-2.6.22.15/kernel/printk.c     2007-07-21 18:00:25.000000000 -0400
17991 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/printk.c        2007-12-09 06:44:23.000000000 -0500
17992 @@ -31,6 +31,7 @@
17993  #include <linux/bootmem.h>
17994  #include <linux/syscalls.h>
17995  #include <linux/jiffies.h>
17996 +#include <linux/vs_cvirt.h>
17997  
17998  #include <asm/uaccess.h>
17999  
18000 @@ -182,18 +183,13 @@ int do_syslog(int type, char __user *buf
18001         unsigned long i, j, limit, count;
18002         int do_clear = 0;
18003         char c;
18004 -       int error = 0;
18005 +       int error;
18006  
18007         error = security_syslog(type);
18008         if (error)
18009                 return error;
18010  
18011 -       switch (type) {
18012 -       case 0:         /* Close log */
18013 -               break;
18014 -       case 1:         /* Open log */
18015 -               break;
18016 -       case 2:         /* Read from log */
18017 +       if ((type >= 2) && (type <= 4)) {
18018                 error = -EINVAL;
18019                 if (!buf || len < 0)
18020                         goto out;
18021 @@ -204,6 +200,16 @@ int do_syslog(int type, char __user *buf
18022                         error = -EFAULT;
18023                         goto out;
18024                 }
18025 +       }
18026 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
18027 +               return vx_do_syslog(type, buf, len);
18028 +
18029 +       switch (type) {
18030 +       case 0:         /* Close log */
18031 +               break;
18032 +       case 1:         /* Open log */
18033 +               break;
18034 +       case 2:         /* Read from log */
18035                 error = wait_event_interruptible(log_wait,
18036                                                         (log_start - log_end));
18037                 if (error)
18038 @@ -228,16 +234,6 @@ int do_syslog(int type, char __user *buf
18039                 do_clear = 1;
18040                 /* FALL THRU */
18041         case 3:         /* Read last kernel messages */
18042 -               error = -EINVAL;
18043 -               if (!buf || len < 0)
18044 -                       goto out;
18045 -               error = 0;
18046 -               if (!len)
18047 -                       goto out;
18048 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
18049 -                       error = -EFAULT;
18050 -                       goto out;
18051 -               }
18052                 count = len;
18053                 if (count > log_buf_len)
18054                         count = log_buf_len;
18055 diff -Nurp linux-2.6.22.15/kernel/ptrace.c linux-2.6.22.15-vs2.3.0.29.1/kernel/ptrace.c
18056 --- linux-2.6.22.15/kernel/ptrace.c     2007-07-21 18:00:25.000000000 -0400
18057 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/ptrace.c        2007-12-09 06:44:23.000000000 -0500
18058 @@ -19,6 +19,7 @@
18059  #include <linux/security.h>
18060  #include <linux/signal.h>
18061  #include <linux/audit.h>
18062 +#include <linux/vs_context.h>
18063  
18064  #include <asm/pgtable.h>
18065  #include <asm/uaccess.h>
18066 @@ -145,6 +146,11 @@ static int may_attach(struct task_struct
18067                 dumpable = task->mm->dumpable;
18068         if (!dumpable && !capable(CAP_SYS_PTRACE))
18069                 return -EPERM;
18070 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
18071 +               return -EPERM;
18072 +       if (!vx_check(task->xid, VS_IDENT) &&
18073 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
18074 +               return -EACCES;
18075  
18076         return security_ptrace(current, task);
18077  }
18078 @@ -471,6 +477,10 @@ asmlinkage long sys_ptrace(long request,
18079                 goto out;
18080         }
18081  
18082 +       ret = -EPERM;
18083 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
18084 +               goto out_put_task_struct;
18085 +
18086         if (request == PTRACE_ATTACH) {
18087                 ret = ptrace_attach(child);
18088                 goto out_put_task_struct;
18089 diff -Nurp linux-2.6.22.15/kernel/sched.c linux-2.6.22.15-vs2.3.0.29.1/kernel/sched.c
18090 --- linux-2.6.22.15/kernel/sched.c      2007-07-21 18:00:25.000000000 -0400
18091 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/sched.c 2007-12-09 06:44:23.000000000 -0500
18092 @@ -56,6 +56,8 @@
18093  
18094  #include <asm/tlb.h>
18095  #include <asm/unistd.h>
18096 +#include <linux/vs_sched.h>
18097 +#include <linux/vs_cvirt.h>
18098  
18099  /*
18100   * Scheduler clock - returns current time in nanosec units.
18101 @@ -281,6 +283,16 @@ struct rq {
18102         struct task_struct *migration_thread;
18103         struct list_head migration_queue;
18104  #endif
18105 +       unsigned long norm_time;
18106 +       unsigned long idle_time;
18107 +#ifdef CONFIG_VSERVER_IDLETIME
18108 +       int idle_skip;
18109 +#endif
18110 +#ifdef CONFIG_VSERVER_HARDCPU
18111 +       struct list_head hold_queue;
18112 +       unsigned long nr_onhold;
18113 +       int idle_tokens;
18114 +#endif
18115  
18116  #ifdef CONFIG_SCHEDSTATS
18117         /* latency stats */
18118 @@ -714,6 +726,7 @@ sched_info_switch(struct task_struct *pr
18119   */
18120  static void dequeue_task(struct task_struct *p, struct prio_array *array)
18121  {
18122 +       BUG_ON(p->state & TASK_ONHOLD);
18123         array->nr_active--;
18124         list_del(&p->run_list);
18125         if (list_empty(array->queue + p->prio))
18126 @@ -722,6 +735,7 @@ static void dequeue_task(struct task_str
18127  
18128  static void enqueue_task(struct task_struct *p, struct prio_array *array)
18129  {
18130 +       BUG_ON(p->state & TASK_ONHOLD);
18131         sched_info_queued(p);
18132         list_add_tail(&p->run_list, array->queue + p->prio);
18133         __set_bit(p->prio, array->bitmap);
18134 @@ -735,12 +749,14 @@ static void enqueue_task(struct task_str
18135   */
18136  static void requeue_task(struct task_struct *p, struct prio_array *array)
18137  {
18138 +       BUG_ON(p->state & TASK_ONHOLD);
18139         list_move_tail(&p->run_list, array->queue + p->prio);
18140  }
18141  
18142  static inline void
18143  enqueue_task_head(struct task_struct *p, struct prio_array *array)
18144  {
18145 +       BUG_ON(p->state & TASK_ONHOLD);
18146         list_add(&p->run_list, array->queue + p->prio);
18147         __set_bit(p->prio, array->bitmap);
18148         array->nr_active++;
18149 @@ -769,6 +785,10 @@ static inline int __normal_prio(struct t
18150         bonus = CURRENT_BONUS(p) - MAX_BONUS / 2;
18151  
18152         prio = p->static_prio - bonus;
18153 +
18154 +       /* adjust effective priority */
18155 +       prio = vx_adjust_prio(p, prio, MAX_USER_PRIO);
18156 +
18157         if (prio < MAX_RT_PRIO)
18158                 prio = MAX_RT_PRIO;
18159         if (prio > MAX_PRIO-1)
18160 @@ -878,6 +898,9 @@ static int effective_prio(struct task_st
18161         return p->prio;
18162  }
18163  
18164 +#include "sched_mon.h"
18165 +
18166 +
18167  /*
18168   * __activate_task - move a task to the runqueue.
18169   */
18170 @@ -887,6 +910,7 @@ static void __activate_task(struct task_
18171  
18172         if (batch_task(p))
18173                 target = rq->expired;
18174 +       vxm_activate_task(p, rq);
18175         enqueue_task(p, target);
18176         inc_nr_running(p, rq);
18177  }
18178 @@ -896,6 +920,7 @@ static void __activate_task(struct task_
18179   */
18180  static inline void __activate_idle_task(struct task_struct *p, struct rq *rq)
18181  {
18182 +       vxm_activate_idle(p, rq);
18183         enqueue_task_head(p, rq->active);
18184         inc_nr_running(p, rq);
18185  }
18186 @@ -1030,19 +1055,30 @@ static void activate_task(struct task_st
18187         }
18188         p->timestamp = now;
18189  out:
18190 +       vx_activate_task(p);
18191         __activate_task(p, rq);
18192  }
18193  
18194  /*
18195 - * deactivate_task - remove a task from the runqueue.
18196 + * __deactivate_task - remove a task from the runqueue.
18197   */
18198 -static void deactivate_task(struct task_struct *p, struct rq *rq)
18199 +static void __deactivate_task(struct task_struct *p, struct rq *rq)
18200  {
18201         dec_nr_running(p, rq);
18202         dequeue_task(p, p->array);
18203 +       vxm_deactivate_task(p, rq);
18204         p->array = NULL;
18205  }
18206  
18207 +static inline
18208 +void deactivate_task(struct task_struct *p, struct rq *rq)
18209 +{
18210 +       vx_deactivate_task(p);
18211 +       __deactivate_task(p, rq);
18212 +}
18213 +
18214 +#include "sched_hard.h"
18215 +
18216  /*
18217   * resched_task - mark a task 'to be rescheduled now'.
18218   *
18219 @@ -1129,6 +1165,7 @@ migrate_task(struct task_struct *p, int 
18220  {
18221         struct rq *rq = task_rq(p);
18222  
18223 +       vxm_migrate_task(p, rq, dest_cpu);
18224         /*
18225          * If the task is not on a runqueue (and not running), then
18226          * it is sufficient to simply update the task's cpu field.
18227 @@ -1518,6 +1555,12 @@ static int try_to_wake_up(struct task_st
18228  
18229         rq = task_rq_lock(p, &flags);
18230         old_state = p->state;
18231 +
18232 +       /* we need to unhold suspended tasks */
18233 +       if (old_state & TASK_ONHOLD) {
18234 +               vx_unhold_task(p, rq);
18235 +               old_state = p->state;
18236 +       }
18237         if (!(old_state & state))
18238                 goto out;
18239  
18240 @@ -1625,6 +1668,7 @@ out_activate:
18241  #endif /* CONFIG_SMP */
18242         if (old_state == TASK_UNINTERRUPTIBLE) {
18243                 rq->nr_uninterruptible--;
18244 +               vx_uninterruptible_dec(p);
18245                 /*
18246                  * Tasks on involuntary sleep don't earn
18247                  * sleep_avg beyond just interactive state.
18248 @@ -1676,7 +1720,7 @@ int fastcall wake_up_state(struct task_s
18249         return try_to_wake_up(p, state, 0);
18250  }
18251  
18252 -static void task_running_tick(struct rq *rq, struct task_struct *p);
18253 +static void task_running_tick(struct rq *rq, struct task_struct *p, int cpu);
18254  /*
18255   * Perform scheduler related setup for a newly forked process p.
18256   * p is forked by current.
18257 @@ -1737,7 +1781,7 @@ void fastcall sched_fork(struct task_str
18258                  * runqueue lock is not a problem.
18259                  */
18260                 current->time_slice = 1;
18261 -               task_running_tick(cpu_rq(cpu), current);
18262 +               task_running_tick(cpu_rq(cpu), current, cpu);
18263         }
18264         local_irq_enable();
18265         put_cpu();
18266 @@ -1772,6 +1816,7 @@ void fastcall wake_up_new_task(struct ta
18267  
18268         p->prio = effective_prio(p);
18269  
18270 +       vx_activate_task(p);
18271         if (likely(cpu == this_cpu)) {
18272                 if (!(clone_flags & CLONE_VM)) {
18273                         /*
18274 @@ -1783,6 +1828,7 @@ void fastcall wake_up_new_task(struct ta
18275                                 __activate_task(p, rq);
18276                         else {
18277                                 p->prio = current->prio;
18278 +                               BUG_ON(p->state & TASK_ONHOLD);
18279                                 p->normal_prio = current->normal_prio;
18280                                 list_add_tail(&p->run_list, &current->run_list);
18281                                 p->array = current->array;
18282 @@ -3351,13 +3397,16 @@ static inline int expired_starving(struc
18283  void account_user_time(struct task_struct *p, cputime_t cputime)
18284  {
18285         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
18286 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
18287         cputime64_t tmp;
18288 +       int nice = (TASK_NICE(p) > 0);
18289  
18290         p->utime = cputime_add(p->utime, cputime);
18291 +       vx_account_user(vxi, cputime, nice);
18292  
18293         /* Add user time to cpustat. */
18294         tmp = cputime_to_cputime64(cputime);
18295 -       if (TASK_NICE(p) > 0)
18296 +       if (nice)
18297                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
18298         else
18299                 cpustat->user = cputime64_add(cpustat->user, tmp);
18300 @@ -3373,10 +3422,12 @@ void account_system_time(struct task_str
18301                          cputime_t cputime)
18302  {
18303         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
18304 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
18305         struct rq *rq = this_rq();
18306         cputime64_t tmp;
18307  
18308         p->stime = cputime_add(p->stime, cputime);
18309 +       vx_account_system(vxi, cputime, (p == rq->idle));
18310  
18311         /* Add system time to cpustat. */
18312         tmp = cputime_to_cputime64(cputime);
18313 @@ -3415,7 +3466,7 @@ void account_steal_time(struct task_stru
18314                 cpustat->steal = cputime64_add(cpustat->steal, tmp);
18315  }
18316  
18317 -static void task_running_tick(struct rq *rq, struct task_struct *p)
18318 +static void task_running_tick(struct rq *rq, struct task_struct *p, int cpu)
18319  {
18320         if (p->array != rq->active) {
18321                 /* Task has expired but was not scheduled yet */
18322 @@ -3445,7 +3496,7 @@ static void task_running_tick(struct rq 
18323                 }
18324                 goto out_unlock;
18325         }
18326 -       if (!--p->time_slice) {
18327 +       if (vx_need_resched(p, --p->time_slice, cpu)) {
18328                 dequeue_task(p, rq->active);
18329                 set_tsk_need_resched(p);
18330                 p->prio = effective_prio(p);
18331 @@ -3506,9 +3557,12 @@ void scheduler_tick(void)
18332         struct rq *rq = cpu_rq(cpu);
18333  
18334         update_cpu_clock(p, rq, now);
18335 +       vxm_sync(now, cpu);
18336  
18337 -       if (!idle_at_tick)
18338 -               task_running_tick(rq, p);
18339 +       if (idle_at_tick)
18340 +               vx_idle_resched(rq);
18341 +       else
18342 +               task_running_tick(rq, p, cpu);
18343  #ifdef CONFIG_SMP
18344         update_load(rq);
18345         rq->idle_at_tick = idle_at_tick;
18346 @@ -3630,14 +3684,25 @@ need_resched_nonpreemptible:
18347                                 unlikely(signal_pending(prev))))
18348                         prev->state = TASK_RUNNING;
18349                 else {
18350 -                       if (prev->state == TASK_UNINTERRUPTIBLE)
18351 +                       if (prev->state == TASK_UNINTERRUPTIBLE) {
18352                                 rq->nr_uninterruptible++;
18353 +                               vx_uninterruptible_inc(prev);
18354 +                       }
18355                         deactivate_task(prev, rq);
18356                 }
18357         }
18358  
18359         cpu = smp_processor_id();
18360 +       vx_set_rq_time(rq, jiffies);
18361 +try_unhold:
18362 +       vx_try_unhold(rq, cpu);
18363 +pick_next:
18364 +
18365         if (unlikely(!rq->nr_running)) {
18366 +               /* can we skip idle time? */
18367 +               if (vx_try_skip(rq, cpu))
18368 +                       goto try_unhold;
18369 +
18370                 idle_balance(cpu, rq);
18371                 if (!rq->nr_running) {
18372                         next = rq->idle;
18373 @@ -3663,6 +3728,10 @@ need_resched_nonpreemptible:
18374         queue = array->queue + idx;
18375         next = list_entry(queue->next, struct task_struct, run_list);
18376  
18377 +       /* check before we schedule this context */
18378 +       if (!vx_schedule(next, rq, cpu))
18379 +               goto pick_next;
18380 +
18381         if (!rt_task(next) && interactive_sleep(next->sleep_type)) {
18382                 unsigned long long delta = now - next->timestamp;
18383                 if (unlikely((long long)(now - next->timestamp) < 0))
18384 @@ -4263,7 +4332,7 @@ asmlinkage long sys_nice(int increment)
18385                 nice = 19;
18386  
18387         if (increment < 0 && !can_nice(current, nice))
18388 -               return -EPERM;
18389 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
18390  
18391         retval = security_task_setnice(current, nice);
18392         if (retval)
18393 @@ -4435,6 +4504,7 @@ recheck:
18394         oldprio = p->prio;
18395         __setscheduler(p, policy, param->sched_priority);
18396         if (array) {
18397 +               vx_activate_task(p);
18398                 __activate_task(p, rq);
18399                 /*
18400                  * Reschedule if we are currently running on this runqueue and
18401 @@ -5188,6 +5258,7 @@ static int __migrate_task(struct task_st
18402                 p->timestamp = p->timestamp - rq_src->most_recent_timestamp
18403                                 + rq_dest->most_recent_timestamp;
18404                 deactivate_task(p, rq_src);
18405 +               vx_activate_task(p);
18406                 __activate_task(p, rq_dest);
18407                 if (TASK_PREEMPTS_CURR(p, rq_dest))
18408                         resched_task(rq_dest->curr);
18409 @@ -7058,7 +7129,10 @@ void __init sched_init(void)
18410                 INIT_LIST_HEAD(&rq->migration_queue);
18411  #endif
18412                 atomic_set(&rq->nr_iowait, 0);
18413 -
18414 +#ifdef CONFIG_VSERVER_HARDCPU
18415 +               INIT_LIST_HEAD(&rq->hold_queue);
18416 +               rq->nr_onhold = 0;
18417 +#endif
18418                 for (j = 0; j < 2; j++) {
18419                         array = rq->arrays + j;
18420                         for (k = 0; k < MAX_PRIO; k++) {
18421 @@ -7144,6 +7218,7 @@ void normalize_rt_tasks(void)
18422                         deactivate_task(p, task_rq(p));
18423                 __setscheduler(p, SCHED_NORMAL, 0);
18424                 if (array) {
18425 +                       vx_activate_task(p);
18426                         __activate_task(p, task_rq(p));
18427                         resched_task(rq->curr);
18428                 }
18429 diff -Nurp linux-2.6.22.15/kernel/sched_hard.h linux-2.6.22.15-vs2.3.0.29.1/kernel/sched_hard.h
18430 --- linux-2.6.22.15/kernel/sched_hard.h 1969-12-31 19:00:00.000000000 -0500
18431 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/sched_hard.h    2007-12-09 06:44:23.000000000 -0500
18432 @@ -0,0 +1,324 @@
18433 +
18434 +#ifdef CONFIG_VSERVER_IDLELIMIT
18435 +
18436 +/*
18437 + * vx_idle_resched - reschedule after maxidle
18438 + */
18439 +static inline
18440 +void vx_idle_resched(struct rq *rq)
18441 +{
18442 +       /* maybe have a better criterion for paused */
18443 +       if (!--rq->idle_tokens && !list_empty(&rq->hold_queue))
18444 +               set_need_resched();
18445 +}
18446 +
18447 +#else /* !CONFIG_VSERVER_IDLELIMIT */
18448 +
18449 +#define vx_idle_resched(rq)
18450 +
18451 +#endif /* CONFIG_VSERVER_IDLELIMIT */
18452 +
18453 +
18454 +
18455 +#ifdef CONFIG_VSERVER_IDLETIME
18456 +
18457 +#define vx_set_rq_min_skip(rq, min)            \
18458 +       (rq)->idle_skip = (min)
18459 +
18460 +#define vx_save_min_skip(ret, min, val)                \
18461 +       __vx_save_min_skip(ret, min, val)
18462 +
18463 +static inline
18464 +void __vx_save_min_skip(int ret, int *min, int val)
18465 +{
18466 +       if (ret > -2)
18467 +               return;
18468 +       if ((*min > val) || !*min)
18469 +               *min = val;
18470 +}
18471 +
18472 +static inline
18473 +int vx_try_skip(struct rq *rq, int cpu)
18474 +{
18475 +       /* artificially advance time */
18476 +       if (rq->idle_skip > 0) {
18477 +               vxdprintk(list_empty(&rq->hold_queue),
18478 +                       "hold queue empty on cpu %d", cpu);
18479 +               rq->idle_time += rq->idle_skip;
18480 +               vxm_idle_skip(rq, cpu);
18481 +               return 1;
18482 +       }
18483 +       return 0;
18484 +}
18485 +
18486 +#else /* !CONFIG_VSERVER_IDLETIME */
18487 +
18488 +#define vx_set_rq_min_skip(rq, min)            \
18489 +       ({ int dummy = (min); dummy; })
18490 +
18491 +#define vx_save_min_skip(ret, min, val)
18492 +
18493 +static inline
18494 +int vx_try_skip(struct rq *rq, int cpu)
18495 +{
18496 +       return 0;
18497 +}
18498 +
18499 +#endif /* CONFIG_VSERVER_IDLETIME */
18500 +
18501 +
18502 +
18503 +#ifdef CONFIG_VSERVER_HARDCPU
18504 +
18505 +#define vx_set_rq_max_idle(rq, max)            \
18506 +       (rq)->idle_tokens = (max)
18507 +
18508 +#define vx_save_max_idle(ret, min, val)                \
18509 +       __vx_save_max_idle(ret, min, val)
18510 +
18511 +static inline
18512 +void __vx_save_max_idle(int ret, int *min, int val)
18513 +{
18514 +       if (*min > val)
18515 +               *min = val;
18516 +}
18517 +
18518 +
18519 +/*
18520 + * vx_hold_task - put a task on the hold queue
18521 + */
18522 +static inline
18523 +void vx_hold_task(struct task_struct *p, struct rq *rq)
18524 +{
18525 +       __deactivate_task(p, rq);
18526 +       p->state |= TASK_ONHOLD;
18527 +       /* a new one on hold */
18528 +       rq->nr_onhold++;
18529 +       vxm_hold_task(p, rq);
18530 +       list_add_tail(&p->run_list, &rq->hold_queue);
18531 +}
18532 +
18533 +/*
18534 + * vx_unhold_task - put a task back to the runqueue
18535 + */
18536 +static inline
18537 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
18538 +{
18539 +       list_del(&p->run_list);
18540 +       /* one less waiting */
18541 +       rq->nr_onhold--;
18542 +       p->state &= ~TASK_ONHOLD;
18543 +       enqueue_task(p, rq->expired);
18544 +       inc_nr_running(p, rq);
18545 +       vxm_unhold_task(p, rq);
18546 +
18547 +       if (p->static_prio < rq->best_expired_prio)
18548 +               rq->best_expired_prio = p->static_prio;
18549 +}
18550 +
18551 +unsigned long nr_onhold(void)
18552 +{
18553 +       unsigned long i, sum = 0;
18554 +
18555 +       for_each_online_cpu(i)
18556 +               sum += cpu_rq(i)->nr_onhold;
18557 +
18558 +       return sum;
18559 +}
18560 +
18561 +
18562 +
18563 +static inline
18564 +int __vx_tokens_avail(struct _vx_sched_pc *sched_pc)
18565 +{
18566 +       return sched_pc->tokens;
18567 +}
18568 +
18569 +static inline
18570 +void __vx_consume_token(struct _vx_sched_pc *sched_pc)
18571 +{
18572 +       sched_pc->tokens--;
18573 +}
18574 +
18575 +static inline
18576 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
18577 +{
18578 +       struct vx_info *vxi = p->vx_info;
18579 +
18580 +       if (vx_info_flags(vxi, VXF_SCHED_HARD|VXF_SCHED_PRIO, 0)) {
18581 +               struct _vx_sched_pc *sched_pc =
18582 +                       &vx_per_cpu(vxi, sched_pc, cpu);
18583 +               int tokens;
18584 +
18585 +               /* maybe we can simplify that to decrement
18586 +                  the token counter unconditional? */
18587 +
18588 +               if ((tokens = __vx_tokens_avail(sched_pc)) > 0)
18589 +                       __vx_consume_token(sched_pc);
18590 +
18591 +               /* for tokens > 0, one token was consumed */
18592 +               if (tokens < 2)
18593 +                       slice = 0;
18594 +       }
18595 +       vxm_need_resched(p, slice, cpu);
18596 +       return (slice == 0);
18597 +}
18598 +
18599 +
18600 +#define vx_set_rq_time(rq, time) do {  \
18601 +       rq->norm_time = time;           \
18602 +} while (0)
18603 +
18604 +
18605 +static inline
18606 +void vx_try_unhold(struct rq *rq, int cpu)
18607 +{
18608 +       struct vx_info *vxi = NULL;
18609 +       struct list_head *l, *n;
18610 +       int maxidle = HZ;
18611 +       int minskip = 0;
18612 +
18613 +       /* nothing to do? what about pause? */
18614 +       if (list_empty(&rq->hold_queue))
18615 +               return;
18616 +
18617 +       list_for_each_safe(l, n, &rq->hold_queue) {
18618 +               int ret, delta_min[2];
18619 +               struct _vx_sched_pc *sched_pc;
18620 +               struct task_struct *p;
18621 +
18622 +               p = list_entry(l, struct task_struct, run_list);
18623 +               /* don't bother with same context */
18624 +               if (vxi == p->vx_info)
18625 +                       continue;
18626 +
18627 +               vxi = p->vx_info;
18628 +               /* ignore paused contexts */
18629 +               if (vx_info_flags(vxi, VXF_SCHED_PAUSE, 0))
18630 +                       continue;
18631 +
18632 +               sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
18633 +
18634 +               /* recalc tokens */
18635 +               vxm_sched_info(sched_pc, vxi, cpu);
18636 +               ret = vx_tokens_recalc(sched_pc,
18637 +                       &rq->norm_time, &rq->idle_time, delta_min);
18638 +               vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
18639 +
18640 +               if (ret > 0) {
18641 +                       /* we found a runable context */
18642 +                       vx_unhold_task(p, rq);
18643 +                       break;
18644 +               }
18645 +               vx_save_max_idle(ret, &maxidle, delta_min[0]);
18646 +               vx_save_min_skip(ret, &minskip, delta_min[1]);
18647 +       }
18648 +       vx_set_rq_max_idle(rq, maxidle);
18649 +       vx_set_rq_min_skip(rq, minskip);
18650 +       vxm_rq_max_min(rq, cpu);
18651 +}
18652 +
18653 +
18654 +static inline
18655 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
18656 +{
18657 +       struct vx_info *vxi = next->vx_info;
18658 +       struct _vx_sched_pc *sched_pc;
18659 +       int delta_min[2];
18660 +       int flags, ret;
18661 +
18662 +       if (!vxi)
18663 +               return 1;
18664 +
18665 +       flags = vxi->vx_flags;
18666 +
18667 +       if (unlikely(vs_check_flags(flags, VXF_SCHED_PAUSE, 0)))
18668 +               goto put_on_hold;
18669 +       if (!vs_check_flags(flags, VXF_SCHED_HARD | VXF_SCHED_PRIO, 0))
18670 +               return 1;
18671 +
18672 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
18673 +#ifdef CONFIG_SMP
18674 +       /* update scheduler params */
18675 +       if (cpu_isset(cpu, vxi->sched.update)) {
18676 +               vx_update_sched_param(&vxi->sched, sched_pc);
18677 +               vxm_update_sched(sched_pc, vxi, cpu);
18678 +               cpu_clear(cpu, vxi->sched.update);
18679 +       }
18680 +#endif
18681 +       vxm_sched_info(sched_pc, vxi, cpu);
18682 +       ret  = vx_tokens_recalc(sched_pc,
18683 +               &rq->norm_time, &rq->idle_time, delta_min);
18684 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
18685 +
18686 +       if (!vs_check_flags(flags, VXF_SCHED_HARD, 0))
18687 +               return 1;
18688 +
18689 +       if (unlikely(ret < 0)) {
18690 +               vx_save_max_idle(ret, &rq->idle_tokens, delta_min[0]);
18691 +               vx_save_min_skip(ret, &rq->idle_skip, delta_min[1]);
18692 +               vxm_rq_max_min(rq, cpu);
18693 +       put_on_hold:
18694 +               vx_hold_task(next, rq);
18695 +               return 0;
18696 +       }
18697 +       return 1;
18698 +}
18699 +
18700 +
18701 +#else /* CONFIG_VSERVER_HARDCPU */
18702 +
18703 +static inline
18704 +void vx_hold_task(struct task_struct *p, struct rq *rq)
18705 +{
18706 +       return;
18707 +}
18708 +
18709 +static inline
18710 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
18711 +{
18712 +       return;
18713 +}
18714 +
18715 +unsigned long nr_onhold(void)
18716 +{
18717 +       return 0;
18718 +}
18719 +
18720 +
18721 +static inline
18722 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
18723 +{
18724 +       return (slice == 0);
18725 +}
18726 +
18727 +
18728 +#define vx_set_rq_time(rq, time)
18729 +
18730 +static inline
18731 +void vx_try_unhold(struct rq *rq, int cpu)
18732 +{
18733 +       return;
18734 +}
18735 +
18736 +static inline
18737 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
18738 +{
18739 +       struct vx_info *vxi = next->vx_info;
18740 +       struct _vx_sched_pc *sched_pc;
18741 +       int delta_min[2];
18742 +       int ret;
18743 +
18744 +       if (!vx_info_flags(vxi, VXF_SCHED_PRIO, 0))
18745 +               return 1;
18746 +
18747 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
18748 +       vxm_sched_info(sched_pc, vxi, cpu);
18749 +       ret  = vx_tokens_recalc(sched_pc,
18750 +               &rq->norm_time, &rq->idle_time, delta_min);
18751 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
18752 +       return 1;
18753 +}
18754 +
18755 +#endif /* CONFIG_VSERVER_HARDCPU */
18756 +
18757 diff -Nurp linux-2.6.22.15/kernel/sched_mon.h linux-2.6.22.15-vs2.3.0.29.1/kernel/sched_mon.h
18758 --- linux-2.6.22.15/kernel/sched_mon.h  1969-12-31 19:00:00.000000000 -0500
18759 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/sched_mon.h     2007-12-09 06:44:23.000000000 -0500
18760 @@ -0,0 +1,200 @@
18761 +
18762 +#include <linux/vserver/monitor.h>
18763 +
18764 +#ifdef  CONFIG_VSERVER_MONITOR
18765 +
18766 +#ifdef CONFIG_VSERVER_HARDCPU
18767 +#define HARDCPU(x) (x)
18768 +#else
18769 +#define HARDCPU(x) (0)
18770 +#endif
18771 +
18772 +#ifdef CONFIG_VSERVER_IDLETIME
18773 +#define IDLETIME(x) (x)
18774 +#else
18775 +#define IDLETIME(x) (0)
18776 +#endif
18777 +
18778 +struct _vx_mon_entry *vxm_advance(int cpu);
18779 +
18780 +
18781 +static inline
18782 +void   __vxm_basic(struct _vx_mon_entry *entry, xid_t xid, int type)
18783 +{
18784 +       entry->type = type;
18785 +       entry->xid = xid;
18786 +}
18787 +
18788 +static inline
18789 +void   __vxm_sync(int cpu)
18790 +{
18791 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18792 +
18793 +       __vxm_basic(entry, 0, VXM_SYNC);
18794 +       entry->ev.sec = xtime.tv_sec;
18795 +       entry->ev.nsec = xtime.tv_nsec;
18796 +}
18797 +
18798 +static inline
18799 +void   __vxm_task(struct task_struct *p, int type)
18800 +{
18801 +       struct _vx_mon_entry *entry = vxm_advance(task_cpu(p));
18802 +
18803 +       __vxm_basic(entry, p->xid, type);
18804 +       entry->ev.tsk.pid = p->pid;
18805 +       entry->ev.tsk.state = p->state;
18806 +}
18807 +
18808 +static inline
18809 +void   __vxm_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
18810 +{
18811 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18812 +
18813 +       __vxm_basic(entry, vxi->vx_id, (VXM_SCHED | s->flags));
18814 +       entry->sd.tokens = s->tokens;
18815 +       entry->sd.norm_time = s->norm_time;
18816 +       entry->sd.idle_time = s->idle_time;
18817 +}
18818 +
18819 +static inline
18820 +void   __vxm_rqinfo1(struct rq *q, int cpu)
18821 +{
18822 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18823 +
18824 +       entry->type = VXM_RQINFO_1;
18825 +       entry->xid = ((unsigned long)q >> 16) & 0xffff;
18826 +       entry->q1.running = q->nr_running;
18827 +       entry->q1.onhold = HARDCPU(q->nr_onhold);
18828 +       entry->q1.iowait = atomic_read(&q->nr_iowait);
18829 +       entry->q1.uintr = q->nr_uninterruptible;
18830 +       entry->q1.idle_tokens = IDLETIME(q->idle_tokens);
18831 +}
18832 +
18833 +static inline
18834 +void   __vxm_rqinfo2(struct rq *q, int cpu)
18835 +{
18836 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18837 +
18838 +       entry->type = VXM_RQINFO_2;
18839 +       entry->xid = (unsigned long)q & 0xffff;
18840 +       entry->q2.norm_time = q->norm_time;
18841 +       entry->q2.idle_time = q->idle_time;
18842 +       entry->q2.idle_skip = IDLETIME(q->idle_skip);
18843 +}
18844 +
18845 +static inline
18846 +void   __vxm_update(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
18847 +{
18848 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18849 +
18850 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE);
18851 +       entry->ev.tokens = s->tokens;
18852 +}
18853 +
18854 +static inline
18855 +void   __vxm_update1(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
18856 +{
18857 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18858 +
18859 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_1);
18860 +       entry->u1.tokens_max = s->tokens_max;
18861 +       entry->u1.fill_rate = s->fill_rate[0];
18862 +       entry->u1.interval = s->interval[0];
18863 +}
18864 +
18865 +static inline
18866 +void   __vxm_update2(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
18867 +{
18868 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18869 +
18870 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_2);
18871 +       entry->u2.tokens_min = s->tokens_min;
18872 +       entry->u2.fill_rate = s->fill_rate[1];
18873 +       entry->u2.interval = s->interval[1];
18874 +}
18875 +
18876 +
18877 +#define        vxm_activate_task(p,q)          __vxm_task(p, VXM_ACTIVATE)
18878 +#define        vxm_activate_idle(p,q)          __vxm_task(p, VXM_IDLE)
18879 +#define        vxm_deactivate_task(p,q)        __vxm_task(p, VXM_DEACTIVATE)
18880 +#define        vxm_hold_task(p,q)              __vxm_task(p, VXM_HOLD)
18881 +#define        vxm_unhold_task(p,q)            __vxm_task(p, VXM_UNHOLD)
18882 +
18883 +static inline
18884 +void   vxm_migrate_task(struct task_struct *p, struct rq *rq, int dest)
18885 +{
18886 +       __vxm_task(p, VXM_MIGRATE);
18887 +       __vxm_rqinfo1(rq, task_cpu(p));
18888 +       __vxm_rqinfo2(rq, task_cpu(p));
18889 +}
18890 +
18891 +static inline
18892 +void   vxm_idle_skip(struct rq *rq, int cpu)
18893 +{
18894 +       __vxm_rqinfo1(rq, cpu);
18895 +       __vxm_rqinfo2(rq, cpu);
18896 +}
18897 +
18898 +static inline
18899 +void   vxm_need_resched(struct task_struct *p, int slice, int cpu)
18900 +{
18901 +       if (slice)
18902 +               return;
18903 +
18904 +       __vxm_task(p, VXM_RESCHED);
18905 +}
18906 +
18907 +static inline
18908 +void   vxm_sync(unsigned long now, int cpu)
18909 +{
18910 +       if (!CONFIG_VSERVER_MONITOR_SYNC ||
18911 +               (now % CONFIG_VSERVER_MONITOR_SYNC))
18912 +               return;
18913 +
18914 +       __vxm_sync(cpu);
18915 +}
18916 +
18917 +#define        vxm_sched_info(s,v,c)           __vxm_sched(s,v,c)
18918 +
18919 +static inline
18920 +void   vxm_tokens_recalc(struct _vx_sched_pc *s, struct rq *rq,
18921 +       struct vx_info *vxi, int cpu)
18922 +{
18923 +       __vxm_sched(s, vxi, cpu);
18924 +       __vxm_rqinfo2(rq, cpu);
18925 +}
18926 +
18927 +static inline
18928 +void   vxm_update_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
18929 +{
18930 +       __vxm_sched(s, vxi, cpu);
18931 +       __vxm_update(s, vxi, cpu);
18932 +       __vxm_update1(s, vxi, cpu);
18933 +       __vxm_update2(s, vxi, cpu);
18934 +}
18935 +
18936 +static inline
18937 +void   vxm_rq_max_min(struct rq *rq, int cpu)
18938 +{
18939 +       __vxm_rqinfo1(rq, cpu);
18940 +       __vxm_rqinfo2(rq, cpu);
18941 +}
18942 +
18943 +#else  /* CONFIG_VSERVER_MONITOR */
18944 +
18945 +#define        vxm_activate_task(t,q)          do { } while (0)
18946 +#define        vxm_activate_idle(t,q)          do { } while (0)
18947 +#define        vxm_deactivate_task(t,q)        do { } while (0)
18948 +#define        vxm_hold_task(t,q)              do { } while (0)
18949 +#define        vxm_unhold_task(t,q)            do { } while (0)
18950 +#define        vxm_migrate_task(t,q,d)         do { } while (0)
18951 +#define        vxm_idle_skip(q,c)              do { } while (0)
18952 +#define        vxm_need_resched(t,s,c)         do { } while (0)
18953 +#define        vxm_sync(s,c)                   do { } while (0)
18954 +#define        vxm_sched_info(s,v,c)           do { } while (0)
18955 +#define        vxm_tokens_recalc(s,q,v,c)      do { } while (0)
18956 +#define        vxm_update_sched(s,v,c)         do { } while (0)
18957 +#define        vxm_rq_max_min(q,c)             do { } while (0)
18958 +
18959 +#endif /* CONFIG_VSERVER_MONITOR */
18960 +
18961 diff -Nurp linux-2.6.22.15/kernel/signal.c linux-2.6.22.15-vs2.3.0.29.1/kernel/signal.c
18962 --- linux-2.6.22.15/kernel/signal.c     2007-09-29 08:11:49.000000000 -0400
18963 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/signal.c        2007-12-09 06:44:23.000000000 -0500
18964 @@ -26,6 +26,8 @@
18965  #include <linux/freezer.h>
18966  #include <linux/pid_namespace.h>
18967  #include <linux/nsproxy.h>
18968 +#include <linux/vs_context.h>
18969 +#include <linux/vs_pid.h>
18970  
18971  #include <asm/param.h>
18972  #include <asm/uaccess.h>
18973 @@ -523,19 +525,34 @@ static int check_kill_permission(int sig
18974         if (!valid_signal(sig))
18975                 return error;
18976  
18977 +       if ((info != SEND_SIG_NOINFO) &&
18978 +               (is_si_special(info) || !SI_FROMUSER(info)))
18979 +               goto skip;
18980 +
18981 +       vxdprintk(VXD_CBIT(misc, 7),
18982 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
18983 +               sig, info, t, vx_task_xid(t), t->pid);
18984 +
18985         error = audit_signal_info(sig, t); /* Let audit system see the signal */
18986         if (error)
18987                 return error;
18988  
18989         error = -EPERM;
18990 -       if ((info == SEND_SIG_NOINFO || (!is_si_special(info) && SI_FROMUSER(info)))
18991 -           && ((sig != SIGCONT) ||
18992 +       if (((sig != SIGCONT) ||
18993                 (process_session(current) != process_session(t)))
18994             && (current->euid ^ t->suid) && (current->euid ^ t->uid)
18995             && (current->uid ^ t->suid) && (current->uid ^ t->uid)
18996             && !capable(CAP_KILL))
18997                 return error;
18998  
18999 +       error = -ESRCH;
19000 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
19001 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
19002 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
19003 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
19004 +               return error;
19005 +       }
19006 +skip:
19007         return security_task_kill(t, info, sig, 0);
19008  }
19009  
19010 @@ -1043,7 +1060,7 @@ int kill_pid_info(int sig, struct siginf
19011  
19012         p = pid_task(pid, PIDTYPE_PID);
19013         error = -ESRCH;
19014 -       if (p)
19015 +       if (p && vx_check(vx_task_xid(p), VS_IDENT))
19016                 error = group_send_sig_info(sig, info, p);
19017  
19018         if (unlikely(sig_needs_tasklist(sig)))
19019 @@ -1057,7 +1074,7 @@ kill_proc_info(int sig, struct siginfo *
19020  {
19021         int error;
19022         rcu_read_lock();
19023 -       error = kill_pid_info(sig, info, find_pid(pid));
19024 +       error = kill_pid_info(sig, info, find_pid(vx_rmap_pid(pid)));
19025         rcu_read_unlock();
19026         return error;
19027  }
19028 @@ -1118,7 +1135,8 @@ static int kill_something_info(int sig, 
19029  
19030                 read_lock(&tasklist_lock);
19031                 for_each_process(p) {
19032 -                       if (p->pid > 1 && p->tgid != current->tgid) {
19033 +                       if (vx_check(vx_task_xid(p), VS_ADMIN_P|VS_IDENT) &&
19034 +                               p->pid > 1 && p->tgid != current->tgid) {
19035                                 int err = group_send_sig_info(sig, info, p);
19036                                 ++count;
19037                                 if (err != -EPERM)
19038 @@ -1814,6 +1832,11 @@ relock:
19039                 if (current == child_reaper(current))
19040                         continue;
19041  
19042 +               /* virtual init is protected against user signals */
19043 +               if ((info->si_code == SI_USER) &&
19044 +                       vx_current_initpid(current->pid))
19045 +                       continue;
19046 +
19047                 if (sig_kernel_stop(signr)) {
19048                         /*
19049                          * The default action is to stop all threads in
19050 diff -Nurp linux-2.6.22.15/kernel/softirq.c linux-2.6.22.15-vs2.3.0.29.1/kernel/softirq.c
19051 --- linux-2.6.22.15/kernel/softirq.c    2007-07-21 18:00:25.000000000 -0400
19052 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/softirq.c       2007-12-09 06:44:23.000000000 -0500
19053 @@ -18,6 +18,7 @@
19054  #include <linux/rcupdate.h>
19055  #include <linux/smp.h>
19056  #include <linux/tick.h>
19057 +#include <linux/vs_context.h>
19058  
19059  #include <asm/irq.h>
19060  /*
19061 diff -Nurp linux-2.6.22.15/kernel/sys.c linux-2.6.22.15-vs2.3.0.29.1/kernel/sys.c
19062 --- linux-2.6.22.15/kernel/sys.c        2007-10-29 21:18:04.000000000 -0400
19063 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/sys.c   2007-12-09 06:44:23.000000000 -0500
19064 @@ -36,6 +36,7 @@
19065  #include <linux/compat.h>
19066  #include <linux/syscalls.h>
19067  #include <linux/kprobes.h>
19068 +#include <linux/vs_pid.h>
19069  
19070  #include <asm/uaccess.h>
19071  #include <asm/io.h>
19072 @@ -639,7 +640,10 @@ static int set_one_prio(struct task_stru
19073                 goto out;
19074         }
19075         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
19076 -               error = -EACCES;
19077 +               if (vx_flags(VXF_IGNEG_NICE, 0))
19078 +                       error = 0;
19079 +               else
19080 +                       error = -EACCES;
19081                 goto out;
19082         }
19083         no_nice = security_task_setnice(p, niceval);
19084 @@ -687,6 +691,8 @@ asmlinkage long sys_setpriority(int whic
19085                         else
19086                                 pgrp = task_pgrp(current);
19087                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
19088 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
19089 +                                       continue;
19090                                 error = set_one_prio(p, niceval, error);
19091                         } while_each_pid_task(pgrp, PIDTYPE_PGID, p);
19092                         break;
19093 @@ -695,7 +701,8 @@ asmlinkage long sys_setpriority(int whic
19094                         if (!who)
19095                                 who = current->uid;
19096                         else
19097 -                               if ((who != current->uid) && !(user = find_user(who)))
19098 +                               if ((who != current->uid) &&
19099 +                                       !(user = find_user(vx_current_xid(), who)))
19100                                         goto out_unlock;        /* No processes for this user */
19101  
19102                         do_each_thread(g, p)
19103 @@ -747,6 +754,8 @@ asmlinkage long sys_getpriority(int whic
19104                         else
19105                                 pgrp = task_pgrp(current);
19106                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
19107 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
19108 +                                       continue;
19109                                 niceval = 20 - task_nice(p);
19110                                 if (niceval > retval)
19111                                         retval = niceval;
19112 @@ -757,7 +766,8 @@ asmlinkage long sys_getpriority(int whic
19113                         if (!who)
19114                                 who = current->uid;
19115                         else
19116 -                               if ((who != current->uid) && !(user = find_user(who)))
19117 +                               if ((who != current->uid) &&
19118 +                                       !(user = find_user(vx_current_xid(), who)))
19119                                         goto out_unlock;        /* No processes for this user */
19120  
19121                         do_each_thread(g, p)
19122 @@ -871,6 +881,9 @@ void kernel_power_off(void)
19123         machine_power_off();
19124  }
19125  EXPORT_SYMBOL_GPL(kernel_power_off);
19126 +
19127 +long vs_reboot(unsigned int, void __user *);
19128 +
19129  /*
19130   * Reboot system call: for obvious reasons only root may call it,
19131   * and even root needs to set up some magic numbers in the registers
19132 @@ -901,6 +914,9 @@ asmlinkage long sys_reboot(int magic1, i
19133         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
19134                 cmd = LINUX_REBOOT_CMD_HALT;
19135  
19136 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
19137 +               return vs_reboot(cmd, arg);
19138 +
19139         lock_kernel();
19140         switch (cmd) {
19141         case LINUX_REBOOT_CMD_RESTART:
19142 @@ -1080,7 +1096,7 @@ static int set_user(uid_t new_ruid, int 
19143  {
19144         struct user_struct *new_user;
19145  
19146 -       new_user = alloc_uid(new_ruid);
19147 +       new_user = alloc_uid(vx_current_xid(), new_ruid);
19148         if (!new_user)
19149                 return -EAGAIN;
19150  
19151 @@ -1434,15 +1450,18 @@ asmlinkage long sys_setpgid(pid_t pid, p
19152  {
19153         struct task_struct *p;
19154         struct task_struct *group_leader = current->group_leader;
19155 +       pid_t rpgid;
19156         int err = -EINVAL;
19157  
19158         if (!pid)
19159 -               pid = group_leader->pid;
19160 +               pid = vx_map_pid(group_leader->pid);
19161         if (!pgid)
19162                 pgid = pid;
19163         if (pgid < 0)
19164                 return -EINVAL;
19165  
19166 +       rpgid = vx_rmap_pid(pgid);
19167 +
19168         /* From this point forward we keep holding onto the tasklist lock
19169          * so that our parent does not change from under us. -DaveM
19170          */
19171 @@ -1476,20 +1495,20 @@ asmlinkage long sys_setpgid(pid_t pid, p
19172  
19173         if (pgid != pid) {
19174                 struct task_struct *g =
19175 -                       find_task_by_pid_type(PIDTYPE_PGID, pgid);
19176 +                       find_task_by_pid_type(PIDTYPE_PGID, rpgid);
19177  
19178                 if (!g || task_session(g) != task_session(group_leader))
19179                         goto out;
19180         }
19181  
19182 -       err = security_task_setpgid(p, pgid);
19183 +       err = security_task_setpgid(p, rpgid);
19184         if (err)
19185                 goto out;
19186  
19187 -       if (process_group(p) != pgid) {
19188 +       if (process_group(p) != rpgid) {
19189                 detach_pid(p, PIDTYPE_PGID);
19190 -               p->signal->pgrp = pgid;
19191 -               attach_pid(p, PIDTYPE_PGID, find_pid(pgid));
19192 +               p->signal->pgrp = rpgid;
19193 +               attach_pid(p, PIDTYPE_PGID, find_pid(rpgid));
19194         }
19195  
19196         err = 0;
19197 @@ -1502,7 +1521,7 @@ out:
19198  asmlinkage long sys_getpgid(pid_t pid)
19199  {
19200         if (!pid)
19201 -               return process_group(current);
19202 +               return vx_rmap_pid(process_group(current));
19203         else {
19204                 int retval;
19205                 struct task_struct *p;
19206 @@ -1514,7 +1533,7 @@ asmlinkage long sys_getpgid(pid_t pid)
19207                 if (p) {
19208                         retval = security_task_getpgid(p);
19209                         if (!retval)
19210 -                               retval = process_group(p);
19211 +                               retval = vx_rmap_pid(process_group(p));
19212                 }
19213                 read_unlock(&tasklist_lock);
19214                 return retval;
19215 @@ -1865,7 +1884,7 @@ asmlinkage long sys_sethostname(char __u
19216         int errno;
19217         char tmp[__NEW_UTS_LEN];
19218  
19219 -       if (!capable(CAP_SYS_ADMIN))
19220 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
19221                 return -EPERM;
19222         if (len < 0 || len > __NEW_UTS_LEN)
19223                 return -EINVAL;
19224 @@ -1910,7 +1929,7 @@ asmlinkage long sys_setdomainname(char _
19225         int errno;
19226         char tmp[__NEW_UTS_LEN];
19227  
19228 -       if (!capable(CAP_SYS_ADMIN))
19229 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
19230                 return -EPERM;
19231         if (len < 0 || len > __NEW_UTS_LEN)
19232                 return -EINVAL;
19233 @@ -1977,7 +1996,7 @@ asmlinkage long sys_setrlimit(unsigned i
19234                 return -EINVAL;
19235         old_rlim = current->signal->rlim + resource;
19236         if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
19237 -           !capable(CAP_SYS_RESOURCE))
19238 +           !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
19239                 return -EPERM;
19240         if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > NR_OPEN)
19241                 return -EPERM;
19242 diff -Nurp linux-2.6.22.15/kernel/sysctl.c linux-2.6.22.15-vs2.3.0.29.1/kernel/sysctl.c
19243 --- linux-2.6.22.15/kernel/sysctl.c     2007-07-21 18:00:25.000000000 -0400
19244 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/sysctl.c        2007-12-09 06:44:23.000000000 -0500
19245 @@ -89,6 +89,7 @@ static int ngroups_max = NGROUPS_MAX;
19246  #ifdef CONFIG_KMOD
19247  extern char modprobe_path[];
19248  #endif
19249 +extern char vshelper_path[];
19250  #ifdef CONFIG_CHR_DEV_SG
19251  extern int sg_big_buff;
19252  #endif
19253 @@ -343,6 +344,15 @@ static ctl_table kern_table[] = {
19254                 .strategy       = &sysctl_string,
19255         },
19256  #endif
19257 +       {
19258 +               .ctl_name       = KERN_VSHELPER,
19259 +               .procname       = "vshelper",
19260 +               .data           = &vshelper_path,
19261 +               .maxlen         = 256,
19262 +               .mode           = 0644,
19263 +               .proc_handler   = &proc_dostring,
19264 +               .strategy       = &sysctl_string,
19265 +       },
19266  #ifdef CONFIG_CHR_DEV_SG
19267         {
19268                 .ctl_name       = KERN_SG_BIG_BUFF,
19269 diff -Nurp linux-2.6.22.15/kernel/time.c linux-2.6.22.15-vs2.3.0.29.1/kernel/time.c
19270 --- linux-2.6.22.15/kernel/time.c       2007-07-21 18:00:25.000000000 -0400
19271 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/time.c  2007-12-09 06:44:23.000000000 -0500
19272 @@ -60,7 +60,7 @@ asmlinkage long sys_time(time_t __user *
19273         time_t i;
19274         struct timeval tv;
19275  
19276 -       do_gettimeofday(&tv);
19277 +       vx_gettimeofday(&tv);
19278         i = tv.tv_sec;
19279  
19280         if (tloc) {
19281 @@ -91,7 +91,7 @@ asmlinkage long sys_stime(time_t __user 
19282         if (err)
19283                 return err;
19284  
19285 -       do_settimeofday(&tv);
19286 +       vx_settimeofday(&tv);
19287         return 0;
19288  }
19289  
19290 @@ -101,7 +101,7 @@ asmlinkage long sys_gettimeofday(struct 
19291  {
19292         if (likely(tv != NULL)) {
19293                 struct timeval ktv;
19294 -               do_gettimeofday(&ktv);
19295 +               vx_gettimeofday(&ktv);
19296                 if (copy_to_user(tv, &ktv, sizeof(ktv)))
19297                         return -EFAULT;
19298         }
19299 @@ -175,7 +175,7 @@ int do_sys_settimeofday(struct timespec 
19300                 /* SMP safe, again the code in arch/foo/time.c should
19301                  * globally block out interrupts when it runs.
19302                  */
19303 -               return do_settimeofday(tv);
19304 +               return vx_settimeofday(tv);
19305         }
19306         return 0;
19307  }
19308 @@ -388,7 +388,7 @@ void getnstimeofday(struct timespec *tv)
19309  {
19310         struct timeval x;
19311  
19312 -       do_gettimeofday(&x);
19313 +       vx_gettimeofday(&x);
19314         tv->tv_sec = x.tv_sec;
19315         tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
19316  }
19317 diff -Nurp linux-2.6.22.15/kernel/timer.c linux-2.6.22.15-vs2.3.0.29.1/kernel/timer.c
19318 --- linux-2.6.22.15/kernel/timer.c      2007-07-21 18:00:25.000000000 -0400
19319 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/timer.c 2007-12-09 06:44:23.000000000 -0500
19320 @@ -36,6 +36,10 @@
19321  #include <linux/delay.h>
19322  #include <linux/tick.h>
19323  #include <linux/kallsyms.h>
19324 +#include <linux/vs_base.h>
19325 +#include <linux/vs_cvirt.h>
19326 +#include <linux/vs_pid.h>
19327 +#include <linux/vserver/sched.h>
19328  
19329  #include <asm/uaccess.h>
19330  #include <asm/unistd.h>
19331 @@ -921,12 +925,6 @@ asmlinkage unsigned long sys_alarm(unsig
19332  
19333  #endif
19334  
19335 -#ifndef __alpha__
19336 -
19337 -/*
19338 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
19339 - * should be moved into arch/i386 instead?
19340 - */
19341  
19342  /**
19343   * sys_getpid - return the thread group id of the current process
19344 @@ -939,7 +937,7 @@ asmlinkage unsigned long sys_alarm(unsig
19345   */
19346  asmlinkage long sys_getpid(void)
19347  {
19348 -       return current->tgid;
19349 +       return vx_map_tgid(current->tgid);
19350  }
19351  
19352  /*
19353 @@ -955,10 +953,23 @@ asmlinkage long sys_getppid(void)
19354         rcu_read_lock();
19355         pid = rcu_dereference(current->real_parent)->tgid;
19356         rcu_read_unlock();
19357 +       return vx_map_pid(pid);
19358 +}
19359 +
19360 +#ifdef __alpha__
19361  
19362 -       return pid;
19363 +/*
19364 + * The Alpha uses getxpid, getxuid, and getxgid instead.
19365 + */
19366 +
19367 +asmlinkage long do_getxpid(long *ppid)
19368 +{
19369 +       *ppid = sys_getppid();
19370 +       return sys_getpid();
19371  }
19372  
19373 +#else /* _alpha_ */
19374 +
19375  asmlinkage long sys_getuid(void)
19376  {
19377         /* Only we change this so SMP safe */
19378 @@ -1118,6 +1129,8 @@ int do_sysinfo(struct sysinfo *info)
19379                         tp.tv_nsec = tp.tv_nsec - NSEC_PER_SEC;
19380                         tp.tv_sec++;
19381                 }
19382 +               if (vx_flags(VXF_VIRT_UPTIME, 0))
19383 +                       vx_vsi_uptime(&tp, NULL);
19384                 info->uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0);
19385  
19386                 info->loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
19387 diff -Nurp linux-2.6.22.15/kernel/user.c linux-2.6.22.15-vs2.3.0.29.1/kernel/user.c
19388 --- linux-2.6.22.15/kernel/user.c       2007-05-04 09:58:24.000000000 -0400
19389 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/user.c  2007-12-09 06:44:23.000000000 -0500
19390 @@ -23,8 +23,8 @@
19391  #define UIDHASH_BITS (CONFIG_BASE_SMALL ? 3 : 8)
19392  #define UIDHASH_SZ             (1 << UIDHASH_BITS)
19393  #define UIDHASH_MASK           (UIDHASH_SZ - 1)
19394 -#define __uidhashfn(uid)       (((uid >> UIDHASH_BITS) + uid) & UIDHASH_MASK)
19395 -#define uidhashentry(uid)      (uidhash_table + __uidhashfn((uid)))
19396 +#define __uidhashfn(xid,uid)   ((((uid) >> UIDHASH_BITS) + ((uid)^(xid))) & UIDHASH_MASK)
19397 +#define uidhashentry(xid,uid)  (uidhash_table + __uidhashfn((xid),(uid)))
19398  
19399  static struct kmem_cache *uid_cachep;
19400  static struct list_head uidhash_table[UIDHASH_SZ];
19401 @@ -66,7 +66,7 @@ static inline void uid_hash_remove(struc
19402         list_del(&up->uidhash_list);
19403  }
19404  
19405 -static inline struct user_struct *uid_hash_find(uid_t uid, struct list_head *hashent)
19406 +static inline struct user_struct *uid_hash_find(xid_t xid, uid_t uid, struct list_head *hashent)
19407  {
19408         struct list_head *up;
19409  
19410 @@ -75,7 +75,7 @@ static inline struct user_struct *uid_ha
19411  
19412                 user = list_entry(up, struct user_struct, uidhash_list);
19413  
19414 -               if(user->uid == uid) {
19415 +               if(user->uid == uid && user->xid == xid) {
19416                         atomic_inc(&user->__count);
19417                         return user;
19418                 }
19419 @@ -90,13 +90,13 @@ static inline struct user_struct *uid_ha
19420   *
19421   * If the user_struct could not be found, return NULL.
19422   */
19423 -struct user_struct *find_user(uid_t uid)
19424 +struct user_struct *find_user(xid_t xid, uid_t uid)
19425  {
19426         struct user_struct *ret;
19427         unsigned long flags;
19428  
19429         spin_lock_irqsave(&uidhash_lock, flags);
19430 -       ret = uid_hash_find(uid, uidhashentry(uid));
19431 +       ret = uid_hash_find(xid, uid, uidhashentry(xid, uid));
19432         spin_unlock_irqrestore(&uidhash_lock, flags);
19433         return ret;
19434  }
19435 @@ -120,13 +120,13 @@ void free_uid(struct user_struct *up)
19436         }
19437  }
19438  
19439 -struct user_struct * alloc_uid(uid_t uid)
19440 +struct user_struct * alloc_uid(xid_t xid, uid_t uid)
19441  {
19442 -       struct list_head *hashent = uidhashentry(uid);
19443 +       struct list_head *hashent = uidhashentry(xid, uid);
19444         struct user_struct *up;
19445  
19446         spin_lock_irq(&uidhash_lock);
19447 -       up = uid_hash_find(uid, hashent);
19448 +       up = uid_hash_find(xid, uid, hashent);
19449         spin_unlock_irq(&uidhash_lock);
19450  
19451         if (!up) {
19452 @@ -136,6 +136,7 @@ struct user_struct * alloc_uid(uid_t uid
19453                 if (!new)
19454                         return NULL;
19455                 new->uid = uid;
19456 +               new->xid = xid;
19457                 atomic_set(&new->__count, 1);
19458                 atomic_set(&new->processes, 0);
19459                 atomic_set(&new->files, 0);
19460 @@ -158,7 +159,7 @@ struct user_struct * alloc_uid(uid_t uid
19461                  * on adding the same user already..
19462                  */
19463                 spin_lock_irq(&uidhash_lock);
19464 -               up = uid_hash_find(uid, hashent);
19465 +               up = uid_hash_find(xid, uid, hashent);
19466                 if (up) {
19467                         key_put(new->uid_keyring);
19468                         key_put(new->session_keyring);
19469 @@ -215,7 +216,7 @@ static int __init uid_cache_init(void)
19470  
19471         /* Insert the root user immediately (init already runs as root) */
19472         spin_lock_irq(&uidhash_lock);
19473 -       uid_hash_insert(&root_user, uidhashentry(0));
19474 +       uid_hash_insert(&root_user, uidhashentry(0,0));
19475         spin_unlock_irq(&uidhash_lock);
19476  
19477         return 0;
19478 diff -Nurp linux-2.6.22.15/kernel/utsname.c linux-2.6.22.15-vs2.3.0.29.1/kernel/utsname.c
19479 --- linux-2.6.22.15/kernel/utsname.c    2007-07-21 18:00:25.000000000 -0400
19480 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/utsname.c       2007-12-09 06:44:23.000000000 -0500
19481 @@ -13,6 +13,7 @@
19482  #include <linux/uts.h>
19483  #include <linux/utsname.h>
19484  #include <linux/version.h>
19485 +#include <linux/vserver/global.h>
19486  
19487  /*
19488   * Clone a new ns copying an original utsname, setting refcount to 1
19489 @@ -27,6 +28,7 @@ static struct uts_namespace *clone_uts_n
19490         if (ns) {
19491                 memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
19492                 kref_init(&ns->kref);
19493 +               atomic_inc(&vs_global_uts_ns);
19494         }
19495         return ns;
19496  }
19497 @@ -58,5 +60,6 @@ void free_uts_ns(struct kref *kref)
19498         struct uts_namespace *ns;
19499  
19500         ns = container_of(kref, struct uts_namespace, kref);
19501 +       atomic_dec(&vs_global_uts_ns);
19502         kfree(ns);
19503  }
19504 diff -Nurp linux-2.6.22.15/kernel/vserver/cacct.c linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/cacct.c
19505 --- linux-2.6.22.15/kernel/vserver/cacct.c      1969-12-31 19:00:00.000000000 -0500
19506 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/cacct.c 2007-12-09 06:44:23.000000000 -0500
19507 @@ -0,0 +1,42 @@
19508 +/*
19509 + *  linux/kernel/vserver/cacct.c
19510 + *
19511 + *  Virtual Server: Context Accounting
19512 + *
19513 + *  Copyright (C) 2006-2007 Herbert Pötzl
19514 + *
19515 + *  V0.01  added accounting stats
19516 + *
19517 + */
19518 +
19519 +#include <linux/types.h>
19520 +#include <linux/vs_context.h>
19521 +#include <linux/vserver/cacct_cmd.h>
19522 +#include <linux/vserver/cacct_int.h>
19523 +
19524 +#include <asm/errno.h>
19525 +#include <asm/uaccess.h>
19526 +
19527 +
19528 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
19529 +{
19530 +       struct vcmd_sock_stat_v0 vc_data;
19531 +       int j, field;
19532 +
19533 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19534 +               return -EFAULT;
19535 +
19536 +       field = vc_data.field;
19537 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
19538 +               return -EINVAL;
19539 +
19540 +       for (j = 0; j < 3; j++) {
19541 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
19542 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
19543 +       }
19544 +
19545 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19546 +               return -EFAULT;
19547 +       return 0;
19548 +}
19549 +
19550 diff -Nurp linux-2.6.22.15/kernel/vserver/cacct_init.h linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/cacct_init.h
19551 --- linux-2.6.22.15/kernel/vserver/cacct_init.h 1969-12-31 19:00:00.000000000 -0500
19552 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/cacct_init.h    2007-12-09 06:44:23.000000000 -0500
19553 @@ -0,0 +1,25 @@
19554 +
19555 +
19556 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
19557 +{
19558 +       int i, j;
19559 +
19560 +
19561 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
19562 +               for (j = 0; j < 3; j++) {
19563 +                       atomic_set(&cacct->sock[i][j].count, 0);
19564 +                       atomic_set(&cacct->sock[i][j].total, 0);
19565 +               }
19566 +       }
19567 +       for (i = 0; i < 8; i++)
19568 +               atomic_set(&cacct->slab[i], 0);
19569 +       for (i = 0; i < 5; i++)
19570 +               for (j = 0; j < 4; j++)
19571 +                       atomic_set(&cacct->page[i][j], 0);
19572 +}
19573 +
19574 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
19575 +{
19576 +       return;
19577 +}
19578 +
19579 diff -Nurp linux-2.6.22.15/kernel/vserver/cacct_proc.h linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/cacct_proc.h
19580 --- linux-2.6.22.15/kernel/vserver/cacct_proc.h 1969-12-31 19:00:00.000000000 -0500
19581 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/cacct_proc.h    2007-12-09 06:44:23.000000000 -0500
19582 @@ -0,0 +1,53 @@
19583 +#ifndef _VX_CACCT_PROC_H
19584 +#define _VX_CACCT_PROC_H
19585 +
19586 +#include <linux/vserver/cacct_int.h>
19587 +
19588 +
19589 +#define VX_SOCKA_TOP   \
19590 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
19591 +
19592 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
19593 +{
19594 +       int i, j, length = 0;
19595 +       static char *type[VXA_SOCK_SIZE] = {
19596 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
19597 +       };
19598 +
19599 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
19600 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
19601 +               length += sprintf(buffer + length, "%s:", type[i]);
19602 +               for (j = 0; j < 3; j++) {
19603 +                       length += sprintf(buffer + length,
19604 +                               "\t%10lu/%-10lu",
19605 +                               vx_sock_count(cacct, i, j),
19606 +                               vx_sock_total(cacct, i, j));
19607 +               }
19608 +               buffer[length++] = '\n';
19609 +       }
19610 +
19611 +       length += sprintf(buffer + length, "\n");
19612 +       length += sprintf(buffer + length,
19613 +               "slab:\t %8u %8u %8u %8u\n",
19614 +               atomic_read(&cacct->slab[1]),
19615 +               atomic_read(&cacct->slab[4]),
19616 +               atomic_read(&cacct->slab[0]),
19617 +               atomic_read(&cacct->slab[2]));
19618 +
19619 +       length += sprintf(buffer + length, "\n");
19620 +       for (i = 0; i < 5; i++) {
19621 +               length += sprintf(buffer + length,
19622 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
19623 +                       atomic_read(&cacct->page[i][0]),
19624 +                       atomic_read(&cacct->page[i][1]),
19625 +                       atomic_read(&cacct->page[i][2]),
19626 +                       atomic_read(&cacct->page[i][3]),
19627 +                       atomic_read(&cacct->page[i][4]),
19628 +                       atomic_read(&cacct->page[i][5]),
19629 +                       atomic_read(&cacct->page[i][6]),
19630 +                       atomic_read(&cacct->page[i][7]));
19631 +       }
19632 +       return length;
19633 +}
19634 +
19635 +#endif /* _VX_CACCT_PROC_H */
19636 diff -Nurp linux-2.6.22.15/kernel/vserver/context.c linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/context.c
19637 --- linux-2.6.22.15/kernel/vserver/context.c    1969-12-31 19:00:00.000000000 -0500
19638 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/context.c       2007-12-09 06:45:11.000000000 -0500
19639 @@ -0,0 +1,964 @@
19640 +/*
19641 + *  linux/kernel/vserver/context.c
19642 + *
19643 + *  Virtual Server: Context Support
19644 + *
19645 + *  Copyright (C) 2003-2007  Herbert Pötzl
19646 + *
19647 + *  V0.01  context helper
19648 + *  V0.02  vx_ctx_kill syscall command
19649 + *  V0.03  replaced context_info calls
19650 + *  V0.04  redesign of struct (de)alloc
19651 + *  V0.05  rlimit basic implementation
19652 + *  V0.06  task_xid and info commands
19653 + *  V0.07  context flags and caps
19654 + *  V0.08  switch to RCU based hash
19655 + *  V0.09  revert to non RCU for now
19656 + *  V0.10  and back to working RCU hash
19657 + *  V0.11  and back to locking again
19658 + *  V0.12  referenced context store
19659 + *  V0.13  separate per cpu data
19660 + *  V0.14  changed vcmds to vxi arg
19661 + *  V0.15  added context stat
19662 + *  V0.16  have __create claim() the vxi
19663 + *  V0.17  removed older and legacy stuff
19664 + *
19665 + */
19666 +
19667 +#include <linux/slab.h>
19668 +#include <linux/types.h>
19669 +#include <linux/pid_namespace.h>
19670 +
19671 +#include <linux/vserver/context.h>
19672 +#include <linux/vserver/network.h>
19673 +#include <linux/vserver/debug.h>
19674 +#include <linux/vserver/limit.h>
19675 +#include <linux/vserver/limit_int.h>
19676 +#include <linux/vserver/space.h>
19677 +
19678 +#include <linux/vs_context.h>
19679 +#include <linux/vs_limit.h>
19680 +#include <linux/vserver/context_cmd.h>
19681 +
19682 +#include "cvirt_init.h"
19683 +#include "cacct_init.h"
19684 +#include "limit_init.h"
19685 +#include "sched_init.h"
19686 +
19687 +
19688 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
19689 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
19690 +
19691 +
19692 +/*     now inactive context structures */
19693 +
19694 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
19695 +
19696 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
19697 +
19698 +
19699 +/*     __alloc_vx_info()
19700 +
19701 +       * allocate an initialized vx_info struct
19702 +       * doesn't make it visible (hash)                        */
19703 +
19704 +static struct vx_info *__alloc_vx_info(xid_t xid)
19705 +{
19706 +       struct vx_info *new = NULL;
19707 +       int cpu;
19708 +
19709 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
19710 +
19711 +       /* would this benefit from a slab cache? */
19712 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
19713 +       if (!new)
19714 +               return 0;
19715 +
19716 +       memset(new, 0, sizeof(struct vx_info));
19717 +#ifdef CONFIG_SMP
19718 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
19719 +       if (!new->ptr_pc)
19720 +               goto error;
19721 +#endif
19722 +       new->vx_id = xid;
19723 +       INIT_HLIST_NODE(&new->vx_hlist);
19724 +       atomic_set(&new->vx_usecnt, 0);
19725 +       atomic_set(&new->vx_tasks, 0);
19726 +       new->vx_parent = NULL;
19727 +       new->vx_state = 0;
19728 +       init_waitqueue_head(&new->vx_wait);
19729 +
19730 +       /* prepare reaper */
19731 +       get_task_struct(init_pid_ns.child_reaper);
19732 +       new->vx_reaper = init_pid_ns.child_reaper;
19733 +       new->vx_badness_bias = 0;
19734 +
19735 +       /* rest of init goes here */
19736 +       vx_info_init_limit(&new->limit);
19737 +       vx_info_init_sched(&new->sched);
19738 +       vx_info_init_cvirt(&new->cvirt);
19739 +       vx_info_init_cacct(&new->cacct);
19740 +
19741 +       /* per cpu data structures */
19742 +       for_each_possible_cpu(cpu) {
19743 +               vx_info_init_sched_pc(
19744 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
19745 +               vx_info_init_cvirt_pc(
19746 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
19747 +       }
19748 +
19749 +       new->vx_flags = VXF_INIT_SET;
19750 +       new->vx_bcaps = CAP_INIT_EFF_SET;
19751 +       new->vx_ccaps = 0;
19752 +       new->vx_cap_bset = cap_bset;
19753 +
19754 +       new->reboot_cmd = 0;
19755 +       new->exit_code = 0;
19756 +
19757 +       vxdprintk(VXD_CBIT(xid, 0),
19758 +               "alloc_vx_info(%d) = %p", xid, new);
19759 +       vxh_alloc_vx_info(new);
19760 +       atomic_inc(&vx_global_ctotal);
19761 +       return new;
19762 +#ifdef CONFIG_SMP
19763 +error:
19764 +       kfree(new);
19765 +       return 0;
19766 +#endif
19767 +}
19768 +
19769 +/*     __dealloc_vx_info()
19770 +
19771 +       * final disposal of vx_info                             */
19772 +
19773 +static void __dealloc_vx_info(struct vx_info *vxi)
19774 +{
19775 +       int cpu;
19776 +
19777 +       vxdprintk(VXD_CBIT(xid, 0),
19778 +               "dealloc_vx_info(%p)", vxi);
19779 +       vxh_dealloc_vx_info(vxi);
19780 +
19781 +       vxi->vx_id = -1;
19782 +
19783 +       vx_info_exit_limit(&vxi->limit);
19784 +       vx_info_exit_sched(&vxi->sched);
19785 +       vx_info_exit_cvirt(&vxi->cvirt);
19786 +       vx_info_exit_cacct(&vxi->cacct);
19787 +
19788 +       for_each_possible_cpu(cpu) {
19789 +               vx_info_exit_sched_pc(
19790 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
19791 +               vx_info_exit_cvirt_pc(
19792 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
19793 +       }
19794 +
19795 +       vxi->vx_state |= VXS_RELEASED;
19796 +
19797 +#ifdef CONFIG_SMP
19798 +       free_percpu(vxi->ptr_pc);
19799 +#endif
19800 +       kfree(vxi);
19801 +       atomic_dec(&vx_global_ctotal);
19802 +}
19803 +
19804 +static void __shutdown_vx_info(struct vx_info *vxi)
19805 +{
19806 +       struct nsproxy *nsproxy;
19807 +       struct fs_struct *fs;
19808 +
19809 +       might_sleep();
19810 +
19811 +       vxi->vx_state |= VXS_SHUTDOWN;
19812 +       vs_state_change(vxi, VSC_SHUTDOWN);
19813 +
19814 +       nsproxy = xchg(&vxi->vx_nsproxy, NULL);
19815 +       fs = xchg(&vxi->vx_fs, NULL);
19816 +
19817 +       if (nsproxy)
19818 +               put_nsproxy(nsproxy);
19819 +       if (fs)
19820 +               put_fs_struct(fs);
19821 +}
19822 +
19823 +/* exported stuff */
19824 +
19825 +void free_vx_info(struct vx_info *vxi)
19826 +{
19827 +       unsigned long flags;
19828 +
19829 +       /* check for reference counts first */
19830 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
19831 +       BUG_ON(atomic_read(&vxi->vx_tasks));
19832 +
19833 +       /* context must not be hashed */
19834 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
19835 +
19836 +       /* context shutdown is mandatory */
19837 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
19838 +
19839 +       BUG_ON(vxi->vx_nsproxy);
19840 +       BUG_ON(vxi->vx_fs);
19841 +
19842 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
19843 +       hlist_del(&vxi->vx_hlist);
19844 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
19845 +
19846 +       __dealloc_vx_info(vxi);
19847 +}
19848 +
19849 +
19850 +/*     hash table for vx_info hash */
19851 +
19852 +#define VX_HASH_SIZE   13
19853 +
19854 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
19855 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
19856 +
19857 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
19858 +
19859 +
19860 +static inline unsigned int __hashval(xid_t xid)
19861 +{
19862 +       return (xid % VX_HASH_SIZE);
19863 +}
19864 +
19865 +
19866 +
19867 +/*     __hash_vx_info()
19868 +
19869 +       * add the vxi to the global hash table
19870 +       * requires the hash_lock to be held                     */
19871 +
19872 +static inline void __hash_vx_info(struct vx_info *vxi)
19873 +{
19874 +       struct hlist_head *head;
19875 +
19876 +       vxd_assert_lock(&vx_info_hash_lock);
19877 +       vxdprintk(VXD_CBIT(xid, 4),
19878 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
19879 +       vxh_hash_vx_info(vxi);
19880 +
19881 +       /* context must not be hashed */
19882 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
19883 +
19884 +       vxi->vx_state |= VXS_HASHED;
19885 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
19886 +       hlist_add_head(&vxi->vx_hlist, head);
19887 +       atomic_inc(&vx_global_cactive);
19888 +}
19889 +
19890 +/*     __unhash_vx_info()
19891 +
19892 +       * remove the vxi from the global hash table
19893 +       * requires the hash_lock to be held                     */
19894 +
19895 +static inline void __unhash_vx_info(struct vx_info *vxi)
19896 +{
19897 +       unsigned long flags;
19898 +
19899 +       vxd_assert_lock(&vx_info_hash_lock);
19900 +       vxdprintk(VXD_CBIT(xid, 4),
19901 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
19902 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
19903 +       vxh_unhash_vx_info(vxi);
19904 +
19905 +       /* context must be hashed */
19906 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
19907 +       /* but without tasks */
19908 +       BUG_ON(atomic_read(&vxi->vx_tasks));
19909 +
19910 +       vxi->vx_state &= ~VXS_HASHED;
19911 +       hlist_del_init(&vxi->vx_hlist);
19912 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
19913 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
19914 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
19915 +       atomic_dec(&vx_global_cactive);
19916 +}
19917 +
19918 +
19919 +/*     __lookup_vx_info()
19920 +
19921 +       * requires the hash_lock to be held
19922 +       * doesn't increment the vx_refcnt                       */
19923 +
19924 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
19925 +{
19926 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
19927 +       struct hlist_node *pos;
19928 +       struct vx_info *vxi;
19929 +
19930 +       vxd_assert_lock(&vx_info_hash_lock);
19931 +       hlist_for_each(pos, head) {
19932 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
19933 +
19934 +               if (vxi->vx_id == xid)
19935 +                       goto found;
19936 +       }
19937 +       vxi = NULL;
19938 +found:
19939 +       vxdprintk(VXD_CBIT(xid, 0),
19940 +               "__lookup_vx_info(#%u): %p[#%u]",
19941 +               xid, vxi, vxi ? vxi->vx_id : 0);
19942 +       vxh_lookup_vx_info(vxi, xid);
19943 +       return vxi;
19944 +}
19945 +
19946 +
19947 +/*     __create_vx_info()
19948 +
19949 +       * create the requested context
19950 +       * get(), claim() and hash it                            */
19951 +
19952 +static struct vx_info *__create_vx_info(int id)
19953 +{
19954 +       struct vx_info *new, *vxi = NULL;
19955 +
19956 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
19957 +
19958 +       if (!(new = __alloc_vx_info(id)))
19959 +               return ERR_PTR(-ENOMEM);
19960 +
19961 +       /* required to make dynamic xids unique */
19962 +       spin_lock(&vx_info_hash_lock);
19963 +
19964 +       /* static context requested */
19965 +       if ((vxi = __lookup_vx_info(id))) {
19966 +               vxdprintk(VXD_CBIT(xid, 0),
19967 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
19968 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
19969 +                       vxi = ERR_PTR(-EBUSY);
19970 +               else
19971 +                       vxi = ERR_PTR(-EEXIST);
19972 +               goto out_unlock;
19973 +       }
19974 +       /* new context */
19975 +       vxdprintk(VXD_CBIT(xid, 0),
19976 +               "create_vx_info(%d) = %p (new)", id, new);
19977 +       claim_vx_info(new, NULL);
19978 +       __hash_vx_info(get_vx_info(new));
19979 +       vxi = new, new = NULL;
19980 +
19981 +out_unlock:
19982 +       spin_unlock(&vx_info_hash_lock);
19983 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
19984 +       if (new)
19985 +               __dealloc_vx_info(new);
19986 +       return vxi;
19987 +}
19988 +
19989 +
19990 +/*     exported stuff                                          */
19991 +
19992 +
19993 +void unhash_vx_info(struct vx_info *vxi)
19994 +{
19995 +       __shutdown_vx_info(vxi);
19996 +       spin_lock(&vx_info_hash_lock);
19997 +       __unhash_vx_info(vxi);
19998 +       spin_unlock(&vx_info_hash_lock);
19999 +       __wakeup_vx_info(vxi);
20000 +}
20001 +
20002 +
20003 +/*     lookup_vx_info()
20004 +
20005 +       * search for a vx_info and get() it
20006 +       * negative id means current                             */
20007 +
20008 +struct vx_info *lookup_vx_info(int id)
20009 +{
20010 +       struct vx_info *vxi = NULL;
20011 +
20012 +       if (id < 0) {
20013 +               vxi = get_vx_info(current->vx_info);
20014 +       } else if (id > 1) {
20015 +               spin_lock(&vx_info_hash_lock);
20016 +               vxi = get_vx_info(__lookup_vx_info(id));
20017 +               spin_unlock(&vx_info_hash_lock);
20018 +       }
20019 +       return vxi;
20020 +}
20021 +
20022 +/*     xid_is_hashed()
20023 +
20024 +       * verify that xid is still hashed                       */
20025 +
20026 +int xid_is_hashed(xid_t xid)
20027 +{
20028 +       int hashed;
20029 +
20030 +       spin_lock(&vx_info_hash_lock);
20031 +       hashed = (__lookup_vx_info(xid) != NULL);
20032 +       spin_unlock(&vx_info_hash_lock);
20033 +       return hashed;
20034 +}
20035 +
20036 +#ifdef CONFIG_PROC_FS
20037 +
20038 +/*     get_xid_list()
20039 +
20040 +       * get a subset of hashed xids for proc
20041 +       * assumes size is at least one                          */
20042 +
20043 +int get_xid_list(int index, unsigned int *xids, int size)
20044 +{
20045 +       int hindex, nr_xids = 0;
20046 +
20047 +       /* only show current and children */
20048 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
20049 +               if (index > 0)
20050 +                       return 0;
20051 +               xids[nr_xids] = vx_current_xid();
20052 +               return 1;
20053 +       }
20054 +
20055 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
20056 +               struct hlist_head *head = &vx_info_hash[hindex];
20057 +               struct hlist_node *pos;
20058 +
20059 +               spin_lock(&vx_info_hash_lock);
20060 +               hlist_for_each(pos, head) {
20061 +                       struct vx_info *vxi;
20062 +
20063 +                       if (--index > 0)
20064 +                               continue;
20065 +
20066 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
20067 +                       xids[nr_xids] = vxi->vx_id;
20068 +                       if (++nr_xids >= size) {
20069 +                               spin_unlock(&vx_info_hash_lock);
20070 +                               goto out;
20071 +                       }
20072 +               }
20073 +               /* keep the lock time short */
20074 +               spin_unlock(&vx_info_hash_lock);
20075 +       }
20076 +out:
20077 +       return nr_xids;
20078 +}
20079 +#endif
20080 +
20081 +#ifdef CONFIG_VSERVER_DEBUG
20082 +
20083 +void   dump_vx_info_inactive(int level)
20084 +{
20085 +       struct hlist_node *entry, *next;
20086 +
20087 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
20088 +               struct vx_info *vxi =
20089 +                       list_entry(entry, struct vx_info, vx_hlist);
20090 +
20091 +               dump_vx_info(vxi, level);
20092 +       }
20093 +}
20094 +
20095 +#endif
20096 +
20097 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
20098 +{
20099 +       struct user_struct *new_user, *old_user;
20100 +
20101 +       if (!p || !vxi)
20102 +               BUG();
20103 +
20104 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
20105 +               return -EACCES;
20106 +
20107 +       new_user = alloc_uid(vxi->vx_id, p->uid);
20108 +       if (!new_user)
20109 +               return -ENOMEM;
20110 +
20111 +       old_user = p->user;
20112 +       if (new_user != old_user) {
20113 +               atomic_inc(&new_user->processes);
20114 +               atomic_dec(&old_user->processes);
20115 +               p->user = new_user;
20116 +       }
20117 +       free_uid(old_user);
20118 +       return 0;
20119 +}
20120 +
20121 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
20122 +{
20123 +       p->cap_effective &= vxi->vx_cap_bset;
20124 +       p->cap_inheritable &= vxi->vx_cap_bset;
20125 +       p->cap_permitted &= vxi->vx_cap_bset;
20126 +}
20127 +
20128 +
20129 +#include <linux/file.h>
20130 +
20131 +static int vx_openfd_task(struct task_struct *tsk)
20132 +{
20133 +       struct files_struct *files = tsk->files;
20134 +       struct fdtable *fdt;
20135 +       const unsigned long *bptr;
20136 +       int count, total;
20137 +
20138 +       /* no rcu_read_lock() because of spin_lock() */
20139 +       spin_lock(&files->file_lock);
20140 +       fdt = files_fdtable(files);
20141 +       bptr = fdt->open_fds->fds_bits;
20142 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
20143 +       for (total = 0; count > 0; count--) {
20144 +               if (*bptr)
20145 +                       total += hweight_long(*bptr);
20146 +               bptr++;
20147 +       }
20148 +       spin_unlock(&files->file_lock);
20149 +       return total;
20150 +}
20151 +
20152 +
20153 +/*     for *space compatibility */
20154 +
20155 +asmlinkage long sys_unshare(unsigned long);
20156 +
20157 +/*
20158 + *     migrate task to new context
20159 + *     gets vxi, puts old_vxi on change
20160 + *     optionally unshares namespaces (hack)
20161 + */
20162 +
20163 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
20164 +{
20165 +       struct vx_info *old_vxi;
20166 +       int ret = 0;
20167 +
20168 +       if (!p || !vxi)
20169 +               BUG();
20170 +
20171 +       vxdprintk(VXD_CBIT(xid, 5),
20172 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
20173 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
20174 +
20175 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
20176 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
20177 +               return -EACCES;
20178 +
20179 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
20180 +               return -EFAULT;
20181 +
20182 +       old_vxi = task_get_vx_info(p);
20183 +       if (old_vxi == vxi)
20184 +               goto out;
20185 +
20186 +       if (!(ret = vx_migrate_user(p, vxi))) {
20187 +               int openfd;
20188 +
20189 +               task_lock(p);
20190 +               openfd = vx_openfd_task(p);
20191 +
20192 +               if (old_vxi) {
20193 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
20194 +                       atomic_dec(&old_vxi->cvirt.nr_running);
20195 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
20196 +                       /* FIXME: what about the struct files here? */
20197 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
20198 +                       /* account for the executable */
20199 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
20200 +               }
20201 +               atomic_inc(&vxi->cvirt.nr_threads);
20202 +               atomic_inc(&vxi->cvirt.nr_running);
20203 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
20204 +               /* FIXME: what about the struct files here? */
20205 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
20206 +               /* account for the executable */
20207 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
20208 +
20209 +               if (old_vxi) {
20210 +                       release_vx_info(old_vxi, p);
20211 +                       clr_vx_info(&p->vx_info);
20212 +               }
20213 +               claim_vx_info(vxi, p);
20214 +               set_vx_info(&p->vx_info, vxi);
20215 +               p->xid = vxi->vx_id;
20216 +
20217 +               vxdprintk(VXD_CBIT(xid, 5),
20218 +                       "moved task %p into vxi:%p[#%d]",
20219 +                       p, vxi, vxi->vx_id);
20220 +
20221 +               vx_mask_cap_bset(vxi, p);
20222 +               task_unlock(p);
20223 +
20224 +               /* hack for *spaces to provide compatibility */
20225 +               if (unshare) {
20226 +                       struct nsproxy *old_nsp, *new_nsp;
20227 +
20228 +                       ret = unshare_nsproxy_namespaces(
20229 +                               CLONE_NEWUTS | CLONE_NEWIPC,
20230 +                               &new_nsp, NULL);
20231 +                       if (ret)
20232 +                               goto out;
20233 +
20234 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
20235 +                       vx_set_space(vxi, CLONE_NEWUTS | CLONE_NEWIPC);
20236 +                       put_nsproxy(old_nsp);
20237 +               }
20238 +       }
20239 +out:
20240 +       put_vx_info(old_vxi);
20241 +       return ret;
20242 +}
20243 +
20244 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
20245 +{
20246 +       struct task_struct *old_reaper;
20247 +
20248 +       if (!vxi)
20249 +               return -EINVAL;
20250 +
20251 +       vxdprintk(VXD_CBIT(xid, 6),
20252 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
20253 +               vxi, vxi->vx_id, p, p->xid, p->pid);
20254 +
20255 +       old_reaper = vxi->vx_reaper;
20256 +       if (old_reaper == p)
20257 +               return 0;
20258 +
20259 +       /* set new child reaper */
20260 +       get_task_struct(p);
20261 +       vxi->vx_reaper = p;
20262 +       put_task_struct(old_reaper);
20263 +       return 0;
20264 +}
20265 +
20266 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
20267 +{
20268 +       if (!vxi)
20269 +               return -EINVAL;
20270 +
20271 +       vxdprintk(VXD_CBIT(xid, 6),
20272 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
20273 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
20274 +
20275 +       vxi->vx_flags &= ~VXF_STATE_INIT;
20276 +       vxi->vx_initpid = p->tgid;
20277 +       return 0;
20278 +}
20279 +
20280 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
20281 +{
20282 +       vxdprintk(VXD_CBIT(xid, 6),
20283 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
20284 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
20285 +
20286 +       vxi->exit_code = code;
20287 +       vxi->vx_initpid = 0;
20288 +}
20289 +
20290 +
20291 +void vx_set_persistent(struct vx_info *vxi)
20292 +{
20293 +       vxdprintk(VXD_CBIT(xid, 6),
20294 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
20295 +
20296 +       get_vx_info(vxi);
20297 +       claim_vx_info(vxi, NULL);
20298 +}
20299 +
20300 +void vx_clear_persistent(struct vx_info *vxi)
20301 +{
20302 +       vxdprintk(VXD_CBIT(xid, 6),
20303 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
20304 +
20305 +       release_vx_info(vxi, NULL);
20306 +       put_vx_info(vxi);
20307 +}
20308 +
20309 +void vx_update_persistent(struct vx_info *vxi)
20310 +{
20311 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
20312 +               vx_set_persistent(vxi);
20313 +       else
20314 +               vx_clear_persistent(vxi);
20315 +}
20316 +
20317 +
20318 +/*     task must be current or locked          */
20319 +
20320 +void   exit_vx_info(struct task_struct *p, int code)
20321 +{
20322 +       struct vx_info *vxi = p->vx_info;
20323 +
20324 +       if (vxi) {
20325 +               atomic_dec(&vxi->cvirt.nr_threads);
20326 +               vx_nproc_dec(p);
20327 +
20328 +               vxi->exit_code = code;
20329 +               release_vx_info(vxi, p);
20330 +       }
20331 +}
20332 +
20333 +void   exit_vx_info_early(struct task_struct *p, int code)
20334 +{
20335 +       struct vx_info *vxi = p->vx_info;
20336 +
20337 +       if (vxi) {
20338 +               if (vxi->vx_initpid == p->tgid)
20339 +                       vx_exit_init(vxi, p, code);
20340 +               if (vxi->vx_reaper == p)
20341 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
20342 +       }
20343 +}
20344 +
20345 +
20346 +/* vserver syscall commands below here */
20347 +
20348 +/* taks xid and vx_info functions */
20349 +
20350 +#include <asm/uaccess.h>
20351 +
20352 +
20353 +int vc_task_xid(uint32_t id)
20354 +{
20355 +       xid_t xid;
20356 +
20357 +       if (id) {
20358 +               struct task_struct *tsk;
20359 +
20360 +               read_lock(&tasklist_lock);
20361 +               tsk = find_task_by_real_pid(id);
20362 +               xid = (tsk) ? tsk->xid : -ESRCH;
20363 +               read_unlock(&tasklist_lock);
20364 +       } else
20365 +               xid = vx_current_xid();
20366 +       return xid;
20367 +}
20368 +
20369 +
20370 +int vc_vx_info(struct vx_info *vxi, void __user *data)
20371 +{
20372 +       struct vcmd_vx_info_v0 vc_data;
20373 +
20374 +       vc_data.xid = vxi->vx_id;
20375 +       vc_data.initpid = vxi->vx_initpid;
20376 +
20377 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20378 +               return -EFAULT;
20379 +       return 0;
20380 +}
20381 +
20382 +
20383 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
20384 +{
20385 +       struct vcmd_ctx_stat_v0 vc_data;
20386 +
20387 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
20388 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
20389 +
20390 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20391 +               return -EFAULT;
20392 +       return 0;
20393 +}
20394 +
20395 +
20396 +/* context functions */
20397 +
20398 +int vc_ctx_create(uint32_t xid, void __user *data)
20399 +{
20400 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
20401 +       struct vx_info *new_vxi;
20402 +       int ret;
20403 +
20404 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20405 +               return -EFAULT;
20406 +
20407 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
20408 +               return -EINVAL;
20409 +
20410 +       new_vxi = __create_vx_info(xid);
20411 +       if (IS_ERR(new_vxi))
20412 +               return PTR_ERR(new_vxi);
20413 +
20414 +       /* initial flags */
20415 +       new_vxi->vx_flags = vc_data.flagword;
20416 +
20417 +       ret = -ENOEXEC;
20418 +       if (vs_state_change(new_vxi, VSC_STARTUP))
20419 +               goto out;
20420 +
20421 +       ret = vx_migrate_task(current, new_vxi, (!data));
20422 +       if (ret)
20423 +               goto out;
20424 +
20425 +       /* return context id on success */
20426 +       ret = new_vxi->vx_id;
20427 +
20428 +       /* get a reference for persistent contexts */
20429 +       if ((vc_data.flagword & VXF_PERSISTENT))
20430 +               vx_set_persistent(new_vxi);
20431 +out:
20432 +       release_vx_info(new_vxi, NULL);
20433 +       put_vx_info(new_vxi);
20434 +       return ret;
20435 +}
20436 +
20437 +
20438 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
20439 +{
20440 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
20441 +       int ret;
20442 +
20443 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20444 +               return -EFAULT;
20445 +
20446 +       ret = vx_migrate_task(current, vxi, 0);
20447 +       if (ret)
20448 +               return ret;
20449 +       if (vc_data.flagword & VXM_SET_INIT)
20450 +               ret = vx_set_init(vxi, current);
20451 +       if (ret)
20452 +               return ret;
20453 +       if (vc_data.flagword & VXM_SET_REAPER)
20454 +               ret = vx_set_reaper(vxi, current);
20455 +       return ret;
20456 +}
20457 +
20458 +
20459 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
20460 +{
20461 +       struct vcmd_ctx_flags_v0 vc_data;
20462 +
20463 +       vc_data.flagword = vxi->vx_flags;
20464 +
20465 +       /* special STATE flag handling */
20466 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
20467 +
20468 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20469 +               return -EFAULT;
20470 +       return 0;
20471 +}
20472 +
20473 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
20474 +{
20475 +       struct vcmd_ctx_flags_v0 vc_data;
20476 +       uint64_t mask, trigger;
20477 +
20478 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20479 +               return -EFAULT;
20480 +
20481 +       /* special STATE flag handling */
20482 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
20483 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
20484 +
20485 +       if (vxi == current->vx_info) {
20486 +               if (trigger & VXF_STATE_SETUP)
20487 +                       vx_mask_cap_bset(vxi, current);
20488 +               if (trigger & VXF_STATE_INIT) {
20489 +                       int ret;
20490 +
20491 +                       ret = vx_set_init(vxi, current);
20492 +                       if (ret)
20493 +                               return ret;
20494 +                       ret = vx_set_reaper(vxi, current);
20495 +                       if (ret)
20496 +                               return ret;
20497 +               }
20498 +       }
20499 +
20500 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
20501 +               vc_data.flagword, mask);
20502 +       if (trigger & VXF_PERSISTENT)
20503 +               vx_update_persistent(vxi);
20504 +
20505 +       return 0;
20506 +}
20507 +
20508 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
20509 +{
20510 +       if (bcaps)
20511 +               *bcaps = vxi->vx_bcaps;
20512 +       if (ccaps)
20513 +               *ccaps = vxi->vx_ccaps;
20514 +
20515 +       return 0;
20516 +}
20517 +
20518 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
20519 +{
20520 +       struct vcmd_ctx_caps_v1 vc_data;
20521 +       int ret;
20522 +
20523 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
20524 +       if (ret)
20525 +               return ret;
20526 +       vc_data.cmask = ~0ULL;
20527 +
20528 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20529 +               return -EFAULT;
20530 +       return 0;
20531 +}
20532 +
20533 +static int do_set_caps(struct vx_info *vxi,
20534 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
20535 +{
20536 +       vxi->vx_bcaps = vs_mask_flags(vxi->vx_bcaps, bcaps, bmask);
20537 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
20538 +
20539 +       return 0;
20540 +}
20541 +
20542 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
20543 +{
20544 +       struct vcmd_ctx_caps_v1 vc_data;
20545 +
20546 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20547 +               return -EFAULT;
20548 +
20549 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
20550 +}
20551 +
20552 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
20553 +{
20554 +       struct vcmd_bcaps vc_data;
20555 +       int ret;
20556 +
20557 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
20558 +       if (ret)
20559 +               return ret;
20560 +       vc_data.bmask = ~0ULL;
20561 +
20562 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20563 +               return -EFAULT;
20564 +       return 0;
20565 +}
20566 +
20567 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
20568 +{
20569 +       struct vcmd_bcaps vc_data;
20570 +
20571 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20572 +               return -EFAULT;
20573 +
20574 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
20575 +}
20576 +
20577 +
20578 +int vc_get_badness(struct vx_info *vxi, void __user *data)
20579 +{
20580 +       struct vcmd_badness_v0 vc_data;
20581 +
20582 +       vc_data.bias = vxi->vx_badness_bias;
20583 +
20584 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20585 +               return -EFAULT;
20586 +       return 0;
20587 +}
20588 +
20589 +int vc_set_badness(struct vx_info *vxi, void __user *data)
20590 +{
20591 +       struct vcmd_badness_v0 vc_data;
20592 +
20593 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20594 +               return -EFAULT;
20595 +
20596 +       vxi->vx_badness_bias = vc_data.bias;
20597 +       return 0;
20598 +}
20599 +
20600 +#include <linux/module.h>
20601 +
20602 +EXPORT_SYMBOL_GPL(free_vx_info);
20603 +
20604 diff -Nurp linux-2.6.22.15/kernel/vserver/cvirt.c linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/cvirt.c
20605 --- linux-2.6.22.15/kernel/vserver/cvirt.c      1969-12-31 19:00:00.000000000 -0500
20606 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/cvirt.c 2007-12-09 06:44:23.000000000 -0500
20607 @@ -0,0 +1,300 @@
20608 +/*
20609 + *  linux/kernel/vserver/cvirt.c
20610 + *
20611 + *  Virtual Server: Context Virtualization
20612 + *
20613 + *  Copyright (C) 2004-2007  Herbert Pötzl
20614 + *
20615 + *  V0.01  broken out from limit.c
20616 + *  V0.02  added utsname stuff
20617 + *  V0.03  changed vcmds to vxi arg
20618 + *
20619 + */
20620 +
20621 +#include <linux/types.h>
20622 +#include <linux/vs_cvirt.h>
20623 +#include <linux/vserver/switch.h>
20624 +#include <linux/vserver/cvirt_cmd.h>
20625 +
20626 +#include <asm/uaccess.h>
20627 +
20628 +
20629 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
20630 +{
20631 +       struct vx_info *vxi = current->vx_info;
20632 +
20633 +       set_normalized_timespec(uptime,
20634 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
20635 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
20636 +       if (!idle)
20637 +               return;
20638 +       set_normalized_timespec(idle,
20639 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
20640 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
20641 +       return;
20642 +}
20643 +
20644 +uint64_t vx_idle_jiffies(void)
20645 +{
20646 +       return init_task.utime + init_task.stime;
20647 +}
20648 +
20649 +
20650 +
20651 +static inline uint32_t __update_loadavg(uint32_t load,
20652 +       int wsize, int delta, int n)
20653 +{
20654 +       unsigned long long calc, prev;
20655 +
20656 +       /* just set it to n */
20657 +       if (unlikely(delta >= wsize))
20658 +               return (n << FSHIFT);
20659 +
20660 +       calc = delta * n;
20661 +       calc <<= FSHIFT;
20662 +       prev = (wsize - delta);
20663 +       prev *= load;
20664 +       calc += prev;
20665 +       do_div(calc, wsize);
20666 +       return calc;
20667 +}
20668 +
20669 +
20670 +void vx_update_load(struct vx_info *vxi)
20671 +{
20672 +       uint32_t now, last, delta;
20673 +       unsigned int nr_running, nr_uninterruptible;
20674 +       unsigned int total;
20675 +       unsigned long flags;
20676 +
20677 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
20678 +
20679 +       now = jiffies;
20680 +       last = vxi->cvirt.load_last;
20681 +       delta = now - last;
20682 +
20683 +       if (delta < 5*HZ)
20684 +               goto out;
20685 +
20686 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
20687 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
20688 +       total = nr_running + nr_uninterruptible;
20689 +
20690 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
20691 +               60*HZ, delta, total);
20692 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
20693 +               5*60*HZ, delta, total);
20694 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
20695 +               15*60*HZ, delta, total);
20696 +
20697 +       vxi->cvirt.load_last = now;
20698 +out:
20699 +       atomic_inc(&vxi->cvirt.load_updates);
20700 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
20701 +}
20702 +
20703 +
20704 +/*
20705 + * Commands to do_syslog:
20706 + *
20707 + *      0 -- Close the log.  Currently a NOP.
20708 + *      1 -- Open the log. Currently a NOP.
20709 + *      2 -- Read from the log.
20710 + *      3 -- Read all messages remaining in the ring buffer.
20711 + *      4 -- Read and clear all messages remaining in the ring buffer
20712 + *      5 -- Clear ring buffer.
20713 + *      6 -- Disable printk's to console
20714 + *      7 -- Enable printk's to console
20715 + *      8 -- Set level of messages printed to console
20716 + *      9 -- Return number of unread characters in the log buffer
20717 + *     10 -- Return size of the log buffer
20718 + */
20719 +int vx_do_syslog(int type, char __user *buf, int len)
20720 +{
20721 +       int error = 0;
20722 +       int do_clear = 0;
20723 +       struct vx_info *vxi = current->vx_info;
20724 +       struct _vx_syslog *log;
20725 +
20726 +       if (!vxi)
20727 +               return -EINVAL;
20728 +       log = &vxi->cvirt.syslog;
20729 +
20730 +       switch (type) {
20731 +       case 0:         /* Close log */
20732 +       case 1:         /* Open log */
20733 +               break;
20734 +       case 2:         /* Read from log */
20735 +               error = wait_event_interruptible(log->log_wait,
20736 +                       (log->log_start - log->log_end));
20737 +               if (error)
20738 +                       break;
20739 +               spin_lock_irq(&log->logbuf_lock);
20740 +               spin_unlock_irq(&log->logbuf_lock);
20741 +               break;
20742 +       case 4:         /* Read/clear last kernel messages */
20743 +               do_clear = 1;
20744 +               /* fall through */
20745 +       case 3:         /* Read last kernel messages */
20746 +               return 0;
20747 +
20748 +       case 5:         /* Clear ring buffer */
20749 +               return 0;
20750 +
20751 +       case 6:         /* Disable logging to console */
20752 +       case 7:         /* Enable logging to console */
20753 +       case 8:         /* Set level of messages printed to console */
20754 +               break;
20755 +
20756 +       case 9:         /* Number of chars in the log buffer */
20757 +               return 0;
20758 +       case 10:        /* Size of the log buffer */
20759 +               return 0;
20760 +       default:
20761 +               error = -EINVAL;
20762 +               break;
20763 +       }
20764 +       return error;
20765 +}
20766 +
20767 +
20768 +/* virtual host info names */
20769 +
20770 +static char *vx_vhi_name(struct vx_info *vxi, int id)
20771 +{
20772 +       struct nsproxy *nsproxy;
20773 +       struct uts_namespace *uts;
20774 +
20775 +
20776 +       if (id == VHIN_CONTEXT)
20777 +               return vxi->vx_name;
20778 +
20779 +       nsproxy = vxi->vx_nsproxy;
20780 +       if (!nsproxy)
20781 +               return NULL;
20782 +
20783 +       uts = nsproxy->uts_ns;
20784 +       if (!uts)
20785 +               return NULL;
20786 +
20787 +       switch (id) {
20788 +       case VHIN_SYSNAME:
20789 +               return uts->name.sysname;
20790 +       case VHIN_NODENAME:
20791 +               return uts->name.nodename;
20792 +       case VHIN_RELEASE:
20793 +               return uts->name.release;
20794 +       case VHIN_VERSION:
20795 +               return uts->name.version;
20796 +       case VHIN_MACHINE:
20797 +               return uts->name.machine;
20798 +       case VHIN_DOMAINNAME:
20799 +               return uts->name.domainname;
20800 +       default:
20801 +               return NULL;
20802 +       }
20803 +       return NULL;
20804 +}
20805 +
20806 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
20807 +{
20808 +       struct vcmd_vhi_name_v0 vc_data;
20809 +       char *name;
20810 +
20811 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20812 +               return -EFAULT;
20813 +
20814 +       name = vx_vhi_name(vxi, vc_data.field);
20815 +       if (!name)
20816 +               return -EINVAL;
20817 +
20818 +       memcpy(name, vc_data.name, 65);
20819 +       return 0;
20820 +}
20821 +
20822 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
20823 +{
20824 +       struct vcmd_vhi_name_v0 vc_data;
20825 +       char *name;
20826 +
20827 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20828 +               return -EFAULT;
20829 +
20830 +       name = vx_vhi_name(vxi, vc_data.field);
20831 +       if (!name)
20832 +               return -EINVAL;
20833 +
20834 +       memcpy(vc_data.name, name, 65);
20835 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20836 +               return -EFAULT;
20837 +       return 0;
20838 +}
20839 +
20840 +
20841 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
20842 +{
20843 +       struct vcmd_virt_stat_v0 vc_data;
20844 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
20845 +       struct timespec uptime;
20846 +
20847 +       do_posix_clock_monotonic_gettime(&uptime);
20848 +       set_normalized_timespec(&uptime,
20849 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
20850 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
20851 +
20852 +       vc_data.offset = timeval_to_ns(&cvirt->bias_tv);
20853 +       vc_data.uptime = timespec_to_ns(&uptime);
20854 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
20855 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
20856 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
20857 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
20858 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
20859 +       vc_data.load[0] = cvirt->load[0];
20860 +       vc_data.load[1] = cvirt->load[1];
20861 +       vc_data.load[2] = cvirt->load[2];
20862 +
20863 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20864 +               return -EFAULT;
20865 +       return 0;
20866 +}
20867 +
20868 +
20869 +#ifdef CONFIG_VSERVER_VTIME
20870 +
20871 +/* virtualized time base */
20872 +
20873 +void vx_gettimeofday(struct timeval *tv)
20874 +{
20875 +       do_gettimeofday(tv);
20876 +       if (!vx_flags(VXF_VIRT_TIME, 0))
20877 +               return;
20878 +
20879 +       tv->tv_sec += current->vx_info->cvirt.bias_tv.tv_sec;
20880 +       tv->tv_usec += current->vx_info->cvirt.bias_tv.tv_usec;
20881 +
20882 +       if (tv->tv_usec >= USEC_PER_SEC) {
20883 +               tv->tv_sec++;
20884 +               tv->tv_usec -= USEC_PER_SEC;
20885 +       } else if (tv->tv_usec < 0) {
20886 +               tv->tv_sec--;
20887 +               tv->tv_usec += USEC_PER_SEC;
20888 +       }
20889 +}
20890 +
20891 +int vx_settimeofday(struct timespec *ts)
20892 +{
20893 +       struct timeval tv;
20894 +
20895 +       if (!vx_flags(VXF_VIRT_TIME, 0))
20896 +               return do_settimeofday(ts);
20897 +
20898 +       do_gettimeofday(&tv);
20899 +       current->vx_info->cvirt.bias_tv.tv_sec =
20900 +               ts->tv_sec - tv.tv_sec;
20901 +       current->vx_info->cvirt.bias_tv.tv_usec =
20902 +               (ts->tv_nsec/NSEC_PER_USEC) - tv.tv_usec;
20903 +       return 0;
20904 +}
20905 +
20906 +#endif
20907 +
20908 diff -Nurp linux-2.6.22.15/kernel/vserver/cvirt_init.h linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/cvirt_init.h
20909 --- linux-2.6.22.15/kernel/vserver/cvirt_init.h 1969-12-31 19:00:00.000000000 -0500
20910 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/cvirt_init.h    2007-12-09 06:44:23.000000000 -0500
20911 @@ -0,0 +1,69 @@
20912 +
20913 +
20914 +extern uint64_t vx_idle_jiffies(void);
20915 +
20916 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
20917 +{
20918 +       uint64_t idle_jiffies = vx_idle_jiffies();
20919 +       uint64_t nsuptime;
20920 +
20921 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
20922 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
20923 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
20924 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
20925 +       cvirt->bias_tv.tv_sec = 0;
20926 +       cvirt->bias_tv.tv_usec = 0;
20927 +
20928 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
20929 +       atomic_set(&cvirt->nr_threads, 0);
20930 +       atomic_set(&cvirt->nr_running, 0);
20931 +       atomic_set(&cvirt->nr_uninterruptible, 0);
20932 +       atomic_set(&cvirt->nr_onhold, 0);
20933 +
20934 +       spin_lock_init(&cvirt->load_lock);
20935 +       cvirt->load_last = jiffies;
20936 +       atomic_set(&cvirt->load_updates, 0);
20937 +       cvirt->load[0] = 0;
20938 +       cvirt->load[1] = 0;
20939 +       cvirt->load[2] = 0;
20940 +       atomic_set(&cvirt->total_forks, 0);
20941 +
20942 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
20943 +       init_waitqueue_head(&cvirt->syslog.log_wait);
20944 +       cvirt->syslog.log_start = 0;
20945 +       cvirt->syslog.log_end = 0;
20946 +       cvirt->syslog.con_start = 0;
20947 +       cvirt->syslog.logged_chars = 0;
20948 +}
20949 +
20950 +static inline
20951 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
20952 +{
20953 +       // cvirt_pc->cpustat = { 0 };
20954 +}
20955 +
20956 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
20957 +{
20958 +       int value;
20959 +
20960 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
20961 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
20962 +               cvirt, value);
20963 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
20964 +               "!!! cvirt: %p[nr_running] = %d on exit.",
20965 +               cvirt, value);
20966 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
20967 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
20968 +               cvirt, value);
20969 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
20970 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
20971 +               cvirt, value);
20972 +       return;
20973 +}
20974 +
20975 +static inline
20976 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
20977 +{
20978 +       return;
20979 +}
20980 +
20981 diff -Nurp linux-2.6.22.15/kernel/vserver/cvirt_proc.h linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/cvirt_proc.h
20982 --- linux-2.6.22.15/kernel/vserver/cvirt_proc.h 1969-12-31 19:00:00.000000000 -0500
20983 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/cvirt_proc.h    2007-12-09 06:44:23.000000000 -0500
20984 @@ -0,0 +1,133 @@
20985 +#ifndef _VX_CVIRT_PROC_H
20986 +#define _VX_CVIRT_PROC_H
20987 +
20988 +#include <linux/nsproxy.h>
20989 +#include <linux/mnt_namespace.h>
20990 +#include <linux/utsname.h>
20991 +#include <linux/ipc.h>
20992 +
20993 +
20994 +static inline
20995 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
20996 +{
20997 +       struct mnt_namespace *ns;
20998 +       struct uts_namespace *uts;
20999 +       struct ipc_namespace *ipc;
21000 +       struct vfsmount *mnt;
21001 +       char *path, *root;
21002 +       int length = 0;
21003 +
21004 +       if (!nsproxy)
21005 +               goto out;
21006 +
21007 +       length += sprintf(buffer + length,
21008 +               "NSProxy:\t%p [%p,%p,%p]\n",
21009 +               nsproxy, nsproxy->mnt_ns,
21010 +               nsproxy->uts_ns, nsproxy->ipc_ns);
21011 +
21012 +       ns = nsproxy->mnt_ns;
21013 +       if (!ns)
21014 +               goto skip_ns;
21015 +
21016 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
21017 +       if (!path)
21018 +               goto skip_ns;
21019 +
21020 +       mnt = ns->root;
21021 +       root = d_path(mnt->mnt_root, mnt->mnt_parent, path, PATH_MAX - 2);
21022 +       length += sprintf(buffer + length,
21023 +               "Namespace:\t%p [#%u]\n"
21024 +               "RootPath:\t%s\n",
21025 +               ns, atomic_read(&ns->count),
21026 +               root);
21027 +       kfree(path);
21028 +skip_ns:
21029 +
21030 +       uts = nsproxy->uts_ns;
21031 +       if (!uts)
21032 +               goto skip_uts;
21033 +
21034 +       length += sprintf(buffer + length,
21035 +               "SysName:\t%.*s\n"
21036 +               "NodeName:\t%.*s\n"
21037 +               "Release:\t%.*s\n"
21038 +               "Version:\t%.*s\n"
21039 +               "Machine:\t%.*s\n"
21040 +               "DomainName:\t%.*s\n",
21041 +               __NEW_UTS_LEN, uts->name.sysname,
21042 +               __NEW_UTS_LEN, uts->name.nodename,
21043 +               __NEW_UTS_LEN, uts->name.release,
21044 +               __NEW_UTS_LEN, uts->name.version,
21045 +               __NEW_UTS_LEN, uts->name.machine,
21046 +               __NEW_UTS_LEN, uts->name.domainname);
21047 +skip_uts:
21048 +
21049 +       ipc = nsproxy->ipc_ns;
21050 +       if (!ipc)
21051 +               goto skip_ipc;
21052 +
21053 +       length += sprintf(buffer + length,
21054 +               "SEMS:\t\t%d %d %d %d  %d\n"
21055 +               "MSG:\t\t%d %d %d\n"
21056 +               "SHM:\t\t%lu %lu  %d %d\n",
21057 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
21058 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
21059 +               ipc->used_sems,
21060 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
21061 +               (unsigned long)ipc->shm_ctlmax,
21062 +               (unsigned long)ipc->shm_ctlall,
21063 +               ipc->shm_ctlmni, ipc->shm_tot);
21064 +skip_ipc:
21065 +out:
21066 +       return length;
21067 +}
21068 +
21069 +
21070 +#include <linux/sched.h>
21071 +
21072 +#define LOAD_INT(x) ((x) >> FSHIFT)
21073 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
21074 +
21075 +static inline
21076 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
21077 +{
21078 +       int length = 0;
21079 +       int a, b, c;
21080 +
21081 +       length += sprintf(buffer + length,
21082 +               "BiasUptime:\t%lu.%02lu\n",
21083 +               (unsigned long)cvirt->bias_uptime.tv_sec,
21084 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
21085 +
21086 +       a = cvirt->load[0] + (FIXED_1 / 200);
21087 +       b = cvirt->load[1] + (FIXED_1 / 200);
21088 +       c = cvirt->load[2] + (FIXED_1 / 200);
21089 +       length += sprintf(buffer + length,
21090 +               "nr_threads:\t%d\n"
21091 +               "nr_running:\t%d\n"
21092 +               "nr_unintr:\t%d\n"
21093 +               "nr_onhold:\t%d\n"
21094 +               "load_updates:\t%d\n"
21095 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
21096 +               "total_forks:\t%d\n",
21097 +               atomic_read(&cvirt->nr_threads),
21098 +               atomic_read(&cvirt->nr_running),
21099 +               atomic_read(&cvirt->nr_uninterruptible),
21100 +               atomic_read(&cvirt->nr_onhold),
21101 +               atomic_read(&cvirt->load_updates),
21102 +               LOAD_INT(a), LOAD_FRAC(a),
21103 +               LOAD_INT(b), LOAD_FRAC(b),
21104 +               LOAD_INT(c), LOAD_FRAC(c),
21105 +               atomic_read(&cvirt->total_forks));
21106 +       return length;
21107 +}
21108 +
21109 +static inline
21110 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
21111 +       char *buffer, int cpu)
21112 +{
21113 +       int length = 0;
21114 +       return length;
21115 +}
21116 +
21117 +#endif /* _VX_CVIRT_PROC_H */
21118 diff -Nurp linux-2.6.22.15/kernel/vserver/debug.c linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/debug.c
21119 --- linux-2.6.22.15/kernel/vserver/debug.c      1969-12-31 19:00:00.000000000 -0500
21120 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/debug.c 2007-12-09 06:44:23.000000000 -0500
21121 @@ -0,0 +1,32 @@
21122 +/*
21123 + *  kernel/vserver/debug.c
21124 + *
21125 + *  Copyright (C) 2005-2007 Herbert Pötzl
21126 + *
21127 + *  V0.01  vx_info dump support
21128 + *
21129 + */
21130 +
21131 +#include <linux/module.h>
21132 +
21133 +#include <linux/vserver/context.h>
21134 +
21135 +
21136 +void   dump_vx_info(struct vx_info *vxi, int level)
21137 +{
21138 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
21139 +               atomic_read(&vxi->vx_usecnt),
21140 +               atomic_read(&vxi->vx_tasks),
21141 +               vxi->vx_state);
21142 +       if (level > 0) {
21143 +               __dump_vx_limit(&vxi->limit);
21144 +               __dump_vx_sched(&vxi->sched);
21145 +               __dump_vx_cvirt(&vxi->cvirt);
21146 +               __dump_vx_cacct(&vxi->cacct);
21147 +       }
21148 +       printk("---\n");
21149 +}
21150 +
21151 +
21152 +EXPORT_SYMBOL_GPL(dump_vx_info);
21153 +
21154 diff -Nurp linux-2.6.22.15/kernel/vserver/device.c linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/device.c
21155 --- linux-2.6.22.15/kernel/vserver/device.c     1969-12-31 19:00:00.000000000 -0500
21156 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/device.c        2007-12-09 06:44:23.000000000 -0500
21157 @@ -0,0 +1,443 @@
21158 +/*
21159 + *  linux/kernel/vserver/device.c
21160 + *
21161 + *  Linux-VServer: Device Support
21162 + *
21163 + *  Copyright (C) 2006  Herbert Pötzl
21164 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
21165 + *
21166 + *  V0.01  device mapping basics
21167 + *  V0.02  added defaults
21168 + *
21169 + */
21170 +
21171 +#include <linux/slab.h>
21172 +#include <linux/rcupdate.h>
21173 +#include <linux/fs.h>
21174 +#include <linux/namei.h>
21175 +#include <linux/hash.h>
21176 +
21177 +#include <asm/errno.h>
21178 +#include <asm/uaccess.h>
21179 +#include <linux/vserver/base.h>
21180 +#include <linux/vserver/debug.h>
21181 +#include <linux/vserver/context.h>
21182 +#include <linux/vserver/device.h>
21183 +#include <linux/vserver/device_cmd.h>
21184 +
21185 +
21186 +#define DMAP_HASH_BITS 4
21187 +
21188 +
21189 +struct vs_mapping {
21190 +       union {
21191 +               struct hlist_node hlist;
21192 +               struct list_head list;
21193 +       } u;
21194 +#define dm_hlist       u.hlist
21195 +#define dm_list                u.list
21196 +       xid_t xid;
21197 +       dev_t device;
21198 +       struct vx_dmap_target target;
21199 +};
21200 +
21201 +
21202 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
21203 +
21204 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
21205 +
21206 +static struct vx_dmap_target dmap_defaults[2] = {
21207 +       { .flags = DATTR_OPEN },
21208 +       { .flags = DATTR_OPEN },
21209 +};
21210 +
21211 +
21212 +struct kmem_cache *dmap_cachep __read_mostly;
21213 +
21214 +int __init dmap_cache_init(void)
21215 +{
21216 +       dmap_cachep = kmem_cache_create("dmap_cache",
21217 +               sizeof(struct vs_mapping), 0,
21218 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
21219 +       return 0;
21220 +}
21221 +
21222 +__initcall(dmap_cache_init);
21223 +
21224 +
21225 +static inline unsigned int __hashval(dev_t dev, int bits)
21226 +{
21227 +       return hash_long((unsigned long)dev, bits);
21228 +}
21229 +
21230 +
21231 +/*     __hash_mapping()
21232 + *     add the mapping to the hash table
21233 + */
21234 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
21235 +{
21236 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
21237 +       struct hlist_head *head, *hash = dmap_main_hash;
21238 +       int device = vdm->device;
21239 +
21240 +       spin_lock(hash_lock);
21241 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
21242 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
21243 +
21244 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
21245 +       hlist_add_head(&vdm->dm_hlist, head);
21246 +       spin_unlock(hash_lock);
21247 +}
21248 +
21249 +
21250 +static inline int __mode_to_default(umode_t mode)
21251 +{
21252 +       switch (mode) {
21253 +       case S_IFBLK:
21254 +               return 0;
21255 +       case S_IFCHR:
21256 +               return 1;
21257 +       default:
21258 +               BUG();
21259 +       }
21260 +}
21261 +
21262 +
21263 +/*     __set_default()
21264 + *     set a default
21265 + */
21266 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
21267 +       struct vx_dmap_target *vdmt)
21268 +{
21269 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
21270 +       spin_lock(hash_lock);
21271 +
21272 +       if (vxi)
21273 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
21274 +       else
21275 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
21276 +
21277 +
21278 +       spin_unlock(hash_lock);
21279 +
21280 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
21281 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
21282 +}
21283 +
21284 +
21285 +/*     __remove_default()
21286 + *     remove a default
21287 + */
21288 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
21289 +{
21290 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
21291 +       spin_lock(hash_lock);
21292 +
21293 +       if (vxi)
21294 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
21295 +       else    /* remove == reset */
21296 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
21297 +
21298 +       spin_unlock(hash_lock);
21299 +       return 0;
21300 +}
21301 +
21302 +
21303 +/*     __find_mapping()
21304 + *     find a mapping in the hash table
21305 + *
21306 + *     caller must hold hash_lock
21307 + */
21308 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
21309 +       struct vs_mapping **local, struct vs_mapping **global)
21310 +{
21311 +       struct hlist_head *hash = dmap_main_hash;
21312 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
21313 +       struct hlist_node *pos;
21314 +       struct vs_mapping *vdm;
21315 +
21316 +       *local = NULL;
21317 +       if (global)
21318 +               *global = NULL;
21319 +
21320 +       hlist_for_each(pos, head) {
21321 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
21322 +
21323 +               if ((vdm->device == device) &&
21324 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
21325 +                       if (vdm->xid == xid) {
21326 +                               *local = vdm;
21327 +                               return 1;
21328 +                       } else if (global && vdm->xid == 0)
21329 +                               *global = vdm;
21330 +               }
21331 +       }
21332 +
21333 +       if (global && *global)
21334 +               return 0;
21335 +       else
21336 +               return -ENOENT;
21337 +}
21338 +
21339 +
21340 +/*     __lookup_mapping()
21341 + *     find a mapping and store the result in target and flags
21342 + */
21343 +static inline int __lookup_mapping(struct vx_info *vxi,
21344 +       dev_t device, dev_t *target, int *flags, umode_t mode)
21345 +{
21346 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
21347 +       struct vs_mapping *vdm, *global;
21348 +       struct vx_dmap_target *vdmt;
21349 +       int ret = 0;
21350 +       xid_t xid = vxi->vx_id;
21351 +       int index;
21352 +
21353 +       spin_lock(hash_lock);
21354 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
21355 +               ret = 1;
21356 +               vdmt = &vdm->target;
21357 +               goto found;
21358 +       }
21359 +
21360 +       index = __mode_to_default(mode);
21361 +       if (vxi && vxi->dmap.targets[index].flags) {
21362 +               ret = 2;
21363 +               vdmt = &vxi->dmap.targets[index];
21364 +       } else if (global) {
21365 +               ret = 3;
21366 +               vdmt = &global->target;
21367 +               goto found;
21368 +       } else {
21369 +               ret = 4;
21370 +               vdmt = &dmap_defaults[index];
21371 +       }
21372 +
21373 +found:
21374 +       if (target && (vdmt->flags & DATTR_REMAP))
21375 +               *target = vdmt->target;
21376 +       else if (target)
21377 +               *target = device;
21378 +       if (flags)
21379 +               *flags = vdmt->flags;
21380 +
21381 +       spin_unlock(hash_lock);
21382 +
21383 +       return ret;
21384 +}
21385 +
21386 +
21387 +/*     __remove_mapping()
21388 + *     remove a mapping from the hash table
21389 + */
21390 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
21391 +       umode_t mode)
21392 +{
21393 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
21394 +       struct vs_mapping *vdm = NULL;
21395 +       int ret = 0;
21396 +
21397 +       spin_lock(hash_lock);
21398 +
21399 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
21400 +               NULL);
21401 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
21402 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
21403 +       if (ret < 0)
21404 +               goto out;
21405 +       hlist_del(&vdm->dm_hlist);
21406 +
21407 +out:
21408 +       spin_unlock(hash_lock);
21409 +       if (vdm)
21410 +               kmem_cache_free(dmap_cachep, vdm);
21411 +       return ret;
21412 +}
21413 +
21414 +
21415 +
21416 +int vs_map_device(struct vx_info *vxi,
21417 +       dev_t device, dev_t *target, umode_t mode)
21418 +{
21419 +       int ret, flags = DATTR_MASK;
21420 +
21421 +       if (!vxi) {
21422 +               if (target)
21423 +                       *target = device;
21424 +               goto out;
21425 +       }
21426 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
21427 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
21428 +               device, target ? *target : 0, flags, mode, ret);
21429 +out:
21430 +       return (flags & DATTR_MASK);
21431 +}
21432 +
21433 +
21434 +
21435 +static int do_set_mapping(struct vx_info *vxi,
21436 +       dev_t device, dev_t target, int flags, umode_t mode)
21437 +{
21438 +       if (device) {
21439 +               struct vs_mapping *new;
21440 +
21441 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
21442 +               if (!new)
21443 +                       return -ENOMEM;
21444 +
21445 +               INIT_HLIST_NODE(&new->dm_hlist);
21446 +               new->device = device;
21447 +               new->target.target = target;
21448 +               new->target.flags = flags | mode;
21449 +               new->xid = (vxi ? vxi->vx_id : 0);
21450 +
21451 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
21452 +               __hash_mapping(vxi, new);
21453 +       } else {
21454 +               struct vx_dmap_target new = {
21455 +                       .target = target,
21456 +                       .flags = flags | mode,
21457 +               };
21458 +               __set_default(vxi, mode, &new);
21459 +       }
21460 +       return 0;
21461 +}
21462 +
21463 +
21464 +static int do_unset_mapping(struct vx_info *vxi,
21465 +       dev_t device, dev_t target, int flags, umode_t mode)
21466 +{
21467 +       int ret = -EINVAL;
21468 +
21469 +       if (device) {
21470 +               ret = __remove_mapping(vxi, device, mode);
21471 +               if (ret < 0)
21472 +                       goto out;
21473 +       } else {
21474 +               ret = __remove_default(vxi, mode);
21475 +               if (ret < 0)
21476 +                       goto out;
21477 +       }
21478 +
21479 +out:
21480 +       return ret;
21481 +}
21482 +
21483 +
21484 +static inline int __user_device(const char __user *name, dev_t *dev,
21485 +       umode_t *mode)
21486 +{
21487 +       struct nameidata nd;
21488 +       int ret;
21489 +
21490 +       if (!name) {
21491 +               *dev = 0;
21492 +               return 0;
21493 +       }
21494 +       ret = user_path_walk_link(name, &nd);
21495 +       if (ret)
21496 +               return ret;
21497 +       if (nd.dentry->d_inode) {
21498 +               *dev = nd.dentry->d_inode->i_rdev;
21499 +               *mode = nd.dentry->d_inode->i_mode;
21500 +       }
21501 +       path_release(&nd);
21502 +       return 0;
21503 +}
21504 +
21505 +static inline int __mapping_mode(dev_t device, dev_t target,
21506 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
21507 +{
21508 +       if (device)
21509 +               *mode = device_mode & S_IFMT;
21510 +       else if (target)
21511 +               *mode = target_mode & S_IFMT;
21512 +       else
21513 +               *mode = 0;
21514 +
21515 +       /* if both given, device and target mode have to match */
21516 +       if (device && target &&
21517 +               ((device_mode ^ target_mode) & S_IFMT))
21518 +               return -EINVAL;
21519 +       return 0;
21520 +}
21521 +
21522 +
21523 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
21524 +       const char __user *target_path, int flags, int set)
21525 +{
21526 +       dev_t device = ~0, target = ~0;
21527 +       umode_t device_mode = 0, target_mode = 0, mode;
21528 +       int ret;
21529 +
21530 +       ret = __user_device(device_path, &device, &device_mode);
21531 +       if (ret)
21532 +               return ret;
21533 +       ret = __user_device(target_path, &target, &target_mode);
21534 +       if (ret)
21535 +               return ret;
21536 +
21537 +       ret = __mapping_mode(device, target,
21538 +               device_mode, target_mode, &mode);
21539 +       if (ret)
21540 +               return ret;
21541 +
21542 +       if (set)
21543 +               return do_set_mapping(vxi, device, target,
21544 +                       flags, mode);
21545 +       else
21546 +               return do_unset_mapping(vxi, device, target,
21547 +                       flags, mode);
21548 +}
21549 +
21550 +
21551 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
21552 +{
21553 +       struct vcmd_set_mapping_v0 vc_data;
21554 +
21555 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21556 +               return -EFAULT;
21557 +
21558 +       return do_mapping(vxi, vc_data.device, vc_data.target,
21559 +               vc_data.flags, 1);
21560 +}
21561 +
21562 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
21563 +{
21564 +       struct vcmd_set_mapping_v0 vc_data;
21565 +
21566 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21567 +               return -EFAULT;
21568 +
21569 +       return do_mapping(vxi, vc_data.device, vc_data.target,
21570 +               vc_data.flags, 0);
21571 +}
21572 +
21573 +
21574 +#ifdef CONFIG_COMPAT
21575 +
21576 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
21577 +{
21578 +       struct vcmd_set_mapping_v0_x32 vc_data;
21579 +
21580 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21581 +               return -EFAULT;
21582 +
21583 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
21584 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
21585 +}
21586 +
21587 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
21588 +{
21589 +       struct vcmd_set_mapping_v0_x32 vc_data;
21590 +
21591 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21592 +               return -EFAULT;
21593 +
21594 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
21595 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
21596 +}
21597 +
21598 +#endif /* CONFIG_COMPAT */
21599 +
21600 +
21601 diff -Nurp linux-2.6.22.15/kernel/vserver/dlimit.c linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/dlimit.c
21602 --- linux-2.6.22.15/kernel/vserver/dlimit.c     1969-12-31 19:00:00.000000000 -0500
21603 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/dlimit.c        2007-12-09 06:44:23.000000000 -0500
21604 @@ -0,0 +1,520 @@
21605 +/*
21606 + *  linux/kernel/vserver/dlimit.c
21607 + *
21608 + *  Virtual Server: Context Disk Limits
21609 + *
21610 + *  Copyright (C) 2004-2007  Herbert Pötzl
21611 + *
21612 + *  V0.01  initial version
21613 + *  V0.02  compat32 splitup
21614 + *
21615 + */
21616 +
21617 +#include <linux/statfs.h>
21618 +#include <linux/vs_tag.h>
21619 +#include <linux/vs_dlimit.h>
21620 +#include <linux/vserver/dlimit_cmd.h>
21621 +
21622 +#include <asm/uaccess.h>
21623 +
21624 +/*     __alloc_dl_info()
21625 +
21626 +       * allocate an initialized dl_info struct
21627 +       * doesn't make it visible (hash)                        */
21628 +
21629 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
21630 +{
21631 +       struct dl_info *new = NULL;
21632 +
21633 +       vxdprintk(VXD_CBIT(dlim, 5),
21634 +               "alloc_dl_info(%p,%d)*", sb, tag);
21635 +
21636 +       /* would this benefit from a slab cache? */
21637 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
21638 +       if (!new)
21639 +               return 0;
21640 +
21641 +       memset(new, 0, sizeof(struct dl_info));
21642 +       new->dl_tag = tag;
21643 +       new->dl_sb = sb;
21644 +       INIT_RCU_HEAD(&new->dl_rcu);
21645 +       INIT_HLIST_NODE(&new->dl_hlist);
21646 +       spin_lock_init(&new->dl_lock);
21647 +       atomic_set(&new->dl_refcnt, 0);
21648 +       atomic_set(&new->dl_usecnt, 0);
21649 +
21650 +       /* rest of init goes here */
21651 +
21652 +       vxdprintk(VXD_CBIT(dlim, 4),
21653 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
21654 +       return new;
21655 +}
21656 +
21657 +/*     __dealloc_dl_info()
21658 +
21659 +       * final disposal of dl_info                             */
21660 +
21661 +static void __dealloc_dl_info(struct dl_info *dli)
21662 +{
21663 +       vxdprintk(VXD_CBIT(dlim, 4),
21664 +               "dealloc_dl_info(%p)", dli);
21665 +
21666 +       dli->dl_hlist.next = LIST_POISON1;
21667 +       dli->dl_tag = -1;
21668 +       dli->dl_sb = 0;
21669 +
21670 +       BUG_ON(atomic_read(&dli->dl_usecnt));
21671 +       BUG_ON(atomic_read(&dli->dl_refcnt));
21672 +
21673 +       kfree(dli);
21674 +}
21675 +
21676 +
21677 +/*     hash table for dl_info hash */
21678 +
21679 +#define DL_HASH_SIZE   13
21680 +
21681 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
21682 +
21683 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
21684 +
21685 +
21686 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
21687 +{
21688 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
21689 +}
21690 +
21691 +
21692 +
21693 +/*     __hash_dl_info()
21694 +
21695 +       * add the dli to the global hash table
21696 +       * requires the hash_lock to be held                     */
21697 +
21698 +static inline void __hash_dl_info(struct dl_info *dli)
21699 +{
21700 +       struct hlist_head *head;
21701 +
21702 +       vxdprintk(VXD_CBIT(dlim, 6),
21703 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
21704 +       get_dl_info(dli);
21705 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
21706 +       hlist_add_head_rcu(&dli->dl_hlist, head);
21707 +}
21708 +
21709 +/*     __unhash_dl_info()
21710 +
21711 +       * remove the dli from the global hash table
21712 +       * requires the hash_lock to be held                     */
21713 +
21714 +static inline void __unhash_dl_info(struct dl_info *dli)
21715 +{
21716 +       vxdprintk(VXD_CBIT(dlim, 6),
21717 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
21718 +       hlist_del_rcu(&dli->dl_hlist);
21719 +       put_dl_info(dli);
21720 +}
21721 +
21722 +
21723 +/*     __lookup_dl_info()
21724 +
21725 +       * requires the rcu_read_lock()
21726 +       * doesn't increment the dl_refcnt                       */
21727 +
21728 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
21729 +{
21730 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
21731 +       struct hlist_node *pos;
21732 +       struct dl_info *dli;
21733 +
21734 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
21735 +
21736 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
21737 +                       return dli;
21738 +               }
21739 +       }
21740 +       return NULL;
21741 +}
21742 +
21743 +
21744 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
21745 +{
21746 +       struct dl_info *dli;
21747 +
21748 +       rcu_read_lock();
21749 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
21750 +       vxdprintk(VXD_CBIT(dlim, 7),
21751 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
21752 +       rcu_read_unlock();
21753 +       return dli;
21754 +}
21755 +
21756 +void rcu_free_dl_info(struct rcu_head *head)
21757 +{
21758 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
21759 +       int usecnt, refcnt;
21760 +
21761 +       BUG_ON(!dli || !head);
21762 +
21763 +       usecnt = atomic_read(&dli->dl_usecnt);
21764 +       BUG_ON(usecnt < 0);
21765 +
21766 +       refcnt = atomic_read(&dli->dl_refcnt);
21767 +       BUG_ON(refcnt < 0);
21768 +
21769 +       vxdprintk(VXD_CBIT(dlim, 3),
21770 +               "rcu_free_dl_info(%p)", dli);
21771 +       if (!usecnt)
21772 +               __dealloc_dl_info(dli);
21773 +       else
21774 +               printk("!!! rcu didn't free\n");
21775 +}
21776 +
21777 +
21778 +
21779 +
21780 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
21781 +       uint32_t flags, int add)
21782 +{
21783 +       struct nameidata nd;
21784 +       int ret;
21785 +
21786 +       ret = user_path_walk_link(name, &nd);
21787 +       if (!ret) {
21788 +               struct super_block *sb;
21789 +               struct dl_info *dli;
21790 +
21791 +               ret = -EINVAL;
21792 +               if (!nd.dentry->d_inode)
21793 +                       goto out_release;
21794 +               if (!(sb = nd.dentry->d_inode->i_sb))
21795 +                       goto out_release;
21796 +
21797 +               if (add) {
21798 +                       dli = __alloc_dl_info(sb, id);
21799 +                       spin_lock(&dl_info_hash_lock);
21800 +
21801 +                       ret = -EEXIST;
21802 +                       if (__lookup_dl_info(sb, id))
21803 +                               goto out_unlock;
21804 +                       __hash_dl_info(dli);
21805 +                       dli = NULL;
21806 +               } else {
21807 +                       spin_lock(&dl_info_hash_lock);
21808 +                       dli = __lookup_dl_info(sb, id);
21809 +
21810 +                       ret = -ESRCH;
21811 +                       if (!dli)
21812 +                               goto out_unlock;
21813 +                       __unhash_dl_info(dli);
21814 +               }
21815 +               ret = 0;
21816 +       out_unlock:
21817 +               spin_unlock(&dl_info_hash_lock);
21818 +               if (add && dli)
21819 +                       __dealloc_dl_info(dli);
21820 +       out_release:
21821 +               path_release(&nd);
21822 +       }
21823 +       return ret;
21824 +}
21825 +
21826 +int vc_add_dlimit(uint32_t id, void __user *data)
21827 +{
21828 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
21829 +
21830 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21831 +               return -EFAULT;
21832 +
21833 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
21834 +}
21835 +
21836 +int vc_rem_dlimit(uint32_t id, void __user *data)
21837 +{
21838 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
21839 +
21840 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21841 +               return -EFAULT;
21842 +
21843 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
21844 +}
21845 +
21846 +#ifdef CONFIG_COMPAT
21847 +
21848 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
21849 +{
21850 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
21851 +
21852 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21853 +               return -EFAULT;
21854 +
21855 +       return do_addrem_dlimit(id,
21856 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
21857 +}
21858 +
21859 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
21860 +{
21861 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
21862 +
21863 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21864 +               return -EFAULT;
21865 +
21866 +       return do_addrem_dlimit(id,
21867 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
21868 +}
21869 +
21870 +#endif /* CONFIG_COMPAT */
21871 +
21872 +
21873 +static inline
21874 +int do_set_dlimit(uint32_t id, const char __user *name,
21875 +       uint32_t space_used, uint32_t space_total,
21876 +       uint32_t inodes_used, uint32_t inodes_total,
21877 +       uint32_t reserved, uint32_t flags)
21878 +{
21879 +       struct nameidata nd;
21880 +       int ret;
21881 +
21882 +       ret = user_path_walk_link(name, &nd);
21883 +       if (!ret) {
21884 +               struct super_block *sb;
21885 +               struct dl_info *dli;
21886 +
21887 +               ret = -EINVAL;
21888 +               if (!nd.dentry->d_inode)
21889 +                       goto out_release;
21890 +               if (!(sb = nd.dentry->d_inode->i_sb))
21891 +                       goto out_release;
21892 +               if ((reserved != CDLIM_KEEP &&
21893 +                       reserved > 100) ||
21894 +                       (inodes_used != CDLIM_KEEP &&
21895 +                       inodes_used > inodes_total) ||
21896 +                       (space_used != CDLIM_KEEP &&
21897 +                       space_used > space_total))
21898 +                       goto out_release;
21899 +
21900 +               ret = -ESRCH;
21901 +               dli = locate_dl_info(sb, id);
21902 +               if (!dli)
21903 +                       goto out_release;
21904 +
21905 +               spin_lock(&dli->dl_lock);
21906 +
21907 +               if (inodes_used != CDLIM_KEEP)
21908 +                       dli->dl_inodes_used = inodes_used;
21909 +               if (inodes_total != CDLIM_KEEP)
21910 +                       dli->dl_inodes_total = inodes_total;
21911 +               if (space_used != CDLIM_KEEP) {
21912 +                       dli->dl_space_used = space_used;
21913 +                       dli->dl_space_used <<= 10;
21914 +               }
21915 +               if (space_total == CDLIM_INFINITY)
21916 +                       dli->dl_space_total = DLIM_INFINITY;
21917 +               else if (space_total != CDLIM_KEEP) {
21918 +                       dli->dl_space_total = space_total;
21919 +                       dli->dl_space_total <<= 10;
21920 +               }
21921 +               if (reserved != CDLIM_KEEP)
21922 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
21923 +
21924 +               spin_unlock(&dli->dl_lock);
21925 +
21926 +               put_dl_info(dli);
21927 +               ret = 0;
21928 +
21929 +       out_release:
21930 +               path_release(&nd);
21931 +       }
21932 +       return ret;
21933 +}
21934 +
21935 +int vc_set_dlimit(uint32_t id, void __user *data)
21936 +{
21937 +       struct vcmd_ctx_dlimit_v0 vc_data;
21938 +
21939 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21940 +               return -EFAULT;
21941 +
21942 +       return do_set_dlimit(id, vc_data.name,
21943 +               vc_data.space_used, vc_data.space_total,
21944 +               vc_data.inodes_used, vc_data.inodes_total,
21945 +               vc_data.reserved, vc_data.flags);
21946 +}
21947 +
21948 +#ifdef CONFIG_COMPAT
21949 +
21950 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
21951 +{
21952 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
21953 +
21954 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21955 +               return -EFAULT;
21956 +
21957 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
21958 +               vc_data.space_used, vc_data.space_total,
21959 +               vc_data.inodes_used, vc_data.inodes_total,
21960 +               vc_data.reserved, vc_data.flags);
21961 +}
21962 +
21963 +#endif /* CONFIG_COMPAT */
21964 +
21965 +
21966 +static inline
21967 +int do_get_dlimit(uint32_t id, const char __user *name,
21968 +       uint32_t *space_used, uint32_t *space_total,
21969 +       uint32_t *inodes_used, uint32_t *inodes_total,
21970 +       uint32_t *reserved, uint32_t *flags)
21971 +{
21972 +       struct nameidata nd;
21973 +       int ret;
21974 +
21975 +       ret = user_path_walk_link(name, &nd);
21976 +       if (!ret) {
21977 +               struct super_block *sb;
21978 +               struct dl_info *dli;
21979 +
21980 +               ret = -EINVAL;
21981 +               if (!nd.dentry->d_inode)
21982 +                       goto out_release;
21983 +               if (!(sb = nd.dentry->d_inode->i_sb))
21984 +                       goto out_release;
21985 +
21986 +               ret = -ESRCH;
21987 +               dli = locate_dl_info(sb, id);
21988 +               if (!dli)
21989 +                       goto out_release;
21990 +
21991 +               spin_lock(&dli->dl_lock);
21992 +               *inodes_used = dli->dl_inodes_used;
21993 +               *inodes_total = dli->dl_inodes_total;
21994 +               *space_used = dli->dl_space_used >> 10;
21995 +               if (dli->dl_space_total == DLIM_INFINITY)
21996 +                       *space_total = CDLIM_INFINITY;
21997 +               else
21998 +                       *space_total = dli->dl_space_total >> 10;
21999 +
22000 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
22001 +               spin_unlock(&dli->dl_lock);
22002 +
22003 +               put_dl_info(dli);
22004 +               ret = -EFAULT;
22005 +
22006 +               ret = 0;
22007 +       out_release:
22008 +               path_release(&nd);
22009 +       }
22010 +       return ret;
22011 +}
22012 +
22013 +
22014 +int vc_get_dlimit(uint32_t id, void __user *data)
22015 +{
22016 +       struct vcmd_ctx_dlimit_v0 vc_data;
22017 +       int ret;
22018 +
22019 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22020 +               return -EFAULT;
22021 +
22022 +       ret = do_get_dlimit(id, vc_data.name,
22023 +               &vc_data.space_used, &vc_data.space_total,
22024 +               &vc_data.inodes_used, &vc_data.inodes_total,
22025 +               &vc_data.reserved, &vc_data.flags);
22026 +       if (ret)
22027 +               return ret;
22028 +
22029 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22030 +               return -EFAULT;
22031 +       return 0;
22032 +}
22033 +
22034 +#ifdef CONFIG_COMPAT
22035 +
22036 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
22037 +{
22038 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
22039 +       int ret;
22040 +
22041 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22042 +               return -EFAULT;
22043 +
22044 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
22045 +               &vc_data.space_used, &vc_data.space_total,
22046 +               &vc_data.inodes_used, &vc_data.inodes_total,
22047 +               &vc_data.reserved, &vc_data.flags);
22048 +       if (ret)
22049 +               return ret;
22050 +
22051 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22052 +               return -EFAULT;
22053 +       return 0;
22054 +}
22055 +
22056 +#endif /* CONFIG_COMPAT */
22057 +
22058 +
22059 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
22060 +{
22061 +       struct dl_info *dli;
22062 +       __u64 blimit, bfree, bavail;
22063 +       __u32 ifree;
22064 +
22065 +       dli = locate_dl_info(sb, dx_current_tag());
22066 +       if (!dli)
22067 +               return;
22068 +
22069 +       spin_lock(&dli->dl_lock);
22070 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
22071 +               goto no_ilim;
22072 +
22073 +       /* reduce max inodes available to limit */
22074 +       if (buf->f_files > dli->dl_inodes_total)
22075 +               buf->f_files = dli->dl_inodes_total;
22076 +
22077 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
22078 +       /* reduce free inodes to min */
22079 +       if (ifree < buf->f_ffree)
22080 +               buf->f_ffree = ifree;
22081 +
22082 +no_ilim:
22083 +       if (dli->dl_space_total == DLIM_INFINITY)
22084 +               goto no_blim;
22085 +
22086 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
22087 +
22088 +       if (dli->dl_space_total < dli->dl_space_used)
22089 +               bfree = 0;
22090 +       else
22091 +               bfree = (dli->dl_space_total - dli->dl_space_used)
22092 +                       >> sb->s_blocksize_bits;
22093 +
22094 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
22095 +       if (bavail < dli->dl_space_used)
22096 +               bavail = 0;
22097 +       else
22098 +               bavail = (bavail - dli->dl_space_used)
22099 +                       >> sb->s_blocksize_bits;
22100 +
22101 +       /* reduce max space available to limit */
22102 +       if (buf->f_blocks > blimit)
22103 +               buf->f_blocks = blimit;
22104 +
22105 +       /* reduce free space to min */
22106 +       if (bfree < buf->f_bfree)
22107 +               buf->f_bfree = bfree;
22108 +
22109 +       /* reduce avail space to min */
22110 +       if (bavail < buf->f_bavail)
22111 +               buf->f_bavail = bavail;
22112 +
22113 +no_blim:
22114 +       spin_unlock(&dli->dl_lock);
22115 +       put_dl_info(dli);
22116 +
22117 +       return;
22118 +}
22119 +
22120 +#include <linux/module.h>
22121 +
22122 +EXPORT_SYMBOL_GPL(locate_dl_info);
22123 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
22124 +
22125 diff -Nurp linux-2.6.22.15/kernel/vserver/helper.c linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/helper.c
22126 --- linux-2.6.22.15/kernel/vserver/helper.c     1969-12-31 19:00:00.000000000 -0500
22127 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/helper.c        2007-12-09 06:44:23.000000000 -0500
22128 @@ -0,0 +1,199 @@
22129 +/*
22130 + *  linux/kernel/vserver/helper.c
22131 + *
22132 + *  Virtual Context Support
22133 + *
22134 + *  Copyright (C) 2004-2007  Herbert Pötzl
22135 + *
22136 + *  V0.01  basic helper
22137 + *
22138 + */
22139 +
22140 +#include <linux/kmod.h>
22141 +#include <linux/reboot.h>
22142 +#include <linux/vs_context.h>
22143 +#include <linux/vs_network.h>
22144 +#include <linux/vserver/signal.h>
22145 +
22146 +
22147 +char vshelper_path[255] = "/sbin/vshelper";
22148 +
22149 +
22150 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
22151 +{
22152 +       int ret;
22153 +
22154 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
22155 +               printk( KERN_WARNING
22156 +                       "%s: (%s %s) returned %s with %d\n",
22157 +                       name, argv[1], argv[2],
22158 +                       sync ? "sync" : "async", ret);
22159 +       }
22160 +       vxdprintk(VXD_CBIT(switch, 4),
22161 +               "%s: (%s %s) returned %s with %d",
22162 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
22163 +       return ret;
22164 +}
22165 +
22166 +/*
22167 + *      vshelper path is set via /proc/sys
22168 + *      invoked by vserver sys_reboot(), with
22169 + *      the following arguments
22170 + *
22171 + *      argv [0] = vshelper_path;
22172 + *      argv [1] = action: "restart", "halt", "poweroff", ...
22173 + *      argv [2] = context identifier
22174 + *
22175 + *      envp [*] = type-specific parameters
22176 + */
22177 +
22178 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
22179 +{
22180 +       char id_buf[8], cmd_buf[16];
22181 +       char uid_buf[16], pid_buf[16];
22182 +       int ret;
22183 +
22184 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
22185 +       char *envp[] = {"HOME=/", "TERM=linux",
22186 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
22187 +                       uid_buf, pid_buf, cmd_buf, 0};
22188 +
22189 +       if (vx_info_state(vxi, VXS_HELPER))
22190 +               return -EAGAIN;
22191 +       vxi->vx_state |= VXS_HELPER;
22192 +
22193 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
22194 +
22195 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
22196 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current->uid);
22197 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
22198 +
22199 +       switch (cmd) {
22200 +       case LINUX_REBOOT_CMD_RESTART:
22201 +               argv[1] = "restart";
22202 +               break;
22203 +
22204 +       case LINUX_REBOOT_CMD_HALT:
22205 +               argv[1] = "halt";
22206 +               break;
22207 +
22208 +       case LINUX_REBOOT_CMD_POWER_OFF:
22209 +               argv[1] = "poweroff";
22210 +               break;
22211 +
22212 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
22213 +               argv[1] = "swsusp";
22214 +               break;
22215 +
22216 +       default:
22217 +               vxi->vx_state &= ~VXS_HELPER;
22218 +               return 0;
22219 +       }
22220 +
22221 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
22222 +       vxi->vx_state &= ~VXS_HELPER;
22223 +       __wakeup_vx_info(vxi);
22224 +       return (ret) ? -EPERM : 0;
22225 +}
22226 +
22227 +
22228 +long vs_reboot(unsigned int cmd, void __user *arg)
22229 +{
22230 +       struct vx_info *vxi = current->vx_info;
22231 +       long ret = 0;
22232 +
22233 +       vxdprintk(VXD_CBIT(misc, 5),
22234 +               "vs_reboot(%p[#%d],%d)",
22235 +               vxi, vxi ? vxi->vx_id : 0, cmd);
22236 +
22237 +       ret = vs_reboot_helper(vxi, cmd, arg);
22238 +       if (ret)
22239 +               return ret;
22240 +
22241 +       vxi->reboot_cmd = cmd;
22242 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
22243 +               switch (cmd) {
22244 +               case LINUX_REBOOT_CMD_RESTART:
22245 +               case LINUX_REBOOT_CMD_HALT:
22246 +               case LINUX_REBOOT_CMD_POWER_OFF:
22247 +                       vx_info_kill(vxi, 0, SIGKILL);
22248 +                       vx_info_kill(vxi, 1, SIGKILL);
22249 +               default:
22250 +                       break;
22251 +               }
22252 +       }
22253 +       return 0;
22254 +}
22255 +
22256 +
22257 +/*
22258 + *      argv [0] = vshelper_path;
22259 + *      argv [1] = action: "startup", "shutdown"
22260 + *      argv [2] = context identifier
22261 + *
22262 + *      envp [*] = type-specific parameters
22263 + */
22264 +
22265 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
22266 +{
22267 +       char id_buf[8], cmd_buf[16];
22268 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
22269 +       char *envp[] = {"HOME=/", "TERM=linux",
22270 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
22271 +
22272 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
22273 +               return 0;
22274 +
22275 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
22276 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
22277 +
22278 +       switch (cmd) {
22279 +       case VSC_STARTUP:
22280 +               argv[1] = "startup";
22281 +               break;
22282 +       case VSC_SHUTDOWN:
22283 +               argv[1] = "shutdown";
22284 +               break;
22285 +       default:
22286 +               return 0;
22287 +       }
22288 +
22289 +       return do_vshelper(vshelper_path, argv, envp, 1);
22290 +}
22291 +
22292 +
22293 +/*
22294 + *      argv [0] = vshelper_path;
22295 + *      argv [1] = action: "netup", "netdown"
22296 + *      argv [2] = context identifier
22297 + *
22298 + *      envp [*] = type-specific parameters
22299 + */
22300 +
22301 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
22302 +{
22303 +       char id_buf[8], cmd_buf[16];
22304 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
22305 +       char *envp[] = {"HOME=/", "TERM=linux",
22306 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
22307 +
22308 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
22309 +               return 0;
22310 +
22311 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
22312 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
22313 +
22314 +       switch (cmd) {
22315 +       case VSC_NETUP:
22316 +               argv[1] = "netup";
22317 +               break;
22318 +       case VSC_NETDOWN:
22319 +               argv[1] = "netdown";
22320 +               break;
22321 +       default:
22322 +               return 0;
22323 +       }
22324 +
22325 +       return do_vshelper(vshelper_path, argv, envp, 1);
22326 +}
22327 +
22328 diff -Nurp linux-2.6.22.15/kernel/vserver/history.c linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/history.c
22329 --- linux-2.6.22.15/kernel/vserver/history.c    1969-12-31 19:00:00.000000000 -0500
22330 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/history.c       2007-12-09 06:44:23.000000000 -0500
22331 @@ -0,0 +1,258 @@
22332 +/*
22333 + *  kernel/vserver/history.c
22334 + *
22335 + *  Virtual Context History Backtrace
22336 + *
22337 + *  Copyright (C) 2004-2007  Herbert Pötzl
22338 + *
22339 + *  V0.01  basic structure
22340 + *  V0.02  hash/unhash and trace
22341 + *  V0.03  preemption fixes
22342 + *
22343 + */
22344 +
22345 +#include <linux/module.h>
22346 +#include <asm/uaccess.h>
22347 +
22348 +#include <linux/vserver/context.h>
22349 +#include <linux/vserver/debug.h>
22350 +#include <linux/vserver/debug_cmd.h>
22351 +#include <linux/vserver/history.h>
22352 +
22353 +
22354 +#ifdef CONFIG_VSERVER_HISTORY
22355 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
22356 +#else
22357 +#define VXH_SIZE       64
22358 +#endif
22359 +
22360 +struct _vx_history {
22361 +       unsigned int counter;
22362 +
22363 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
22364 +};
22365 +
22366 +
22367 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
22368 +
22369 +unsigned volatile int vxh_active = 1;
22370 +
22371 +static atomic_t sequence = ATOMIC_INIT(0);
22372 +
22373 +
22374 +/*     vxh_advance()
22375 +
22376 +       * requires disabled preemption                          */
22377 +
22378 +struct _vx_hist_entry *vxh_advance(void *loc)
22379 +{
22380 +       unsigned int cpu = smp_processor_id();
22381 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
22382 +       struct _vx_hist_entry *entry;
22383 +       unsigned int index;
22384 +
22385 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
22386 +       entry = &hist->entry[index];
22387 +
22388 +       entry->seq = atomic_inc_return(&sequence);
22389 +       entry->loc = loc;
22390 +       return entry;
22391 +}
22392 +
22393 +EXPORT_SYMBOL_GPL(vxh_advance);
22394 +
22395 +
22396 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
22397 +
22398 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
22399 +
22400 +
22401 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
22402 +
22403 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
22404 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
22405 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
22406 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
22407 +
22408 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
22409 +{
22410 +       switch (e->type) {
22411 +       case VXH_THROW_OOPS:
22412 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
22413 +               break;
22414 +
22415 +       case VXH_GET_VX_INFO:
22416 +       case VXH_PUT_VX_INFO:
22417 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
22418 +                       VXH_LOC_ARGS(e),
22419 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
22420 +                       VXH_VXI_ARGS(e));
22421 +               break;
22422 +
22423 +       case VXH_INIT_VX_INFO:
22424 +       case VXH_SET_VX_INFO:
22425 +       case VXH_CLR_VX_INFO:
22426 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
22427 +                       VXH_LOC_ARGS(e),
22428 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
22429 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
22430 +                       VXH_VXI_ARGS(e), e->sc.data);
22431 +               break;
22432 +
22433 +       case VXH_CLAIM_VX_INFO:
22434 +       case VXH_RELEASE_VX_INFO:
22435 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
22436 +                       VXH_LOC_ARGS(e),
22437 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
22438 +                       VXH_VXI_ARGS(e), e->sc.data);
22439 +               break;
22440 +
22441 +       case VXH_ALLOC_VX_INFO:
22442 +       case VXH_DEALLOC_VX_INFO:
22443 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
22444 +                       VXH_LOC_ARGS(e),
22445 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
22446 +                       VXH_VXI_ARGS(e));
22447 +               break;
22448 +
22449 +       case VXH_HASH_VX_INFO:
22450 +       case VXH_UNHASH_VX_INFO:
22451 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
22452 +                       VXH_LOC_ARGS(e),
22453 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
22454 +                       VXH_VXI_ARGS(e));
22455 +               break;
22456 +
22457 +       case VXH_LOC_VX_INFO:
22458 +       case VXH_LOOKUP_VX_INFO:
22459 +       case VXH_CREATE_VX_INFO:
22460 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
22461 +                       VXH_LOC_ARGS(e),
22462 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
22463 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
22464 +                       e->ll.arg, VXH_VXI_ARGS(e));
22465 +               break;
22466 +       }
22467 +}
22468 +
22469 +static void __vxh_dump_history(void)
22470 +{
22471 +       unsigned int i, cpu;
22472 +
22473 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
22474 +               atomic_read(&sequence), NR_CPUS);
22475 +
22476 +       for (i = 0; i < VXH_SIZE; i++) {
22477 +               for_each_online_cpu(cpu) {
22478 +                       struct _vx_history *hist =
22479 +                               &per_cpu(vx_history_buffer, cpu);
22480 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
22481 +                       struct _vx_hist_entry *entry = &hist->entry[index];
22482 +
22483 +                       vxh_dump_entry(entry, cpu);
22484 +               }
22485 +       }
22486 +}
22487 +
22488 +void   vxh_dump_history(void)
22489 +{
22490 +       vxh_active = 0;
22491 +#ifdef CONFIG_SMP
22492 +       local_irq_enable();
22493 +       smp_send_stop();
22494 +       local_irq_disable();
22495 +#endif
22496 +       __vxh_dump_history();
22497 +}
22498 +
22499 +
22500 +/* vserver syscall commands below here */
22501 +
22502 +
22503 +int vc_dump_history(uint32_t id)
22504 +{
22505 +       vxh_active = 0;
22506 +       __vxh_dump_history();
22507 +       vxh_active = 1;
22508 +
22509 +       return 0;
22510 +}
22511 +
22512 +
22513 +int do_read_history(struct __user _vx_hist_entry *data,
22514 +       int cpu, uint32_t *index, uint32_t *count)
22515 +{
22516 +       int pos, ret = 0;
22517 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
22518 +       int end = hist->counter;
22519 +       int start = end - VXH_SIZE + 2;
22520 +       int idx = *index;
22521 +
22522 +       /* special case: get current pos */
22523 +       if (!*count) {
22524 +               *index = end;
22525 +               return 0;
22526 +       }
22527 +
22528 +       /* have we lost some data? */
22529 +       if (idx < start)
22530 +               idx = start;
22531 +
22532 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
22533 +               struct _vx_hist_entry *entry =
22534 +                       &hist->entry[idx % VXH_SIZE];
22535 +
22536 +               /* send entry to userspace */
22537 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
22538 +               if (ret)
22539 +                       break;
22540 +       }
22541 +       /* save new index and count */
22542 +       *index = idx;
22543 +       *count = pos;
22544 +       return ret ? ret : (*index < end);
22545 +}
22546 +
22547 +int vc_read_history(uint32_t id, void __user *data)
22548 +{
22549 +       struct vcmd_read_history_v0 vc_data;
22550 +       int ret;
22551 +
22552 +       if (id >= NR_CPUS)
22553 +               return -EINVAL;
22554 +
22555 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22556 +               return -EFAULT;
22557 +
22558 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
22559 +               id, &vc_data.index, &vc_data.count);
22560 +
22561 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22562 +               return -EFAULT;
22563 +       return ret;
22564 +}
22565 +
22566 +#ifdef CONFIG_COMPAT
22567 +
22568 +int vc_read_history_x32(uint32_t id, void __user *data)
22569 +{
22570 +       struct vcmd_read_history_v0_x32 vc_data;
22571 +       int ret;
22572 +
22573 +       if (id >= NR_CPUS)
22574 +               return -EINVAL;
22575 +
22576 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22577 +               return -EFAULT;
22578 +
22579 +       ret = do_read_history((struct __user _vx_hist_entry *)
22580 +               compat_ptr(vc_data.data_ptr),
22581 +               id, &vc_data.index, &vc_data.count);
22582 +
22583 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22584 +               return -EFAULT;
22585 +       return ret;
22586 +}
22587 +
22588 +#endif /* CONFIG_COMPAT */
22589 +
22590 diff -Nurp linux-2.6.22.15/kernel/vserver/inet.c linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/inet.c
22591 --- linux-2.6.22.15/kernel/vserver/inet.c       1969-12-31 19:00:00.000000000 -0500
22592 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/inet.c  2007-12-09 06:44:23.000000000 -0500
22593 @@ -0,0 +1,222 @@
22594 +
22595 +#include <linux/in.h>
22596 +#include <linux/inetdevice.h>
22597 +#include <linux/vs_inet6.h>
22598 +#include <linux/vserver/debug.h>
22599 +#include <net/route.h>
22600 +#include <net/addrconf.h>
22601 +
22602 +
22603 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
22604 +{
22605 +       int ret = 0;
22606 +
22607 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
22608 +               ret = 1;
22609 +       else {
22610 +               struct nx_addr_v4 *ptr;
22611 +
22612 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
22613 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
22614 +                               ret = 1;
22615 +                               break;
22616 +                       }
22617 +               }
22618 +       }
22619 +
22620 +       vxdprintk(VXD_CBIT(net, 2),
22621 +               "nx_v4_addr_conflict(%p,%p): %d",
22622 +               nxi1, nxi2, ret);
22623 +
22624 +       return ret;
22625 +}
22626 +
22627 +
22628 +#ifdef CONFIG_IPV6
22629 +
22630 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
22631 +{
22632 +       int ret = 0;
22633 +
22634 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
22635 +               ret = 1;
22636 +       else {
22637 +               struct nx_addr_v6 *ptr;
22638 +
22639 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
22640 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
22641 +                               ret = 1;
22642 +                               break;
22643 +                       }
22644 +               }
22645 +       }
22646 +
22647 +       vxdprintk(VXD_CBIT(net, 2),
22648 +               "nx_v6_addr_conflict(%p,%p): %d",
22649 +               nxi1, nxi2, ret);
22650 +
22651 +       return ret;
22652 +}
22653 +
22654 +#endif
22655 +
22656 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
22657 +{
22658 +       struct in_device *in_dev;
22659 +       struct in_ifaddr **ifap;
22660 +       struct in_ifaddr *ifa;
22661 +       int ret = 0;
22662 +
22663 +       if (!dev)
22664 +               goto out;
22665 +       in_dev = in_dev_get(dev);
22666 +       if (!in_dev)
22667 +               goto out;
22668 +
22669 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
22670 +               ifap = &ifa->ifa_next) {
22671 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
22672 +                       ret = 1;
22673 +                       break;
22674 +               }
22675 +       }
22676 +       in_dev_put(in_dev);
22677 +out:
22678 +       return ret;
22679 +}
22680 +
22681 +
22682 +#ifdef CONFIG_IPV6
22683 +
22684 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
22685 +{
22686 +       struct inet6_dev *in_dev;
22687 +       struct inet6_ifaddr **ifap;
22688 +       struct inet6_ifaddr *ifa;
22689 +       int ret = 0;
22690 +
22691 +       if (!dev)
22692 +               goto out;
22693 +       in_dev = in6_dev_get(dev);
22694 +       if (!in_dev)
22695 +               goto out;
22696 +
22697 +       for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
22698 +               ifap = &ifa->if_next) {
22699 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
22700 +                       ret = 1;
22701 +                       break;
22702 +               }
22703 +       }
22704 +       in6_dev_put(in_dev);
22705 +out:
22706 +       return ret;
22707 +}
22708 +
22709 +#endif
22710 +
22711 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
22712 +{
22713 +       int ret = 1;
22714 +
22715 +       if (!nxi)
22716 +               goto out;
22717 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
22718 +               goto out;
22719 +#ifdef CONFIG_IPV6
22720 +       ret = 2;
22721 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
22722 +               goto out;
22723 +#endif
22724 +       ret = 0;
22725 +out:
22726 +       vxdprintk(VXD_CBIT(net, 3),
22727 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
22728 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
22729 +       return ret;
22730 +}
22731 +
22732 +int ip_v4_find_src(struct nx_info *nxi, struct rtable **rp, struct flowi *fl)
22733 +{
22734 +       if (!nxi)
22735 +               return 0;
22736 +
22737 +       /* FIXME: handle lback only case */
22738 +       if (!NX_IPV4(nxi))
22739 +               return -EPERM;
22740 +
22741 +       vxdprintk(VXD_CBIT(net, 4),
22742 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
22743 +               nxi, nxi ? nxi->nx_id : 0,
22744 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
22745 +
22746 +       /* single IP is unconditional */
22747 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
22748 +               (fl->fl4_src == INADDR_ANY))
22749 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
22750 +
22751 +       if (fl->fl4_src == INADDR_ANY) {
22752 +               struct nx_addr_v4 *ptr;
22753 +               __be32 found;
22754 +               int err;
22755 +
22756 +               err = __ip_route_output_key(rp, fl);
22757 +               if (!err) {
22758 +                       found = (*rp)->rt_src;
22759 +                       ip_rt_put(*rp);
22760 +                       vxdprintk(VXD_CBIT(net, 4),
22761 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
22762 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
22763 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
22764 +                               goto found;
22765 +               }
22766 +
22767 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
22768 +                       __be32 primary = ptr->ip[0].s_addr;
22769 +                       __be32 mask = ptr->mask.s_addr;
22770 +                       __be32 net = primary & mask;
22771 +
22772 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
22773 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
22774 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
22775 +                               NIPQUAD(mask), NIPQUAD(net));
22776 +                       if ((found & mask) != net)
22777 +                               continue;
22778 +
22779 +                       fl->fl4_src = primary;
22780 +                       err = __ip_route_output_key(rp, fl);
22781 +                       vxdprintk(VXD_CBIT(net, 4),
22782 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
22783 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
22784 +                       if (!err) {
22785 +                               found = (*rp)->rt_src;
22786 +                               ip_rt_put(*rp);
22787 +                               if (found == primary)
22788 +                                       goto found;
22789 +                       }
22790 +               }
22791 +               /* still no source ip? */
22792 +               found = LOOPBACK(fl->fl4_dst)
22793 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
22794 +       found:
22795 +               /* assign src ip to flow */
22796 +               fl->fl4_src = found;
22797 +
22798 +       } else {
22799 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
22800 +                       return -EPERM;
22801 +       }
22802 +
22803 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
22804 +               if (LOOPBACK(fl->fl4_dst))
22805 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
22806 +               if (LOOPBACK(fl->fl4_src))
22807 +                       fl->fl4_src = nxi->v4_lback.s_addr;
22808 +       } else if (LOOPBACK(fl->fl4_dst))
22809 +               return -EPERM;
22810 +
22811 +       return 0;
22812 +}
22813 +
22814 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
22815 +
22816 diff -Nurp linux-2.6.22.15/kernel/vserver/init.c linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/init.c
22817 --- linux-2.6.22.15/kernel/vserver/init.c       1969-12-31 19:00:00.000000000 -0500
22818 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/init.c  2007-12-09 06:44:23.000000000 -0500
22819 @@ -0,0 +1,45 @@
22820 +/*
22821 + *  linux/kernel/init.c
22822 + *
22823 + *  Virtual Server Init
22824 + *
22825 + *  Copyright (C) 2004-2007  Herbert Pötzl
22826 + *
22827 + *  V0.01  basic structure
22828 + *
22829 + */
22830 +
22831 +#include <linux/init.h>
22832 +
22833 +int    vserver_register_sysctl(void);
22834 +void   vserver_unregister_sysctl(void);
22835 +
22836 +
22837 +static int __init init_vserver(void)
22838 +{
22839 +       int ret = 0;
22840 +
22841 +#ifdef CONFIG_VSERVER_DEBUG
22842 +       vserver_register_sysctl();
22843 +#endif
22844 +       return ret;
22845 +}
22846 +
22847 +
22848 +static void __exit exit_vserver(void)
22849 +{
22850 +
22851 +#ifdef CONFIG_VSERVER_DEBUG
22852 +       vserver_unregister_sysctl();
22853 +#endif
22854 +       return;
22855 +}
22856 +
22857 +/* FIXME: GFP_ZONETYPES gone
22858 +long vx_slab[GFP_ZONETYPES]; */
22859 +long vx_area;
22860 +
22861 +
22862 +module_init(init_vserver);
22863 +module_exit(exit_vserver);
22864 +
22865 diff -Nurp linux-2.6.22.15/kernel/vserver/inode.c linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/inode.c
22866 --- linux-2.6.22.15/kernel/vserver/inode.c      1969-12-31 19:00:00.000000000 -0500
22867 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/inode.c 2007-12-09 06:44:23.000000000 -0500
22868 @@ -0,0 +1,409 @@
22869 +/*
22870 + *  linux/kernel/vserver/inode.c
22871 + *
22872 + *  Virtual Server: File System Support
22873 + *
22874 + *  Copyright (C) 2004-2007  Herbert Pötzl
22875 + *
22876 + *  V0.01  separated from vcontext V0.05
22877 + *  V0.02  moved to tag (instead of xid)
22878 + *
22879 + */
22880 +
22881 +#include <linux/tty.h>
22882 +#include <linux/proc_fs.h>
22883 +#include <linux/devpts_fs.h>
22884 +#include <linux/fs.h>
22885 +#include <linux/file.h>
22886 +#include <linux/mount.h>
22887 +#include <linux/parser.h>
22888 +#include <linux/vserver/inode.h>
22889 +#include <linux/vserver/inode_cmd.h>
22890 +#include <linux/vs_base.h>
22891 +#include <linux/vs_tag.h>
22892 +
22893 +#include <asm/uaccess.h>
22894 +
22895 +
22896 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
22897 +{
22898 +       struct proc_dir_entry *entry;
22899 +
22900 +       if (!in || !in->i_sb)
22901 +               return -ESRCH;
22902 +
22903 +       *flags = IATTR_TAG
22904 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
22905 +               | (IS_IUNLINK(in) ? IATTR_IUNLINK : 0)
22906 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0);
22907 +       *mask = IATTR_IUNLINK | IATTR_IMMUTABLE;
22908 +
22909 +       if (S_ISDIR(in->i_mode))
22910 +               *mask |= IATTR_BARRIER;
22911 +
22912 +       if (IS_TAGGED(in)) {
22913 +               *tag = in->i_tag;
22914 +               *mask |= IATTR_TAG;
22915 +       }
22916 +
22917 +       switch (in->i_sb->s_magic) {
22918 +       case PROC_SUPER_MAGIC:
22919 +               entry = PROC_I(in)->pde;
22920 +
22921 +               /* check for specific inodes? */
22922 +               if (entry)
22923 +                       *mask |= IATTR_FLAGS;
22924 +               if (entry)
22925 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
22926 +               else
22927 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
22928 +               break;
22929 +
22930 +       case DEVPTS_SUPER_MAGIC:
22931 +               *tag = in->i_tag;
22932 +               *mask |= IATTR_TAG;
22933 +               break;
22934 +
22935 +       default:
22936 +               break;
22937 +       }
22938 +       return 0;
22939 +}
22940 +
22941 +int vc_get_iattr(void __user *data)
22942 +{
22943 +       struct nameidata nd;
22944 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
22945 +       int ret;
22946 +
22947 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22948 +               return -EFAULT;
22949 +
22950 +       ret = user_path_walk_link(vc_data.name, &nd);
22951 +       if (!ret) {
22952 +               ret = __vc_get_iattr(nd.dentry->d_inode,
22953 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
22954 +               path_release(&nd);
22955 +       }
22956 +       if (ret)
22957 +               return ret;
22958 +
22959 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22960 +               ret = -EFAULT;
22961 +       return ret;
22962 +}
22963 +
22964 +#ifdef CONFIG_COMPAT
22965 +
22966 +int vc_get_iattr_x32(void __user *data)
22967 +{
22968 +       struct nameidata nd;
22969 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
22970 +       int ret;
22971 +
22972 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22973 +               return -EFAULT;
22974 +
22975 +       ret = user_path_walk_link(compat_ptr(vc_data.name_ptr), &nd);
22976 +       if (!ret) {
22977 +               ret = __vc_get_iattr(nd.dentry->d_inode,
22978 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
22979 +               path_release(&nd);
22980 +       }
22981 +       if (ret)
22982 +               return ret;
22983 +
22984 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22985 +               ret = -EFAULT;
22986 +       return ret;
22987 +}
22988 +
22989 +#endif /* CONFIG_COMPAT */
22990 +
22991 +
22992 +int vc_fget_iattr(uint32_t fd, void __user *data)
22993 +{
22994 +       struct file *filp;
22995 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
22996 +       int ret;
22997 +
22998 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22999 +               return -EFAULT;
23000 +
23001 +       filp = fget(fd);
23002 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
23003 +               return -EBADF;
23004 +
23005 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
23006 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
23007 +
23008 +       fput(filp);
23009 +
23010 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23011 +               ret = -EFAULT;
23012 +       return ret;
23013 +}
23014 +
23015 +
23016 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
23017 +{
23018 +       struct inode *in = de->d_inode;
23019 +       int error = 0, is_proc = 0, has_tag = 0;
23020 +       struct iattr attr = { 0 };
23021 +
23022 +       if (!in || !in->i_sb)
23023 +               return -ESRCH;
23024 +
23025 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
23026 +       if ((*mask & IATTR_FLAGS) && !is_proc)
23027 +               return -EINVAL;
23028 +
23029 +       has_tag = IS_TAGGED(in) ||
23030 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
23031 +       if ((*mask & IATTR_TAG) && !has_tag)
23032 +               return -EINVAL;
23033 +
23034 +       mutex_lock(&in->i_mutex);
23035 +       if (*mask & IATTR_TAG) {
23036 +               attr.ia_tag = *tag;
23037 +               attr.ia_valid |= ATTR_TAG;
23038 +       }
23039 +
23040 +       if (*mask & IATTR_FLAGS) {
23041 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
23042 +               unsigned int iflags = PROC_I(in)->vx_flags;
23043 +
23044 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
23045 +                       | (*flags & IATTR_FLAGS);
23046 +               PROC_I(in)->vx_flags = iflags;
23047 +               if (entry)
23048 +                       entry->vx_flags = iflags;
23049 +       }
23050 +
23051 +       if (*mask & (IATTR_BARRIER | IATTR_IUNLINK | IATTR_IMMUTABLE)) {
23052 +               if (*mask & IATTR_IMMUTABLE) {
23053 +                       if (*flags & IATTR_IMMUTABLE)
23054 +                               in->i_flags |= S_IMMUTABLE;
23055 +                       else
23056 +                               in->i_flags &= ~S_IMMUTABLE;
23057 +               }
23058 +               if (*mask & IATTR_IUNLINK) {
23059 +                       if (*flags & IATTR_IUNLINK)
23060 +                               in->i_flags |= S_IUNLINK;
23061 +                       else
23062 +                               in->i_flags &= ~S_IUNLINK;
23063 +               }
23064 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
23065 +                       if (*flags & IATTR_BARRIER)
23066 +                               in->i_flags |= S_BARRIER;
23067 +                       else
23068 +                               in->i_flags &= ~S_BARRIER;
23069 +               }
23070 +               if (in->i_op && in->i_op->sync_flags) {
23071 +                       error = in->i_op->sync_flags(in);
23072 +                       if (error)
23073 +                               goto out;
23074 +               }
23075 +       }
23076 +
23077 +       if (attr.ia_valid) {
23078 +               if (in->i_op && in->i_op->setattr)
23079 +                       error = in->i_op->setattr(de, &attr);
23080 +               else {
23081 +                       error = inode_change_ok(in, &attr);
23082 +                       if (!error)
23083 +                               error = inode_setattr(in, &attr);
23084 +               }
23085 +       }
23086 +
23087 +out:
23088 +       mutex_unlock(&in->i_mutex);
23089 +       return error;
23090 +}
23091 +
23092 +int vc_set_iattr(void __user *data)
23093 +{
23094 +       struct nameidata nd;
23095 +       struct vcmd_ctx_iattr_v1 vc_data;
23096 +       int ret;
23097 +
23098 +       if (!capable(CAP_LINUX_IMMUTABLE))
23099 +               return -EPERM;
23100 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23101 +               return -EFAULT;
23102 +
23103 +       ret = user_path_walk_link(vc_data.name, &nd);
23104 +       if (!ret) {
23105 +               ret = __vc_set_iattr(nd.dentry,
23106 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
23107 +               path_release(&nd);
23108 +       }
23109 +
23110 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23111 +               ret = -EFAULT;
23112 +       return ret;
23113 +}
23114 +
23115 +#ifdef CONFIG_COMPAT
23116 +
23117 +int vc_set_iattr_x32(void __user *data)
23118 +{
23119 +       struct nameidata nd;
23120 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
23121 +       int ret;
23122 +
23123 +       if (!capable(CAP_LINUX_IMMUTABLE))
23124 +               return -EPERM;
23125 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23126 +               return -EFAULT;
23127 +
23128 +       ret = user_path_walk_link(compat_ptr(vc_data.name_ptr), &nd);
23129 +       if (!ret) {
23130 +               ret = __vc_set_iattr(nd.dentry,
23131 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
23132 +               path_release(&nd);
23133 +       }
23134 +
23135 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23136 +               ret = -EFAULT;
23137 +       return ret;
23138 +}
23139 +
23140 +#endif /* CONFIG_COMPAT */
23141 +
23142 +int vc_fset_iattr(uint32_t fd, void __user *data)
23143 +{
23144 +       struct file *filp;
23145 +       struct vcmd_ctx_fiattr_v0 vc_data;
23146 +       int ret;
23147 +
23148 +       if (!capable(CAP_LINUX_IMMUTABLE))
23149 +               return -EPERM;
23150 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23151 +               return -EFAULT;
23152 +
23153 +       filp = fget(fd);
23154 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
23155 +               return -EBADF;
23156 +
23157 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
23158 +               &vc_data.flags, &vc_data.mask);
23159 +
23160 +       fput(filp);
23161 +
23162 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23163 +               return -EFAULT;
23164 +       return ret;
23165 +}
23166 +
23167 +
23168 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
23169 +
23170 +static match_table_t tokens = {
23171 +       {Opt_notagcheck, "notagcheck"},
23172 +#ifdef CONFIG_PROPAGATE
23173 +       {Opt_notag, "notag"},
23174 +       {Opt_tag, "tag"},
23175 +       {Opt_tagid, "tagid=%u"},
23176 +#endif
23177 +       {Opt_err, NULL}
23178 +};
23179 +
23180 +
23181 +static void __dx_parse_remove(char *string, char *opt)
23182 +{
23183 +       char *p = strstr(string, opt);
23184 +       char *q = p;
23185 +
23186 +       if (p) {
23187 +               while (*q != '\0' && *q != ',')
23188 +                       q++;
23189 +               while (*q)
23190 +                       *p++ = *q++;
23191 +               while (*p)
23192 +                       *p++ = '\0';
23193 +       }
23194 +}
23195 +
23196 +static inline
23197 +int __dx_parse_tag(char *string, tag_t *tag, int remove)
23198 +{
23199 +       substring_t args[MAX_OPT_ARGS];
23200 +       int token, option = 0;
23201 +
23202 +       if (!string)
23203 +               return 0;
23204 +
23205 +       token = match_token(string, tokens, args);
23206 +
23207 +       vxdprintk(VXD_CBIT(tag, 7),
23208 +               "dx_parse_tag(»%s«): %d:#%d",
23209 +               string, token, option);
23210 +
23211 +       switch (token) {
23212 +       case Opt_tag:
23213 +               if (tag)
23214 +                       *tag = 0;
23215 +               if (remove)
23216 +                       __dx_parse_remove(string, "tag");
23217 +               return MNT_TAGID;
23218 +       case Opt_notag:
23219 +               if (remove)
23220 +                       __dx_parse_remove(string, "notag");
23221 +               return MNT_NOTAG;
23222 +       case Opt_notagcheck:
23223 +               if (remove)
23224 +                       __dx_parse_remove(string, "notagcheck");
23225 +               return MNT_NOTAGCHECK;
23226 +       case Opt_tagid:
23227 +               if (tag && !match_int(args, &option))
23228 +                       *tag = option;
23229 +               if (remove)
23230 +                       __dx_parse_remove(string, "tagid");
23231 +               return MNT_TAGID;
23232 +       }
23233 +       return 0;
23234 +}
23235 +
23236 +int dx_parse_tag(char *string, tag_t *tag, int remove)
23237 +{
23238 +       int retval, flags = 0;
23239 +
23240 +       while ((retval = __dx_parse_tag(string, tag, remove)))
23241 +               flags |= retval;
23242 +       return flags;
23243 +}
23244 +
23245 +#ifdef CONFIG_PROPAGATE
23246 +
23247 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
23248 +{
23249 +       tag_t new_tag = 0;
23250 +       struct vfsmount *mnt;
23251 +       int propagate;
23252 +
23253 +       if (!nd)
23254 +               return;
23255 +       mnt = nd->mnt;
23256 +       if (!mnt)
23257 +               return;
23258 +
23259 +       propagate = (mnt->mnt_flags & MNT_TAGID);
23260 +       if (propagate)
23261 +               new_tag = mnt->mnt_tag;
23262 +
23263 +       vxdprintk(VXD_CBIT(tag, 7),
23264 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
23265 +               inode, inode->i_ino, inode->i_tag,
23266 +               new_tag, (propagate) ? 1 : 0);
23267 +
23268 +       if (propagate)
23269 +               inode->i_tag = new_tag;
23270 +}
23271 +
23272 +#include <linux/module.h>
23273 +
23274 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
23275 +
23276 +#endif /* CONFIG_PROPAGATE */
23277 +
23278 diff -Nurp linux-2.6.22.15/kernel/vserver/Kconfig linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/Kconfig
23279 --- linux-2.6.22.15/kernel/vserver/Kconfig      1969-12-31 19:00:00.000000000 -0500
23280 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/Kconfig 2007-12-09 06:44:23.000000000 -0500
23281 @@ -0,0 +1,249 @@
23282 +#
23283 +# Linux VServer configuration
23284 +#
23285 +
23286 +menu "Linux VServer"
23287 +
23288 +config VSERVER_AUTO_LBACK
23289 +       bool    "Automatically Assign Loopback IP"
23290 +       default y
23291 +       help
23292 +         Automatically assign a guest specific loopback
23293 +         IP and add it to the kernel network stack on
23294 +         startup.
23295 +
23296 +config VSERVER_AUTO_SINGLE
23297 +       bool    "Automatic Single IP Special Casing"
23298 +       depends on EXPERIMENTAL
23299 +       default y
23300 +       help
23301 +         This allows network contexts with a single IP to
23302 +         automatically remap 0.0.0.0 bindings to that IP,
23303 +         avoiding further network checks and improving
23304 +         performance.
23305 +
23306 +         (note: such guests do not allow to change the ip
23307 +          on the fly and do not show loopback addresses)
23308 +
23309 +config VSERVER_COWBL
23310 +       bool    "Enable COW Immutable Link Breaking"
23311 +       default y
23312 +       help
23313 +         This enables the COW (Copy-On-Write) link break code.
23314 +         It allows you to treat unified files like normal files
23315 +         when writing to them (which will implicitely break the
23316 +         link and create a copy of the unified file)
23317 +
23318 +config VSERVER_VTIME
23319 +       bool    "Enable Virtualized Guest Time"
23320 +       depends on EXPERIMENTAL
23321 +       default n
23322 +       help
23323 +         This enables per guest time offsets to allow for
23324 +         adjusting the system clock individually per guest.
23325 +         this adds some overhead to the time functions and
23326 +         therefore should not be enabled without good reason.
23327 +
23328 +config VSERVER_DEVICE
23329 +       bool    "Enable Guest Device Mapping"
23330 +       depends on EXPERIMENTAL
23331 +       default n
23332 +       help
23333 +         This enables generic device remapping.
23334 +
23335 +config VSERVER_PROC_SECURE
23336 +       bool    "Enable Proc Security"
23337 +       depends on PROC_FS
23338 +       default y
23339 +       help
23340 +         This configures ProcFS security to initially hide
23341 +         non-process entries for all contexts except the main and
23342 +         spectator context (i.e. for all guests), which is a secure
23343 +         default.
23344 +
23345 +         (note: on 1.2x the entries were visible by default)
23346 +
23347 +config VSERVER_HARDCPU
23348 +       bool    "Enable Hard CPU Limits"
23349 +       default y
23350 +       help
23351 +         Activate the Hard CPU Limits
23352 +
23353 +         This will compile in code that allows the Token Bucket
23354 +         Scheduler to put processes on hold when a context's
23355 +         tokens are depleted (provided that its per-context
23356 +         sched_hard flag is set).
23357 +
23358 +         Processes belonging to that context will not be able
23359 +         to consume CPU resources again until a per-context
23360 +         configured minimum of tokens has been reached.
23361 +
23362 +config VSERVER_IDLETIME
23363 +       bool    "Avoid idle CPUs by skipping Time"
23364 +       depends on VSERVER_HARDCPU
23365 +       default y
23366 +       help
23367 +         This option allows the scheduler to artificially
23368 +         advance time (per cpu) when otherwise the idle
23369 +         task would be scheduled, thus keeping the cpu
23370 +         busy and sharing the available resources among
23371 +         certain contexts.
23372 +
23373 +config VSERVER_IDLELIMIT
23374 +       bool    "Limit the IDLE task"
23375 +       depends on VSERVER_HARDCPU
23376 +       default n
23377 +       help
23378 +         Limit the idle slices, so the the next context
23379 +         will be scheduled as soon as possible.
23380 +
23381 +         This might improve interactivity and latency, but
23382 +         will also marginally increase scheduling overhead.
23383 +
23384 +choice
23385 +       prompt  "Persistent Inode Tagging"
23386 +       default TAGGING_ID24
23387 +       help
23388 +         This adds persistent context information to filesystems
23389 +         mounted with the tagxid option. Tagging is a requirement
23390 +         for per-context disk limits and per-context quota.
23391 +
23392 +
23393 +config TAGGING_NONE
23394 +       bool    "Disabled"
23395 +       help
23396 +         do not store per-context information in inodes.
23397 +
23398 +config TAGGING_UID16
23399 +       bool    "UID16/GID32"
23400 +       help
23401 +         reduces UID to 16 bit, but leaves GID at 32 bit.
23402 +
23403 +config TAGGING_GID16
23404 +       bool    "UID32/GID16"
23405 +       help
23406 +         reduces GID to 16 bit, but leaves UID at 32 bit.
23407 +
23408 +config TAGGING_ID24
23409 +       bool    "UID24/GID24"
23410 +       help
23411 +         uses the upper 8bit from UID and GID for XID tagging
23412 +         which leaves 24bit for UID/GID each, which should be
23413 +         more than sufficient for normal use.
23414 +
23415 +config TAGGING_INTERN
23416 +       bool    "UID32/GID32"
23417 +       help
23418 +         this uses otherwise reserved inode fields in the on
23419 +         disk representation, which limits the use to a few
23420 +         filesystems (currently ext2 and ext3)
23421 +
23422 +endchoice
23423 +
23424 +config TAG_NFSD
23425 +       bool    "Tag NFSD User Auth and Files"
23426 +       default n
23427 +       help
23428 +         Enable this if you do want the in-kernel NFS
23429 +         Server to use the tagging specified above.
23430 +         (will require patched clients too)
23431 +
23432 +config VSERVER_PRIVACY
23433 +       bool    "Honor Privacy Aspects of Guests"
23434 +       default n
23435 +       help
23436 +         When enabled, most context checks will disallow
23437 +         access to structures assigned to a specific context,
23438 +         like ptys or loop devices.
23439 +
23440 +config VSERVER_CONTEXTS
23441 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
23442 +       range 1 65533
23443 +       default "768"   if 64BIT
23444 +       default "256"
23445 +       help
23446 +         This setting will optimize certain data structures
23447 +         and memory allocations according to the expected
23448 +         maximum.
23449 +
23450 +         note: this is not a strict upper limit.
23451 +
23452 +config VSERVER_WARN
23453 +       bool    "VServer Warnings"
23454 +       default y
23455 +       help
23456 +         This enables various runtime warnings, which will
23457 +         notify about potential manipulation attempts or
23458 +         resource shortage. It is generally considered to
23459 +         be a good idea to have that enabled.
23460 +
23461 +config VSERVER_DEBUG
23462 +       bool    "VServer Debugging Code"
23463 +       default n
23464 +       help
23465 +         Set this to yes if you want to be able to activate
23466 +         debugging output at runtime. It adds a very small
23467 +         overhead to all vserver related functions and
23468 +         increases the kernel size by about 20k.
23469 +
23470 +config VSERVER_HISTORY
23471 +       bool    "VServer History Tracing"
23472 +       depends on VSERVER_DEBUG
23473 +       default n
23474 +       help
23475 +         Set this to yes if you want to record the history of
23476 +         linux-vserver activities, so they can be replayed in
23477 +         the event of a kernel panic or oops.
23478 +
23479 +config VSERVER_HISTORY_SIZE
23480 +       int     "Per-CPU History Size (32-65536)"
23481 +       depends on VSERVER_HISTORY
23482 +       range 32 65536
23483 +       default 64
23484 +       help
23485 +         This allows you to specify the number of entries in
23486 +         the per-CPU history buffer.
23487 +
23488 +config VSERVER_MONITOR
23489 +       bool    "VServer Scheduling Monitor"
23490 +       depends on VSERVER_DEBUG
23491 +       default n
23492 +       help
23493 +         Set this to yes if you want to record the scheduling
23494 +         decisions, so that they can be relayed to userspace
23495 +         for detailed analysis.
23496 +
23497 +config VSERVER_MONITOR_SIZE
23498 +       int     "Per-CPU Monitor Queue Size (32-65536)"
23499 +       depends on VSERVER_MONITOR
23500 +       range 32 65536
23501 +       default 1024
23502 +       help
23503 +         This allows you to specify the number of entries in
23504 +         the per-CPU scheduling monitor buffer.
23505 +
23506 +config VSERVER_MONITOR_SYNC
23507 +       int     "Per-CPU Monitor Sync Interval (0-65536)"
23508 +       depends on VSERVER_MONITOR
23509 +       range 0 65536
23510 +       default 256
23511 +       help
23512 +         This allows you to specify the interval in ticks
23513 +         when a time sync entry is inserted.
23514 +
23515 +endmenu
23516 +
23517 +
23518 +config VSERVER
23519 +       bool
23520 +       default y
23521 +       select UTS_NS
23522 +       select SYSVIPC
23523 +       select IPC_NS
23524 +
23525 +config VSERVER_SECURITY
23526 +       bool
23527 +       depends on SECURITY
23528 +       default y
23529 +       select SECURITY_CAPABILITIES
23530 +
23531 diff -Nurp linux-2.6.22.15/kernel/vserver/limit.c linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/limit.c
23532 --- linux-2.6.22.15/kernel/vserver/limit.c      1969-12-31 19:00:00.000000000 -0500
23533 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/limit.c 2007-12-09 06:44:23.000000000 -0500
23534 @@ -0,0 +1,318 @@
23535 +/*
23536 + *  linux/kernel/vserver/limit.c
23537 + *
23538 + *  Virtual Server: Context Limits
23539 + *
23540 + *  Copyright (C) 2004-2007  Herbert Pötzl
23541 + *
23542 + *  V0.01  broken out from vcontext V0.05
23543 + *  V0.02  changed vcmds to vxi arg
23544 + *
23545 + */
23546 +
23547 +#include <linux/module.h>
23548 +#include <linux/vs_limit.h>
23549 +#include <linux/vserver/limit.h>
23550 +#include <linux/vserver/limit_cmd.h>
23551 +
23552 +#include <asm/uaccess.h>
23553 +
23554 +
23555 +const char *vlimit_name[NUM_LIMITS] = {
23556 +       [RLIMIT_CPU]            = "CPU",
23557 +       [RLIMIT_RSS]            = "RSS",
23558 +       [RLIMIT_NPROC]          = "NPROC",
23559 +       [RLIMIT_NOFILE]         = "NOFILE",
23560 +       [RLIMIT_MEMLOCK]        = "VML",
23561 +       [RLIMIT_AS]             = "VM",
23562 +       [RLIMIT_LOCKS]          = "LOCKS",
23563 +       [RLIMIT_SIGPENDING]     = "SIGP",
23564 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
23565 +
23566 +       [VLIMIT_NSOCK]          = "NSOCK",
23567 +       [VLIMIT_OPENFD]         = "OPENFD",
23568 +       [VLIMIT_ANON]           = "ANON",
23569 +       [VLIMIT_SHMEM]          = "SHMEM",
23570 +       [VLIMIT_DENTRY]         = "DENTRY",
23571 +};
23572 +
23573 +EXPORT_SYMBOL_GPL(vlimit_name);
23574 +
23575 +#define MASK_ENTRY(x)  (1 << (x))
23576 +
23577 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
23578 +               /* minimum */
23579 +       0
23580 +       ,       /* softlimit */
23581 +       MASK_ENTRY( RLIMIT_RSS          ) |
23582 +       MASK_ENTRY( VLIMIT_ANON         ) |
23583 +       0
23584 +       ,       /* maximum */
23585 +       MASK_ENTRY( RLIMIT_RSS          ) |
23586 +       MASK_ENTRY( RLIMIT_NPROC        ) |
23587 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
23588 +       MASK_ENTRY( RLIMIT_MEMLOCK      ) |
23589 +       MASK_ENTRY( RLIMIT_AS           ) |
23590 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
23591 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
23592 +
23593 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
23594 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
23595 +       MASK_ENTRY( VLIMIT_ANON         ) |
23596 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
23597 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
23598 +       0
23599 +};
23600 +               /* accounting only */
23601 +uint32_t account_mask =
23602 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
23603 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
23604 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
23605 +       0;
23606 +
23607 +
23608 +static int is_valid_vlimit(int id)
23609 +{
23610 +       uint32_t mask = vlimit_mask.minimum |
23611 +               vlimit_mask.softlimit | vlimit_mask.maximum;
23612 +       return mask & (1 << id);
23613 +}
23614 +
23615 +static int is_accounted_vlimit(int id)
23616 +{
23617 +       if (is_valid_vlimit(id))
23618 +               return 1;
23619 +       return account_mask & (1 << id);
23620 +}
23621 +
23622 +
23623 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
23624 +{
23625 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
23626 +       return VX_VLIM(limit);
23627 +}
23628 +
23629 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
23630 +{
23631 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
23632 +       return VX_VLIM(limit);
23633 +}
23634 +
23635 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
23636 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
23637 +{
23638 +       if (!is_valid_vlimit(id))
23639 +               return -EINVAL;
23640 +
23641 +       if (minimum)
23642 +               *minimum = CRLIM_UNSET;
23643 +       if (softlimit)
23644 +               *softlimit = vc_get_soft(vxi, id);
23645 +       if (maximum)
23646 +               *maximum = vc_get_hard(vxi, id);
23647 +       return 0;
23648 +}
23649 +
23650 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
23651 +{
23652 +       struct vcmd_ctx_rlimit_v0 vc_data;
23653 +       int ret;
23654 +
23655 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23656 +               return -EFAULT;
23657 +
23658 +       ret = do_get_rlimit(vxi, vc_data.id,
23659 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
23660 +       if (ret)
23661 +               return ret;
23662 +
23663 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23664 +               return -EFAULT;
23665 +       return 0;
23666 +}
23667 +
23668 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
23669 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
23670 +{
23671 +       if (!is_valid_vlimit(id))
23672 +               return -EINVAL;
23673 +
23674 +       if (maximum != CRLIM_KEEP)
23675 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
23676 +       if (softlimit != CRLIM_KEEP)
23677 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
23678 +
23679 +       /* clamp soft limit */
23680 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
23681 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
23682 +
23683 +       return 0;
23684 +}
23685 +
23686 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
23687 +{
23688 +       struct vcmd_ctx_rlimit_v0 vc_data;
23689 +
23690 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23691 +               return -EFAULT;
23692 +
23693 +       return do_set_rlimit(vxi, vc_data.id,
23694 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
23695 +}
23696 +
23697 +#ifdef CONFIG_IA32_EMULATION
23698 +
23699 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
23700 +{
23701 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
23702 +
23703 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23704 +               return -EFAULT;
23705 +
23706 +       return do_set_rlimit(vxi, vc_data.id,
23707 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
23708 +}
23709 +
23710 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
23711 +{
23712 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
23713 +       int ret;
23714 +
23715 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23716 +               return -EFAULT;
23717 +
23718 +       ret = do_get_rlimit(vxi, vc_data.id,
23719 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
23720 +       if (ret)
23721 +               return ret;
23722 +
23723 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23724 +               return -EFAULT;
23725 +       return 0;
23726 +}
23727 +
23728 +#endif /* CONFIG_IA32_EMULATION */
23729 +
23730 +
23731 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
23732 +{
23733 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
23734 +               return -EFAULT;
23735 +       return 0;
23736 +}
23737 +
23738 +
23739 +static inline void vx_reset_minmax(struct _vx_limit *limit)
23740 +{
23741 +       rlim_t value;
23742 +       int lim;
23743 +
23744 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
23745 +               value = __rlim_get(limit, lim);
23746 +               __rlim_rmax(limit, lim) = value;
23747 +               __rlim_rmin(limit, lim) = value;
23748 +       }
23749 +}
23750 +
23751 +
23752 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
23753 +{
23754 +       vx_reset_minmax(&vxi->limit);
23755 +       return 0;
23756 +}
23757 +
23758 +
23759 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
23760 +{
23761 +       struct vcmd_rlimit_stat_v0 vc_data;
23762 +       struct _vx_limit *limit = &vxi->limit;
23763 +       int id;
23764 +
23765 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23766 +               return -EFAULT;
23767 +
23768 +       id = vc_data.id;
23769 +       if (!is_accounted_vlimit(id))
23770 +               return -EINVAL;
23771 +
23772 +       vx_limit_fixup(limit, id);
23773 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
23774 +       vc_data.value = __rlim_get(limit, id);
23775 +       vc_data.minimum = __rlim_rmin(limit, id);
23776 +       vc_data.maximum = __rlim_rmax(limit, id);
23777 +
23778 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23779 +               return -EFAULT;
23780 +       return 0;
23781 +}
23782 +
23783 +
23784 +void vx_vsi_meminfo(struct sysinfo *val)
23785 +{
23786 +       struct vx_info *vxi = current->vx_info;
23787 +       unsigned long totalram, freeram;
23788 +       rlim_t v;
23789 +
23790 +       /* we blindly accept the max */
23791 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
23792 +       totalram = (v != RLIM_INFINITY) ? v : val->totalram;
23793 +
23794 +       /* total minus used equals free */
23795 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
23796 +       freeram = (v < totalram) ? totalram - v : 0;
23797 +
23798 +       val->totalram = totalram;
23799 +       val->freeram = freeram;
23800 +       val->bufferram = 0;
23801 +       val->totalhigh = 0;
23802 +       val->freehigh = 0;
23803 +       return;
23804 +}
23805 +
23806 +void vx_vsi_swapinfo(struct sysinfo *val)
23807 +{
23808 +       struct vx_info *vxi = current->vx_info;
23809 +       unsigned long totalswap, freeswap;
23810 +       rlim_t v, w;
23811 +
23812 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
23813 +       if (v == RLIM_INFINITY) {
23814 +               val->freeswap = val->totalswap;
23815 +               return;
23816 +       }
23817 +
23818 +       /* we blindly accept the max */
23819 +       w = __rlim_hard(&vxi->limit, RLIMIT_RSS);
23820 +       totalswap = (w != RLIM_INFINITY) ? (w - v) : val->totalswap;
23821 +
23822 +       /* currently 'used' swap */
23823 +       w = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
23824 +       w -= (w > v) ? v : w;
23825 +
23826 +       /* total minus used equals free */
23827 +       freeswap = (w < totalswap) ? totalswap - w : 0;
23828 +
23829 +       val->totalswap = totalswap;
23830 +       val->freeswap = freeswap;
23831 +       return;
23832 +}
23833 +
23834 +
23835 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
23836 +{
23837 +       struct vx_info *vxi = mm->mm_vx_info;
23838 +       unsigned long points;
23839 +       rlim_t v, w;
23840 +
23841 +       if (!vxi)
23842 +               return 0;
23843 +
23844 +       points = vxi->vx_badness_bias;
23845 +
23846 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
23847 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
23848 +       points += (v > w) ? (v - w) : 0;
23849 +
23850 +       return points;
23851 +}
23852 +
23853 diff -Nurp linux-2.6.22.15/kernel/vserver/limit_init.h linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/limit_init.h
23854 --- linux-2.6.22.15/kernel/vserver/limit_init.h 1969-12-31 19:00:00.000000000 -0500
23855 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/limit_init.h    2007-12-09 06:44:23.000000000 -0500
23856 @@ -0,0 +1,33 @@
23857 +
23858 +
23859 +static inline void vx_info_init_limit(struct _vx_limit *limit)
23860 +{
23861 +       int lim;
23862 +
23863 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
23864 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
23865 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
23866 +               __rlim_set(limit, lim, 0);
23867 +               atomic_set(&__rlim_lhit(limit, lim), 0);
23868 +               __rlim_rmin(limit, lim) = 0;
23869 +               __rlim_rmax(limit, lim) = 0;
23870 +       }
23871 +}
23872 +
23873 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
23874 +{
23875 +#ifdef CONFIG_VSERVER_WARN
23876 +       rlim_t value;
23877 +       int lim;
23878 +
23879 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
23880 +               if ((1 << lim) & VLIM_NOCHECK)
23881 +                       continue;
23882 +               value = __rlim_get(limit, lim);
23883 +               vxwprintk_xid(value,
23884 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
23885 +                       limit, vlimit_name[lim], lim, (long)value);
23886 +       }
23887 +#endif
23888 +}
23889 +
23890 diff -Nurp linux-2.6.22.15/kernel/vserver/limit_proc.h linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/limit_proc.h
23891 --- linux-2.6.22.15/kernel/vserver/limit_proc.h 1969-12-31 19:00:00.000000000 -0500
23892 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/limit_proc.h    2007-12-09 06:44:23.000000000 -0500
23893 @@ -0,0 +1,57 @@
23894 +#ifndef _VX_LIMIT_PROC_H
23895 +#define _VX_LIMIT_PROC_H
23896 +
23897 +#include <linux/vserver/limit_int.h>
23898 +
23899 +
23900 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
23901 +#define VX_LIMIT_TOP   \
23902 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
23903 +
23904 +#define VX_LIMIT_ARG(r)                                \
23905 +       (unsigned long)__rlim_get(limit, r),    \
23906 +       (unsigned long)__rlim_rmin(limit, r),   \
23907 +       (unsigned long)__rlim_rmax(limit, r),   \
23908 +       VX_VLIM(__rlim_soft(limit, r)),         \
23909 +       VX_VLIM(__rlim_hard(limit, r)),         \
23910 +       atomic_read(&__rlim_lhit(limit, r))
23911 +
23912 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
23913 +{
23914 +       vx_limit_fixup(limit, -1);
23915 +       return sprintf(buffer, VX_LIMIT_TOP
23916 +               "PROC"  VX_LIMIT_FMT
23917 +               "VM"    VX_LIMIT_FMT
23918 +               "VML"   VX_LIMIT_FMT
23919 +               "RSS"   VX_LIMIT_FMT
23920 +               "ANON"  VX_LIMIT_FMT
23921 +               "RMAP"  VX_LIMIT_FMT
23922 +               "FILES" VX_LIMIT_FMT
23923 +               "OFD"   VX_LIMIT_FMT
23924 +               "LOCKS" VX_LIMIT_FMT
23925 +               "SOCK"  VX_LIMIT_FMT
23926 +               "MSGQ"  VX_LIMIT_FMT
23927 +               "SHM"   VX_LIMIT_FMT
23928 +               "SEMA"  VX_LIMIT_FMT
23929 +               "SEMS"  VX_LIMIT_FMT
23930 +               "DENT"  VX_LIMIT_FMT,
23931 +               VX_LIMIT_ARG(RLIMIT_NPROC),
23932 +               VX_LIMIT_ARG(RLIMIT_AS),
23933 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
23934 +               VX_LIMIT_ARG(RLIMIT_RSS),
23935 +               VX_LIMIT_ARG(VLIMIT_ANON),
23936 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
23937 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
23938 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
23939 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
23940 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
23941 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
23942 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
23943 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
23944 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
23945 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
23946 +}
23947 +
23948 +#endif /* _VX_LIMIT_PROC_H */
23949 +
23950 +
23951 diff -Nurp linux-2.6.22.15/kernel/vserver/Makefile linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/Makefile
23952 --- linux-2.6.22.15/kernel/vserver/Makefile     1969-12-31 19:00:00.000000000 -0500
23953 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/Makefile        2007-12-09 06:44:23.000000000 -0500
23954 @@ -0,0 +1,18 @@
23955 +#
23956 +# Makefile for the Linux vserver routines.
23957 +#
23958 +
23959 +
23960 +obj-y          += vserver.o
23961 +
23962 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
23963 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
23964 +                  dlimit.o tag.o
23965 +
23966 +vserver-$(CONFIG_INET) += inet.o
23967 +vserver-$(CONFIG_PROC_FS) += proc.o
23968 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
23969 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
23970 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
23971 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
23972 +
23973 diff -Nurp linux-2.6.22.15/kernel/vserver/monitor.c linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/monitor.c
23974 --- linux-2.6.22.15/kernel/vserver/monitor.c    1969-12-31 19:00:00.000000000 -0500
23975 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/monitor.c       2007-12-09 06:44:23.000000000 -0500
23976 @@ -0,0 +1,138 @@
23977 +/*
23978 + *  kernel/vserver/monitor.c
23979 + *
23980 + *  Virtual Context Scheduler Monitor
23981 + *
23982 + *  Copyright (C) 2006-2007 Herbert Pötzl
23983 + *
23984 + *  V0.01  basic design
23985 + *
23986 + */
23987 +
23988 +#include <linux/module.h>
23989 +#include <linux/jiffies.h>
23990 +#include <asm/uaccess.h>
23991 +#include <asm/atomic.h>
23992 +
23993 +#include <linux/vserver/monitor.h>
23994 +#include <linux/vserver/debug_cmd.h>
23995 +
23996 +
23997 +#ifdef CONFIG_VSERVER_MONITOR
23998 +#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
23999 +#else
24000 +#define VXM_SIZE       64
24001 +#endif
24002 +
24003 +struct _vx_monitor {
24004 +       unsigned int counter;
24005 +
24006 +       struct _vx_mon_entry entry[VXM_SIZE+1];
24007 +};
24008 +
24009 +
24010 +DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
24011 +
24012 +unsigned volatile int vxm_active = 1;
24013 +
24014 +static atomic_t sequence = ATOMIC_INIT(0);
24015 +
24016 +
24017 +/*     vxm_advance()
24018 +
24019 +       * requires disabled preemption                          */
24020 +
24021 +struct _vx_mon_entry *vxm_advance(int cpu)
24022 +{
24023 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
24024 +       struct _vx_mon_entry *entry;
24025 +       unsigned int index;
24026 +
24027 +       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
24028 +       entry = &mon->entry[index];
24029 +
24030 +       entry->ev.seq = atomic_inc_return(&sequence);
24031 +       entry->ev.jif = jiffies;
24032 +       return entry;
24033 +}
24034 +
24035 +EXPORT_SYMBOL_GPL(vxm_advance);
24036 +
24037 +
24038 +int do_read_monitor(struct __user _vx_mon_entry *data,
24039 +       int cpu, uint32_t *index, uint32_t *count)
24040 +{
24041 +       int pos, ret = 0;
24042 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
24043 +       int end = mon->counter;
24044 +       int start = end - VXM_SIZE + 2;
24045 +       int idx = *index;
24046 +
24047 +       /* special case: get current pos */
24048 +       if (!*count) {
24049 +               *index = end;
24050 +               return 0;
24051 +       }
24052 +
24053 +       /* have we lost some data? */
24054 +       if (idx < start)
24055 +               idx = start;
24056 +
24057 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
24058 +               struct _vx_mon_entry *entry =
24059 +                       &mon->entry[idx % VXM_SIZE];
24060 +
24061 +               /* send entry to userspace */
24062 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
24063 +               if (ret)
24064 +                       break;
24065 +       }
24066 +       /* save new index and count */
24067 +       *index = idx;
24068 +       *count = pos;
24069 +       return ret ? ret : (*index < end);
24070 +}
24071 +
24072 +int vc_read_monitor(uint32_t id, void __user *data)
24073 +{
24074 +       struct vcmd_read_monitor_v0 vc_data;
24075 +       int ret;
24076 +
24077 +       if (id >= NR_CPUS)
24078 +               return -EINVAL;
24079 +
24080 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24081 +               return -EFAULT;
24082 +
24083 +       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
24084 +               id, &vc_data.index, &vc_data.count);
24085 +
24086 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24087 +               return -EFAULT;
24088 +       return ret;
24089 +}
24090 +
24091 +#ifdef CONFIG_COMPAT
24092 +
24093 +int vc_read_monitor_x32(uint32_t id, void __user *data)
24094 +{
24095 +       struct vcmd_read_monitor_v0_x32 vc_data;
24096 +       int ret;
24097 +
24098 +       if (id >= NR_CPUS)
24099 +               return -EINVAL;
24100 +
24101 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24102 +               return -EFAULT;
24103 +
24104 +       ret = do_read_monitor((struct __user _vx_mon_entry *)
24105 +               compat_ptr(vc_data.data_ptr),
24106 +               id, &vc_data.index, &vc_data.count);
24107 +
24108 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24109 +               return -EFAULT;
24110 +       return ret;
24111 +}
24112 +
24113 +#endif /* CONFIG_COMPAT */
24114 +
24115 diff -Nurp linux-2.6.22.15/kernel/vserver/network.c linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/network.c
24116 --- linux-2.6.22.15/kernel/vserver/network.c    1969-12-31 19:00:00.000000000 -0500
24117 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/network.c       2007-12-09 06:44:23.000000000 -0500
24118 @@ -0,0 +1,862 @@
24119 +/*
24120 + *  linux/kernel/vserver/network.c
24121 + *
24122 + *  Virtual Server: Network Support
24123 + *
24124 + *  Copyright (C) 2003-2007  Herbert Pötzl
24125 + *
24126 + *  V0.01  broken out from vcontext V0.05
24127 + *  V0.02  cleaned up implementation
24128 + *  V0.03  added equiv nx commands
24129 + *  V0.04  switch to RCU based hash
24130 + *  V0.05  and back to locking again
24131 + *  V0.06  changed vcmds to nxi arg
24132 + *  V0.07  have __create claim() the nxi
24133 + *
24134 + */
24135 +
24136 +#include <linux/err.h>
24137 +#include <linux/slab.h>
24138 +#include <linux/rcupdate.h>
24139 +
24140 +#include <linux/vs_network.h>
24141 +#include <linux/vserver/network_cmd.h>
24142 +
24143 +
24144 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
24145 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
24146 +
24147 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
24148 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
24149 +
24150 +
24151 +static int __init init_network(void)
24152 +{
24153 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
24154 +               sizeof(struct nx_addr_v4), 0, SLAB_PANIC, NULL, NULL);
24155 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
24156 +               sizeof(struct nx_addr_v6), 0, SLAB_PANIC, NULL, NULL);
24157 +       return 0;
24158 +}
24159 +
24160 +
24161 +/*     __alloc_nx_addr_v4()                                    */
24162 +
24163 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
24164 +{
24165 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
24166 +               nx_addr_v4_cachep, GFP_KERNEL);
24167 +
24168 +       if (!IS_ERR(nxa))
24169 +               memset(nxa, 0, sizeof(*nxa));
24170 +       return nxa;
24171 +}
24172 +
24173 +/*     __dealloc_nx_addr_v4()                                  */
24174 +
24175 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
24176 +{
24177 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
24178 +}
24179 +
24180 +/*     __dealloc_nx_addr_v4_all()                              */
24181 +
24182 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
24183 +{
24184 +       while (nxa) {
24185 +               struct nx_addr_v4 *next = nxa->next;
24186 +
24187 +               __dealloc_nx_addr_v4(nxa);
24188 +               nxa = next;
24189 +       }
24190 +}
24191 +
24192 +
24193 +#ifdef CONFIG_IPV6
24194 +
24195 +/*     __alloc_nx_addr_v6()                                    */
24196 +
24197 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
24198 +{
24199 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
24200 +               nx_addr_v6_cachep, GFP_KERNEL);
24201 +
24202 +       if (!IS_ERR(nxa))
24203 +               memset(nxa, 0, sizeof(*nxa));
24204 +       return nxa;
24205 +}
24206 +
24207 +/*     __dealloc_nx_addr_v6()                                  */
24208 +
24209 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
24210 +{
24211 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
24212 +}
24213 +
24214 +/*     __dealloc_nx_addr_v6_all()                              */
24215 +
24216 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
24217 +{
24218 +       while (nxa) {
24219 +               struct nx_addr_v6 *next = nxa->next;
24220 +
24221 +               __dealloc_nx_addr_v6(nxa);
24222 +               nxa = next;
24223 +       }
24224 +}
24225 +
24226 +#endif /* CONFIG_IPV6 */
24227 +
24228 +
24229 +/*     __alloc_nx_info()
24230 +
24231 +       * allocate an initialized nx_info struct
24232 +       * doesn't make it visible (hash)                        */
24233 +
24234 +static struct nx_info *__alloc_nx_info(nid_t nid)
24235 +{
24236 +       struct nx_info *new = NULL;
24237 +
24238 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
24239 +
24240 +       /* would this benefit from a slab cache? */
24241 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
24242 +       if (!new)
24243 +               return 0;
24244 +
24245 +       memset(new, 0, sizeof(struct nx_info));
24246 +       new->nx_id = nid;
24247 +       INIT_HLIST_NODE(&new->nx_hlist);
24248 +       atomic_set(&new->nx_usecnt, 0);
24249 +       atomic_set(&new->nx_tasks, 0);
24250 +       new->nx_state = 0;
24251 +
24252 +       new->nx_flags = NXF_INIT_SET;
24253 +
24254 +       /* rest of init goes here */
24255 +
24256 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
24257 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
24258 +
24259 +       vxdprintk(VXD_CBIT(nid, 0),
24260 +               "alloc_nx_info(%d) = %p", nid, new);
24261 +       atomic_inc(&nx_global_ctotal);
24262 +       return new;
24263 +}
24264 +
24265 +/*     __dealloc_nx_info()
24266 +
24267 +       * final disposal of nx_info                             */
24268 +
24269 +static void __dealloc_nx_info(struct nx_info *nxi)
24270 +{
24271 +       vxdprintk(VXD_CBIT(nid, 0),
24272 +               "dealloc_nx_info(%p)", nxi);
24273 +
24274 +       nxi->nx_hlist.next = LIST_POISON1;
24275 +       nxi->nx_id = -1;
24276 +
24277 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
24278 +       BUG_ON(atomic_read(&nxi->nx_tasks));
24279 +
24280 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
24281 +
24282 +       nxi->nx_state |= NXS_RELEASED;
24283 +       kfree(nxi);
24284 +       atomic_dec(&nx_global_ctotal);
24285 +}
24286 +
24287 +static void __shutdown_nx_info(struct nx_info *nxi)
24288 +{
24289 +       nxi->nx_state |= NXS_SHUTDOWN;
24290 +       vs_net_change(nxi, VSC_NETDOWN);
24291 +}
24292 +
24293 +/*     exported stuff                                          */
24294 +
24295 +void free_nx_info(struct nx_info *nxi)
24296 +{
24297 +       /* context shutdown is mandatory */
24298 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
24299 +
24300 +       /* context must not be hashed */
24301 +       BUG_ON(nxi->nx_state & NXS_HASHED);
24302 +
24303 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
24304 +       BUG_ON(atomic_read(&nxi->nx_tasks));
24305 +
24306 +       __dealloc_nx_info(nxi);
24307 +}
24308 +
24309 +
24310 +void __nx_set_lback(struct nx_info *nxi)
24311 +{
24312 +       int nid = nxi->nx_id;
24313 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
24314 +
24315 +       nxi->v4_lback.s_addr = lback;
24316 +}
24317 +
24318 +extern int __nx_inet_add_lback(__be32 addr);
24319 +extern int __nx_inet_del_lback(__be32 addr);
24320 +
24321 +
24322 +/*     hash table for nx_info hash */
24323 +
24324 +#define NX_HASH_SIZE   13
24325 +
24326 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
24327 +
24328 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
24329 +
24330 +
24331 +static inline unsigned int __hashval(nid_t nid)
24332 +{
24333 +       return (nid % NX_HASH_SIZE);
24334 +}
24335 +
24336 +
24337 +
24338 +/*     __hash_nx_info()
24339 +
24340 +       * add the nxi to the global hash table
24341 +       * requires the hash_lock to be held                     */
24342 +
24343 +static inline void __hash_nx_info(struct nx_info *nxi)
24344 +{
24345 +       struct hlist_head *head;
24346 +
24347 +       vxd_assert_lock(&nx_info_hash_lock);
24348 +       vxdprintk(VXD_CBIT(nid, 4),
24349 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
24350 +
24351 +       /* context must not be hashed */
24352 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
24353 +
24354 +       nxi->nx_state |= NXS_HASHED;
24355 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
24356 +       hlist_add_head(&nxi->nx_hlist, head);
24357 +       atomic_inc(&nx_global_cactive);
24358 +}
24359 +
24360 +/*     __unhash_nx_info()
24361 +
24362 +       * remove the nxi from the global hash table
24363 +       * requires the hash_lock to be held                     */
24364 +
24365 +static inline void __unhash_nx_info(struct nx_info *nxi)
24366 +{
24367 +       vxd_assert_lock(&nx_info_hash_lock);
24368 +       vxdprintk(VXD_CBIT(nid, 4),
24369 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
24370 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
24371 +
24372 +       /* context must be hashed */
24373 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
24374 +       /* but without tasks */
24375 +       BUG_ON(atomic_read(&nxi->nx_tasks));
24376 +
24377 +       nxi->nx_state &= ~NXS_HASHED;
24378 +       hlist_del(&nxi->nx_hlist);
24379 +       atomic_dec(&nx_global_cactive);
24380 +}
24381 +
24382 +
24383 +/*     __lookup_nx_info()
24384 +
24385 +       * requires the hash_lock to be held
24386 +       * doesn't increment the nx_refcnt                       */
24387 +
24388 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
24389 +{
24390 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
24391 +       struct hlist_node *pos;
24392 +       struct nx_info *nxi;
24393 +
24394 +       vxd_assert_lock(&nx_info_hash_lock);
24395 +       hlist_for_each(pos, head) {
24396 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
24397 +
24398 +               if (nxi->nx_id == nid)
24399 +                       goto found;
24400 +       }
24401 +       nxi = NULL;
24402 +found:
24403 +       vxdprintk(VXD_CBIT(nid, 0),
24404 +               "__lookup_nx_info(#%u): %p[#%u]",
24405 +               nid, nxi, nxi ? nxi->nx_id : 0);
24406 +       return nxi;
24407 +}
24408 +
24409 +
24410 +/*     __create_nx_info()
24411 +
24412 +       * create the requested context
24413 +       * get(), claim() and hash it                            */
24414 +
24415 +static struct nx_info *__create_nx_info(int id)
24416 +{
24417 +       struct nx_info *new, *nxi = NULL;
24418 +
24419 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
24420 +
24421 +       if (!(new = __alloc_nx_info(id)))
24422 +               return ERR_PTR(-ENOMEM);
24423 +
24424 +       /* required to make dynamic xids unique */
24425 +       spin_lock(&nx_info_hash_lock);
24426 +
24427 +       /* static context requested */
24428 +       if ((nxi = __lookup_nx_info(id))) {
24429 +               vxdprintk(VXD_CBIT(nid, 0),
24430 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
24431 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
24432 +                       nxi = ERR_PTR(-EBUSY);
24433 +               else
24434 +                       nxi = ERR_PTR(-EEXIST);
24435 +               goto out_unlock;
24436 +       }
24437 +       /* new context */
24438 +       vxdprintk(VXD_CBIT(nid, 0),
24439 +               "create_nx_info(%d) = %p (new)", id, new);
24440 +       claim_nx_info(new, NULL);
24441 +       __nx_set_lback(new);
24442 +       __hash_nx_info(get_nx_info(new));
24443 +       nxi = new, new = NULL;
24444 +
24445 +out_unlock:
24446 +       spin_unlock(&nx_info_hash_lock);
24447 +       if (new)
24448 +               __dealloc_nx_info(new);
24449 +       return nxi;
24450 +}
24451 +
24452 +
24453 +
24454 +/*     exported stuff                                          */
24455 +
24456 +
24457 +void unhash_nx_info(struct nx_info *nxi)
24458 +{
24459 +       __shutdown_nx_info(nxi);
24460 +       spin_lock(&nx_info_hash_lock);
24461 +       __unhash_nx_info(nxi);
24462 +       spin_unlock(&nx_info_hash_lock);
24463 +}
24464 +
24465 +/*     lookup_nx_info()
24466 +
24467 +       * search for a nx_info and get() it
24468 +       * negative id means current                             */
24469 +
24470 +struct nx_info *lookup_nx_info(int id)
24471 +{
24472 +       struct nx_info *nxi = NULL;
24473 +
24474 +       if (id < 0) {
24475 +               nxi = get_nx_info(current->nx_info);
24476 +       } else if (id > 1) {
24477 +               spin_lock(&nx_info_hash_lock);
24478 +               nxi = get_nx_info(__lookup_nx_info(id));
24479 +               spin_unlock(&nx_info_hash_lock);
24480 +       }
24481 +       return nxi;
24482 +}
24483 +
24484 +/*     nid_is_hashed()
24485 +
24486 +       * verify that nid is still hashed                       */
24487 +
24488 +int nid_is_hashed(nid_t nid)
24489 +{
24490 +       int hashed;
24491 +
24492 +       spin_lock(&nx_info_hash_lock);
24493 +       hashed = (__lookup_nx_info(nid) != NULL);
24494 +       spin_unlock(&nx_info_hash_lock);
24495 +       return hashed;
24496 +}
24497 +
24498 +
24499 +#ifdef CONFIG_PROC_FS
24500 +
24501 +/*     get_nid_list()
24502 +
24503 +       * get a subset of hashed nids for proc
24504 +       * assumes size is at least one                          */
24505 +
24506 +int get_nid_list(int index, unsigned int *nids, int size)
24507 +{
24508 +       int hindex, nr_nids = 0;
24509 +
24510 +       /* only show current and children */
24511 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
24512 +               if (index > 0)
24513 +                       return 0;
24514 +               nids[nr_nids] = nx_current_nid();
24515 +               return 1;
24516 +       }
24517 +
24518 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
24519 +               struct hlist_head *head = &nx_info_hash[hindex];
24520 +               struct hlist_node *pos;
24521 +
24522 +               spin_lock(&nx_info_hash_lock);
24523 +               hlist_for_each(pos, head) {
24524 +                       struct nx_info *nxi;
24525 +
24526 +                       if (--index > 0)
24527 +                               continue;
24528 +
24529 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
24530 +                       nids[nr_nids] = nxi->nx_id;
24531 +                       if (++nr_nids >= size) {
24532 +                               spin_unlock(&nx_info_hash_lock);
24533 +                               goto out;
24534 +                       }
24535 +               }
24536 +               /* keep the lock time short */
24537 +               spin_unlock(&nx_info_hash_lock);
24538 +       }
24539 +out:
24540 +       return nr_nids;
24541 +}
24542 +#endif
24543 +
24544 +
24545 +/*
24546 + *     migrate task to new network
24547 + *     gets nxi, puts old_nxi on change
24548 + */
24549 +
24550 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
24551 +{
24552 +       struct nx_info *old_nxi;
24553 +       int ret = 0;
24554 +
24555 +       if (!p || !nxi)
24556 +               BUG();
24557 +
24558 +       vxdprintk(VXD_CBIT(nid, 5),
24559 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
24560 +               p, nxi, nxi->nx_id,
24561 +               atomic_read(&nxi->nx_usecnt),
24562 +               atomic_read(&nxi->nx_tasks));
24563 +
24564 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
24565 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
24566 +               return -EACCES;
24567 +
24568 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
24569 +               return -EFAULT;
24570 +
24571 +       /* maybe disallow this completely? */
24572 +       old_nxi = task_get_nx_info(p);
24573 +       if (old_nxi == nxi)
24574 +               goto out;
24575 +
24576 +       task_lock(p);
24577 +       if (old_nxi)
24578 +               clr_nx_info(&p->nx_info);
24579 +       claim_nx_info(nxi, p);
24580 +       set_nx_info(&p->nx_info, nxi);
24581 +       p->nid = nxi->nx_id;
24582 +       task_unlock(p);
24583 +
24584 +       vxdprintk(VXD_CBIT(nid, 5),
24585 +               "moved task %p into nxi:%p[#%d]",
24586 +               p, nxi, nxi->nx_id);
24587 +
24588 +       if (old_nxi)
24589 +               release_nx_info(old_nxi, p);
24590 +       ret = 0;
24591 +out:
24592 +       put_nx_info(old_nxi);
24593 +       return ret;
24594 +}
24595 +
24596 +
24597 +void nx_set_persistent(struct nx_info *nxi)
24598 +{
24599 +       vxdprintk(VXD_CBIT(nid, 6),
24600 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
24601 +
24602 +       get_nx_info(nxi);
24603 +       claim_nx_info(nxi, NULL);
24604 +}
24605 +
24606 +void nx_clear_persistent(struct nx_info *nxi)
24607 +{
24608 +       vxdprintk(VXD_CBIT(nid, 6),
24609 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
24610 +
24611 +       release_nx_info(nxi, NULL);
24612 +       put_nx_info(nxi);
24613 +}
24614 +
24615 +void nx_update_persistent(struct nx_info *nxi)
24616 +{
24617 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
24618 +               nx_set_persistent(nxi);
24619 +       else
24620 +               nx_clear_persistent(nxi);
24621 +}
24622 +
24623 +/* vserver syscall commands below here */
24624 +
24625 +/* taks nid and nx_info functions */
24626 +
24627 +#include <asm/uaccess.h>
24628 +
24629 +
24630 +int vc_task_nid(uint32_t id)
24631 +{
24632 +       nid_t nid;
24633 +
24634 +       if (id) {
24635 +               struct task_struct *tsk;
24636 +
24637 +               read_lock(&tasklist_lock);
24638 +               tsk = find_task_by_real_pid(id);
24639 +               nid = (tsk) ? tsk->nid : -ESRCH;
24640 +               read_unlock(&tasklist_lock);
24641 +       } else
24642 +               nid = nx_current_nid();
24643 +       return nid;
24644 +}
24645 +
24646 +
24647 +int vc_nx_info(struct nx_info *nxi, void __user *data)
24648 +{
24649 +       struct vcmd_nx_info_v0 vc_data;
24650 +
24651 +       vc_data.nid = nxi->nx_id;
24652 +
24653 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24654 +               return -EFAULT;
24655 +       return 0;
24656 +}
24657 +
24658 +
24659 +/* network functions */
24660 +
24661 +int vc_net_create(uint32_t nid, void __user *data)
24662 +{
24663 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
24664 +       struct nx_info *new_nxi;
24665 +       int ret;
24666 +
24667 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24668 +               return -EFAULT;
24669 +
24670 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
24671 +               return -EINVAL;
24672 +
24673 +       new_nxi = __create_nx_info(nid);
24674 +       if (IS_ERR(new_nxi))
24675 +               return PTR_ERR(new_nxi);
24676 +
24677 +       /* initial flags */
24678 +       new_nxi->nx_flags = vc_data.flagword;
24679 +
24680 +       ret = -ENOEXEC;
24681 +       if (vs_net_change(new_nxi, VSC_NETUP))
24682 +               goto out;
24683 +
24684 +       ret = nx_migrate_task(current, new_nxi);
24685 +       if (ret)
24686 +               goto out;
24687 +
24688 +       /* return context id on success */
24689 +       ret = new_nxi->nx_id;
24690 +
24691 +       /* get a reference for persistent contexts */
24692 +       if ((vc_data.flagword & NXF_PERSISTENT))
24693 +               nx_set_persistent(new_nxi);
24694 +out:
24695 +       release_nx_info(new_nxi, NULL);
24696 +       put_nx_info(new_nxi);
24697 +       return ret;
24698 +}
24699 +
24700 +
24701 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
24702 +{
24703 +       return nx_migrate_task(current, nxi);
24704 +}
24705 +
24706 +
24707 +
24708 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
24709 +       uint16_t type, uint16_t flags)
24710 +{
24711 +       struct nx_addr_v4 *nxa = &nxi->v4;
24712 +
24713 +       if (NX_IPV4(nxi)) {
24714 +               /* locate last entry */
24715 +               for (; nxa->next; nxa = nxa->next);
24716 +               nxa->next = __alloc_nx_addr_v4();
24717 +               nxa = nxa->next;
24718 +
24719 +               if (IS_ERR(nxa))
24720 +                       return PTR_ERR(nxa);
24721 +       }
24722 +
24723 +       if (nxi->v4.next)
24724 +               /* remove single ip for ip list */
24725 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
24726 +
24727 +       nxa->ip[0].s_addr = ip;
24728 +       nxa->ip[1].s_addr = ip2;
24729 +       nxa->mask.s_addr = mask;
24730 +       nxa->type = type;
24731 +       nxa->flags = flags;
24732 +       return 0;
24733 +}
24734 +
24735 +
24736 +int vc_net_add(struct nx_info *nxi, void __user *data)
24737 +{
24738 +       struct vcmd_net_addr_v0 vc_data;
24739 +       int index, ret = 0;
24740 +
24741 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24742 +               return -EFAULT;
24743 +
24744 +       switch (vc_data.type) {
24745 +       case NXA_TYPE_IPV4:
24746 +               if ((vc_data.count < 1) || (vc_data.count > 4))
24747 +                       return -EINVAL;
24748 +
24749 +               index = 0;
24750 +               while (index < vc_data.count) {
24751 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
24752 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
24753 +                       if (ret)
24754 +                               return ret;
24755 +                       index++;
24756 +               }
24757 +               ret = index;
24758 +               break;
24759 +
24760 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
24761 +               nxi->v4_bcast = vc_data.ip[0];
24762 +               ret = 1;
24763 +               break;
24764 +
24765 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
24766 +               nxi->v4_lback = vc_data.ip[0];
24767 +               ret = 1;
24768 +               break;
24769 +
24770 +       default:
24771 +               ret = -EINVAL;
24772 +               break;
24773 +       }
24774 +       return ret;
24775 +}
24776 +
24777 +int vc_net_remove(struct nx_info *nxi, void __user *data)
24778 +{
24779 +       struct vcmd_net_addr_v0 vc_data;
24780 +
24781 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24782 +               return -EFAULT;
24783 +
24784 +       switch (vc_data.type) {
24785 +       case NXA_TYPE_ANY:
24786 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
24787 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
24788 +               break;
24789 +
24790 +       default:
24791 +               return -EINVAL;
24792 +       }
24793 +       return 0;
24794 +}
24795 +
24796 +
24797 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
24798 +{
24799 +       struct vcmd_net_addr_ipv4_v1 vc_data;
24800 +
24801 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24802 +               return -EFAULT;
24803 +
24804 +       switch (vc_data.type) {
24805 +       case NXA_TYPE_ADDR:
24806 +       case NXA_TYPE_RANGE:
24807 +       case NXA_TYPE_MASK:
24808 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
24809 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
24810 +
24811 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
24812 +               nxi->v4_bcast = vc_data.ip;
24813 +               break;
24814 +
24815 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
24816 +               nxi->v4_lback = vc_data.ip;
24817 +               break;
24818 +
24819 +       default:
24820 +               return -EINVAL;
24821 +       }
24822 +       return 0;
24823 +}
24824 +
24825 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
24826 +{
24827 +       struct vcmd_net_addr_ipv4_v1 vc_data;
24828 +
24829 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24830 +               return -EFAULT;
24831 +
24832 +       switch (vc_data.type) {
24833 +/*     case NXA_TYPE_ADDR:
24834 +               break;          */
24835 +
24836 +       case NXA_TYPE_ANY:
24837 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
24838 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
24839 +               break;
24840 +
24841 +       default:
24842 +               return -EINVAL;
24843 +       }
24844 +       return 0;
24845 +}
24846 +
24847 +
24848 +#ifdef CONFIG_IPV6
24849 +
24850 +int do_add_v6_addr(struct nx_info *nxi,
24851 +       struct in6_addr *ip, struct in6_addr *mask,
24852 +       uint32_t prefix, uint16_t type, uint16_t flags)
24853 +{
24854 +       struct nx_addr_v6 *nxa = &nxi->v6;
24855 +
24856 +       if (NX_IPV6(nxi)) {
24857 +               /* locate last entry */
24858 +               for (; nxa->next; nxa = nxa->next);
24859 +               nxa->next = __alloc_nx_addr_v6();
24860 +               nxa = nxa->next;
24861 +
24862 +               if (IS_ERR(nxa))
24863 +                       return PTR_ERR(nxa);
24864 +       }
24865 +
24866 +       nxa->ip = *ip;
24867 +       nxa->mask = *mask;
24868 +       nxa->prefix = prefix;
24869 +       nxa->type = type;
24870 +       nxa->flags = flags;
24871 +       return 0;
24872 +}
24873 +
24874 +
24875 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
24876 +{
24877 +       struct vcmd_net_addr_ipv6_v1 vc_data;
24878 +
24879 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24880 +               return -EFAULT;
24881 +
24882 +       switch (vc_data.type) {
24883 +       case NXA_TYPE_ADDR:
24884 +       case NXA_TYPE_MASK:
24885 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
24886 +                       vc_data.prefix, vc_data.type, vc_data.flags);
24887 +       default:
24888 +               return -EINVAL;
24889 +       }
24890 +       return 0;
24891 +}
24892 +
24893 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
24894 +{
24895 +       struct vcmd_net_addr_ipv6_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_ANY:
24902 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
24903 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
24904 +               break;
24905 +
24906 +       default:
24907 +               return -EINVAL;
24908 +       }
24909 +       return 0;
24910 +}
24911 +
24912 +#endif /* CONFIG_IPV6 */
24913 +
24914 +
24915 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
24916 +{
24917 +       struct vcmd_net_flags_v0 vc_data;
24918 +
24919 +       vc_data.flagword = nxi->nx_flags;
24920 +
24921 +       /* special STATE flag handling */
24922 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
24923 +
24924 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24925 +               return -EFAULT;
24926 +       return 0;
24927 +}
24928 +
24929 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
24930 +{
24931 +       struct vcmd_net_flags_v0 vc_data;
24932 +       uint64_t mask, trigger;
24933 +
24934 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24935 +               return -EFAULT;
24936 +
24937 +       /* special STATE flag handling */
24938 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
24939 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
24940 +
24941 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
24942 +               vc_data.flagword, mask);
24943 +       if (trigger & NXF_PERSISTENT)
24944 +               nx_update_persistent(nxi);
24945 +
24946 +       return 0;
24947 +}
24948 +
24949 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
24950 +{
24951 +       struct vcmd_net_caps_v0 vc_data;
24952 +
24953 +       vc_data.ncaps = nxi->nx_ncaps;
24954 +       vc_data.cmask = ~0ULL;
24955 +
24956 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24957 +               return -EFAULT;
24958 +       return 0;
24959 +}
24960 +
24961 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
24962 +{
24963 +       struct vcmd_net_caps_v0 vc_data;
24964 +
24965 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24966 +               return -EFAULT;
24967 +
24968 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
24969 +               vc_data.ncaps, vc_data.cmask);
24970 +       return 0;
24971 +}
24972 +
24973 +
24974 +#include <linux/module.h>
24975 +
24976 +module_init(init_network);
24977 +
24978 +EXPORT_SYMBOL_GPL(free_nx_info);
24979 +EXPORT_SYMBOL_GPL(unhash_nx_info);
24980 +
24981 diff -Nurp linux-2.6.22.15/kernel/vserver/proc.c linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/proc.c
24982 --- linux-2.6.22.15/kernel/vserver/proc.c       1969-12-31 19:00:00.000000000 -0500
24983 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/proc.c  2007-12-09 06:44:23.000000000 -0500
24984 @@ -0,0 +1,1065 @@
24985 +/*
24986 + *  linux/kernel/vserver/proc.c
24987 + *
24988 + *  Virtual Context Support
24989 + *
24990 + *  Copyright (C) 2003-2007  Herbert Pötzl
24991 + *
24992 + *  V0.01  basic structure
24993 + *  V0.02  adaptation vs1.3.0
24994 + *  V0.03  proc permissions
24995 + *  V0.04  locking/generic
24996 + *  V0.05  next generation procfs
24997 + *  V0.06  inode validation
24998 + *  V0.07  generic rewrite vid
24999 + *  V0.08  remove inode type
25000 + *
25001 + */
25002 +
25003 +#include <linux/proc_fs.h>
25004 +#include <asm/unistd.h>
25005 +
25006 +#include <linux/vs_context.h>
25007 +#include <linux/vs_network.h>
25008 +#include <linux/vs_cvirt.h>
25009 +#include <linux/vs_inet.h>
25010 +#include <linux/vs_inet6.h>
25011 +
25012 +#include <linux/vserver/global.h>
25013 +
25014 +#include "cvirt_proc.h"
25015 +#include "cacct_proc.h"
25016 +#include "limit_proc.h"
25017 +#include "sched_proc.h"
25018 +#include "vci_config.h"
25019 +
25020 +static struct proc_dir_entry *proc_virtual;
25021 +
25022 +static struct proc_dir_entry *proc_virtnet;
25023 +
25024 +
25025 +/* first the actual feeds */
25026 +
25027 +
25028 +static int proc_vci(char *buffer)
25029 +{
25030 +       return sprintf(buffer,
25031 +               "VCIVersion:\t%04x:%04x\n"
25032 +               "VCISyscall:\t%d\n"
25033 +               "VCIKernel:\t%08x\n",
25034 +               VCI_VERSION >> 16,
25035 +               VCI_VERSION & 0xFFFF,
25036 +               __NR_vserver,
25037 +               vci_kernel_config());
25038 +}
25039 +
25040 +static int proc_virtual_info(char *buffer)
25041 +{
25042 +       return proc_vci(buffer);
25043 +}
25044 +
25045 +static int proc_virtual_status(char *buffer)
25046 +{
25047 +       return sprintf(buffer,
25048 +               "#CTotal:\t%d\n"
25049 +               "#CActive:\t%d\n"
25050 +               "#NSProxy:\t%d\t%d %d %d %d\n",
25051 +               atomic_read(&vx_global_ctotal),
25052 +               atomic_read(&vx_global_cactive),
25053 +               atomic_read(&vs_global_nsproxy),
25054 +               atomic_read(&vs_global_fs),
25055 +               atomic_read(&vs_global_mnt_ns),
25056 +               atomic_read(&vs_global_uts_ns),
25057 +               atomic_read(&vs_global_ipc_ns));
25058 +}
25059 +
25060 +
25061 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
25062 +{
25063 +       int length;
25064 +
25065 +       length = sprintf(buffer,
25066 +               "ID:\t%d\n"
25067 +               "Info:\t%p\n"
25068 +               "Init:\t%d\n"
25069 +               "OOM:\t%lld\n",
25070 +               vxi->vx_id,
25071 +               vxi,
25072 +               vxi->vx_initpid,
25073 +               vxi->vx_badness_bias);
25074 +       return length;
25075 +}
25076 +
25077 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
25078 +{
25079 +       int length;
25080 +
25081 +       length = sprintf(buffer,
25082 +               "UseCnt:\t%d\n"
25083 +               "Tasks:\t%d\n"
25084 +               "Flags:\t%016llx\n"
25085 +               "BCaps:\t%016llx\n"
25086 +               "CCaps:\t%016llx\n"
25087 +               "Spaces:\t%08lx\n",
25088 +               atomic_read(&vxi->vx_usecnt),
25089 +               atomic_read(&vxi->vx_tasks),
25090 +               (unsigned long long)vxi->vx_flags,
25091 +               (unsigned long long)vxi->vx_bcaps,
25092 +               (unsigned long long)vxi->vx_ccaps,
25093 +               vxi->vx_nsmask);
25094 +       return length;
25095 +}
25096 +
25097 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
25098 +{
25099 +       return vx_info_proc_limit(&vxi->limit, buffer);
25100 +}
25101 +
25102 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
25103 +{
25104 +       int cpu, length;
25105 +
25106 +       length = vx_info_proc_sched(&vxi->sched, buffer);
25107 +       for_each_online_cpu(cpu) {
25108 +               length += vx_info_proc_sched_pc(
25109 +                       &vx_per_cpu(vxi, sched_pc, cpu),
25110 +                       buffer + length, cpu);
25111 +       }
25112 +       return length;
25113 +}
25114 +
25115 +int proc_vxi_nsproxy(struct vx_info *vxi, char *buffer)
25116 +{
25117 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy, buffer);
25118 +}
25119 +
25120 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
25121 +{
25122 +       int cpu, length;
25123 +
25124 +       vx_update_load(vxi);
25125 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
25126 +       for_each_online_cpu(cpu) {
25127 +               length += vx_info_proc_cvirt_pc(
25128 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
25129 +                       buffer + length, cpu);
25130 +       }
25131 +       return length;
25132 +}
25133 +
25134 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
25135 +{
25136 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
25137 +}
25138 +
25139 +
25140 +static int proc_virtnet_info(char *buffer)
25141 +{
25142 +       return proc_vci(buffer);
25143 +}
25144 +
25145 +static int proc_virtnet_status(char *buffer)
25146 +{
25147 +       return sprintf(buffer,
25148 +               "#CTotal:\t%d\n"
25149 +               "#CActive:\t%d\n",
25150 +               atomic_read(&nx_global_ctotal),
25151 +               atomic_read(&nx_global_cactive));
25152 +}
25153 +
25154 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
25155 +{
25156 +       struct nx_addr_v4 *v4a;
25157 +#ifdef CONFIG_IPV6
25158 +       struct nx_addr_v6 *v6a;
25159 +#endif
25160 +       int length, i;
25161 +
25162 +       length = sprintf(buffer,
25163 +               "ID:\t%d\n"
25164 +               "Info:\t%p\n"
25165 +               "Bcast:\t" NIPQUAD_FMT "\n"
25166 +               "Lback:\t" NIPQUAD_FMT "\n",
25167 +               nxi->nx_id,
25168 +               nxi,
25169 +               NIPQUAD(nxi->v4_bcast.s_addr),
25170 +               NIPQUAD(nxi->v4_lback.s_addr));
25171 +
25172 +       if (!NX_IPV4(nxi))
25173 +               goto skip_v4;
25174 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
25175 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
25176 +                       i, NXAV4(v4a));
25177 +skip_v4:
25178 +#ifdef CONFIG_IPV6
25179 +       if (!NX_IPV6(nxi))
25180 +               goto skip_v6;
25181 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
25182 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
25183 +                       i, NXAV6(v6a));
25184 +skip_v6:
25185 +#endif
25186 +       return length;
25187 +}
25188 +
25189 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
25190 +{
25191 +       int length;
25192 +
25193 +       length = sprintf(buffer,
25194 +               "UseCnt:\t%d\n"
25195 +               "Tasks:\t%d\n"
25196 +               "Flags:\t%016llx\n"
25197 +               "NCaps:\t%016llx\n",
25198 +               atomic_read(&nxi->nx_usecnt),
25199 +               atomic_read(&nxi->nx_tasks),
25200 +               (unsigned long long)nxi->nx_flags,
25201 +               (unsigned long long)nxi->nx_ncaps);
25202 +       return length;
25203 +}
25204 +
25205 +
25206 +
25207 +/* here the inode helpers */
25208 +
25209 +struct vs_entry {
25210 +       int len;
25211 +       char *name;
25212 +       mode_t mode;
25213 +       struct inode_operations *iop;
25214 +       struct file_operations *fop;
25215 +       union proc_op op;
25216 +};
25217 +
25218 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
25219 +{
25220 +       struct inode *inode = new_inode(sb);
25221 +
25222 +       if (!inode)
25223 +               goto out;
25224 +
25225 +       inode->i_mode = p->mode;
25226 +       if (p->iop)
25227 +               inode->i_op = p->iop;
25228 +       if (p->fop)
25229 +               inode->i_fop = p->fop;
25230 +
25231 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
25232 +       inode->i_flags |= S_IMMUTABLE;
25233 +
25234 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
25235 +
25236 +       inode->i_uid = 0;
25237 +       inode->i_gid = 0;
25238 +       inode->i_tag = 0;
25239 +out:
25240 +       return inode;
25241 +}
25242 +
25243 +static struct dentry *vs_proc_instantiate(struct inode *dir,
25244 +       struct dentry *dentry, int id, void *ptr)
25245 +{
25246 +       struct vs_entry *p = ptr;
25247 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
25248 +       struct dentry *error = ERR_PTR(-EINVAL);
25249 +
25250 +       if (!inode)
25251 +               goto out;
25252 +
25253 +       PROC_I(inode)->op = p->op;
25254 +       PROC_I(inode)->fd = id;
25255 +       d_add(dentry, inode);
25256 +       error = NULL;
25257 +out:
25258 +       return error;
25259 +}
25260 +
25261 +/* Lookups */
25262 +
25263 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
25264 +
25265 +/*
25266 + * Fill a directory entry.
25267 + *
25268 + * If possible create the dcache entry and derive our inode number and
25269 + * file type from dcache entry.
25270 + *
25271 + * Since all of the proc inode numbers are dynamically generated, the inode
25272 + * numbers do not exist until the inode is cache.  This means creating the
25273 + * the dcache entry in readdir is necessary to keep the inode numbers
25274 + * reported by readdir in sync with the inode numbers reported
25275 + * by stat.
25276 + */
25277 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
25278 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
25279 +{
25280 +       struct dentry *child, *dir = filp->f_dentry;
25281 +       struct inode *inode;
25282 +       struct qstr qname;
25283 +       ino_t ino = 0;
25284 +       unsigned type = DT_UNKNOWN;
25285 +
25286 +       qname.name = name;
25287 +       qname.len  = len;
25288 +       qname.hash = full_name_hash(name, len);
25289 +
25290 +       child = d_lookup(dir, &qname);
25291 +       if (!child) {
25292 +               struct dentry *new;
25293 +               new = d_alloc(dir, &qname);
25294 +               if (new) {
25295 +                       child = instantiate(dir->d_inode, new, id, ptr);
25296 +                       if (child)
25297 +                               dput(new);
25298 +                       else
25299 +                               child = new;
25300 +               }
25301 +       }
25302 +       if (!child || IS_ERR(child) || !child->d_inode)
25303 +               goto end_instantiate;
25304 +       inode = child->d_inode;
25305 +       if (inode) {
25306 +               ino = inode->i_ino;
25307 +               type = inode->i_mode >> 12;
25308 +       }
25309 +       dput(child);
25310 +end_instantiate:
25311 +       if (!ino)
25312 +               ino = find_inode_number(dir, &qname);
25313 +       if (!ino)
25314 +               ino = 1;
25315 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
25316 +}
25317 +
25318 +
25319 +
25320 +/* get and revalidate vx_info/xid */
25321 +
25322 +static inline
25323 +struct vx_info *get_proc_vx_info(struct inode *inode)
25324 +{
25325 +       return lookup_vx_info(PROC_I(inode)->fd);
25326 +}
25327 +
25328 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
25329 +{
25330 +       struct inode *inode = dentry->d_inode;
25331 +       xid_t xid = PROC_I(inode)->fd;
25332 +
25333 +       if (!xid || xid_is_hashed(xid))
25334 +               return 1;
25335 +       d_drop(dentry);
25336 +       return 0;
25337 +}
25338 +
25339 +
25340 +/* get and revalidate nx_info/nid */
25341 +
25342 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
25343 +{
25344 +       struct inode *inode = dentry->d_inode;
25345 +       nid_t nid = PROC_I(inode)->fd;
25346 +
25347 +       if (!nid || nid_is_hashed(nid))
25348 +               return 1;
25349 +       d_drop(dentry);
25350 +       return 0;
25351 +}
25352 +
25353 +
25354 +
25355 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
25356 +
25357 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
25358 +                         size_t count, loff_t *ppos)
25359 +{
25360 +       struct inode *inode = file->f_dentry->d_inode;
25361 +       unsigned long page;
25362 +       ssize_t length = 0;
25363 +
25364 +       if (count > PROC_BLOCK_SIZE)
25365 +               count = PROC_BLOCK_SIZE;
25366 +
25367 +       /* fade that out as soon as stable */
25368 +       WARN_ON(PROC_I(inode)->fd);
25369 +
25370 +       if (!(page = __get_free_page(GFP_KERNEL)))
25371 +               return -ENOMEM;
25372 +
25373 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
25374 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
25375 +
25376 +       if (length >= 0)
25377 +               length = simple_read_from_buffer(buf, count, ppos,
25378 +                       (char *)page, length);
25379 +
25380 +       free_page(page);
25381 +       return length;
25382 +}
25383 +
25384 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
25385 +                         size_t count, loff_t *ppos)
25386 +{
25387 +       struct inode *inode = file->f_dentry->d_inode;
25388 +       struct vx_info *vxi = NULL;
25389 +       xid_t xid = PROC_I(inode)->fd;
25390 +       unsigned long page;
25391 +       ssize_t length = 0;
25392 +
25393 +       if (count > PROC_BLOCK_SIZE)
25394 +               count = PROC_BLOCK_SIZE;
25395 +
25396 +       /* fade that out as soon as stable */
25397 +       WARN_ON(!xid);
25398 +       vxi = lookup_vx_info(xid);
25399 +       if (!vxi)
25400 +               goto out;
25401 +
25402 +       length = -ENOMEM;
25403 +       if (!(page = __get_free_page(GFP_KERNEL)))
25404 +               goto out_put;
25405 +
25406 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
25407 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
25408 +
25409 +       if (length >= 0)
25410 +               length = simple_read_from_buffer(buf, count, ppos,
25411 +                       (char *)page, length);
25412 +
25413 +       free_page(page);
25414 +out_put:
25415 +       put_vx_info(vxi);
25416 +out:
25417 +       return length;
25418 +}
25419 +
25420 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
25421 +                         size_t count, loff_t *ppos)
25422 +{
25423 +       struct inode *inode = file->f_dentry->d_inode;
25424 +       struct nx_info *nxi = NULL;
25425 +       nid_t nid = PROC_I(inode)->fd;
25426 +       unsigned long page;
25427 +       ssize_t length = 0;
25428 +
25429 +       if (count > PROC_BLOCK_SIZE)
25430 +               count = PROC_BLOCK_SIZE;
25431 +
25432 +       /* fade that out as soon as stable */
25433 +       WARN_ON(!nid);
25434 +       nxi = lookup_nx_info(nid);
25435 +       if (!nxi)
25436 +               goto out;
25437 +
25438 +       length = -ENOMEM;
25439 +       if (!(page = __get_free_page(GFP_KERNEL)))
25440 +               goto out_put;
25441 +
25442 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
25443 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
25444 +
25445 +       if (length >= 0)
25446 +               length = simple_read_from_buffer(buf, count, ppos,
25447 +                       (char *)page, length);
25448 +
25449 +       free_page(page);
25450 +out_put:
25451 +       put_nx_info(nxi);
25452 +out:
25453 +       return length;
25454 +}
25455 +
25456 +
25457 +
25458 +/* here comes the lower level */
25459 +
25460 +
25461 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
25462 +       .len  = sizeof(NAME) - 1,       \
25463 +       .name = (NAME),                 \
25464 +       .mode = MODE,                   \
25465 +       .iop  = IOP,                    \
25466 +       .fop  = FOP,                    \
25467 +       .op   = OP,                     \
25468 +}
25469 +
25470 +
25471 +#define DIR(NAME, MODE, OTYPE)                         \
25472 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
25473 +               &proc_ ## OTYPE ## _inode_operations,   \
25474 +               &proc_ ## OTYPE ## _file_operations, { } )
25475 +
25476 +#define INF(NAME, MODE, OTYPE)                         \
25477 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
25478 +               &proc_vs_info_file_operations,          \
25479 +               { .proc_vs_read = &proc_##OTYPE } )
25480 +
25481 +#define VINF(NAME, MODE, OTYPE)                                \
25482 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
25483 +               &proc_vx_info_file_operations,          \
25484 +               { .proc_vxi_read = &proc_##OTYPE } )
25485 +
25486 +#define NINF(NAME, MODE, OTYPE)                                \
25487 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
25488 +               &proc_nx_info_file_operations,          \
25489 +               { .proc_nxi_read = &proc_##OTYPE } )
25490 +
25491 +
25492 +static struct file_operations proc_vs_info_file_operations = {
25493 +       .read =         proc_vs_info_read,
25494 +};
25495 +
25496 +static struct file_operations proc_vx_info_file_operations = {
25497 +       .read =         proc_vx_info_read,
25498 +};
25499 +
25500 +static struct dentry_operations proc_xid_dentry_operations = {
25501 +       .d_revalidate = proc_xid_revalidate,
25502 +};
25503 +
25504 +static struct vs_entry vx_base_stuff[] = {
25505 +       VINF("info",    S_IRUGO, vxi_info),
25506 +       VINF("status",  S_IRUGO, vxi_status),
25507 +       VINF("limit",   S_IRUGO, vxi_limit),
25508 +       VINF("sched",   S_IRUGO, vxi_sched),
25509 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy),
25510 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
25511 +       VINF("cacct",   S_IRUGO, vxi_cacct),
25512 +       {}
25513 +};
25514 +
25515 +
25516 +
25517 +
25518 +static struct dentry *proc_xid_instantiate(struct inode *dir,
25519 +       struct dentry *dentry, int id, void *ptr)
25520 +{
25521 +       dentry->d_op = &proc_xid_dentry_operations;
25522 +       return vs_proc_instantiate(dir, dentry, id, ptr);
25523 +}
25524 +
25525 +static struct dentry *proc_xid_lookup(struct inode *dir,
25526 +       struct dentry *dentry, struct nameidata *nd)
25527 +{
25528 +       struct vs_entry *p = vx_base_stuff;
25529 +       struct dentry *error = ERR_PTR(-ENOENT);
25530 +
25531 +       for (; p->name; p++) {
25532 +               if (p->len != dentry->d_name.len)
25533 +                       continue;
25534 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
25535 +                       break;
25536 +       }
25537 +       if (!p->name)
25538 +               goto out;
25539 +
25540 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
25541 +out:
25542 +       return error;
25543 +}
25544 +
25545 +static int proc_xid_readdir(struct file *filp,
25546 +       void *dirent, filldir_t filldir)
25547 +{
25548 +       struct dentry *dentry = filp->f_dentry;
25549 +       struct inode *inode = dentry->d_inode;
25550 +       struct vs_entry *p = vx_base_stuff;
25551 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
25552 +       int pos, index;
25553 +       u64 ino;
25554 +
25555 +       pos = filp->f_pos;
25556 +       switch (pos) {
25557 +       case 0:
25558 +               ino = inode->i_ino;
25559 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
25560 +                       goto out;
25561 +               pos++;
25562 +               /* fall through */
25563 +       case 1:
25564 +               ino = parent_ino(dentry);
25565 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
25566 +                       goto out;
25567 +               pos++;
25568 +               /* fall through */
25569 +       default:
25570 +               index = pos - 2;
25571 +               if (index >= size)
25572 +                       goto out;
25573 +               for (p += index; p->name; p++) {
25574 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
25575 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
25576 +                               goto out;
25577 +                       pos++;
25578 +               }
25579 +       }
25580 +out:
25581 +       filp->f_pos = pos;
25582 +       return 1;
25583 +}
25584 +
25585 +
25586 +
25587 +static struct file_operations proc_nx_info_file_operations = {
25588 +       .read =         proc_nx_info_read,
25589 +};
25590 +
25591 +static struct dentry_operations proc_nid_dentry_operations = {
25592 +       .d_revalidate = proc_nid_revalidate,
25593 +};
25594 +
25595 +static struct vs_entry nx_base_stuff[] = {
25596 +       NINF("info",    S_IRUGO, nxi_info),
25597 +       NINF("status",  S_IRUGO, nxi_status),
25598 +       {}
25599 +};
25600 +
25601 +
25602 +static struct dentry *proc_nid_instantiate(struct inode *dir,
25603 +       struct dentry *dentry, int id, void *ptr)
25604 +{
25605 +       dentry->d_op = &proc_nid_dentry_operations;
25606 +       return vs_proc_instantiate(dir, dentry, id, ptr);
25607 +}
25608 +
25609 +static struct dentry *proc_nid_lookup(struct inode *dir,
25610 +       struct dentry *dentry, struct nameidata *nd)
25611 +{
25612 +       struct vs_entry *p = nx_base_stuff;
25613 +       struct dentry *error = ERR_PTR(-ENOENT);
25614 +
25615 +       for (; p->name; p++) {
25616 +               if (p->len != dentry->d_name.len)
25617 +                       continue;
25618 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
25619 +                       break;
25620 +       }
25621 +       if (!p->name)
25622 +               goto out;
25623 +
25624 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
25625 +out:
25626 +       return error;
25627 +}
25628 +
25629 +static int proc_nid_readdir(struct file *filp,
25630 +       void *dirent, filldir_t filldir)
25631 +{
25632 +       struct dentry *dentry = filp->f_dentry;
25633 +       struct inode *inode = dentry->d_inode;
25634 +       struct vs_entry *p = nx_base_stuff;
25635 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
25636 +       int pos, index;
25637 +       u64 ino;
25638 +
25639 +       pos = filp->f_pos;
25640 +       switch (pos) {
25641 +       case 0:
25642 +               ino = inode->i_ino;
25643 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
25644 +                       goto out;
25645 +               pos++;
25646 +               /* fall through */
25647 +       case 1:
25648 +               ino = parent_ino(dentry);
25649 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
25650 +                       goto out;
25651 +               pos++;
25652 +               /* fall through */
25653 +       default:
25654 +               index = pos - 2;
25655 +               if (index >= size)
25656 +                       goto out;
25657 +               for (p += index; p->name; p++) {
25658 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
25659 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
25660 +                               goto out;
25661 +                       pos++;
25662 +               }
25663 +       }
25664 +out:
25665 +       filp->f_pos = pos;
25666 +       return 1;
25667 +}
25668 +
25669 +
25670 +#define MAX_MULBY10    ((~0U - 9) / 10)
25671 +
25672 +static inline int atovid(const char *str, int len)
25673 +{
25674 +       int vid, c;
25675 +
25676 +       vid = 0;
25677 +       while (len-- > 0) {
25678 +               c = *str - '0';
25679 +               str++;
25680 +               if (c > 9)
25681 +                       return -1;
25682 +               if (vid >= MAX_MULBY10)
25683 +                       return -1;
25684 +               vid *= 10;
25685 +               vid += c;
25686 +               if (!vid)
25687 +                       return -1;
25688 +       }
25689 +       return vid;
25690 +}
25691 +
25692 +/* now the upper level (virtual) */
25693 +
25694 +
25695 +static struct file_operations proc_xid_file_operations = {
25696 +       .read =         generic_read_dir,
25697 +       .readdir =      proc_xid_readdir,
25698 +};
25699 +
25700 +static struct inode_operations proc_xid_inode_operations = {
25701 +       .lookup =       proc_xid_lookup,
25702 +};
25703 +
25704 +static struct vs_entry vx_virtual_stuff[] = {
25705 +       INF("info",     S_IRUGO, virtual_info),
25706 +       INF("status",   S_IRUGO, virtual_status),
25707 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
25708 +};
25709 +
25710 +
25711 +static struct dentry *proc_virtual_lookup(struct inode *dir,
25712 +       struct dentry *dentry, struct nameidata *nd)
25713 +{
25714 +       struct vs_entry *p = vx_virtual_stuff;
25715 +       struct dentry *error = ERR_PTR(-ENOENT);
25716 +       int id = 0;
25717 +
25718 +       for (; p->name; p++) {
25719 +               if (p->len != dentry->d_name.len)
25720 +                       continue;
25721 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
25722 +                       break;
25723 +       }
25724 +       if (p->name)
25725 +               goto instantiate;
25726 +
25727 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
25728 +       if ((id < 0) || !xid_is_hashed(id))
25729 +               goto out;
25730 +
25731 +instantiate:
25732 +       error = proc_xid_instantiate(dir, dentry, id, p);
25733 +out:
25734 +       return error;
25735 +}
25736 +
25737 +static struct file_operations proc_nid_file_operations = {
25738 +       .read =         generic_read_dir,
25739 +       .readdir =      proc_nid_readdir,
25740 +};
25741 +
25742 +static struct inode_operations proc_nid_inode_operations = {
25743 +       .lookup =       proc_nid_lookup,
25744 +};
25745 +
25746 +static struct vs_entry nx_virtnet_stuff[] = {
25747 +       INF("info",     S_IRUGO, virtnet_info),
25748 +       INF("status",   S_IRUGO, virtnet_status),
25749 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
25750 +};
25751 +
25752 +
25753 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
25754 +       struct dentry *dentry, struct nameidata *nd)
25755 +{
25756 +       struct vs_entry *p = nx_virtnet_stuff;
25757 +       struct dentry *error = ERR_PTR(-ENOENT);
25758 +       int id = 0;
25759 +
25760 +       for (; p->name; p++) {
25761 +               if (p->len != dentry->d_name.len)
25762 +                       continue;
25763 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
25764 +                       break;
25765 +       }
25766 +       if (p->name)
25767 +               goto instantiate;
25768 +
25769 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
25770 +       if ((id < 0) || !nid_is_hashed(id))
25771 +               goto out;
25772 +
25773 +instantiate:
25774 +       error = proc_nid_instantiate(dir, dentry, id, p);
25775 +out:
25776 +       return error;
25777 +}
25778 +
25779 +
25780 +
25781 +#define PROC_NUMBUF 10
25782 +#define PROC_MAXVIDS 32
25783 +
25784 +int proc_virtual_readdir(struct file *filp,
25785 +       void *dirent, filldir_t filldir)
25786 +{
25787 +       struct dentry *dentry = filp->f_dentry;
25788 +       struct inode *inode = dentry->d_inode;
25789 +       struct vs_entry *p = vx_virtual_stuff;
25790 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
25791 +       int pos, index;
25792 +       unsigned int xid_array[PROC_MAXVIDS];
25793 +       char buf[PROC_NUMBUF];
25794 +       unsigned int nr_xids, i;
25795 +       u64 ino;
25796 +
25797 +       pos = filp->f_pos;
25798 +       switch (pos) {
25799 +       case 0:
25800 +               ino = inode->i_ino;
25801 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
25802 +                       goto out;
25803 +               pos++;
25804 +               /* fall through */
25805 +       case 1:
25806 +               ino = parent_ino(dentry);
25807 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
25808 +                       goto out;
25809 +               pos++;
25810 +               /* fall through */
25811 +       default:
25812 +               index = pos - 2;
25813 +               if (index >= size)
25814 +                       goto entries;
25815 +               for (p += index; p->name; p++) {
25816 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
25817 +                               vs_proc_instantiate, 0, p))
25818 +                               goto out;
25819 +                       pos++;
25820 +               }
25821 +       entries:
25822 +               index = pos - size;
25823 +               p = &vx_virtual_stuff[size - 1];
25824 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
25825 +               for (i = 0; i < nr_xids; i++) {
25826 +                       int n, xid = xid_array[i];
25827 +                       unsigned int j = PROC_NUMBUF;
25828 +
25829 +                       n = xid;
25830 +                       do
25831 +                               buf[--j] = '0' + (n % 10);
25832 +                       while (n /= 10);
25833 +
25834 +                       if (proc_fill_cache(filp, dirent, filldir,
25835 +                               buf + j, PROC_NUMBUF - j,
25836 +                               vs_proc_instantiate, xid, p))
25837 +                               goto out;
25838 +                       pos++;
25839 +               }
25840 +       }
25841 +out:
25842 +       filp->f_pos = pos;
25843 +       return 0;
25844 +}
25845 +
25846 +static int proc_virtual_getattr(struct vfsmount *mnt,
25847 +       struct dentry *dentry, struct kstat *stat)
25848 +{
25849 +       struct inode *inode = dentry->d_inode;
25850 +
25851 +       generic_fillattr(inode, stat);
25852 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
25853 +       return 0;
25854 +}
25855 +
25856 +static struct file_operations proc_virtual_dir_operations = {
25857 +       .read =         generic_read_dir,
25858 +       .readdir =      proc_virtual_readdir,
25859 +};
25860 +
25861 +static struct inode_operations proc_virtual_dir_inode_operations = {
25862 +       .getattr =      proc_virtual_getattr,
25863 +       .lookup =       proc_virtual_lookup,
25864 +};
25865 +
25866 +
25867 +
25868 +
25869 +
25870 +int proc_virtnet_readdir(struct file *filp,
25871 +       void *dirent, filldir_t filldir)
25872 +{
25873 +       struct dentry *dentry = filp->f_dentry;
25874 +       struct inode *inode = dentry->d_inode;
25875 +       struct vs_entry *p = nx_virtnet_stuff;
25876 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
25877 +       int pos, index;
25878 +       unsigned int nid_array[PROC_MAXVIDS];
25879 +       char buf[PROC_NUMBUF];
25880 +       unsigned int nr_nids, i;
25881 +       u64 ino;
25882 +
25883 +       pos = filp->f_pos;
25884 +       switch (pos) {
25885 +       case 0:
25886 +               ino = inode->i_ino;
25887 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
25888 +                       goto out;
25889 +               pos++;
25890 +               /* fall through */
25891 +       case 1:
25892 +               ino = parent_ino(dentry);
25893 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
25894 +                       goto out;
25895 +               pos++;
25896 +               /* fall through */
25897 +       default:
25898 +               index = pos - 2;
25899 +               if (index >= size)
25900 +                       goto entries;
25901 +               for (p += index; p->name; p++) {
25902 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
25903 +                               vs_proc_instantiate, 0, p))
25904 +                               goto out;
25905 +                       pos++;
25906 +               }
25907 +       entries:
25908 +               index = pos - size;
25909 +               p = &nx_virtnet_stuff[size - 1];
25910 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
25911 +               for (i = 0; i < nr_nids; i++) {
25912 +                       int n, nid = nid_array[i];
25913 +                       unsigned int j = PROC_NUMBUF;
25914 +
25915 +                       n = nid;
25916 +                       do
25917 +                               buf[--j] = '0' + (n % 10);
25918 +                       while (n /= 10);
25919 +
25920 +                       if (proc_fill_cache(filp, dirent, filldir,
25921 +                               buf + j, PROC_NUMBUF - j,
25922 +                               vs_proc_instantiate, nid, p))
25923 +                               goto out;
25924 +                       pos++;
25925 +               }
25926 +       }
25927 +out:
25928 +       filp->f_pos = pos;
25929 +       return 0;
25930 +}
25931 +
25932 +static int proc_virtnet_getattr(struct vfsmount *mnt,
25933 +       struct dentry *dentry, struct kstat *stat)
25934 +{
25935 +       struct inode *inode = dentry->d_inode;
25936 +
25937 +       generic_fillattr(inode, stat);
25938 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
25939 +       return 0;
25940 +}
25941 +
25942 +static struct file_operations proc_virtnet_dir_operations = {
25943 +       .read =         generic_read_dir,
25944 +       .readdir =      proc_virtnet_readdir,
25945 +};
25946 +
25947 +static struct inode_operations proc_virtnet_dir_inode_operations = {
25948 +       .getattr =      proc_virtnet_getattr,
25949 +       .lookup =       proc_virtnet_lookup,
25950 +};
25951 +
25952 +
25953 +
25954 +void proc_vx_init(void)
25955 +{
25956 +       struct proc_dir_entry *ent;
25957 +
25958 +       ent = proc_mkdir("virtual", 0);
25959 +       if (ent) {
25960 +               ent->proc_fops = &proc_virtual_dir_operations;
25961 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
25962 +       }
25963 +       proc_virtual = ent;
25964 +
25965 +       ent = proc_mkdir("virtnet", 0);
25966 +       if (ent) {
25967 +               ent->proc_fops = &proc_virtnet_dir_operations;
25968 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
25969 +       }
25970 +       proc_virtnet = ent;
25971 +}
25972 +
25973 +
25974 +
25975 +
25976 +/* per pid info */
25977 +
25978 +
25979 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
25980 +{
25981 +       struct vx_info *vxi;
25982 +       char *orig = buffer;
25983 +
25984 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
25985 +
25986 +       vxi = task_get_vx_info(p);
25987 +       if (!vxi)
25988 +               goto out;
25989 +
25990 +       buffer += sprintf(buffer, "BCaps:\t%016llx\n",
25991 +               (unsigned long long)vxi->vx_bcaps);
25992 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
25993 +               (unsigned long long)vxi->vx_ccaps);
25994 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
25995 +               (unsigned long long)vxi->vx_flags);
25996 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
25997 +
25998 +       put_vx_info(vxi);
25999 +out:
26000 +       return buffer - orig;
26001 +}
26002 +
26003 +
26004 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
26005 +{
26006 +       struct nx_info *nxi;
26007 +       struct nx_addr_v4 *v4a;
26008 +#ifdef CONFIG_IPV6
26009 +       struct nx_addr_v6 *v6a;
26010 +#endif
26011 +       char *orig = buffer;
26012 +       int i;
26013 +
26014 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
26015 +
26016 +       nxi = task_get_nx_info(p);
26017 +       if (!nxi)
26018 +               goto out;
26019 +
26020 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
26021 +               (unsigned long long)nxi->nx_ncaps);
26022 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
26023 +               (unsigned long long)nxi->nx_flags);
26024 +
26025 +       buffer += sprintf(buffer,
26026 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
26027 +               NIPQUAD(nxi->v4_bcast.s_addr));
26028 +       buffer += sprintf (buffer,
26029 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
26030 +               NIPQUAD(nxi->v4_lback.s_addr));
26031 +       if (!NX_IPV4(nxi))
26032 +               goto skip_v4;
26033 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
26034 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
26035 +                       i, NXAV4(v4a));
26036 +skip_v4:
26037 +#ifdef CONFIG_IPV6
26038 +       if (!NX_IPV6(nxi))
26039 +               goto skip_v6;
26040 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
26041 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
26042 +                       i, NXAV6(v6a));
26043 +skip_v6:
26044 +#endif
26045 +       put_nx_info(nxi);
26046 +out:
26047 +       return buffer - orig;
26048 +}
26049 +
26050 diff -Nurp linux-2.6.22.15/kernel/vserver/sched.c linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/sched.c
26051 --- linux-2.6.22.15/kernel/vserver/sched.c      1969-12-31 19:00:00.000000000 -0500
26052 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/sched.c 2007-12-09 06:44:23.000000000 -0500
26053 @@ -0,0 +1,413 @@
26054 +/*
26055 + *  linux/kernel/vserver/sched.c
26056 + *
26057 + *  Virtual Server: Scheduler Support
26058 + *
26059 + *  Copyright (C) 2004-2007  Herbert Pötzl
26060 + *
26061 + *  V0.01  adapted Sam Vilains version to 2.6.3
26062 + *  V0.02  removed legacy interface
26063 + *  V0.03  changed vcmds to vxi arg
26064 + *  V0.04  removed older and legacy interfaces
26065 + *
26066 + */
26067 +
26068 +#include <linux/vs_context.h>
26069 +#include <linux/vs_sched.h>
26070 +#include <linux/vserver/sched_cmd.h>
26071 +
26072 +#include <asm/uaccess.h>
26073 +
26074 +
26075 +#define vxd_check_range(val, min, max) do {            \
26076 +       vxlprintk((val < min) || (val > max),           \
26077 +               "check_range(%ld,%ld,%ld)",             \
26078 +               (long)val, (long)min, (long)max,        \
26079 +               __FILE__, __LINE__);                    \
26080 +       } while (0)
26081 +
26082 +
26083 +void vx_update_sched_param(struct _vx_sched *sched,
26084 +       struct _vx_sched_pc *sched_pc)
26085 +{
26086 +       unsigned int set_mask = sched->update_mask;
26087 +
26088 +       if (set_mask & VXSM_FILL_RATE)
26089 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
26090 +       if (set_mask & VXSM_INTERVAL)
26091 +               sched_pc->interval[0] = sched->interval[0];
26092 +       if (set_mask & VXSM_FILL_RATE2)
26093 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
26094 +       if (set_mask & VXSM_INTERVAL2)
26095 +               sched_pc->interval[1] = sched->interval[1];
26096 +       if (set_mask & VXSM_TOKENS)
26097 +               sched_pc->tokens = sched->tokens;
26098 +       if (set_mask & VXSM_TOKENS_MIN)
26099 +               sched_pc->tokens_min = sched->tokens_min;
26100 +       if (set_mask & VXSM_TOKENS_MAX)
26101 +               sched_pc->tokens_max = sched->tokens_max;
26102 +       if (set_mask & VXSM_PRIO_BIAS)
26103 +               sched_pc->prio_bias = sched->prio_bias;
26104 +
26105 +       if (set_mask & VXSM_IDLE_TIME)
26106 +               sched_pc->flags |= VXSF_IDLE_TIME;
26107 +       else
26108 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
26109 +
26110 +       /* reset time */
26111 +       sched_pc->norm_time = jiffies;
26112 +}
26113 +
26114 +
26115 +/*
26116 + * recalculate the context's scheduling tokens
26117 + *
26118 + * ret > 0 : number of tokens available
26119 + * ret < 0 : on hold, check delta_min[]
26120 + *          -1 only jiffies
26121 + *          -2 also idle time
26122 + *
26123 + */
26124 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
26125 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
26126 +{
26127 +       long delta;
26128 +       long tokens = 0;
26129 +       int flags = sched_pc->flags;
26130 +
26131 +       /* how much time did pass? */
26132 +       delta = *norm_time - sched_pc->norm_time;
26133 +       vxd_check_range(delta, 0, INT_MAX);
26134 +
26135 +       if (delta >= sched_pc->interval[0]) {
26136 +               long tokens, integral;
26137 +
26138 +               /* calc integral token part */
26139 +               tokens = delta / sched_pc->interval[0];
26140 +               integral = tokens * sched_pc->interval[0];
26141 +               tokens *= sched_pc->fill_rate[0];
26142 +#ifdef CONFIG_VSERVER_HARDCPU
26143 +               delta_min[0] = delta - integral;
26144 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
26145 +#endif
26146 +               /* advance time */
26147 +               sched_pc->norm_time += delta;
26148 +
26149 +               /* add tokens */
26150 +               sched_pc->tokens += tokens;
26151 +               sched_pc->token_time += tokens;
26152 +       } else
26153 +               delta_min[0] = delta;
26154 +
26155 +#ifdef CONFIG_VSERVER_IDLETIME
26156 +       if (!(flags & VXSF_IDLE_TIME))
26157 +               goto skip_idle;
26158 +
26159 +       /* how much was the idle skip? */
26160 +       delta = *idle_time - sched_pc->idle_time;
26161 +       vxd_check_range(delta, 0, INT_MAX);
26162 +
26163 +       if (delta >= sched_pc->interval[1]) {
26164 +               long tokens, integral;
26165 +
26166 +               /* calc fair share token part */
26167 +               tokens = delta / sched_pc->interval[1];
26168 +               integral = tokens * sched_pc->interval[1];
26169 +               tokens *= sched_pc->fill_rate[1];
26170 +               delta_min[1] = delta - integral;
26171 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
26172 +
26173 +               /* advance idle time */
26174 +               sched_pc->idle_time += integral;
26175 +
26176 +               /* add tokens */
26177 +               sched_pc->tokens += tokens;
26178 +               sched_pc->token_time += tokens;
26179 +       } else
26180 +               delta_min[1] = delta;
26181 +skip_idle:
26182 +#endif
26183 +
26184 +       /* clip at maximum */
26185 +       if (sched_pc->tokens > sched_pc->tokens_max)
26186 +               sched_pc->tokens = sched_pc->tokens_max;
26187 +       tokens = sched_pc->tokens;
26188 +
26189 +       if ((flags & VXSF_ONHOLD)) {
26190 +               /* can we unhold? */
26191 +               if (tokens >= sched_pc->tokens_min) {
26192 +                       flags &= ~VXSF_ONHOLD;
26193 +                       sched_pc->hold_ticks +=
26194 +                               *norm_time - sched_pc->onhold;
26195 +               } else
26196 +                       goto on_hold;
26197 +       } else {
26198 +               /* put on hold? */
26199 +               if (tokens <= 0) {
26200 +                       flags |= VXSF_ONHOLD;
26201 +                       sched_pc->onhold = *norm_time;
26202 +                       goto on_hold;
26203 +               }
26204 +       }
26205 +       sched_pc->flags = flags;
26206 +       return tokens;
26207 +
26208 +on_hold:
26209 +       tokens = sched_pc->tokens_min - tokens;
26210 +       sched_pc->flags = flags;
26211 +       BUG_ON(tokens < 0);
26212 +
26213 +#ifdef CONFIG_VSERVER_HARDCPU
26214 +       /* next interval? */
26215 +       if (!sched_pc->fill_rate[0])
26216 +               delta_min[0] = HZ;
26217 +       else if (tokens > sched_pc->fill_rate[0])
26218 +               delta_min[0] += sched_pc->interval[0] *
26219 +                       tokens / sched_pc->fill_rate[0];
26220 +       else
26221 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
26222 +       vxd_check_range(delta_min[0], 0, INT_MAX);
26223 +
26224 +#ifdef CONFIG_VSERVER_IDLETIME
26225 +       if (!(flags & VXSF_IDLE_TIME))
26226 +               return -1;
26227 +
26228 +       /* next interval? */
26229 +       if (!sched_pc->fill_rate[1])
26230 +               delta_min[1] = HZ;
26231 +       else if (tokens > sched_pc->fill_rate[1])
26232 +               delta_min[1] += sched_pc->interval[1] *
26233 +                       tokens / sched_pc->fill_rate[1];
26234 +       else
26235 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
26236 +       vxd_check_range(delta_min[1], 0, INT_MAX);
26237 +
26238 +       return -2;
26239 +#else
26240 +       return -1;
26241 +#endif /* CONFIG_VSERVER_IDLETIME */
26242 +#else
26243 +       return 0;
26244 +#endif /* CONFIG_VSERVER_HARDCPU */
26245 +}
26246 +
26247 +static inline unsigned long msec_to_ticks(unsigned long msec)
26248 +{
26249 +       return msecs_to_jiffies(msec);
26250 +}
26251 +
26252 +static inline unsigned long ticks_to_msec(unsigned long ticks)
26253 +{
26254 +       return jiffies_to_msecs(ticks);
26255 +}
26256 +
26257 +static inline unsigned long ticks_to_usec(unsigned long ticks)
26258 +{
26259 +       return jiffies_to_usecs(ticks);
26260 +}
26261 +
26262 +
26263 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
26264 +{
26265 +       unsigned int set_mask = data->mask;
26266 +       unsigned int update_mask;
26267 +       int i, cpu;
26268 +
26269 +       /* Sanity check data values */
26270 +       if (data->tokens_max <= 0)
26271 +               data->tokens_max = HZ;
26272 +       if (data->tokens_min < 0)
26273 +               data->tokens_min = HZ / 3;
26274 +       if (data->tokens_min >= data->tokens_max)
26275 +               data->tokens_min = data->tokens_max;
26276 +
26277 +       if (data->prio_bias > MAX_PRIO_BIAS)
26278 +               data->prio_bias = MAX_PRIO_BIAS;
26279 +       if (data->prio_bias < MIN_PRIO_BIAS)
26280 +               data->prio_bias = MIN_PRIO_BIAS;
26281 +
26282 +       spin_lock(&vxi->sched.tokens_lock);
26283 +
26284 +       /* sync up on delayed updates */
26285 +       for_each_cpu_mask(cpu, vxi->sched.update)
26286 +               vx_update_sched_param(&vxi->sched,
26287 +                       &vx_per_cpu(vxi, sched_pc, cpu));
26288 +
26289 +       if (set_mask & VXSM_FILL_RATE)
26290 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
26291 +       if (set_mask & VXSM_FILL_RATE2)
26292 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
26293 +       if (set_mask & VXSM_INTERVAL)
26294 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
26295 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
26296 +       if (set_mask & VXSM_INTERVAL2)
26297 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
26298 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
26299 +       if (set_mask & VXSM_TOKENS)
26300 +               vxi->sched.tokens = data->tokens;
26301 +       if (set_mask & VXSM_TOKENS_MIN)
26302 +               vxi->sched.tokens_min = data->tokens_min;
26303 +       if (set_mask & VXSM_TOKENS_MAX)
26304 +               vxi->sched.tokens_max = data->tokens_max;
26305 +       if (set_mask & VXSM_PRIO_BIAS)
26306 +               vxi->sched.prio_bias = data->prio_bias;
26307 +
26308 +       /* Sanity check rate/interval */
26309 +       for (i = 0; i < 2; i++) {
26310 +               if (data->fill_rate[i] < 0)
26311 +                       data->fill_rate[i] = 0;
26312 +               if (data->interval[i] <= 0)
26313 +                       data->interval[i] = HZ;
26314 +       }
26315 +
26316 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
26317 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
26318 +       vxi->sched.update_mask = update_mask;
26319 +
26320 +#ifdef CONFIG_SMP
26321 +       rmb();
26322 +       if (set_mask & VXSM_CPU_ID) {
26323 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
26324 +               cpus_and(vxi->sched.update, cpu_online_map,
26325 +                       vxi->sched.update);
26326 +       } else
26327 +               vxi->sched.update = cpu_online_map;
26328 +
26329 +       /* forced reload? */
26330 +       if (set_mask & VXSM_FORCE) {
26331 +               for_each_cpu_mask(cpu, vxi->sched.update)
26332 +                       vx_update_sched_param(&vxi->sched,
26333 +                               &vx_per_cpu(vxi, sched_pc, cpu));
26334 +               vxi->sched.update = CPU_MASK_NONE;
26335 +       }
26336 +#else
26337 +       /* on UP we update immediately */
26338 +       vx_update_sched_param(&vxi->sched,
26339 +               &vx_per_cpu(vxi, sched_pc, 0));
26340 +#endif
26341 +
26342 +       spin_unlock(&vxi->sched.tokens_lock);
26343 +       return 0;
26344 +}
26345 +
26346 +
26347 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
26348 +#define COPY_PRI(C) C(prio_bias)
26349 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
26350 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
26351 +                   C(fill_rate[1]); C(interval[1]);
26352 +
26353 +#define COPY_VALUE(name) vc_data.name = data->name
26354 +
26355 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
26356 +{
26357 +       struct vcmd_sched_v5 vc_data;
26358 +
26359 +       vc_data.mask = data->set_mask;
26360 +       COPY_IDS(COPY_VALUE);
26361 +       COPY_PRI(COPY_VALUE);
26362 +       COPY_TOK(COPY_VALUE);
26363 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
26364 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
26365 +       return do_set_sched(vxi, &vc_data);
26366 +}
26367 +
26368 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
26369 +{
26370 +       struct vcmd_set_sched_v4 vc_data;
26371 +
26372 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
26373 +               return -EFAULT;
26374 +
26375 +       return do_set_sched_v4(vxi, &vc_data);
26376 +}
26377 +
26378 +       /* latest interface is v5 */
26379 +
26380 +int vc_set_sched(struct vx_info *vxi, void __user *data)
26381 +{
26382 +       struct vcmd_sched_v5 vc_data;
26383 +
26384 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
26385 +               return -EFAULT;
26386 +
26387 +       return do_set_sched(vxi, &vc_data);
26388 +}
26389 +
26390 +
26391 +#define COPY_PRI(C) C(prio_bias)
26392 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
26393 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);    \
26394 +                   C(fill_rate[1]); C(interval[1]);
26395 +
26396 +#define COPY_VALUE(name) vc_data.name = data->name
26397 +
26398 +
26399 +int vc_get_sched(struct vx_info *vxi, void __user *data)
26400 +{
26401 +       struct vcmd_sched_v5 vc_data;
26402 +
26403 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
26404 +               return -EFAULT;
26405 +
26406 +       if (vc_data.mask & VXSM_CPU_ID) {
26407 +               int cpu = vc_data.cpu_id;
26408 +               struct _vx_sched_pc *data;
26409 +
26410 +               if (!cpu_possible(cpu))
26411 +                       return -EINVAL;
26412 +
26413 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
26414 +               COPY_TOK(COPY_VALUE);
26415 +               COPY_PRI(COPY_VALUE);
26416 +               COPY_FRI(COPY_VALUE);
26417 +
26418 +               if (data->flags & VXSF_IDLE_TIME)
26419 +                       vc_data.mask |= VXSM_IDLE_TIME;
26420 +       } else {
26421 +               struct _vx_sched *data = &vxi->sched;
26422 +
26423 +               COPY_TOK(COPY_VALUE);
26424 +               COPY_PRI(COPY_VALUE);
26425 +               COPY_FRI(COPY_VALUE);
26426 +       }
26427 +
26428 +       if (vc_data.mask & VXSM_MSEC) {
26429 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
26430 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
26431 +       }
26432 +
26433 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
26434 +               return -EFAULT;
26435 +       return 0;
26436 +}
26437 +
26438 +
26439 +int vc_sched_info(struct vx_info *vxi, void __user *data)
26440 +{
26441 +       struct vcmd_sched_info vc_data;
26442 +       int cpu;
26443 +
26444 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
26445 +               return -EFAULT;
26446 +
26447 +       cpu = vc_data.cpu_id;
26448 +       if (!cpu_possible(cpu))
26449 +               return -EINVAL;
26450 +
26451 +       if (vxi) {
26452 +               struct _vx_sched_pc *sched_pc =
26453 +                       &vx_per_cpu(vxi, sched_pc, cpu);
26454 +
26455 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
26456 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
26457 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
26458 +               vc_data.vavavoom = sched_pc->vavavoom;
26459 +       }
26460 +       vc_data.token_usec = ticks_to_usec(1);
26461 +
26462 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
26463 +               return -EFAULT;
26464 +       return 0;
26465 +}
26466 +
26467 diff -Nurp linux-2.6.22.15/kernel/vserver/sched_init.h linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/sched_init.h
26468 --- linux-2.6.22.15/kernel/vserver/sched_init.h 1969-12-31 19:00:00.000000000 -0500
26469 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/sched_init.h    2007-12-09 06:44:23.000000000 -0500
26470 @@ -0,0 +1,50 @@
26471 +
26472 +static inline void vx_info_init_sched(struct _vx_sched *sched)
26473 +{
26474 +       static struct lock_class_key tokens_lock_key;
26475 +
26476 +       /* scheduling; hard code starting values as constants */
26477 +       sched->fill_rate[0]     = 1;
26478 +       sched->interval[0]      = 4;
26479 +       sched->fill_rate[1]     = 1;
26480 +       sched->interval[1]      = 8;
26481 +       sched->tokens           = HZ >> 2;
26482 +       sched->tokens_min       = HZ >> 4;
26483 +       sched->tokens_max       = HZ >> 1;
26484 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
26485 +       sched->prio_bias        = 0;
26486 +
26487 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
26488 +}
26489 +
26490 +static inline
26491 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
26492 +{
26493 +       sched_pc->fill_rate[0]  = 1;
26494 +       sched_pc->interval[0]   = 4;
26495 +       sched_pc->fill_rate[1]  = 1;
26496 +       sched_pc->interval[1]   = 8;
26497 +       sched_pc->tokens        = HZ >> 2;
26498 +       sched_pc->tokens_min    = HZ >> 4;
26499 +       sched_pc->tokens_max    = HZ >> 1;
26500 +       sched_pc->prio_bias     = 0;
26501 +       sched_pc->vavavoom      = 0;
26502 +       sched_pc->token_time    = 0;
26503 +       sched_pc->idle_time     = 0;
26504 +       sched_pc->norm_time     = jiffies;
26505 +
26506 +       sched_pc->user_ticks = 0;
26507 +       sched_pc->sys_ticks = 0;
26508 +       sched_pc->hold_ticks = 0;
26509 +}
26510 +
26511 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
26512 +{
26513 +       return;
26514 +}
26515 +
26516 +static inline
26517 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
26518 +{
26519 +       return;
26520 +}
26521 diff -Nurp linux-2.6.22.15/kernel/vserver/sched_proc.h linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/sched_proc.h
26522 --- linux-2.6.22.15/kernel/vserver/sched_proc.h 1969-12-31 19:00:00.000000000 -0500
26523 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/sched_proc.h    2007-12-09 06:44:23.000000000 -0500
26524 @@ -0,0 +1,57 @@
26525 +#ifndef _VX_SCHED_PROC_H
26526 +#define _VX_SCHED_PROC_H
26527 +
26528 +
26529 +static inline
26530 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
26531 +{
26532 +       int length = 0;
26533 +
26534 +       length += sprintf(buffer,
26535 +               "FillRate:\t%8d,%d\n"
26536 +               "Interval:\t%8d,%d\n"
26537 +               "TokensMin:\t%8d\n"
26538 +               "TokensMax:\t%8d\n"
26539 +               "PrioBias:\t%8d\n",
26540 +               sched->fill_rate[0],
26541 +               sched->fill_rate[1],
26542 +               sched->interval[0],
26543 +               sched->interval[1],
26544 +               sched->tokens_min,
26545 +               sched->tokens_max,
26546 +               sched->prio_bias);
26547 +       return length;
26548 +}
26549 +
26550 +static inline
26551 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
26552 +       char *buffer, int cpu)
26553 +{
26554 +       int length = 0;
26555 +
26556 +       length += sprintf(buffer + length,
26557 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
26558 +               (unsigned long long)sched_pc->user_ticks,
26559 +               (unsigned long long)sched_pc->sys_ticks,
26560 +               (unsigned long long)sched_pc->hold_ticks,
26561 +               sched_pc->token_time,
26562 +               sched_pc->idle_time);
26563 +       length += sprintf(buffer + length,
26564 +               " %c%c %d %d %d %d/%d %d/%d",
26565 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
26566 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
26567 +               sched_pc->tokens,
26568 +               sched_pc->tokens_min,
26569 +               sched_pc->tokens_max,
26570 +               sched_pc->fill_rate[0],
26571 +               sched_pc->interval[0],
26572 +               sched_pc->fill_rate[1],
26573 +               sched_pc->interval[1]);
26574 +       length += sprintf(buffer + length,
26575 +               " %d %d\n",
26576 +               sched_pc->prio_bias,
26577 +               sched_pc->vavavoom);
26578 +       return length;
26579 +}
26580 +
26581 +#endif /* _VX_SCHED_PROC_H */
26582 diff -Nurp linux-2.6.22.15/kernel/vserver/signal.c linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/signal.c
26583 --- linux-2.6.22.15/kernel/vserver/signal.c     1969-12-31 19:00:00.000000000 -0500
26584 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/signal.c        2007-12-09 06:44:23.000000000 -0500
26585 @@ -0,0 +1,131 @@
26586 +/*
26587 + *  linux/kernel/vserver/signal.c
26588 + *
26589 + *  Virtual Server: Signal Support
26590 + *
26591 + *  Copyright (C) 2003-2007  Herbert Pötzl
26592 + *
26593 + *  V0.01  broken out from vcontext V0.05
26594 + *  V0.02  changed vcmds to vxi arg
26595 + *  V0.03  adjusted siginfo for kill
26596 + *
26597 + */
26598 +
26599 +#include <asm/uaccess.h>
26600 +
26601 +#include <linux/vs_context.h>
26602 +#include <linux/vserver/signal_cmd.h>
26603 +
26604 +
26605 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
26606 +{
26607 +       int retval, count = 0;
26608 +       struct task_struct *p;
26609 +       struct siginfo *sip = SEND_SIG_PRIV;
26610 +
26611 +       retval = -ESRCH;
26612 +       vxdprintk(VXD_CBIT(misc, 4),
26613 +               "vx_info_kill(%p[#%d],%d,%d)*",
26614 +               vxi, vxi->vx_id, pid, sig);
26615 +       read_lock(&tasklist_lock);
26616 +       switch (pid) {
26617 +       case  0:
26618 +       case -1:
26619 +               for_each_process(p) {
26620 +                       int err = 0;
26621 +
26622 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
26623 +                               (pid && vxi->vx_initpid == p->pid))
26624 +                               continue;
26625 +
26626 +                       err = group_send_sig_info(sig, sip, p);
26627 +                       ++count;
26628 +                       if (err != -EPERM)
26629 +                               retval = err;
26630 +               }
26631 +               break;
26632 +
26633 +       case 1:
26634 +               if (vxi->vx_initpid) {
26635 +                       pid = vxi->vx_initpid;
26636 +                       /* for now, only SIGINT to private init ... */
26637 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
26638 +                               /* ... as long as there are tasks left */
26639 +                               (atomic_read(&vxi->vx_tasks) > 1))
26640 +                               sig = SIGINT;
26641 +               }
26642 +               /* fallthrough */
26643 +       default:
26644 +               p = find_task_by_real_pid(pid);
26645 +               if (p) {
26646 +                       if (vx_task_xid(p) == vxi->vx_id)
26647 +                               retval = group_send_sig_info(sig, sip, p);
26648 +               }
26649 +               break;
26650 +       }
26651 +       read_unlock(&tasklist_lock);
26652 +       vxdprintk(VXD_CBIT(misc, 4),
26653 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
26654 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
26655 +       return retval;
26656 +}
26657 +
26658 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
26659 +{
26660 +       struct vcmd_ctx_kill_v0 vc_data;
26661 +
26662 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
26663 +               return -EFAULT;
26664 +
26665 +       /* special check to allow guest shutdown */
26666 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
26667 +               /* forbid killall pid=0 when init is present */
26668 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
26669 +               (vc_data.pid > 1)))
26670 +               return -EACCES;
26671 +
26672 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
26673 +}
26674 +
26675 +
26676 +static int __wait_exit(struct vx_info *vxi)
26677 +{
26678 +       DECLARE_WAITQUEUE(wait, current);
26679 +       int ret = 0;
26680 +
26681 +       add_wait_queue(&vxi->vx_wait, &wait);
26682 +       set_current_state(TASK_INTERRUPTIBLE);
26683 +
26684 +wait:
26685 +       if (vx_info_state(vxi,
26686 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
26687 +               goto out;
26688 +       if (signal_pending(current)) {
26689 +               ret = -ERESTARTSYS;
26690 +               goto out;
26691 +       }
26692 +       schedule();
26693 +       goto wait;
26694 +
26695 +out:
26696 +       set_current_state(TASK_RUNNING);
26697 +       remove_wait_queue(&vxi->vx_wait, &wait);
26698 +       return ret;
26699 +}
26700 +
26701 +
26702 +
26703 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
26704 +{
26705 +       struct vcmd_wait_exit_v0 vc_data;
26706 +       int ret;
26707 +
26708 +       ret = __wait_exit(vxi);
26709 +       vc_data.reboot_cmd = vxi->reboot_cmd;
26710 +       vc_data.exit_code = vxi->exit_code;
26711 +
26712 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
26713 +               ret = -EFAULT;
26714 +       return ret;
26715 +}
26716 +
26717 diff -Nurp linux-2.6.22.15/kernel/vserver/space.c linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/space.c
26718 --- linux-2.6.22.15/kernel/vserver/space.c      1969-12-31 19:00:00.000000000 -0500
26719 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/space.c 2007-12-09 06:44:23.000000000 -0500
26720 @@ -0,0 +1,277 @@
26721 +/*
26722 + *  linux/kernel/vserver/space.c
26723 + *
26724 + *  Virtual Server: Context Space Support
26725 + *
26726 + *  Copyright (C) 2003-2007  Herbert Pötzl
26727 + *
26728 + *  V0.01  broken out from context.c 0.07
26729 + *  V0.02  added task locking for namespace
26730 + *  V0.03  broken out vx_enter_namespace
26731 + *  V0.04  added *space support and commands
26732 + *
26733 + */
26734 +
26735 +#include <linux/utsname.h>
26736 +#include <linux/nsproxy.h>
26737 +#include <linux/err.h>
26738 +#include <asm/uaccess.h>
26739 +
26740 +#include <linux/vs_context.h>
26741 +#include <linux/vserver/space.h>
26742 +#include <linux/vserver/space_cmd.h>
26743 +
26744 +
26745 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
26746 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
26747 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
26748 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
26749 +atomic_t vs_global_ipc_ns      = ATOMIC_INIT(0);
26750 +
26751 +
26752 +/* namespace functions */
26753 +
26754 +#include <linux/mnt_namespace.h>
26755 +
26756 +const struct vcmd_space_mask space_mask = {
26757 +       .mask = CLONE_NEWNS |
26758 +               CLONE_NEWUTS |
26759 +               CLONE_NEWIPC |
26760 +               CLONE_FS
26761 +};
26762 +
26763 +
26764 +/*
26765 + *     build a new nsproxy mix
26766 + *      assumes that both proxies are 'const'
26767 + *     does not touch nsproxy refcounts
26768 + *     will hold a reference on the result.
26769 + */
26770 +
26771 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
26772 +       struct nsproxy *new_nsproxy, unsigned long mask)
26773 +{
26774 +       struct mnt_namespace *old_ns;
26775 +       struct uts_namespace *old_uts;
26776 +       struct ipc_namespace *old_ipc;
26777 +       struct nsproxy *nsproxy;
26778 +
26779 +       nsproxy = copy_nsproxy(old_nsproxy);
26780 +       if (!nsproxy)
26781 +               goto out;
26782 +
26783 +       if (mask & CLONE_NEWNS) {
26784 +               old_ns = nsproxy->mnt_ns;
26785 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
26786 +               if (nsproxy->mnt_ns)
26787 +                       get_mnt_ns(nsproxy->mnt_ns);
26788 +       } else
26789 +               old_ns = NULL;
26790 +
26791 +       if (mask & CLONE_NEWUTS) {
26792 +               old_uts = nsproxy->uts_ns;
26793 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
26794 +               if (nsproxy->uts_ns)
26795 +                       get_uts_ns(nsproxy->uts_ns);
26796 +       } else
26797 +               old_uts = NULL;
26798 +
26799 +       if (mask & CLONE_NEWIPC) {
26800 +               old_ipc = nsproxy->ipc_ns;
26801 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
26802 +               if (nsproxy->ipc_ns)
26803 +                       get_ipc_ns(nsproxy->ipc_ns);
26804 +       } else
26805 +               old_ipc = NULL;
26806 +
26807 +       if (old_ns)
26808 +               put_mnt_ns(old_ns);
26809 +       if (old_uts)
26810 +               put_uts_ns(old_uts);
26811 +       if (old_ipc)
26812 +               put_ipc_ns(old_ipc);
26813 +out:
26814 +       return nsproxy;
26815 +}
26816 +
26817 +
26818 +/*
26819 + *     merge two nsproxy structs into a new one.
26820 + *     will hold a reference on the result.
26821 + */
26822 +
26823 +static inline
26824 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
26825 +       struct nsproxy *proxy, unsigned long mask)
26826 +{
26827 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
26828 +
26829 +       if (!proxy)
26830 +               return NULL;
26831 +
26832 +       if (mask) {
26833 +               /* vs_mix_nsproxy returns with reference */
26834 +               return vs_mix_nsproxy(old ? old : &null_proxy,
26835 +                       proxy, mask);
26836 +       }
26837 +       get_nsproxy(proxy);
26838 +       return proxy;
26839 +}
26840 +
26841 +/*
26842 + *     merge two fs structs into a new one.
26843 + *     will take a reference on the result.
26844 + */
26845 +
26846 +static inline
26847 +struct fs_struct *__vs_merge_fs(struct fs_struct *old,
26848 +       struct fs_struct *fs, unsigned long mask)
26849 +{
26850 +       if (!(mask & CLONE_FS)) {
26851 +               if (old)
26852 +                       atomic_inc(&old->count);
26853 +               return old;
26854 +       }
26855 +
26856 +       if (!fs)
26857 +               return NULL;
26858 +
26859 +       return copy_fs_struct(fs);
26860 +}
26861 +
26862 +
26863 +int vx_enter_space(struct vx_info *vxi, unsigned long mask)
26864 +{
26865 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
26866 +       struct fs_struct *fs, *fs_cur, *fs_new;
26867 +       int ret;
26868 +
26869 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
26870 +               return -EACCES;
26871 +
26872 +       if (!mask)
26873 +               mask = vxi->vx_nsmask;
26874 +
26875 +       if ((mask & vxi->vx_nsmask) != mask)
26876 +               return -EINVAL;
26877 +
26878 +       proxy = vxi->vx_nsproxy;
26879 +       fs = vxi->vx_fs;
26880 +
26881 +       task_lock(current);
26882 +       fs_cur = current->fs;
26883 +       atomic_inc(&fs_cur->count);
26884 +       proxy_cur = current->nsproxy;
26885 +       get_nsproxy(proxy_cur);
26886 +       task_unlock(current);
26887 +
26888 +       fs_new = __vs_merge_fs(fs_cur, fs, mask);
26889 +       if (IS_ERR(fs_new)) {
26890 +               ret = PTR_ERR(fs_new);
26891 +               goto out_put;
26892 +       }
26893 +
26894 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
26895 +       if (IS_ERR(proxy_new)) {
26896 +               ret = PTR_ERR(proxy_new);
26897 +               goto out_put_fs;
26898 +       }
26899 +
26900 +       fs_new = xchg(&current->fs, fs_new);
26901 +       proxy_new = xchg(&current->nsproxy, proxy_new);
26902 +       ret = 0;
26903 +
26904 +       if (proxy_new)
26905 +               put_nsproxy(proxy_new);
26906 +out_put_fs:
26907 +       if (fs_new)
26908 +               put_fs_struct(fs_new);
26909 +out_put:
26910 +       if (proxy_cur)
26911 +               put_nsproxy(proxy_cur);
26912 +       if (fs_cur)
26913 +               put_fs_struct(fs_cur);
26914 +       return ret;
26915 +}
26916 +
26917 +
26918 +int vx_set_space(struct vx_info *vxi, unsigned long mask)
26919 +{
26920 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
26921 +       struct fs_struct *fs_vxi, *fs_cur, *fs_new;
26922 +       int ret;
26923 +
26924 +       if (!mask)
26925 +               mask = space_mask.mask;
26926 +
26927 +       if ((mask & space_mask.mask) != mask)
26928 +               return -EINVAL;
26929 +
26930 +       proxy_vxi = vxi->vx_nsproxy;
26931 +       fs_vxi = vxi->vx_fs;
26932 +
26933 +       task_lock(current);
26934 +       fs_cur = current->fs;
26935 +       atomic_inc(&fs_cur->count);
26936 +       proxy_cur = current->nsproxy;
26937 +       get_nsproxy(proxy_cur);
26938 +       task_unlock(current);
26939 +
26940 +       fs_new = __vs_merge_fs(fs_vxi, fs_cur, mask);
26941 +       if (IS_ERR(fs_new)) {
26942 +               ret = PTR_ERR(fs_new);
26943 +               goto out_put;
26944 +       }
26945 +
26946 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
26947 +       if (IS_ERR(proxy_new)) {
26948 +               ret = PTR_ERR(proxy_new);
26949 +               goto out_put_fs;
26950 +       }
26951 +
26952 +       fs_new = xchg(&vxi->vx_fs, fs_new);
26953 +       proxy_new = xchg(&vxi->vx_nsproxy, proxy_new);
26954 +       vxi->vx_nsmask |= mask;
26955 +       ret = 0;
26956 +
26957 +       if (proxy_new)
26958 +               put_nsproxy(proxy_new);
26959 +out_put_fs:
26960 +       if (fs_new)
26961 +               put_fs_struct(fs_new);
26962 +out_put:
26963 +       if (proxy_cur)
26964 +               put_nsproxy(proxy_cur);
26965 +       if (fs_cur)
26966 +               put_fs_struct(fs_cur);
26967 +       return ret;
26968 +}
26969 +
26970 +
26971 +int vc_enter_space(struct vx_info *vxi, void __user *data)
26972 +{
26973 +       struct vcmd_space_mask vc_data = { .mask = 0 };
26974 +
26975 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
26976 +               return -EFAULT;
26977 +
26978 +       return vx_enter_space(vxi, vc_data.mask);
26979 +}
26980 +
26981 +int vc_set_space(struct vx_info *vxi, void __user *data)
26982 +{
26983 +       struct vcmd_space_mask vc_data = { .mask = 0 };
26984 +
26985 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
26986 +               return -EFAULT;
26987 +
26988 +       return vx_set_space(vxi, vc_data.mask);
26989 +}
26990 +
26991 +int vc_get_space_mask(struct vx_info *vxi, void __user *data)
26992 +{
26993 +       if (copy_to_user(data, &space_mask, sizeof(space_mask)))
26994 +               return -EFAULT;
26995 +       return 0;
26996 +}
26997 +
26998 diff -Nurp linux-2.6.22.15/kernel/vserver/switch.c linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/switch.c
26999 --- linux-2.6.22.15/kernel/vserver/switch.c     1969-12-31 19:00:00.000000000 -0500
27000 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/switch.c        2007-12-09 06:44:23.000000000 -0500
27001 @@ -0,0 +1,529 @@
27002 +/*
27003 + *  linux/kernel/vserver/switch.c
27004 + *
27005 + *  Virtual Server: Syscall Switch
27006 + *
27007 + *  Copyright (C) 2003-2007  Herbert Pötzl
27008 + *
27009 + *  V0.01  syscall switch
27010 + *  V0.02  added signal to context
27011 + *  V0.03  added rlimit functions
27012 + *  V0.04  added iattr, task/xid functions
27013 + *  V0.05  added debug/history stuff
27014 + *  V0.06  added compat32 layer
27015 + *  V0.07  vcmd args and perms
27016 + *  V0.08  added status commands
27017 + *  V0.09  added tag commands
27018 + *  V0.10  added oom bias
27019 + *  V0.11  added device commands
27020 + *
27021 + */
27022 +
27023 +#include <linux/vs_context.h>
27024 +#include <linux/vs_network.h>
27025 +#include <linux/vserver/switch.h>
27026 +
27027 +#include "vci_config.h"
27028 +
27029 +
27030 +static inline
27031 +int vc_get_version(uint32_t id)
27032 +{
27033 +       return VCI_VERSION;
27034 +}
27035 +
27036 +static inline
27037 +int vc_get_vci(uint32_t id)
27038 +{
27039 +       return vci_kernel_config();
27040 +}
27041 +
27042 +#include <linux/vserver/context_cmd.h>
27043 +#include <linux/vserver/cvirt_cmd.h>
27044 +#include <linux/vserver/cacct_cmd.h>
27045 +#include <linux/vserver/limit_cmd.h>
27046 +#include <linux/vserver/network_cmd.h>
27047 +#include <linux/vserver/sched_cmd.h>
27048 +#include <linux/vserver/debug_cmd.h>
27049 +#include <linux/vserver/inode_cmd.h>
27050 +#include <linux/vserver/dlimit_cmd.h>
27051 +#include <linux/vserver/signal_cmd.h>
27052 +#include <linux/vserver/space_cmd.h>
27053 +#include <linux/vserver/tag_cmd.h>
27054 +#include <linux/vserver/device_cmd.h>
27055 +
27056 +#include <linux/vserver/inode.h>
27057 +#include <linux/vserver/dlimit.h>
27058 +
27059 +
27060 +#ifdef CONFIG_COMPAT
27061 +#define __COMPAT(name, id, data, compat)       \
27062 +       (compat) ? name ## _x32(id, data) : name(id, data)
27063 +#define __COMPAT_NO_ID(name, data, compat)     \
27064 +       (compat) ? name ## _x32(data) : name(data)
27065 +#else
27066 +#define __COMPAT(name, id, data, compat)       \
27067 +       name(id, data)
27068 +#define __COMPAT_NO_ID(name, data, compat)     \
27069 +       name(data)
27070 +#endif
27071 +
27072 +
27073 +static inline
27074 +long do_vcmd(uint32_t cmd, uint32_t id,
27075 +       struct vx_info *vxi, struct nx_info *nxi,
27076 +       void __user *data, int compat)
27077 +{
27078 +       switch (cmd) {
27079 +
27080 +       case VCMD_get_version:
27081 +               return vc_get_version(id);
27082 +       case VCMD_get_vci:
27083 +               return vc_get_vci(id);
27084 +
27085 +       case VCMD_task_xid:
27086 +               return vc_task_xid(id);
27087 +       case VCMD_vx_info:
27088 +               return vc_vx_info(vxi, data);
27089 +
27090 +       case VCMD_task_nid:
27091 +               return vc_task_nid(id);
27092 +       case VCMD_nx_info:
27093 +               return vc_nx_info(nxi, data);
27094 +
27095 +       case VCMD_task_tag:
27096 +               return vc_task_tag(id);
27097 +
27098 +       /* this is version 1 */
27099 +       case VCMD_set_space:
27100 +               return vc_set_space(vxi, data);
27101 +
27102 +       case VCMD_get_space_mask:
27103 +               return vc_get_space_mask(vxi, data);
27104 +
27105 +#ifdef CONFIG_IA32_EMULATION
27106 +       case VCMD_get_rlimit:
27107 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
27108 +       case VCMD_set_rlimit:
27109 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
27110 +#else
27111 +       case VCMD_get_rlimit:
27112 +               return vc_get_rlimit(vxi, data);
27113 +       case VCMD_set_rlimit:
27114 +               return vc_set_rlimit(vxi, data);
27115 +#endif
27116 +       case VCMD_get_rlimit_mask:
27117 +               return vc_get_rlimit_mask(id, data);
27118 +       case VCMD_reset_minmax:
27119 +               return vc_reset_minmax(vxi, data);
27120 +
27121 +       case VCMD_get_vhi_name:
27122 +               return vc_get_vhi_name(vxi, data);
27123 +       case VCMD_set_vhi_name:
27124 +               return vc_set_vhi_name(vxi, data);
27125 +
27126 +       case VCMD_ctx_stat:
27127 +               return vc_ctx_stat(vxi, data);
27128 +       case VCMD_virt_stat:
27129 +               return vc_virt_stat(vxi, data);
27130 +       case VCMD_sock_stat:
27131 +               return vc_sock_stat(vxi, data);
27132 +       case VCMD_rlimit_stat:
27133 +               return vc_rlimit_stat(vxi, data);
27134 +
27135 +       case VCMD_set_cflags:
27136 +               return vc_set_cflags(vxi, data);
27137 +       case VCMD_get_cflags:
27138 +               return vc_get_cflags(vxi, data);
27139 +
27140 +       /* this is version 1 */
27141 +       case VCMD_set_ccaps:
27142 +               return vc_set_ccaps(vxi, data);
27143 +       /* this is version 1 */
27144 +       case VCMD_get_ccaps:
27145 +               return vc_get_ccaps(vxi, data);
27146 +       case VCMD_set_bcaps:
27147 +               return vc_set_bcaps(vxi, data);
27148 +       case VCMD_get_bcaps:
27149 +               return vc_get_bcaps(vxi, data);
27150 +
27151 +       case VCMD_set_badness:
27152 +               return vc_set_badness(vxi, data);
27153 +       case VCMD_get_badness:
27154 +               return vc_get_badness(vxi, data);
27155 +
27156 +       case VCMD_set_nflags:
27157 +               return vc_set_nflags(nxi, data);
27158 +       case VCMD_get_nflags:
27159 +               return vc_get_nflags(nxi, data);
27160 +
27161 +       case VCMD_set_ncaps:
27162 +               return vc_set_ncaps(nxi, data);
27163 +       case VCMD_get_ncaps:
27164 +               return vc_get_ncaps(nxi, data);
27165 +
27166 +       case VCMD_set_sched_v4:
27167 +               return vc_set_sched_v4(vxi, data);
27168 +       /* this is version 5 */
27169 +       case VCMD_set_sched:
27170 +               return vc_set_sched(vxi, data);
27171 +       case VCMD_get_sched:
27172 +               return vc_get_sched(vxi, data);
27173 +       case VCMD_sched_info:
27174 +               return vc_sched_info(vxi, data);
27175 +
27176 +       case VCMD_add_dlimit:
27177 +               return __COMPAT(vc_add_dlimit, id, data, compat);
27178 +       case VCMD_rem_dlimit:
27179 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
27180 +       case VCMD_set_dlimit:
27181 +               return __COMPAT(vc_set_dlimit, id, data, compat);
27182 +       case VCMD_get_dlimit:
27183 +               return __COMPAT(vc_get_dlimit, id, data, compat);
27184 +
27185 +       case VCMD_ctx_kill:
27186 +               return vc_ctx_kill(vxi, data);
27187 +
27188 +       case VCMD_wait_exit:
27189 +               return vc_wait_exit(vxi, data);
27190 +
27191 +       case VCMD_get_iattr:
27192 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
27193 +       case VCMD_set_iattr:
27194 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
27195 +
27196 +       case VCMD_fget_iattr:
27197 +               return vc_fget_iattr(id, data);
27198 +       case VCMD_fset_iattr:
27199 +               return vc_fset_iattr(id, data);
27200 +
27201 +       case VCMD_enter_space_v0:
27202 +               return vc_enter_space(vxi, NULL);
27203 +       /* this is version 1 */
27204 +       case VCMD_enter_space:
27205 +               return vc_enter_space(vxi, data);
27206 +
27207 +       case VCMD_ctx_create_v0:
27208 +               return vc_ctx_create(id, NULL);
27209 +       case VCMD_ctx_create:
27210 +               return vc_ctx_create(id, data);
27211 +       case VCMD_ctx_migrate_v0:
27212 +               return vc_ctx_migrate(vxi, NULL);
27213 +       case VCMD_ctx_migrate:
27214 +               return vc_ctx_migrate(vxi, data);
27215 +
27216 +       case VCMD_net_create_v0:
27217 +               return vc_net_create(id, NULL);
27218 +       case VCMD_net_create:
27219 +               return vc_net_create(id, data);
27220 +       case VCMD_net_migrate:
27221 +               return vc_net_migrate(nxi, data);
27222 +
27223 +       case VCMD_tag_migrate:
27224 +               return vc_tag_migrate(id);
27225 +
27226 +       case VCMD_net_add:
27227 +               return vc_net_add(nxi, data);
27228 +       case VCMD_net_remove:
27229 +               return vc_net_remove(nxi, data);
27230 +
27231 +       case VCMD_net_add_ipv4:
27232 +               return vc_net_add_ipv4(nxi, data);
27233 +       case VCMD_net_remove_ipv4:
27234 +               return vc_net_remove_ipv4(nxi, data);
27235 +#ifdef CONFIG_IPV6
27236 +       case VCMD_net_add_ipv6:
27237 +               return vc_net_add_ipv6(nxi, data);
27238 +       case VCMD_net_remove_ipv6:
27239 +               return vc_net_remove_ipv6(nxi, data);
27240 +#endif
27241 +/*     case VCMD_add_match_ipv4:
27242 +               return vc_add_match_ipv4(nxi, data);
27243 +       case VCMD_get_match_ipv4:
27244 +               return vc_get_match_ipv4(nxi, data);
27245 +#ifdef CONFIG_IPV6
27246 +       case VCMD_add_match_ipv6:
27247 +               return vc_add_match_ipv6(nxi, data);
27248 +       case VCMD_get_match_ipv6:
27249 +               return vc_get_match_ipv6(nxi, data);
27250 +#endif */
27251 +
27252 +#ifdef CONFIG_VSERVER_DEVICE
27253 +       case VCMD_set_mapping:
27254 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
27255 +       case VCMD_unset_mapping:
27256 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
27257 +#endif
27258 +#ifdef CONFIG_VSERVER_HISTORY
27259 +       case VCMD_dump_history:
27260 +               return vc_dump_history(id);
27261 +       case VCMD_read_history:
27262 +               return __COMPAT(vc_read_history, id, data, compat);
27263 +#endif
27264 +#ifdef CONFIG_VSERVER_MONITOR
27265 +       case VCMD_read_monitor:
27266 +               return __COMPAT(vc_read_monitor, id, data, compat);
27267 +#endif
27268 +       default:
27269 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
27270 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
27271 +       }
27272 +       return -ENOSYS;
27273 +}
27274 +
27275 +
27276 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
27277 +       case VCMD_ ## vcmd: perm = _perm;               \
27278 +               args = _args; flags = _flags; break
27279 +
27280 +
27281 +#define VCA_NONE       0x00
27282 +#define VCA_VXI                0x01
27283 +#define VCA_NXI                0x02
27284 +
27285 +#define VCF_NONE       0x00
27286 +#define VCF_INFO       0x01
27287 +#define VCF_ADMIN      0x02
27288 +#define VCF_ARES       0x06    /* includes admin */
27289 +#define VCF_SETUP      0x08
27290 +
27291 +#define VCF_ZIDOK      0x10    /* zero id okay */
27292 +
27293 +
27294 +static inline
27295 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
27296 +{
27297 +       long ret;
27298 +       int permit = -1, state = 0;
27299 +       int perm = -1, args = 0, flags = 0;
27300 +       struct vx_info *vxi = NULL;
27301 +       struct nx_info *nxi = NULL;
27302 +
27303 +       switch (cmd) {
27304 +       /* unpriviledged commands */
27305 +       __VCMD(get_version,      0, VCA_NONE,   0);
27306 +       __VCMD(get_vci,          0, VCA_NONE,   0);
27307 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
27308 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
27309 +
27310 +       /* info commands */
27311 +       __VCMD(task_xid,         2, VCA_NONE,   0);
27312 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
27313 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
27314 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
27315 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
27316 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
27317 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
27318 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
27319 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
27320 +
27321 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
27322 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
27323 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
27324 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
27325 +
27326 +       __VCMD(task_nid,         2, VCA_NONE,   0);
27327 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
27328 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
27329 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
27330 +
27331 +       __VCMD(task_tag,         2, VCA_NONE,   0);
27332 +
27333 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
27334 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
27335 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
27336 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
27337 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
27338 +
27339 +       /* lower admin commands */
27340 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
27341 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
27342 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
27343 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
27344 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
27345 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
27346 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
27347 +
27348 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
27349 +       __VCMD(net_create,       5, VCA_NONE,   0);
27350 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
27351 +
27352 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
27353 +
27354 +       /* higher admin commands */
27355 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
27356 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27357 +
27358 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27359 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27360 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27361 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27362 +
27363 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27364 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27365 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27366 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27367 +
27368 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
27369 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
27370 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27371 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27372 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27373 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27374 +#ifdef CONFIG_IPV6
27375 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27376 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27377 +#endif
27378 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
27379 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
27380 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
27381 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
27382 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
27383 +
27384 +#ifdef CONFIG_VSERVER_DEVICE
27385 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
27386 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
27387 +#endif
27388 +       /* debug level admin commands */
27389 +#ifdef CONFIG_VSERVER_HISTORY
27390 +       __VCMD(dump_history,     9, VCA_NONE,   0);
27391 +       __VCMD(read_history,     9, VCA_NONE,   0);
27392 +#endif
27393 +#ifdef CONFIG_VSERVER_MONITOR
27394 +       __VCMD(read_monitor,     9, VCA_NONE,   0);
27395 +#endif
27396 +
27397 +       default:
27398 +               perm = -1;
27399 +       }
27400 +
27401 +       vxdprintk(VXD_CBIT(switch, 0),
27402 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
27403 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
27404 +               VC_VERSION(cmd), id, data, compat,
27405 +               perm, args, flags);
27406 +
27407 +       ret = -ENOSYS;
27408 +       if (perm < 0)
27409 +               goto out;
27410 +
27411 +       state = 1;
27412 +       if (!capable(CAP_CONTEXT))
27413 +               goto out;
27414 +
27415 +       state = 2;
27416 +       /* moved here from the individual commands */
27417 +       ret = -EPERM;
27418 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
27419 +               goto out;
27420 +
27421 +       state = 3;
27422 +       /* vcmd involves resource management  */
27423 +       ret = -EPERM;
27424 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
27425 +               goto out;
27426 +
27427 +       state = 4;
27428 +       /* various legacy exceptions */
27429 +       switch (cmd) {
27430 +       /* will go away when spectator is a cap */
27431 +       case VCMD_ctx_migrate_v0:
27432 +       case VCMD_ctx_migrate:
27433 +               if (id == 1) {
27434 +                       current->xid = 1;
27435 +                       ret = 1;
27436 +                       goto out;
27437 +               }
27438 +               break;
27439 +
27440 +       /* will go away when spectator is a cap */
27441 +       case VCMD_net_migrate:
27442 +               if (id == 1) {
27443 +                       current->nid = 1;
27444 +                       ret = 1;
27445 +                       goto out;
27446 +               }
27447 +               break;
27448 +       }
27449 +
27450 +       /* vcmds are fine by default */
27451 +       permit = 1;
27452 +
27453 +       /* admin type vcmds require admin ... */
27454 +       if (flags & VCF_ADMIN)
27455 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
27456 +
27457 +       /* ... but setup type vcmds override that */
27458 +       if (!permit && (flags & VCF_SETUP))
27459 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
27460 +
27461 +       state = 5;
27462 +       ret = -EPERM;
27463 +       if (!permit)
27464 +               goto out;
27465 +
27466 +       state = 6;
27467 +       if (!id && (flags & VCF_ZIDOK))
27468 +               goto skip_id;
27469 +
27470 +       ret = -ESRCH;
27471 +       if (args & VCA_VXI) {
27472 +               vxi = lookup_vx_info(id);
27473 +               if (!vxi)
27474 +                       goto out;
27475 +
27476 +               if ((flags & VCF_ADMIN) &&
27477 +                       /* special case kill for shutdown */
27478 +                       (cmd != VCMD_ctx_kill) &&
27479 +                       /* can context be administrated? */
27480 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
27481 +                       ret = -EACCES;
27482 +                       goto out_vxi;
27483 +               }
27484 +       }
27485 +       state = 7;
27486 +       if (args & VCA_NXI) {
27487 +               nxi = lookup_nx_info(id);
27488 +               if (!nxi)
27489 +                       goto out_vxi;
27490 +
27491 +               if ((flags & VCF_ADMIN) &&
27492 +                       /* can context be administrated? */
27493 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
27494 +                       ret = -EACCES;
27495 +                       goto out_nxi;
27496 +               }
27497 +       }
27498 +skip_id:
27499 +       state = 8;
27500 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
27501 +
27502 +out_nxi:
27503 +       if ((args & VCA_NXI) && nxi)
27504 +               put_nx_info(nxi);
27505 +out_vxi:
27506 +       if ((args & VCA_VXI) && vxi)
27507 +               put_vx_info(vxi);
27508 +out:
27509 +       vxdprintk(VXD_CBIT(switch, 1),
27510 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
27511 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
27512 +               VC_VERSION(cmd), ret, ret, state, permit);
27513 +       return ret;
27514 +}
27515 +
27516 +asmlinkage long
27517 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
27518 +{
27519 +       return do_vserver(cmd, id, data, 0);
27520 +}
27521 +
27522 +#ifdef CONFIG_COMPAT
27523 +
27524 +asmlinkage long
27525 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
27526 +{
27527 +       return do_vserver(cmd, id, data, 1);
27528 +}
27529 +
27530 +#endif /* CONFIG_COMPAT */
27531 diff -Nurp linux-2.6.22.15/kernel/vserver/sysctl.c linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/sysctl.c
27532 --- linux-2.6.22.15/kernel/vserver/sysctl.c     1969-12-31 19:00:00.000000000 -0500
27533 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/sysctl.c        2007-12-09 06:44:23.000000000 -0500
27534 @@ -0,0 +1,243 @@
27535 +/*
27536 + *  kernel/vserver/sysctl.c
27537 + *
27538 + *  Virtual Context Support
27539 + *
27540 + *  Copyright (C) 2004-2007  Herbert Pötzl
27541 + *
27542 + *  V0.01  basic structure
27543 + *
27544 + */
27545 +
27546 +#include <linux/module.h>
27547 +#include <linux/ctype.h>
27548 +#include <linux/sysctl.h>
27549 +#include <linux/parser.h>
27550 +#include <asm/uaccess.h>
27551 +
27552 +
27553 +#define CTL_VSERVER    4242    /* unused? */
27554 +
27555 +enum {
27556 +       CTL_DEBUG_ERROR         = 0,
27557 +       CTL_DEBUG_SWITCH        = 1,
27558 +       CTL_DEBUG_XID,
27559 +       CTL_DEBUG_NID,
27560 +       CTL_DEBUG_TAG,
27561 +       CTL_DEBUG_NET,
27562 +       CTL_DEBUG_LIMIT,
27563 +       CTL_DEBUG_CRES,
27564 +       CTL_DEBUG_DLIM,
27565 +       CTL_DEBUG_QUOTA,
27566 +       CTL_DEBUG_CVIRT,
27567 +       CTL_DEBUG_SPACE,
27568 +       CTL_DEBUG_MISC,
27569 +};
27570 +
27571 +
27572 +unsigned int vx_debug_switch   = 0;
27573 +unsigned int vx_debug_xid      = 0;
27574 +unsigned int vx_debug_nid      = 0;
27575 +unsigned int vx_debug_tag      = 0;
27576 +unsigned int vx_debug_net      = 0;
27577 +unsigned int vx_debug_limit    = 0;
27578 +unsigned int vx_debug_cres     = 0;
27579 +unsigned int vx_debug_dlim     = 0;
27580 +unsigned int vx_debug_quota    = 0;
27581 +unsigned int vx_debug_cvirt    = 0;
27582 +unsigned int vx_debug_space    = 0;
27583 +unsigned int vx_debug_misc     = 0;
27584 +
27585 +
27586 +static struct ctl_table_header *vserver_table_header;
27587 +static ctl_table vserver_table[];
27588 +
27589 +
27590 +void vserver_register_sysctl(void)
27591 +{
27592 +       if (!vserver_table_header) {
27593 +               vserver_table_header = register_sysctl_table(vserver_table);
27594 +       }
27595 +
27596 +}
27597 +
27598 +void vserver_unregister_sysctl(void)
27599 +{
27600 +       if (vserver_table_header) {
27601 +               unregister_sysctl_table(vserver_table_header);
27602 +               vserver_table_header = NULL;
27603 +       }
27604 +}
27605 +
27606 +
27607 +static int proc_dodebug(ctl_table *table, int write,
27608 +       struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
27609 +{
27610 +       char            tmpbuf[20], *p, c;
27611 +       unsigned int    value;
27612 +       size_t          left, len;
27613 +
27614 +       if ((*ppos && !write) || !*lenp) {
27615 +               *lenp = 0;
27616 +               return 0;
27617 +       }
27618 +
27619 +       left = *lenp;
27620 +
27621 +       if (write) {
27622 +               if (!access_ok(VERIFY_READ, buffer, left))
27623 +                       return -EFAULT;
27624 +               p = (char *)buffer;
27625 +               while (left && __get_user(c, p) >= 0 && isspace(c))
27626 +                       left--, p++;
27627 +               if (!left)
27628 +                       goto done;
27629 +
27630 +               if (left > sizeof(tmpbuf) - 1)
27631 +                       return -EINVAL;
27632 +               if (copy_from_user(tmpbuf, p, left))
27633 +                       return -EFAULT;
27634 +               tmpbuf[left] = '\0';
27635 +
27636 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
27637 +                       value = 10 * value + (*p - '0');
27638 +               if (*p && !isspace(*p))
27639 +                       return -EINVAL;
27640 +               while (left && isspace(*p))
27641 +                       left--, p++;
27642 +               *(unsigned int *)table->data = value;
27643 +       } else {
27644 +               if (!access_ok(VERIFY_WRITE, buffer, left))
27645 +                       return -EFAULT;
27646 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
27647 +               if (len > left)
27648 +                       len = left;
27649 +               if (__copy_to_user(buffer, tmpbuf, len))
27650 +                       return -EFAULT;
27651 +               if ((left -= len) > 0) {
27652 +                       if (put_user('\n', (char *)buffer + len))
27653 +                               return -EFAULT;
27654 +                       left--;
27655 +               }
27656 +       }
27657 +
27658 +done:
27659 +       *lenp -= left;
27660 +       *ppos += *lenp;
27661 +       return 0;
27662 +}
27663 +
27664 +
27665 +#define        CTL_ENTRY(ctl, name)                            \
27666 +       {                                               \
27667 +               .ctl_name       = ctl,                  \
27668 +               .procname       = #name,                \
27669 +               .data           = &vx_ ## name,         \
27670 +               .maxlen         = sizeof(int),          \
27671 +               .mode           = 0644,                 \
27672 +               .proc_handler   = &proc_dodebug         \
27673 +       }
27674 +
27675 +static ctl_table debug_table[] = {
27676 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
27677 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
27678 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
27679 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
27680 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
27681 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
27682 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
27683 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
27684 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
27685 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
27686 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
27687 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
27688 +       { .ctl_name = 0 }
27689 +};
27690 +
27691 +static ctl_table vserver_table[] = {
27692 +       {
27693 +               .ctl_name       = CTL_VSERVER,
27694 +               .procname       = "vserver",
27695 +               .mode           = 0555,
27696 +               .child          = debug_table
27697 +       },
27698 +       { .ctl_name = 0 }
27699 +};
27700 +
27701 +
27702 +static match_table_t tokens = {
27703 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
27704 +       { CTL_DEBUG_XID,        "xid=%x"        },
27705 +       { CTL_DEBUG_NID,        "nid=%x"        },
27706 +       { CTL_DEBUG_TAG,        "tag=%x"        },
27707 +       { CTL_DEBUG_NET,        "net=%x"        },
27708 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
27709 +       { CTL_DEBUG_CRES,       "cres=%x"       },
27710 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
27711 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
27712 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
27713 +       { CTL_DEBUG_SPACE,      "space=%x"      },
27714 +       { CTL_DEBUG_MISC,       "misc=%x"       },
27715 +       { CTL_DEBUG_ERROR,      NULL            }
27716 +};
27717 +
27718 +#define        HANDLE_CASE(id, name, val)                              \
27719 +       case CTL_DEBUG_ ## id:                                  \
27720 +               vx_debug_ ## name = val;                        \
27721 +               printk("vs_debug_" #name "=0x%x\n", val);       \
27722 +               break
27723 +
27724 +
27725 +static int __init vs_debug_setup(char *str)
27726 +{
27727 +       char *p;
27728 +       int token;
27729 +
27730 +       printk("vs_debug_setup(%s)\n", str);
27731 +       while ((p = strsep(&str, ",")) != NULL) {
27732 +               substring_t args[MAX_OPT_ARGS];
27733 +               unsigned int value;
27734 +
27735 +               if (!*p)
27736 +                       continue;
27737 +
27738 +               token = match_token(p, tokens, args);
27739 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
27740 +
27741 +               switch (token) {
27742 +               HANDLE_CASE(SWITCH, switch, value);
27743 +               HANDLE_CASE(XID,    xid,    value);
27744 +               HANDLE_CASE(NID,    nid,    value);
27745 +               HANDLE_CASE(TAG,    tag,    value);
27746 +               HANDLE_CASE(NET,    net,    value);
27747 +               HANDLE_CASE(LIMIT,  limit,  value);
27748 +               HANDLE_CASE(CRES,   cres,   value);
27749 +               HANDLE_CASE(DLIM,   dlim,   value);
27750 +               HANDLE_CASE(QUOTA,  quota,  value);
27751 +               HANDLE_CASE(CVIRT,  cvirt,  value);
27752 +               HANDLE_CASE(SPACE,  space,  value);
27753 +               HANDLE_CASE(MISC,   misc,   value);
27754 +               default:
27755 +                       return -EINVAL;
27756 +                       break;
27757 +               }
27758 +       }
27759 +       return 1;
27760 +}
27761 +
27762 +__setup("vsdebug=", vs_debug_setup);
27763 +
27764 +
27765 +
27766 +EXPORT_SYMBOL_GPL(vx_debug_switch);
27767 +EXPORT_SYMBOL_GPL(vx_debug_xid);
27768 +EXPORT_SYMBOL_GPL(vx_debug_nid);
27769 +EXPORT_SYMBOL_GPL(vx_debug_net);
27770 +EXPORT_SYMBOL_GPL(vx_debug_limit);
27771 +EXPORT_SYMBOL_GPL(vx_debug_cres);
27772 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
27773 +EXPORT_SYMBOL_GPL(vx_debug_quota);
27774 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
27775 +EXPORT_SYMBOL_GPL(vx_debug_space);
27776 +EXPORT_SYMBOL_GPL(vx_debug_misc);
27777 +
27778 diff -Nurp linux-2.6.22.15/kernel/vserver/tag.c linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/tag.c
27779 --- linux-2.6.22.15/kernel/vserver/tag.c        1969-12-31 19:00:00.000000000 -0500
27780 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/tag.c   2007-12-09 06:44:23.000000000 -0500
27781 @@ -0,0 +1,62 @@
27782 +/*
27783 + *  linux/kernel/vserver/tag.c
27784 + *
27785 + *  Virtual Server: Shallow Tag Space
27786 + *
27787 + *  Copyright (C) 2007  Herbert Pötzl
27788 + *
27789 + *  V0.01  basic implementation
27790 + *
27791 + */
27792 +
27793 +#include <linux/sched.h>
27794 +#include <linux/vserver/debug.h>
27795 +#include <linux/vs_tag.h>
27796 +
27797 +#include <linux/vserver/tag_cmd.h>
27798 +
27799 +
27800 +int dx_migrate_task(struct task_struct *p, tag_t tag)
27801 +{
27802 +       if (!p)
27803 +               BUG();
27804 +
27805 +       vxdprintk(VXD_CBIT(tag, 5),
27806 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
27807 +
27808 +       task_lock(p);
27809 +       p->tag = tag;
27810 +       task_unlock(p);
27811 +
27812 +       vxdprintk(VXD_CBIT(tag, 5),
27813 +               "moved task %p into [#%d]", p, tag);
27814 +       return 0;
27815 +}
27816 +
27817 +/* vserver syscall commands below here */
27818 +
27819 +/* taks xid and vx_info functions */
27820 +
27821 +
27822 +int vc_task_tag(uint32_t id)
27823 +{
27824 +       tag_t tag;
27825 +
27826 +       if (id) {
27827 +               struct task_struct *tsk;
27828 +               read_lock(&tasklist_lock);
27829 +               tsk = find_task_by_real_pid(id);
27830 +               tag = (tsk) ? tsk->tag : -ESRCH;
27831 +               read_unlock(&tasklist_lock);
27832 +       } else
27833 +               tag = dx_current_tag();
27834 +       return tag;
27835 +}
27836 +
27837 +
27838 +int vc_tag_migrate(uint32_t tag)
27839 +{
27840 +       return dx_migrate_task(current, tag & 0xFFFF);
27841 +}
27842 +
27843 +
27844 diff -Nurp linux-2.6.22.15/kernel/vserver/vci_config.h linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/vci_config.h
27845 --- linux-2.6.22.15/kernel/vserver/vci_config.h 1969-12-31 19:00:00.000000000 -0500
27846 +++ linux-2.6.22.15-vs2.3.0.29.1/kernel/vserver/vci_config.h    2007-12-09 06:44:23.000000000 -0500
27847 @@ -0,0 +1,81 @@
27848 +
27849 +/*  interface version */
27850 +
27851 +#define VCI_VERSION            0x00020302
27852 +
27853 +
27854 +enum {
27855 +       VCI_KCBIT_NO_DYNAMIC = 0,
27856 +
27857 +       VCI_KCBIT_PROC_SECURE = 4,
27858 +       VCI_KCBIT_HARDCPU = 5,
27859 +       VCI_KCBIT_IDLELIMIT = 6,
27860 +       VCI_KCBIT_IDLETIME = 7,
27861 +
27862 +       VCI_KCBIT_COWBL = 8,
27863 +       VCI_KCBIT_FULLCOWBL = 9,
27864 +       VCI_KCBIT_SPACES = 10,
27865 +       VCI_KCBIT_NETV2 = 11,
27866 +
27867 +       VCI_KCBIT_DEBUG = 16,
27868 +       VCI_KCBIT_HISTORY = 20,
27869 +       VCI_KCBIT_TAGGED = 24,
27870 +       VCI_KCBIT_PPTAG = 28,
27871 +
27872 +       VCI_KCBIT_MORE = 31,
27873 +};
27874 +
27875 +
27876 +static inline uint32_t vci_kernel_config(void)
27877 +{
27878 +       return
27879 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
27880 +
27881 +       /* configured features */
27882 +#ifdef CONFIG_VSERVER_PROC_SECURE
27883 +       (1 << VCI_KCBIT_PROC_SECURE) |
27884 +#endif
27885 +#ifdef CONFIG_VSERVER_HARDCPU
27886 +       (1 << VCI_KCBIT_HARDCPU) |
27887 +#endif
27888 +#ifdef CONFIG_VSERVER_IDLELIMIT
27889 +       (1 << VCI_KCBIT_IDLELIMIT) |
27890 +#endif
27891 +#ifdef CONFIG_VSERVER_IDLETIME
27892 +       (1 << VCI_KCBIT_IDLETIME) |
27893 +#endif
27894 +#ifdef CONFIG_VSERVER_COWBL
27895 +       (1 << VCI_KCBIT_COWBL) |
27896 +       (1 << VCI_KCBIT_FULLCOWBL) |
27897 +#endif
27898 +       (1 << VCI_KCBIT_SPACES) |
27899 +       (1 << VCI_KCBIT_NETV2) |
27900 +
27901 +       /* debug options */
27902 +#ifdef CONFIG_VSERVER_DEBUG
27903 +       (1 << VCI_KCBIT_DEBUG) |
27904 +#endif
27905 +#ifdef CONFIG_VSERVER_HISTORY
27906 +       (1 << VCI_KCBIT_HISTORY) |
27907 +#endif
27908 +
27909 +       /* inode context tagging */
27910 +#if    defined(CONFIG_TAGGING_NONE)
27911 +       (0 << VCI_KCBIT_TAGGED) |
27912 +#elif  defined(CONFIG_TAGGING_UID16)
27913 +       (1 << VCI_KCBIT_TAGGED) |
27914 +#elif  defined(CONFIG_TAGGING_GID16)
27915 +       (2 << VCI_KCBIT_TAGGED) |
27916 +#elif  defined(CONFIG_TAGGING_ID24)
27917 +       (3 << VCI_KCBIT_TAGGED) |
27918 +#elif  defined(CONFIG_TAGGING_INTERN)
27919 +       (4 << VCI_KCBIT_TAGGED) |
27920 +#elif  defined(CONFIG_TAGGING_RUNTIME)
27921 +       (5 << VCI_KCBIT_TAGGED) |
27922 +#else
27923 +       (7 << VCI_KCBIT_TAGGED) |
27924 +#endif
27925 +       (1 << VCI_KCBIT_PPTAG) |
27926 +       0;
27927 +}
27928 +
27929 diff -Nurp linux-2.6.22.15/Makefile linux-2.6.22.15-vs2.3.0.29.1/Makefile
27930 --- linux-2.6.22.15/Makefile    2007-12-09 06:43:53.000000000 -0500
27931 +++ linux-2.6.22.15-vs2.3.0.29.1/Makefile       2007-12-09 06:44:39.000000000 -0500
27932 @@ -1,7 +1,7 @@
27933  VERSION = 2
27934  PATCHLEVEL = 6
27935  SUBLEVEL = 22
27936 -EXTRAVERSION = .19
27937 +EXTRAVERSION = .19-vs2.3.0.29.1
27938  NAME = Holy Dancing Manatees, Batman!
27939  
27940  # *DOCUMENTATION*
27941 diff -Nurp linux-2.6.22.15/mm/filemap_xip.c linux-2.6.22.15-vs2.3.0.29.1/mm/filemap_xip.c
27942 --- linux-2.6.22.15/mm/filemap_xip.c    2007-07-21 18:00:25.000000000 -0400
27943 +++ linux-2.6.22.15-vs2.3.0.29.1/mm/filemap_xip.c       2007-12-09 06:44:23.000000000 -0500
27944 @@ -14,6 +14,7 @@
27945  #include <linux/uio.h>
27946  #include <linux/rmap.h>
27947  #include <linux/sched.h>
27948 +#include <linux/vs_memory.h>
27949  #include <asm/tlbflush.h>
27950  #include "filemap.h"
27951  
27952 diff -Nurp linux-2.6.22.15/mm/fremap.c linux-2.6.22.15-vs2.3.0.29.1/mm/fremap.c
27953 --- linux-2.6.22.15/mm/fremap.c 2007-05-04 09:58:24.000000000 -0400
27954 +++ linux-2.6.22.15-vs2.3.0.29.1/mm/fremap.c    2007-12-09 06:44:23.000000000 -0500
27955 @@ -15,6 +15,7 @@
27956  #include <linux/rmap.h>
27957  #include <linux/module.h>
27958  #include <linux/syscalls.h>
27959 +#include <linux/vs_memory.h>
27960  
27961  #include <asm/mmu_context.h>
27962  #include <asm/cacheflush.h>
27963 @@ -74,6 +75,8 @@ int install_page(struct mm_struct *mm, s
27964         err = -ENOMEM;
27965         if (page_mapcount(page) > INT_MAX/2)
27966                 goto unlock;
27967 +       if (!vx_rss_avail(mm, 1))
27968 +               goto unlock;
27969  
27970         if (pte_none(*pte) || !zap_pte(mm, vma, addr, pte))
27971                 inc_mm_counter(mm, file_rss);
27972 diff -Nurp linux-2.6.22.15/mm/hugetlb.c linux-2.6.22.15-vs2.3.0.29.1/mm/hugetlb.c
27973 --- linux-2.6.22.15/mm/hugetlb.c        2007-08-11 21:54:37.000000000 -0400
27974 +++ linux-2.6.22.15-vs2.3.0.29.1/mm/hugetlb.c   2007-12-09 06:44:23.000000000 -0500
27975 @@ -19,6 +19,7 @@
27976  #include <asm/pgtable.h>
27977  
27978  #include <linux/hugetlb.h>
27979 +#include <linux/vs_memory.h>
27980  #include "internal.h"
27981  
27982  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
27983 diff -Nurp linux-2.6.22.15/mm/memory.c linux-2.6.22.15-vs2.3.0.29.1/mm/memory.c
27984 --- linux-2.6.22.15/mm/memory.c 2007-07-21 18:00:25.000000000 -0400
27985 +++ linux-2.6.22.15-vs2.3.0.29.1/mm/memory.c    2007-12-09 06:44:23.000000000 -0500
27986 @@ -498,6 +498,9 @@ static int copy_pte_range(struct mm_stru
27987         int progress = 0;
27988         int rss[2];
27989  
27990 +       if (!vx_rss_avail(dst_mm, ((end - addr)/PAGE_SIZE + 1)))
27991 +               return -ENOMEM;
27992 +
27993  again:
27994         rss[1] = rss[0] = 0;
27995         dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
27996 @@ -2157,6 +2160,11 @@ static int do_swap_page(struct mm_struct
27997                 count_vm_event(PGMAJFAULT);
27998         }
27999  
28000 +       if (!vx_rss_avail(mm, 1)) {
28001 +               ret = VM_FAULT_OOM;
28002 +               goto out;
28003 +       }
28004 +
28005         delayacct_clear_flag(DELAYACCT_PF_SWAPIN);
28006         mark_page_accessed(page);
28007         lock_page(page);
28008 @@ -2229,6 +2237,8 @@ static int do_anonymous_page(struct mm_s
28009                 /* Allocate our own private page. */
28010                 pte_unmap(page_table);
28011  
28012 +               if (!vx_rss_avail(mm, 1))
28013 +                       goto oom;
28014                 if (unlikely(anon_vma_prepare(vma)))
28015                         goto oom;
28016                 page = alloc_zeroed_user_highpage(vma, address);
28017 @@ -2302,6 +2312,9 @@ static int do_no_page(struct mm_struct *
28018         pte_unmap(page_table);
28019         BUG_ON(vma->vm_flags & VM_PFNMAP);
28020  
28021 +       if (!vx_rss_avail(mm, 1))
28022 +               return VM_FAULT_OOM;
28023 +
28024         if (vma->vm_file) {
28025                 mapping = vma->vm_file->f_mapping;
28026                 sequence = mapping->truncate_count;
28027 @@ -2527,6 +2540,7 @@ static inline int handle_pte_fault(struc
28028  {
28029         pte_t entry;
28030         spinlock_t *ptl;
28031 +       int ret, type = VXPT_UNKNOWN;
28032  
28033         entry = *pte;
28034         if (!pte_present(entry)) {
28035 @@ -2555,9 +2569,12 @@ static inline int handle_pte_fault(struc
28036         if (unlikely(!pte_same(*pte, entry)))
28037                 goto unlock;
28038         if (write_access) {
28039 -               if (!pte_write(entry))
28040 -                       return do_wp_page(mm, vma, address,
28041 +               if (!pte_write(entry)) {
28042 +                       ret = do_wp_page(mm, vma, address,
28043                                         pte, pmd, ptl, entry);
28044 +                       type = VXPT_WRITE;
28045 +                       goto out;
28046 +               }
28047                 entry = pte_mkdirty(entry);
28048         }
28049         entry = pte_mkyoung(entry);
28050 @@ -2576,7 +2593,10 @@ static inline int handle_pte_fault(struc
28051         }
28052  unlock:
28053         pte_unmap_unlock(pte, ptl);
28054 -       return VM_FAULT_MINOR;
28055 +       ret = VM_FAULT_MINOR;
28056 +out:
28057 +       vx_page_fault(mm, vma, type, ret);
28058 +       return ret;
28059  }
28060  
28061  /*
28062 diff -Nurp linux-2.6.22.15/mm/mlock.c linux-2.6.22.15-vs2.3.0.29.1/mm/mlock.c
28063 --- linux-2.6.22.15/mm/mlock.c  2007-08-11 21:54:37.000000000 -0400
28064 +++ linux-2.6.22.15-vs2.3.0.29.1/mm/mlock.c     2007-12-09 06:44:23.000000000 -0500
28065 @@ -12,6 +12,7 @@
28066  #include <linux/syscalls.h>
28067  #include <linux/sched.h>
28068  #include <linux/module.h>
28069 +#include <linux/vs_memory.h>
28070  
28071  int can_do_mlock(void)
28072  {
28073 @@ -76,7 +77,7 @@ success:
28074                         ret = make_pages_present(start, end);
28075         }
28076  
28077 -       mm->locked_vm -= pages;
28078 +       vx_vmlocked_sub(mm, pages);
28079  out:
28080         if (ret == -ENOMEM)
28081                 ret = -EAGAIN;
28082 @@ -134,7 +135,7 @@ static int do_mlock(unsigned long start,
28083  
28084  asmlinkage long sys_mlock(unsigned long start, size_t len)
28085  {
28086 -       unsigned long locked;
28087 +       unsigned long locked, grow;
28088         unsigned long lock_limit;
28089         int error = -ENOMEM;
28090  
28091 @@ -145,8 +146,10 @@ asmlinkage long sys_mlock(unsigned long 
28092         len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
28093         start &= PAGE_MASK;
28094  
28095 -       locked = len >> PAGE_SHIFT;
28096 -       locked += current->mm->locked_vm;
28097 +       grow = len >> PAGE_SHIFT;
28098 +       if (!vx_vmlocked_avail(current->mm, grow))
28099 +               goto out;
28100 +       locked = current->mm->locked_vm + grow;
28101  
28102         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
28103         lock_limit >>= PAGE_SHIFT;
28104 @@ -154,6 +157,7 @@ asmlinkage long sys_mlock(unsigned long 
28105         /* check against resource limits */
28106         if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
28107                 error = do_mlock(start, len, 1);
28108 +out:
28109         up_write(&current->mm->mmap_sem);
28110         return error;
28111  }
28112 @@ -213,6 +217,8 @@ asmlinkage long sys_mlockall(int flags)
28113         lock_limit >>= PAGE_SHIFT;
28114  
28115         ret = -ENOMEM;
28116 +       if (!vx_vmlocked_avail(current->mm, current->mm->total_vm))
28117 +               goto out;
28118         if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
28119             capable(CAP_IPC_LOCK))
28120                 ret = do_mlockall(flags);
28121 diff -Nurp linux-2.6.22.15/mm/mmap.c linux-2.6.22.15-vs2.3.0.29.1/mm/mmap.c
28122 --- linux-2.6.22.15/mm/mmap.c   2007-07-21 18:00:25.000000000 -0400
28123 +++ linux-2.6.22.15-vs2.3.0.29.1/mm/mmap.c      2007-12-09 06:44:23.000000000 -0500
28124 @@ -1144,10 +1144,10 @@ munmap_back:
28125                 kmem_cache_free(vm_area_cachep, vma);
28126         }
28127  out:   
28128 -       mm->total_vm += len >> PAGE_SHIFT;
28129 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
28130         vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
28131         if (vm_flags & VM_LOCKED) {
28132 -               mm->locked_vm += len >> PAGE_SHIFT;
28133 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
28134                 make_pages_present(addr, addr + len);
28135         }
28136         if (flags & MAP_POPULATE) {
28137 @@ -1502,9 +1502,9 @@ static int acct_stack_growth(struct vm_a
28138                 return -ENOMEM;
28139  
28140         /* Ok, everything looks good - let it rip */
28141 -       mm->total_vm += grow;
28142 +       vx_vmpages_add(mm, grow);
28143         if (vma->vm_flags & VM_LOCKED)
28144 -               mm->locked_vm += grow;
28145 +               vx_vmlocked_add(mm, grow);
28146         vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
28147         return 0;
28148  }
28149 @@ -1662,9 +1662,9 @@ static void remove_vma_list(struct mm_st
28150         do {
28151                 long nrpages = vma_pages(vma);
28152  
28153 -               mm->total_vm -= nrpages;
28154 +               vx_vmpages_sub(mm, nrpages);
28155                 if (vma->vm_flags & VM_LOCKED)
28156 -                       mm->locked_vm -= nrpages;
28157 +                       vx_vmlocked_sub(mm, nrpages);
28158                 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
28159                 vma = remove_vma(vma);
28160         } while (vma);
28161 @@ -1903,6 +1903,8 @@ unsigned long do_brk(unsigned long addr,
28162                 lock_limit >>= PAGE_SHIFT;
28163                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
28164                         return -EAGAIN;
28165 +               if (!vx_vmlocked_avail(mm, len >> PAGE_SHIFT))
28166 +                       return -ENOMEM;
28167         }
28168  
28169         /*
28170 @@ -1929,7 +1931,8 @@ unsigned long do_brk(unsigned long addr,
28171         if (mm->map_count > sysctl_max_map_count)
28172                 return -ENOMEM;
28173  
28174 -       if (security_vm_enough_memory(len >> PAGE_SHIFT))
28175 +       if (security_vm_enough_memory(len >> PAGE_SHIFT) ||
28176 +               !vx_vmpages_avail(mm, len >> PAGE_SHIFT))
28177                 return -ENOMEM;
28178  
28179         /* Can we just expand an old private anonymous mapping? */
28180 @@ -1955,9 +1958,9 @@ unsigned long do_brk(unsigned long addr,
28181                                 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)];
28182         vma_link(mm, vma, prev, rb_link, rb_parent);
28183  out:
28184 -       mm->total_vm += len >> PAGE_SHIFT;
28185 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
28186         if (flags & VM_LOCKED) {
28187 -               mm->locked_vm += len >> PAGE_SHIFT;
28188 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
28189                 make_pages_present(addr, addr + len);
28190         }
28191         return addr;
28192 @@ -1986,6 +1989,11 @@ void exit_mmap(struct mm_struct *mm)
28193         free_pgtables(&tlb, vma, FIRST_USER_ADDRESS, 0);
28194         tlb_finish_mmu(tlb, 0, end);
28195  
28196 +       set_mm_counter(mm, file_rss, 0);
28197 +       set_mm_counter(mm, anon_rss, 0);
28198 +       vx_vmpages_sub(mm, mm->total_vm);
28199 +       vx_vmlocked_sub(mm, mm->locked_vm);
28200 +
28201         /*
28202          * Walk the list again, actually closing and freeing it,
28203          * with preemption enabled, without holding any MM locks.
28204 @@ -2025,7 +2033,8 @@ int insert_vm_struct(struct mm_struct * 
28205         if (__vma && __vma->vm_start < vma->vm_end)
28206                 return -ENOMEM;
28207         if ((vma->vm_flags & VM_ACCOUNT) &&
28208 -            security_vm_enough_memory(vma_pages(vma)))
28209 +               (security_vm_enough_memory(vma_pages(vma)) ||
28210 +               !vx_vmpages_avail(mm, vma_pages(vma))))
28211                 return -ENOMEM;
28212         vma_link(mm, vma, prev, rb_link, rb_parent);
28213         return 0;
28214 @@ -2098,6 +2107,8 @@ int may_expand_vm(struct mm_struct *mm, 
28215  
28216         if (cur + npages > lim)
28217                 return 0;
28218 +       if (!vx_vmpages_avail(mm, npages))
28219 +               return 0;
28220         return 1;
28221  }
28222  
28223 @@ -2168,7 +2179,6 @@ int install_special_mapping(struct mm_st
28224                 return -ENOMEM;
28225         }
28226  
28227 -       mm->total_vm += len >> PAGE_SHIFT;
28228 -
28229 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
28230         return 0;
28231  }
28232 diff -Nurp linux-2.6.22.15/mm/mremap.c linux-2.6.22.15-vs2.3.0.29.1/mm/mremap.c
28233 --- linux-2.6.22.15/mm/mremap.c 2007-05-04 09:58:24.000000000 -0400
28234 +++ linux-2.6.22.15-vs2.3.0.29.1/mm/mremap.c    2007-12-09 06:44:23.000000000 -0500
28235 @@ -18,6 +18,7 @@
28236  #include <linux/highmem.h>
28237  #include <linux/security.h>
28238  #include <linux/syscalls.h>
28239 +#include <linux/vs_memory.h>
28240  
28241  #include <asm/uaccess.h>
28242  #include <asm/cacheflush.h>
28243 @@ -212,7 +213,7 @@ static unsigned long move_vma(struct vm_
28244          * If this were a serious issue, we'd add a flag to do_munmap().
28245          */
28246         hiwater_vm = mm->hiwater_vm;
28247 -       mm->total_vm += new_len >> PAGE_SHIFT;
28248 +       vx_vmpages_add(mm, new_len >> PAGE_SHIFT);
28249         vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
28250  
28251         if (do_munmap(mm, old_addr, old_len) < 0) {
28252 @@ -230,7 +231,7 @@ static unsigned long move_vma(struct vm_
28253         }
28254  
28255         if (vm_flags & VM_LOCKED) {
28256 -               mm->locked_vm += new_len >> PAGE_SHIFT;
28257 +               vx_vmlocked_add(mm, new_len >> PAGE_SHIFT);
28258                 if (new_len > old_len)
28259                         make_pages_present(new_addr + old_len,
28260                                            new_addr + new_len);
28261 @@ -337,6 +338,9 @@ unsigned long do_mremap(unsigned long ad
28262                 ret = -EAGAIN;
28263                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
28264                         goto out;
28265 +               if (!vx_vmlocked_avail(current->mm,
28266 +                       (new_len - old_len) >> PAGE_SHIFT))
28267 +                       goto out;
28268         }
28269         if (!may_expand_vm(mm, (new_len - old_len) >> PAGE_SHIFT)) {
28270                 ret = -ENOMEM;
28271 @@ -365,10 +369,10 @@ unsigned long do_mremap(unsigned long ad
28272                         vma_adjust(vma, vma->vm_start,
28273                                 addr + new_len, vma->vm_pgoff, NULL);
28274  
28275 -                       mm->total_vm += pages;
28276 +                       vx_vmpages_add(mm, pages);
28277                         vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages);
28278                         if (vma->vm_flags & VM_LOCKED) {
28279 -                               mm->locked_vm += pages;
28280 +                               vx_vmlocked_add(mm, pages);
28281                                 make_pages_present(addr + old_len,
28282                                                    addr + new_len);
28283                         }
28284 diff -Nurp linux-2.6.22.15/mm/nommu.c linux-2.6.22.15-vs2.3.0.29.1/mm/nommu.c
28285 --- linux-2.6.22.15/mm/nommu.c  2007-07-21 18:00:25.000000000 -0400
28286 +++ linux-2.6.22.15-vs2.3.0.29.1/mm/nommu.c     2007-12-09 06:44:23.000000000 -0500
28287 @@ -936,7 +936,7 @@ unsigned long do_mmap_pgoff(struct file 
28288         realalloc += kobjsize(vma);
28289         askedalloc += sizeof(*vma);
28290  
28291 -       current->mm->total_vm += len >> PAGE_SHIFT;
28292 +       vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
28293  
28294         add_nommu_vma(vma);
28295  
28296 @@ -1061,7 +1061,7 @@ int do_munmap(struct mm_struct *mm, unsi
28297         kfree(vml);
28298  
28299         update_hiwater_vm(mm);
28300 -       mm->total_vm -= len >> PAGE_SHIFT;
28301 +       vx_vmpages_sub(mm, len >> PAGE_SHIFT);
28302  
28303  #ifdef DEBUG
28304         show_process_blocks();
28305 @@ -1093,7 +1093,7 @@ void exit_mmap(struct mm_struct * mm)
28306                 printk("Exit_mmap:\n");
28307  #endif
28308  
28309 -               mm->total_vm = 0;
28310 +               vx_vmpages_sub(mm, mm->total_vm);
28311  
28312                 while ((tmp = mm->context.vmlist)) {
28313                         mm->context.vmlist = tmp->next;
28314 diff -Nurp linux-2.6.22.15/mm/oom_kill.c linux-2.6.22.15-vs2.3.0.29.1/mm/oom_kill.c
28315 --- linux-2.6.22.15/mm/oom_kill.c       2007-07-21 18:00:25.000000000 -0400
28316 +++ linux-2.6.22.15-vs2.3.0.29.1/mm/oom_kill.c  2007-12-09 06:44:23.000000000 -0500
28317 @@ -24,6 +24,7 @@
28318  #include <linux/cpuset.h>
28319  #include <linux/module.h>
28320  #include <linux/notifier.h>
28321 +#include <linux/vs_memory.h>
28322  
28323  int sysctl_panic_on_oom;
28324  /* #define DEBUG */
28325 @@ -66,6 +67,12 @@ unsigned long badness(struct task_struct
28326         points = mm->total_vm;
28327  
28328         /*
28329 +        * add points for context badness
28330 +        */
28331 +
28332 +       points += vx_badness(p, mm);
28333 +
28334 +       /*
28335          * After this unlock we can no longer dereference local variable `mm'
28336          */
28337         task_unlock(p);
28338 @@ -156,8 +163,8 @@ unsigned long badness(struct task_struct
28339         }
28340  
28341  #ifdef DEBUG
28342 -       printk(KERN_DEBUG "OOMkill: task %d (%s) got %d points\n",
28343 -       p->pid, p->comm, points);
28344 +       printk(KERN_DEBUG "OOMkill: task %d:#%u (%s) got %d points\n",
28345 +               p->pid, p->xid, p->comm, points);
28346  #endif
28347         return points;
28348  }
28349 @@ -288,7 +295,8 @@ static void __oom_kill_task(struct task_
28350         }
28351  
28352         if (verbose)
28353 -               printk(KERN_ERR "Killed process %d (%s)\n", p->pid, p->comm);
28354 +               printk(KERN_ERR "Killed process %d:#%u (%s)\n",
28355 +                               p->pid, p->xid, p->comm);
28356  
28357         /*
28358          * We give our sacrificial lamb high priority and access to
28359 @@ -358,8 +366,8 @@ static int oom_kill_process(struct task_
28360                 return 0;
28361         }
28362  
28363 -       printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n",
28364 -                                       message, p->pid, p->comm, points);
28365 +       printk(KERN_ERR "%s: kill process %d:#%u (%s) score %li or a child\n",
28366 +                               message, p->pid, p->xid, p->comm, points);
28367  
28368         /* Try to kill a child first */
28369         list_for_each(tsk, &p->children) {
28370 diff -Nurp linux-2.6.22.15/mm/page_alloc.c linux-2.6.22.15-vs2.3.0.29.1/mm/page_alloc.c
28371 --- linux-2.6.22.15/mm/page_alloc.c     2007-07-21 18:00:25.000000000 -0400
28372 +++ linux-2.6.22.15-vs2.3.0.29.1/mm/page_alloc.c        2007-12-09 06:44:23.000000000 -0500
28373 @@ -41,6 +41,8 @@
28374  #include <linux/pfn.h>
28375  #include <linux/backing-dev.h>
28376  #include <linux/fault-inject.h>
28377 +#include <linux/vs_base.h>
28378 +#include <linux/vs_limit.h>
28379  
28380  #include <asm/tlbflush.h>
28381  #include <asm/div64.h>
28382 @@ -1488,6 +1490,9 @@ void si_meminfo(struct sysinfo *val)
28383         val->totalhigh = totalhigh_pages;
28384         val->freehigh = nr_free_highpages();
28385         val->mem_unit = PAGE_SIZE;
28386 +
28387 +       if (vx_flags(VXF_VIRT_MEM, 0))
28388 +               vx_vsi_meminfo(val);
28389  }
28390  
28391  EXPORT_SYMBOL(si_meminfo);
28392 @@ -1508,6 +1513,9 @@ void si_meminfo_node(struct sysinfo *val
28393         val->freehigh = 0;
28394  #endif
28395         val->mem_unit = PAGE_SIZE;
28396 +
28397 +       if (vx_flags(VXF_VIRT_MEM, 0))
28398 +               vx_vsi_meminfo(val);
28399  }
28400  #endif
28401  
28402 diff -Nurp linux-2.6.22.15/mm/rmap.c linux-2.6.22.15-vs2.3.0.29.1/mm/rmap.c
28403 --- linux-2.6.22.15/mm/rmap.c   2007-07-21 18:00:25.000000000 -0400
28404 +++ linux-2.6.22.15-vs2.3.0.29.1/mm/rmap.c      2007-12-09 06:44:23.000000000 -0500
28405 @@ -48,6 +48,7 @@
28406  #include <linux/rcupdate.h>
28407  #include <linux/module.h>
28408  #include <linux/kallsyms.h>
28409 +#include <linux/vs_memory.h>
28410  
28411  #include <asm/tlbflush.h>
28412  
28413 diff -Nurp linux-2.6.22.15/mm/shmem.c linux-2.6.22.15-vs2.3.0.29.1/mm/shmem.c
28414 --- linux-2.6.22.15/mm/shmem.c  2007-12-09 06:43:53.000000000 -0500
28415 +++ linux-2.6.22.15-vs2.3.0.29.1/mm/shmem.c     2007-12-09 06:44:23.000000000 -0500
28416 @@ -55,7 +55,6 @@
28417  #include <asm/pgtable.h>
28418  
28419  /* This magic number is used in glibc for posix shared memory */
28420 -#define TMPFS_MAGIC    0x01021994
28421  
28422  #define ENTRIES_PER_PAGE (PAGE_CACHE_SIZE/sizeof(unsigned long))
28423  #define ENTRIES_PER_PAGEPAGE (ENTRIES_PER_PAGE*ENTRIES_PER_PAGE)
28424 @@ -1749,7 +1748,7 @@ static int shmem_statfs(struct dentry *d
28425  {
28426         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
28427  
28428 -       buf->f_type = TMPFS_MAGIC;
28429 +       buf->f_type = TMPFS_SUPER_MAGIC;
28430         buf->f_bsize = PAGE_CACHE_SIZE;
28431         buf->f_namelen = NAME_MAX;
28432         spin_lock(&sbinfo->stat_lock);
28433 @@ -2323,7 +2322,7 @@ static int shmem_fill_super(struct super
28434         sb->s_maxbytes = SHMEM_MAX_BYTES;
28435         sb->s_blocksize = PAGE_CACHE_SIZE;
28436         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
28437 -       sb->s_magic = TMPFS_MAGIC;
28438 +       sb->s_magic = TMPFS_SUPER_MAGIC;
28439         sb->s_op = &shmem_ops;
28440         sb->s_time_gran = 1;
28441  #ifdef CONFIG_TMPFS_POSIX_ACL
28442 diff -Nurp linux-2.6.22.15/mm/slab.c linux-2.6.22.15-vs2.3.0.29.1/mm/slab.c
28443 --- linux-2.6.22.15/mm/slab.c   2007-07-21 18:00:25.000000000 -0400
28444 +++ linux-2.6.22.15-vs2.3.0.29.1/mm/slab.c      2007-12-09 06:44:23.000000000 -0500
28445 @@ -510,6 +510,8 @@ struct kmem_cache {
28446  #define STATS_INC_FREEMISS(x)  do { } while (0)
28447  #endif
28448  
28449 +#include "slab_vs.h"
28450 +
28451  #if DEBUG
28452  
28453  /*
28454 @@ -3314,6 +3316,7 @@ retry:
28455  
28456         obj = slab_get_obj(cachep, slabp, nodeid);
28457         check_slabp(cachep, slabp);
28458 +       vx_slab_alloc(cachep, flags);
28459         l3->free_objects--;
28460         /* move slabp to correct slabp list: */
28461         list_del(&slabp->list);
28462 @@ -3386,6 +3389,7 @@ __cache_alloc_node(struct kmem_cache *ca
28463         /* ___cache_alloc_node can fall back to other nodes */
28464         ptr = ____cache_alloc_node(cachep, flags, nodeid);
28465    out:
28466 +       vx_slab_alloc(cachep, flags);
28467         local_irq_restore(save_flags);
28468         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
28469  
28470 @@ -3551,6 +3555,7 @@ static inline void __cache_free(struct k
28471  
28472         check_irq_off();
28473         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
28474 +       vx_slab_free(cachep);
28475  
28476         if (cache_free_alien(cachep, objp))
28477                 return;
28478 diff -Nurp linux-2.6.22.15/mm/slab_vs.h linux-2.6.22.15-vs2.3.0.29.1/mm/slab_vs.h
28479 --- linux-2.6.22.15/mm/slab_vs.h        1969-12-31 19:00:00.000000000 -0500
28480 +++ linux-2.6.22.15-vs2.3.0.29.1/mm/slab_vs.h   2007-12-09 06:44:23.000000000 -0500
28481 @@ -0,0 +1,27 @@
28482 +
28483 +#include <linux/vserver/context.h>
28484 +
28485 +#include <linux/vs_context.h>
28486 +
28487 +static inline
28488 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
28489 +{
28490 +       int what = gfp_zone(cachep->gfpflags);
28491 +
28492 +       if (!current->vx_info)
28493 +               return;
28494 +
28495 +       atomic_add(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
28496 +}
28497 +
28498 +static inline
28499 +void vx_slab_free(struct kmem_cache *cachep)
28500 +{
28501 +       int what = gfp_zone(cachep->gfpflags);
28502 +
28503 +       if (!current->vx_info)
28504 +               return;
28505 +
28506 +       atomic_sub(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
28507 +}
28508 +
28509 diff -Nurp linux-2.6.22.15/mm/swapfile.c linux-2.6.22.15-vs2.3.0.29.1/mm/swapfile.c
28510 --- linux-2.6.22.15/mm/swapfile.c       2007-07-21 18:00:25.000000000 -0400
28511 +++ linux-2.6.22.15-vs2.3.0.29.1/mm/swapfile.c  2007-12-09 06:44:23.000000000 -0500
28512 @@ -31,6 +31,8 @@
28513  #include <asm/pgtable.h>
28514  #include <asm/tlbflush.h>
28515  #include <linux/swapops.h>
28516 +#include <linux/vs_base.h>
28517 +#include <linux/vs_memory.h>
28518  
28519  DEFINE_SPINLOCK(swap_lock);
28520  unsigned int nr_swapfiles;
28521 @@ -1712,6 +1714,8 @@ void si_swapinfo(struct sysinfo *val)
28522         val->freeswap = nr_swap_pages + nr_to_be_unused;
28523         val->totalswap = total_swap_pages + nr_to_be_unused;
28524         spin_unlock(&swap_lock);
28525 +       if (vx_flags(VXF_VIRT_MEM, 0))
28526 +               vx_vsi_swapinfo(val);
28527  }
28528  
28529  /*
28530 diff -Nurp linux-2.6.22.15/net/core/dev.c linux-2.6.22.15-vs2.3.0.29.1/net/core/dev.c
28531 --- linux-2.6.22.15/net/core/dev.c      2007-09-05 01:07:59.000000000 -0400
28532 +++ linux-2.6.22.15-vs2.3.0.29.1/net/core/dev.c 2007-12-09 06:44:23.000000000 -0500
28533 @@ -117,6 +117,7 @@
28534  #include <linux/err.h>
28535  #include <linux/ctype.h>
28536  #include <linux/if_arp.h>
28537 +#include <linux/vs_inet.h>
28538  
28539  /*
28540   *     The list of packet types we will receive (as opposed to discard)
28541 @@ -2120,6 +2121,8 @@ static int dev_ifconf(char __user *arg)
28542  
28543         total = 0;
28544         for_each_netdev(dev) {
28545 +               if (!nx_dev_visible(current->nx_info, dev))
28546 +                       continue;
28547                 for (i = 0; i < NPROTO; i++) {
28548                         if (gifconf_list[i]) {
28549                                 int done;
28550 @@ -2184,6 +2187,9 @@ static void dev_seq_printf_stats(struct 
28551  {
28552         struct net_device_stats *stats = dev->get_stats(dev);
28553  
28554 +       if (!nx_dev_visible(current->nx_info, dev))
28555 +               return;
28556 +
28557         seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
28558                    "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
28559                    dev->name, stats->rx_bytes, stats->rx_packets,
28560 diff -Nurp linux-2.6.22.15/net/core/rtnetlink.c linux-2.6.22.15-vs2.3.0.29.1/net/core/rtnetlink.c
28561 --- linux-2.6.22.15/net/core/rtnetlink.c        2007-07-21 18:00:25.000000000 -0400
28562 +++ linux-2.6.22.15-vs2.3.0.29.1/net/core/rtnetlink.c   2007-12-09 06:44:23.000000000 -0500
28563 @@ -537,6 +537,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
28564  
28565         idx = 0;
28566         for_each_netdev(dev) {
28567 +               if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
28568 +                       continue;
28569                 if (idx < s_idx)
28570                         goto cont;
28571                 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
28572 @@ -797,6 +799,9 @@ void rtmsg_ifinfo(int type, struct net_d
28573         struct sk_buff *skb;
28574         int err = -ENOBUFS;
28575  
28576 +       if (!nx_dev_visible(current->nx_info, dev))
28577 +               return;
28578 +
28579         skb = nlmsg_new(if_nlmsg_size(), GFP_KERNEL);
28580         if (skb == NULL)
28581                 goto errout;
28582 diff -Nurp linux-2.6.22.15/net/core/sock.c linux-2.6.22.15-vs2.3.0.29.1/net/core/sock.c
28583 --- linux-2.6.22.15/net/core/sock.c     2007-07-21 18:00:25.000000000 -0400
28584 +++ linux-2.6.22.15-vs2.3.0.29.1/net/core/sock.c        2007-12-09 06:44:23.000000000 -0500
28585 @@ -125,6 +125,10 @@
28586  #include <linux/ipsec.h>
28587  
28588  #include <linux/filter.h>
28589 +#include <linux/vs_socket.h>
28590 +#include <linux/vs_limit.h>
28591 +#include <linux/vs_context.h>
28592 +#include <linux/vs_network.h>
28593  
28594  #ifdef CONFIG_INET
28595  #include <net/tcp.h>
28596 @@ -812,6 +816,9 @@ int sock_getsockopt(struct socket *sock,
28597         case SO_PEERSEC:
28598                 return security_socket_getpeersec_stream(sock, optval, optlen, len);
28599  
28600 +               case SO_PEERTAG:
28601 +                       return vx_socket_peer_tag(sock, level, optval, optlen, len);
28602 +
28603         default:
28604                 return -ENOPROTOOPT;
28605         }
28606 @@ -869,6 +876,8 @@ struct sock *sk_alloc(int family, gfp_t 
28607                         sk->sk_prot = sk->sk_prot_creator = prot;
28608                         sock_lock_init(sk);
28609                 }
28610 +               sock_vx_init(sk);
28611 +               sock_nx_init(sk);
28612  
28613                 if (security_sk_alloc(sk, family, priority))
28614                         goto out_free;
28615 @@ -907,6 +916,11 @@ void sk_free(struct sock *sk)
28616                        __FUNCTION__, atomic_read(&sk->sk_omem_alloc));
28617  
28618         security_sk_free(sk);
28619 +       vx_sock_dec(sk);
28620 +       clr_vx_info(&sk->sk_vx_info);
28621 +       sk->sk_xid = -1;
28622 +       clr_nx_info(&sk->sk_nx_info);
28623 +       sk->sk_nid = -1;
28624         if (sk->sk_prot_creator->slab != NULL)
28625                 kmem_cache_free(sk->sk_prot_creator->slab, sk);
28626         else
28627 @@ -924,6 +938,8 @@ struct sock *sk_clone(const struct sock 
28628                 sock_copy(newsk, sk);
28629  
28630                 /* SANITY */
28631 +               sock_vx_init(newsk);
28632 +               sock_nx_init(newsk);
28633                 sk_node_init(&newsk->sk_node);
28634                 sock_lock_init(newsk);
28635                 bh_lock_sock(newsk);
28636 @@ -969,6 +985,12 @@ struct sock *sk_clone(const struct sock 
28637                 newsk->sk_priority = 0;
28638                 atomic_set(&newsk->sk_refcnt, 2);
28639  
28640 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
28641 +               newsk->sk_xid = sk->sk_xid;
28642 +               vx_sock_inc(newsk);
28643 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
28644 +               newsk->sk_nid = sk->sk_nid;
28645 +
28646                 /*
28647                  * Increment the counter in the same struct proto as the master
28648                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
28649 @@ -1551,6 +1573,11 @@ void sock_init_data(struct socket *sock,
28650  
28651         sk->sk_stamp = ktime_set(-1L, -1L);
28652  
28653 +       set_vx_info(&sk->sk_vx_info, current->vx_info);
28654 +       sk->sk_xid = vx_current_xid();
28655 +       vx_sock_inc(sk);
28656 +       set_nx_info(&sk->sk_nx_info, current->nx_info);
28657 +       sk->sk_nid = nx_current_nid();
28658         atomic_set(&sk->sk_refcnt, 1);
28659  }
28660  
28661 diff -Nurp linux-2.6.22.15/net/ipv4/af_inet.c linux-2.6.22.15-vs2.3.0.29.1/net/ipv4/af_inet.c
28662 --- linux-2.6.22.15/net/ipv4/af_inet.c  2007-09-05 01:07:59.000000000 -0400
28663 +++ linux-2.6.22.15-vs2.3.0.29.1/net/ipv4/af_inet.c     2007-12-09 06:44:23.000000000 -0500
28664 @@ -115,6 +115,7 @@
28665  #ifdef CONFIG_IP_MROUTE
28666  #include <linux/mroute.h>
28667  #endif
28668 +#include <linux/vs_limit.h>
28669  
28670  DEFINE_SNMP_STAT(struct linux_mib, net_statistics) __read_mostly;
28671  
28672 @@ -308,9 +309,12 @@ lookup_protocol:
28673         }
28674  
28675         err = -EPERM;
28676 +       if ((protocol == IPPROTO_ICMP) &&
28677 +               nx_capable(answer->capability, NXC_RAW_ICMP))
28678 +               goto override;
28679         if (answer->capability > 0 && !capable(answer->capability))
28680                 goto out_rcu_unlock;
28681 -
28682 +override:
28683         sock->ops = answer->ops;
28684         answer_prot = answer->prot;
28685         answer_no_check = answer->no_check;
28686 @@ -424,6 +428,7 @@ int inet_bind(struct socket *sock, struc
28687         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
28688         struct sock *sk = sock->sk;
28689         struct inet_sock *inet = inet_sk(sk);
28690 +       struct nx_v4_sock_addr nsa;
28691         unsigned short snum;
28692         int chk_addr_ret;
28693         int err;
28694 @@ -437,7 +442,11 @@ int inet_bind(struct socket *sock, struc
28695         if (addr_len < sizeof(struct sockaddr_in))
28696                 goto out;
28697  
28698 -       chk_addr_ret = inet_addr_type(addr->sin_addr.s_addr);
28699 +       err = v4_map_sock_addr(inet, addr, &nsa);
28700 +       if (err)
28701 +               goto out;
28702 +
28703 +       chk_addr_ret = inet_addr_type(nsa.saddr);
28704  
28705         /* Not specified by any standard per-se, however it breaks too
28706          * many applications when removed.  It is unfortunate since
28707 @@ -449,7 +458,7 @@ int inet_bind(struct socket *sock, struc
28708         err = -EADDRNOTAVAIL;
28709         if (!sysctl_ip_nonlocal_bind &&
28710             !inet->freebind &&
28711 -           addr->sin_addr.s_addr != INADDR_ANY &&
28712 +           nsa.saddr != INADDR_ANY &&
28713             chk_addr_ret != RTN_LOCAL &&
28714             chk_addr_ret != RTN_MULTICAST &&
28715             chk_addr_ret != RTN_BROADCAST)
28716 @@ -474,7 +483,7 @@ int inet_bind(struct socket *sock, struc
28717         if (sk->sk_state != TCP_CLOSE || inet->num)
28718                 goto out_release_sock;
28719  
28720 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
28721 +       v4_set_sock_addr(inet, &nsa);
28722         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
28723                 inet->saddr = 0;  /* Use device */
28724  
28725 @@ -667,11 +676,13 @@ int inet_getname(struct socket *sock, st
28726                      peer == 1))
28727                         return -ENOTCONN;
28728                 sin->sin_port = inet->dport;
28729 -               sin->sin_addr.s_addr = inet->daddr;
28730 +               sin->sin_addr.s_addr =
28731 +                       nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
28732         } else {
28733                 __be32 addr = inet->rcv_saddr;
28734                 if (!addr)
28735                         addr = inet->saddr;
28736 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
28737                 sin->sin_port = inet->sport;
28738                 sin->sin_addr.s_addr = addr;
28739         }
28740 diff -Nurp linux-2.6.22.15/net/ipv4/devinet.c linux-2.6.22.15-vs2.3.0.29.1/net/ipv4/devinet.c
28741 --- linux-2.6.22.15/net/ipv4/devinet.c  2007-09-29 08:11:49.000000000 -0400
28742 +++ linux-2.6.22.15-vs2.3.0.29.1/net/ipv4/devinet.c     2007-12-09 06:44:23.000000000 -0500
28743 @@ -427,6 +427,7 @@ struct in_device *inetdev_by_index(int i
28744         return in_dev;
28745  }
28746  
28747 +
28748  /* Called only from RTNL semaphored context. No locks. */
28749  
28750  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
28751 @@ -676,6 +677,8 @@ int devinet_ioctl(unsigned int cmd, void
28752                 *colon = ':';
28753  
28754         if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) {
28755 +               struct nx_info *nxi = current->nx_info;
28756 +
28757                 if (tryaddrmatch) {
28758                         /* Matthias Andree */
28759                         /* compare label and address (4.4BSD style) */
28760 @@ -684,6 +687,8 @@ int devinet_ioctl(unsigned int cmd, void
28761                            This is checked above. */
28762                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
28763                              ifap = &ifa->ifa_next) {
28764 +                               if (!nx_v4_ifa_visible(nxi, ifa))
28765 +                                       continue;
28766                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
28767                                     sin_orig.sin_addr.s_addr ==
28768                                                         ifa->ifa_address) {
28769 @@ -696,9 +701,12 @@ int devinet_ioctl(unsigned int cmd, void
28770                    comparing just the label */
28771                 if (!ifa) {
28772                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
28773 -                            ifap = &ifa->ifa_next)
28774 +                            ifap = &ifa->ifa_next) {
28775 +                               if (!nx_v4_ifa_visible(nxi, ifa))
28776 +                                       continue;
28777                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
28778                                         break;
28779 +                       }
28780                 }
28781         }
28782  
28783 @@ -849,6 +857,8 @@ static int inet_gifconf(struct net_devic
28784                 goto out;
28785  
28786         for (; ifa; ifa = ifa->ifa_next) {
28787 +               if (!nx_v4_ifa_visible(current->nx_info, ifa))
28788 +                       continue;
28789                 if (!buf) {
28790                         done += sizeof(ifr);
28791                         continue;
28792 @@ -1179,6 +1189,7 @@ static int inet_dump_ifaddr(struct sk_bu
28793         struct net_device *dev;
28794         struct in_device *in_dev;
28795         struct in_ifaddr *ifa;
28796 +       struct sock *sk = skb->sk;
28797         int s_ip_idx, s_idx = cb->args[0];
28798  
28799         s_ip_idx = ip_idx = cb->args[1];
28800 @@ -1193,6 +1204,8 @@ static int inet_dump_ifaddr(struct sk_bu
28801  
28802                 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
28803                      ifa = ifa->ifa_next, ip_idx++) {
28804 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
28805 +                               continue;
28806                         if (ip_idx < s_ip_idx)
28807                                 continue;
28808                         if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
28809 diff -Nurp linux-2.6.22.15/net/ipv4/fib_hash.c linux-2.6.22.15-vs2.3.0.29.1/net/ipv4/fib_hash.c
28810 --- linux-2.6.22.15/net/ipv4/fib_hash.c 2007-07-21 18:00:25.000000000 -0400
28811 +++ linux-2.6.22.15-vs2.3.0.29.1/net/ipv4/fib_hash.c    2007-12-09 06:44:23.000000000 -0500
28812 @@ -1012,7 +1012,7 @@ static int fib_seq_show(struct seq_file 
28813         prefix  = f->fn_key;
28814         mask    = FZ_MASK(iter->zone);
28815         flags   = fib_flag_trans(fa->fa_type, mask, fi);
28816 -       if (fi)
28817 +       if (fi && nx_dev_visible(current->nx_info, fi->fib_dev))
28818                 snprintf(bf, sizeof(bf),
28819                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u",
28820                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
28821 diff -Nurp linux-2.6.22.15/net/ipv4/inet_connection_sock.c linux-2.6.22.15-vs2.3.0.29.1/net/ipv4/inet_connection_sock.c
28822 --- linux-2.6.22.15/net/ipv4/inet_connection_sock.c     2007-07-21 18:00:25.000000000 -0400
28823 +++ linux-2.6.22.15-vs2.3.0.29.1/net/ipv4/inet_connection_sock.c        2007-12-09 06:44:23.000000000 -0500
28824 @@ -34,10 +34,40 @@ EXPORT_SYMBOL(inet_csk_timer_bug_msg);
28825   */
28826  int sysctl_local_port_range[2] = { 32768, 61000 };
28827  
28828 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
28829 +{
28830 +       __be32  sk1_rcv_saddr = inet_rcv_saddr(sk1),
28831 +               sk2_rcv_saddr = inet_rcv_saddr(sk2);
28832 +
28833 +       if (inet_v6_ipv6only(sk2))
28834 +               return 0;
28835 +
28836 +       if (sk1_rcv_saddr &&
28837 +           sk2_rcv_saddr &&
28838 +           sk1_rcv_saddr == sk2_rcv_saddr)
28839 +               return 1;
28840 +
28841 +       if (sk1_rcv_saddr &&
28842 +           !sk2_rcv_saddr &&
28843 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
28844 +               return 1;
28845 +
28846 +       if (sk2_rcv_saddr &&
28847 +           !sk1_rcv_saddr &&
28848 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
28849 +               return 1;
28850 +
28851 +       if (!sk1_rcv_saddr &&
28852 +           !sk2_rcv_saddr &&
28853 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
28854 +               return 1;
28855 +
28856 +       return 0;
28857 +}
28858 +
28859  int inet_csk_bind_conflict(const struct sock *sk,
28860                            const struct inet_bind_bucket *tb)
28861  {
28862 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
28863         struct sock *sk2;
28864         struct hlist_node *node;
28865         int reuse = sk->sk_reuse;
28866 @@ -50,9 +80,7 @@ int inet_csk_bind_conflict(const struct 
28867                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
28868                         if (!reuse || !sk2->sk_reuse ||
28869                             sk2->sk_state == TCP_LISTEN) {
28870 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
28871 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
28872 -                                   sk2_rcv_saddr == sk_rcv_saddr)
28873 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
28874                                         break;
28875                         }
28876                 }
28877 diff -Nurp linux-2.6.22.15/net/ipv4/inet_diag.c linux-2.6.22.15-vs2.3.0.29.1/net/ipv4/inet_diag.c
28878 --- linux-2.6.22.15/net/ipv4/inet_diag.c        2007-09-29 08:11:49.000000000 -0400
28879 +++ linux-2.6.22.15-vs2.3.0.29.1/net/ipv4/inet_diag.c   2007-12-09 06:44:23.000000000 -0500
28880 @@ -98,8 +98,8 @@ static int inet_csk_diag_fill(struct soc
28881  
28882         r->id.idiag_sport = inet->sport;
28883         r->id.idiag_dport = inet->dport;
28884 -       r->id.idiag_src[0] = inet->rcv_saddr;
28885 -       r->id.idiag_dst[0] = inet->daddr;
28886 +       r->id.idiag_src[0] = nx_map_sock_lback(skb->sk->sk_nx_info, inet->rcv_saddr);
28887 +       r->id.idiag_dst[0] = nx_map_sock_lback(skb->sk->sk_nx_info, inet->daddr);
28888  
28889  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
28890         if (r->idiag_family == AF_INET6) {
28891 @@ -186,8 +186,8 @@ static int inet_twsk_diag_fill(struct in
28892         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
28893         r->id.idiag_sport     = tw->tw_sport;
28894         r->id.idiag_dport     = tw->tw_dport;
28895 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
28896 -       r->id.idiag_dst[0]    = tw->tw_daddr;
28897 +       r->id.idiag_src[0]    = nx_map_sock_lback(skb->sk->sk_nx_info, tw->tw_rcv_saddr);
28898 +       r->id.idiag_dst[0]    = nx_map_sock_lback(skb->sk->sk_nx_info, tw->tw_daddr);
28899         r->idiag_state        = tw->tw_substate;
28900         r->idiag_timer        = 3;
28901         r->idiag_expires      = (tmo * 1000 + HZ - 1) / HZ;
28902 @@ -239,6 +239,7 @@ static int inet_diag_get_exact(struct sk
28903         hashinfo = handler->idiag_hashinfo;
28904  
28905         if (req->idiag_family == AF_INET) {
28906 +               /* TODO: lback */
28907                 sk = inet_lookup(hashinfo, req->id.idiag_dst[0],
28908                                  req->id.idiag_dport, req->id.idiag_src[0],
28909                                  req->id.idiag_sport, req->id.idiag_if);
28910 @@ -478,6 +479,7 @@ static int inet_csk_diag_dump(struct soc
28911                 } else
28912  #endif
28913                 {
28914 +                       /* TODO: lback */
28915                         entry.saddr = &inet->rcv_saddr;
28916                         entry.daddr = &inet->daddr;
28917                 }
28918 @@ -514,6 +516,7 @@ static int inet_twsk_diag_dump(struct in
28919                 } else
28920  #endif
28921                 {
28922 +                       /* TODO: lback */
28923                         entry.saddr = &tw->tw_rcv_saddr;
28924                         entry.daddr = &tw->tw_daddr;
28925                 }
28926 @@ -560,8 +563,8 @@ static int inet_diag_fill_req(struct sk_
28927  
28928         r->id.idiag_sport = inet->sport;
28929         r->id.idiag_dport = ireq->rmt_port;
28930 -       r->id.idiag_src[0] = ireq->loc_addr;
28931 -       r->id.idiag_dst[0] = ireq->rmt_addr;
28932 +       r->id.idiag_src[0] = nx_map_sock_lback(skb->sk->sk_nx_info, ireq->loc_addr);
28933 +       r->id.idiag_dst[0] = nx_map_sock_lback(skb->sk->sk_nx_info, ireq->rmt_addr);
28934         r->idiag_expires = jiffies_to_msecs(tmo);
28935         r->idiag_rqueue = 0;
28936         r->idiag_wqueue = 0;
28937 @@ -631,6 +634,7 @@ static int inet_diag_dump_reqs(struct sk
28938                                 continue;
28939  
28940                         if (bc) {
28941 +                               /* TODO: lback */
28942                                 entry.saddr =
28943  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
28944                                         (entry.family == AF_INET6) ?
28945 @@ -697,6 +701,8 @@ static int inet_diag_dump(struct sk_buff
28946                         sk_for_each(sk, node, &hashinfo->listening_hash[i]) {
28947                                 struct inet_sock *inet = inet_sk(sk);
28948  
28949 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
28950 +                                       continue;
28951                                 if (num < s_num) {
28952                                         num++;
28953                                         continue;
28954 @@ -757,6 +763,8 @@ skip_listen_ht:
28955                 sk_for_each(sk, node, &head->chain) {
28956                         struct inet_sock *inet = inet_sk(sk);
28957  
28958 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
28959 +                               continue;
28960                         if (num < s_num)
28961                                 goto next_normal;
28962                         if (!(r->idiag_states & (1 << sk->sk_state)))
28963 @@ -781,6 +789,8 @@ next_normal:
28964                         inet_twsk_for_each(tw, node,
28965                                     &head->twchain) {
28966  
28967 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
28968 +                                       continue;
28969                                 if (num < s_num)
28970                                         goto next_dying;
28971                                 if (r->id.idiag_sport != tw->tw_sport &&
28972 diff -Nurp linux-2.6.22.15/net/ipv4/inet_hashtables.c linux-2.6.22.15-vs2.3.0.29.1/net/ipv4/inet_hashtables.c
28973 --- linux-2.6.22.15/net/ipv4/inet_hashtables.c  2007-07-21 17:58:55.000000000 -0400
28974 +++ linux-2.6.22.15-vs2.3.0.29.1/net/ipv4/inet_hashtables.c     2007-12-09 06:44:23.000000000 -0500
28975 @@ -140,11 +140,10 @@ static struct sock *inet_lookup_listener
28976                         const __be32 rcv_saddr = inet->rcv_saddr;
28977                         int score = sk->sk_family == PF_INET ? 1 : 0;
28978  
28979 -                       if (rcv_saddr) {
28980 -                               if (rcv_saddr != daddr)
28981 -                                       continue;
28982 +                       if (v4_inet_addr_match(sk->sk_nx_info, daddr, rcv_saddr))
28983                                 score += 2;
28984 -                       }
28985 +                       else
28986 +                               continue;
28987                         if (sk->sk_bound_dev_if) {
28988                                 if (sk->sk_bound_dev_if != dif)
28989                                         continue;
28990 @@ -175,7 +174,7 @@ struct sock *__inet_lookup_listener(stru
28991                 const struct inet_sock *inet = inet_sk((sk = __sk_head(head)));
28992  
28993                 if (inet->num == hnum && !sk->sk_node.next &&
28994 -                   (!inet->rcv_saddr || inet->rcv_saddr == daddr) &&
28995 +                   v4_inet_addr_match(sk->sk_nx_info, daddr, inet->rcv_saddr) &&
28996                     (sk->sk_family == PF_INET || !ipv6_only_sock(sk)) &&
28997                     !sk->sk_bound_dev_if)
28998                         goto sherry_cache;
28999 diff -Nurp linux-2.6.22.15/net/ipv4/raw.c linux-2.6.22.15-vs2.3.0.29.1/net/ipv4/raw.c
29000 --- linux-2.6.22.15/net/ipv4/raw.c      2007-07-21 18:00:27.000000000 -0400
29001 +++ linux-2.6.22.15-vs2.3.0.29.1/net/ipv4/raw.c 2007-12-09 06:44:23.000000000 -0500
29002 @@ -112,7 +112,7 @@ struct sock *__raw_v4_lookup(struct sock
29003  
29004                 if (inet->num == num                                    &&
29005                     !(inet->daddr && inet->daddr != raddr)              &&
29006 -                   !(inet->rcv_saddr && inet->rcv_saddr != laddr)      &&
29007 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
29008                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
29009                         goto found; /* gotcha */
29010         }
29011 @@ -314,6 +314,12 @@ static int raw_send_hdrinc(struct sock *
29012                 iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
29013         }
29014  
29015 +       err = -EPERM;
29016 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
29017 +               sk->sk_nx_info &&
29018 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
29019 +               goto error_free;
29020 +
29021         err = NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
29022                       dst_output);
29023         if (err > 0)
29024 @@ -325,6 +331,7 @@ out:
29025  
29026  error_fault:
29027         err = -EFAULT;
29028 +error_free:
29029         kfree_skb(skb);
29030  error:
29031         IP_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
29032 @@ -491,6 +498,12 @@ static int raw_sendmsg(struct kiocb *ioc
29033                 }
29034  
29035                 security_sk_classify_flow(sk, &fl);
29036 +               if (sk->sk_nx_info) {
29037 +                       err = ip_v4_find_src(sk->sk_nx_info, &rt, &fl);
29038 +
29039 +                       if (err)
29040 +                               goto done;
29041 +               }
29042                 err = ip_route_output_flow(&rt, &fl, sk, 1);
29043         }
29044         if (err)
29045 @@ -553,17 +566,19 @@ static int raw_bind(struct sock *sk, str
29046  {
29047         struct inet_sock *inet = inet_sk(sk);
29048         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
29049 +       struct nx_v4_sock_addr nsa = { 0 };
29050         int ret = -EINVAL;
29051         int chk_addr_ret;
29052  
29053         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
29054                 goto out;
29055 -       chk_addr_ret = inet_addr_type(addr->sin_addr.s_addr);
29056 +       v4_map_sock_addr(inet, addr, &nsa);
29057 +       chk_addr_ret = inet_addr_type(nsa.saddr);
29058         ret = -EADDRNOTAVAIL;
29059 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
29060 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
29061             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
29062                 goto out;
29063 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
29064 +       v4_set_sock_addr(inet, &nsa);
29065         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
29066                 inet->saddr = 0;  /* Use device */
29067         sk_dst_reset(sk);
29068 @@ -615,7 +630,8 @@ static int raw_recvmsg(struct kiocb *ioc
29069         /* Copy the address. */
29070         if (sin) {
29071                 sin->sin_family = AF_INET;
29072 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
29073 +               sin->sin_addr.s_addr =
29074 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
29075                 sin->sin_port = 0;
29076                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
29077         }
29078 @@ -795,7 +811,8 @@ static struct sock *raw_get_first(struct
29079                 struct hlist_node *node;
29080  
29081                 sk_for_each(sk, node, &raw_v4_htable[state->bucket])
29082 -                       if (sk->sk_family == PF_INET)
29083 +                       if (sk->sk_family == PF_INET &&
29084 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29085                                 goto found;
29086         }
29087         sk = NULL;
29088 @@ -811,7 +828,8 @@ static struct sock *raw_get_next(struct 
29089                 sk = sk_next(sk);
29090  try_again:
29091                 ;
29092 -       } while (sk && sk->sk_family != PF_INET);
29093 +       } while (sk && (sk->sk_family != PF_INET ||
29094 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
29095  
29096         if (!sk && ++state->bucket < RAWV4_HTABLE_SIZE) {
29097                 sk = sk_head(&raw_v4_htable[state->bucket]);
29098 @@ -863,7 +881,10 @@ static __inline__ char *get_raw_sock(str
29099  
29100         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
29101                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p",
29102 -               i, src, srcp, dest, destp, sp->sk_state,
29103 +               i,
29104 +               nx_map_sock_lback(current_nx_info(), src), srcp,
29105 +               nx_map_sock_lback(current_nx_info(), dest), destp,
29106 +               sp->sk_state,
29107                 atomic_read(&sp->sk_wmem_alloc),
29108                 atomic_read(&sp->sk_rmem_alloc),
29109                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
29110 diff -Nurp linux-2.6.22.15/net/ipv4/tcp.c linux-2.6.22.15-vs2.3.0.29.1/net/ipv4/tcp.c
29111 --- linux-2.6.22.15/net/ipv4/tcp.c      2007-09-05 01:07:59.000000000 -0400
29112 +++ linux-2.6.22.15-vs2.3.0.29.1/net/ipv4/tcp.c 2007-12-09 06:44:23.000000000 -0500
29113 @@ -258,6 +258,7 @@
29114  #include <linux/cache.h>
29115  #include <linux/err.h>
29116  #include <linux/crypto.h>
29117 +#include <linux/in.h>
29118  
29119  #include <net/icmp.h>
29120  #include <net/tcp.h>
29121 diff -Nurp linux-2.6.22.15/net/ipv4/tcp_ipv4.c linux-2.6.22.15-vs2.3.0.29.1/net/ipv4/tcp_ipv4.c
29122 --- linux-2.6.22.15/net/ipv4/tcp_ipv4.c 2007-12-09 06:43:41.000000000 -0500
29123 +++ linux-2.6.22.15-vs2.3.0.29.1/net/ipv4/tcp_ipv4.c    2007-12-09 06:44:23.000000000 -0500
29124 @@ -1974,6 +1974,12 @@ static void *listening_get_next(struct s
29125                 req = req->dl_next;
29126                 while (1) {
29127                         while (req) {
29128 +                               vxdprintk(VXD_CBIT(net, 6),
29129 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
29130 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
29131 +                               if (req->sk &&
29132 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
29133 +                                       continue;
29134                                 if (req->rsk_ops->family == st->family) {
29135                                         cur = req;
29136                                         goto out;
29137 @@ -1998,6 +2004,10 @@ get_req:
29138         }
29139  get_sk:
29140         sk_for_each_from(sk, node) {
29141 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
29142 +                       sk, sk->sk_nid, nx_current_nid());
29143 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29144 +                       continue;
29145                 if (sk->sk_family == st->family) {
29146                         cur = sk;
29147                         goto out;
29148 @@ -2049,18 +2059,26 @@ static void *established_get_first(struc
29149  
29150                 read_lock(&tcp_hashinfo.ehash[st->bucket].lock);
29151                 sk_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
29152 -                       if (sk->sk_family != st->family) {
29153 +                       vxdprintk(VXD_CBIT(net, 6),
29154 +                               "sk,egf: %p [#%d] (from %d)",
29155 +                               sk, sk->sk_nid, nx_current_nid());
29156 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29157 +                               continue;
29158 +                       if (sk->sk_family != st->family)
29159                                 continue;
29160 -                       }
29161                         rc = sk;
29162                         goto out;
29163                 }
29164                 st->state = TCP_SEQ_STATE_TIME_WAIT;
29165                 inet_twsk_for_each(tw, node,
29166                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
29167 -                       if (tw->tw_family != st->family) {
29168 +                       vxdprintk(VXD_CBIT(net, 6),
29169 +                               "tw: %p [#%d] (from %d)",
29170 +                               tw, tw->tw_nid, nx_current_nid());
29171 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
29172 +                               continue;
29173 +                       if (tw->tw_family != st->family)
29174                                 continue;
29175 -                       }
29176                         rc = tw;
29177                         goto out;
29178                 }
29179 @@ -2084,7 +2102,8 @@ static void *established_get_next(struct
29180                 tw = cur;
29181                 tw = tw_next(tw);
29182  get_tw:
29183 -               while (tw && tw->tw_family != st->family) {
29184 +               while (tw && (tw->tw_family != st->family ||
29185 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
29186                         tw = tw_next(tw);
29187                 }
29188                 if (tw) {
29189 @@ -2108,6 +2127,11 @@ get_tw:
29190                 sk = sk_next(sk);
29191  
29192         sk_for_each_from(sk, node) {
29193 +               vxdprintk(VXD_CBIT(net, 6),
29194 +                       "sk,egn: %p [#%d] (from %d)",
29195 +                       sk, sk->sk_nid, nx_current_nid());
29196 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29197 +                       continue;
29198                 if (sk->sk_family == st->family)
29199                         goto found;
29200         }
29201 @@ -2283,9 +2307,9 @@ static void get_openreq4(struct sock *sk
29202         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
29203                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p",
29204                 i,
29205 -               ireq->loc_addr,
29206 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
29207                 ntohs(inet_sk(sk)->sport),
29208 -               ireq->rmt_addr,
29209 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
29210                 ntohs(ireq->rmt_port),
29211                 TCP_SYN_RECV,
29212                 0, 0, /* could print option size, but that is af dependent. */
29213 @@ -2327,7 +2351,10 @@ static void get_tcp4_sock(struct sock *s
29214  
29215         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
29216                         "%08X %5d %8d %lu %d %p %u %u %u %u %d",
29217 -               i, src, srcp, dest, destp, sk->sk_state,
29218 +               i,
29219 +               nx_map_sock_lback(current_nx_info(), src), srcp,
29220 +               nx_map_sock_lback(current_nx_info(), dest), destp,
29221 +               sk->sk_state,
29222                 tp->write_seq - tp->snd_una,
29223                 sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog :
29224                                              (tp->rcv_nxt - tp->copied_seq),
29225 @@ -2362,7 +2389,10 @@ static void get_timewait4_sock(struct in
29226  
29227         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
29228                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p",
29229 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
29230 +               i,
29231 +               nx_map_sock_lback(current_nx_info(), src), srcp,
29232 +               nx_map_sock_lback(current_nx_info(), dest), destp,
29233 +               tw->tw_substate, 0, 0,
29234                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
29235                 atomic_read(&tw->tw_refcnt), tw);
29236  }
29237 diff -Nurp linux-2.6.22.15/net/ipv4/tcp_minisocks.c linux-2.6.22.15-vs2.3.0.29.1/net/ipv4/tcp_minisocks.c
29238 --- linux-2.6.22.15/net/ipv4/tcp_minisocks.c    2007-07-21 18:00:27.000000000 -0400
29239 +++ linux-2.6.22.15-vs2.3.0.29.1/net/ipv4/tcp_minisocks.c       2007-12-09 06:44:23.000000000 -0500
29240 @@ -28,6 +28,10 @@
29241  #include <net/inet_common.h>
29242  #include <net/xfrm.h>
29243  
29244 +#include <linux/vs_limit.h>
29245 +#include <linux/vs_socket.h>
29246 +#include <linux/vs_context.h>
29247 +
29248  #ifdef CONFIG_SYSCTL
29249  #define SYNC_INIT 0 /* let the user enable it */
29250  #else
29251 @@ -293,6 +297,11 @@ void tcp_time_wait(struct sock *sk, int 
29252                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
29253                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
29254  
29255 +               tw->tw_xid              = sk->sk_xid;
29256 +               tw->tw_vx_info          = NULL;
29257 +               tw->tw_nid              = sk->sk_nid;
29258 +               tw->tw_nx_info          = NULL;
29259 +
29260  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
29261                 if (tw->tw_family == PF_INET6) {
29262                         struct ipv6_pinfo *np = inet6_sk(sk);
29263 diff -Nurp linux-2.6.22.15/net/ipv4/udp.c linux-2.6.22.15-vs2.3.0.29.1/net/ipv4/udp.c
29264 --- linux-2.6.22.15/net/ipv4/udp.c      2007-07-21 18:00:27.000000000 -0400
29265 +++ linux-2.6.22.15-vs2.3.0.29.1/net/ipv4/udp.c 2007-12-09 06:44:23.000000000 -0500
29266 @@ -219,14 +219,7 @@ int udp_get_port(struct sock *sk, unsign
29267         return  __udp_lib_get_port(sk, snum, udp_hash, &udp_port_rover, scmp);
29268  }
29269  
29270 -int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
29271 -{
29272 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
29273 -
29274 -       return  ( !ipv6_only_sock(sk2)  &&
29275 -                 (!inet1->rcv_saddr || !inet2->rcv_saddr ||
29276 -                  inet1->rcv_saddr == inet2->rcv_saddr      ));
29277 -}
29278 +extern int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2);
29279  
29280  static inline int udp_v4_get_port(struct sock *sk, unsigned short snum)
29281  {
29282 @@ -246,15 +239,22 @@ static struct sock *__udp4_lib_lookup(__
29283         int badness = -1;
29284  
29285         read_lock(&udp_hash_lock);
29286 +
29287         sk_for_each(sk, node, &udptable[hnum & (UDP_HTABLE_SIZE - 1)]) {
29288                 struct inet_sock *inet = inet_sk(sk);
29289  
29290                 if (sk->sk_hash == hnum && !ipv6_only_sock(sk)) {
29291                         int score = (sk->sk_family == PF_INET ? 1 : 0);
29292 +
29293                         if (inet->rcv_saddr) {
29294                                 if (inet->rcv_saddr != daddr)
29295                                         continue;
29296                                 score+=2;
29297 +                       } else {
29298 +                               /* block non nx_info ips */
29299 +                               if (!v4_addr_in_nx_info(sk->sk_nx_info,
29300 +                                       daddr, NXA_MASK_BIND))
29301 +                                       continue;
29302                         }
29303                         if (inet->daddr) {
29304                                 if (inet->daddr != saddr)
29305 @@ -280,6 +280,7 @@ static struct sock *__udp4_lib_lookup(__
29306                         }
29307                 }
29308         }
29309 +
29310         if (result)
29311                 sock_hold(result);
29312         read_unlock(&udp_hash_lock);
29313 @@ -301,7 +302,7 @@ static inline struct sock *udp_v4_mcast_
29314                 if (s->sk_hash != hnum                                  ||
29315                     (inet->daddr && inet->daddr != rmt_addr)            ||
29316                     (inet->dport != rmt_port && inet->dport)            ||
29317 -                   (inet->rcv_saddr && inet->rcv_saddr != loc_addr)    ||
29318 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
29319                     ipv6_only_sock(s)                                   ||
29320                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
29321                         continue;
29322 @@ -631,7 +632,14 @@ int udp_sendmsg(struct kiocb *iocb, stru
29323                                     .uli_u = { .ports =
29324                                                { .sport = inet->sport,
29325                                                  .dport = dport } } };
29326 +               struct nx_info *nxi = sk->sk_nx_info;
29327 +
29328                 security_sk_classify_flow(sk, &fl);
29329 +
29330 +               err = ip_v4_find_src(nxi, &rt, &fl);
29331 +               if (err)
29332 +                       goto out;
29333 +
29334                 err = ip_route_output_flow(&rt, &fl, sk, 1);
29335                 if (err) {
29336                         if (err == -ENETUNREACH)
29337 @@ -871,7 +879,8 @@ try_again:
29338         {
29339                 sin->sin_family = AF_INET;
29340                 sin->sin_port = udp_hdr(skb)->source;
29341 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
29342 +               sin->sin_addr.s_addr = nx_map_sock_lback(
29343 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
29344                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
29345         }
29346         if (inet->cmsg_flags)
29347 @@ -1551,7 +1560,8 @@ static struct sock *udp_get_first(struct
29348         for (state->bucket = 0; state->bucket < UDP_HTABLE_SIZE; ++state->bucket) {
29349                 struct hlist_node *node;
29350                 sk_for_each(sk, node, state->hashtable + state->bucket) {
29351 -                       if (sk->sk_family == state->family)
29352 +                       if (sk->sk_family == state->family &&
29353 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29354                                 goto found;
29355                 }
29356         }
29357 @@ -1568,7 +1578,8 @@ static struct sock *udp_get_next(struct 
29358                 sk = sk_next(sk);
29359  try_again:
29360                 ;
29361 -       } while (sk && sk->sk_family != state->family);
29362 +       } while (sk && (sk->sk_family != state->family ||
29363 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
29364  
29365         if (!sk && ++state->bucket < UDP_HTABLE_SIZE) {
29366                 sk = sk_head(state->hashtable + state->bucket);
29367 @@ -1681,7 +1692,10 @@ static void udp4_format_sock(struct sock
29368  
29369         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
29370                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p",
29371 -               bucket, src, srcp, dest, destp, sp->sk_state,
29372 +               bucket,
29373 +               nx_map_sock_lback(current_nx_info(), src), srcp,
29374 +               nx_map_sock_lback(current_nx_info(), dest), destp,
29375 +               sp->sk_state,
29376                 atomic_read(&sp->sk_wmem_alloc),
29377                 atomic_read(&sp->sk_rmem_alloc),
29378                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
29379 diff -Nurp linux-2.6.22.15/net/ipv6/addrconf.c linux-2.6.22.15-vs2.3.0.29.1/net/ipv6/addrconf.c
29380 --- linux-2.6.22.15/net/ipv6/addrconf.c 2007-12-09 06:43:41.000000000 -0500
29381 +++ linux-2.6.22.15-vs2.3.0.29.1/net/ipv6/addrconf.c    2007-12-09 06:44:23.000000000 -0500
29382 @@ -86,6 +86,7 @@
29383  
29384  #include <linux/proc_fs.h>
29385  #include <linux/seq_file.h>
29386 +#include <linux/vs_inet6.h>
29387  
29388  /* Set to 3 to get tracing... */
29389  #define ACONF_DEBUG 2
29390 @@ -904,7 +905,8 @@ static inline int ipv6_saddr_label(const
29391  }
29392  
29393  int ipv6_dev_get_saddr(struct net_device *daddr_dev,
29394 -                      struct in6_addr *daddr, struct in6_addr *saddr)
29395 +                      struct in6_addr *daddr, struct in6_addr *saddr,
29396 +                      struct nx_info *nxi)
29397  {
29398         struct ipv6_saddr_score hiscore;
29399         struct inet6_ifaddr *ifa_result = NULL;
29400 @@ -949,6 +951,10 @@ int ipv6_dev_get_saddr(struct net_device
29401  
29402                         score.addr_type = __ipv6_addr_type(&ifa->addr);
29403  
29404 +                       /* Use only addresses assigned to the context */
29405 +                       if (!v6_ifa_in_nx_info(ifa, nxi))
29406 +                               continue;
29407 +
29408                         /* Rule 0:
29409                          * - Tentative Address (RFC2462 section 5.4)
29410                          *  - A tentative address is not considered
29411 @@ -1162,9 +1168,10 @@ record_it:
29412  
29413  
29414  int ipv6_get_saddr(struct dst_entry *dst,
29415 -                  struct in6_addr *daddr, struct in6_addr *saddr)
29416 +                  struct in6_addr *daddr, struct in6_addr *saddr,
29417 +                  struct nx_info *nxi)
29418  {
29419 -       return ipv6_dev_get_saddr(dst ? ip6_dst_idev(dst)->dev : NULL, daddr, saddr);
29420 +       return ipv6_dev_get_saddr(dst ? ip6_dst_idev(dst)->dev : NULL, daddr, saddr, nxi);
29421  }
29422  
29423  EXPORT_SYMBOL(ipv6_get_saddr);
29424 @@ -1260,35 +1267,46 @@ struct inet6_ifaddr * ipv6_get_ifaddr(st
29425         return ifp;
29426  }
29427  
29428 +extern int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2);
29429 +
29430  int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
29431  {
29432         const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
29433         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
29434 -       __be32 sk_rcv_saddr = inet_sk(sk)->rcv_saddr;
29435         __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
29436         int sk_ipv6only = ipv6_only_sock(sk);
29437         int sk2_ipv6only = inet_v6_ipv6only(sk2);
29438         int addr_type = ipv6_addr_type(sk_rcv_saddr6);
29439         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
29440  
29441 -       if (!sk2_rcv_saddr && !sk_ipv6only)
29442 +       /* FIXME: needs handling for v4 ANY */
29443 +       if (!sk2_rcv_saddr && !sk_ipv6only && !sk2->sk_nx_info)
29444                 return 1;
29445  
29446         if (addr_type2 == IPV6_ADDR_ANY &&
29447 -           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
29448 +           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED) &&
29449 +           v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1))
29450                 return 1;
29451  
29452         if (addr_type == IPV6_ADDR_ANY &&
29453 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
29454 +           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED) &&
29455 +           (sk2_rcv_saddr6 && v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1)))
29456 +               return 1;
29457 +
29458 +       if (addr_type == IPV6_ADDR_ANY &&
29459 +           addr_type2 == IPV6_ADDR_ANY &&
29460 +           nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info))
29461                 return 1;
29462  
29463         if (sk2_rcv_saddr6 &&
29464 +           addr_type != IPV6_ADDR_ANY &&
29465 +           addr_type != IPV6_ADDR_ANY &&
29466             ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
29467                 return 1;
29468  
29469         if (addr_type == IPV6_ADDR_MAPPED &&
29470             !sk2_ipv6only &&
29471 -           (!sk2_rcv_saddr || !sk_rcv_saddr || sk_rcv_saddr == sk2_rcv_saddr))
29472 +           ipv4_rcv_saddr_equal(sk, sk2))
29473                 return 1;
29474  
29475         return 0;
29476 @@ -2779,7 +2797,10 @@ static void if6_seq_stop(struct seq_file
29477  static int if6_seq_show(struct seq_file *seq, void *v)
29478  {
29479         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
29480 -       seq_printf(seq,
29481 +
29482 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
29483 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
29484 +               seq_printf(seq,
29485                    NIP6_SEQFMT " %02x %02x %02x %02x %8s\n",
29486                    NIP6(ifp->addr),
29487                    ifp->idev->dev->ifindex,
29488 @@ -3261,6 +3282,11 @@ static int inet6_dump_addr(struct sk_buf
29489         struct inet6_ifaddr *ifa;
29490         struct ifmcaddr6 *ifmca;
29491         struct ifacaddr6 *ifaca;
29492 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
29493 +
29494 +       /* disable ipv6 on non v6 guests */
29495 +       if (nxi && !nx_info_has_v6(nxi))
29496 +               return skb->len;
29497  
29498         s_idx = cb->args[0];
29499         s_ip_idx = ip_idx = cb->args[1];
29500 @@ -3282,6 +3308,8 @@ static int inet6_dump_addr(struct sk_buf
29501                              ifa = ifa->if_next, ip_idx++) {
29502                                 if (ip_idx < s_ip_idx)
29503                                         continue;
29504 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
29505 +                                       continue;
29506                                 if ((err = inet6_fill_ifaddr(skb, ifa,
29507                                     NETLINK_CB(cb->skb).pid,
29508                                     cb->nlh->nlmsg_seq, RTM_NEWADDR,
29509 @@ -3295,6 +3323,8 @@ static int inet6_dump_addr(struct sk_buf
29510                              ifmca = ifmca->next, ip_idx++) {
29511                                 if (ip_idx < s_ip_idx)
29512                                         continue;
29513 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
29514 +                                       continue;
29515                                 if ((err = inet6_fill_ifmcaddr(skb, ifmca,
29516                                     NETLINK_CB(cb->skb).pid,
29517                                     cb->nlh->nlmsg_seq, RTM_GETMULTICAST,
29518 @@ -3308,6 +3338,8 @@ static int inet6_dump_addr(struct sk_buf
29519                              ifaca = ifaca->aca_next, ip_idx++) {
29520                                 if (ip_idx < s_ip_idx)
29521                                         continue;
29522 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
29523 +                                       continue;
29524                                 if ((err = inet6_fill_ifacaddr(skb, ifaca,
29525                                     NETLINK_CB(cb->skb).pid,
29526                                     cb->nlh->nlmsg_seq, RTM_GETANYCAST,
29527 @@ -3584,12 +3616,19 @@ static int inet6_dump_ifinfo(struct sk_b
29528         int s_idx = cb->args[0];
29529         struct net_device *dev;
29530         struct inet6_dev *idev;
29531 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
29532 +
29533 +       /* FIXME: maybe disable ipv6 on non v6 guests?
29534 +       if (skb->sk && skb->sk->sk_vx_info)
29535 +               return skb->len;        */
29536  
29537         read_lock(&dev_base_lock);
29538         idx = 0;
29539         for_each_netdev(dev) {
29540                 if (idx < s_idx)
29541                         goto cont;
29542 +               if (!v6_dev_in_nx_info(dev, nxi))
29543 +                       goto cont;
29544                 if ((idev = in6_dev_get(dev)) == NULL)
29545                         goto cont;
29546                 err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
29547 diff -Nurp linux-2.6.22.15/net/ipv6/af_inet6.c linux-2.6.22.15-vs2.3.0.29.1/net/ipv6/af_inet6.c
29548 --- linux-2.6.22.15/net/ipv6/af_inet6.c 2007-09-05 01:08:00.000000000 -0400
29549 +++ linux-2.6.22.15-vs2.3.0.29.1/net/ipv6/af_inet6.c    2007-12-09 06:44:23.000000000 -0500
29550 @@ -43,6 +43,7 @@
29551  #include <linux/netdevice.h>
29552  #include <linux/icmpv6.h>
29553  #include <linux/netfilter_ipv6.h>
29554 +#include <linux/vs_inet6.h>
29555  
29556  #include <net/ip.h>
29557  #include <net/ipv6.h>
29558 @@ -150,9 +151,12 @@ lookup_protocol:
29559         }
29560  
29561         err = -EPERM;
29562 +       if ((protocol == IPPROTO_ICMPV6) &&
29563 +               nx_capable(answer->capability, NXC_RAW_ICMP))
29564 +               goto override;
29565         if (answer->capability > 0 && !capable(answer->capability))
29566                 goto out_rcu_unlock;
29567 -
29568 +override:
29569         sock->ops = answer->ops;
29570         answer_prot = answer->prot;
29571         answer_no_check = answer->no_check;
29572 @@ -250,6 +254,7 @@ int inet6_bind(struct socket *sock, stru
29573         struct sock *sk = sock->sk;
29574         struct inet_sock *inet = inet_sk(sk);
29575         struct ipv6_pinfo *np = inet6_sk(sk);
29576 +       struct nx_v6_sock_addr nsa;
29577         __be32 v4addr = 0;
29578         unsigned short snum;
29579         int addr_type = 0;
29580 @@ -261,6 +266,11 @@ int inet6_bind(struct socket *sock, stru
29581  
29582         if (addr_len < SIN6_LEN_RFC2133)
29583                 return -EINVAL;
29584 +
29585 +       err = v6_map_sock_addr(inet, addr, &nsa);
29586 +       if (err)
29587 +               return err;
29588 +
29589         addr_type = ipv6_addr_type(&addr->sin6_addr);
29590         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
29591                 return -EINVAL;
29592 @@ -284,6 +294,10 @@ int inet6_bind(struct socket *sock, stru
29593                         err = -EADDRNOTAVAIL;
29594                         goto out;
29595                 }
29596 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
29597 +                       err = -EADDRNOTAVAIL;
29598 +                       goto out;
29599 +               }
29600         } else {
29601                 if (addr_type != IPV6_ADDR_ANY) {
29602                         struct net_device *dev = NULL;
29603 @@ -309,6 +323,11 @@ int inet6_bind(struct socket *sock, stru
29604                                 }
29605                         }
29606  
29607 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
29608 +                               err = -EADDRNOTAVAIL;
29609 +                               goto out;
29610 +                       }
29611 +
29612                         /* ipv4 addr of the socket is invalid.  Only the
29613                          * unspecified and mapped address have a v4 equivalent.
29614                          */
29615 @@ -326,6 +345,8 @@ int inet6_bind(struct socket *sock, stru
29616                 }
29617         }
29618  
29619 +       v6_set_sock_addr(inet, &nsa);
29620 +
29621         inet->rcv_saddr = v4addr;
29622         inet->saddr = v4addr;
29623  
29624 @@ -420,9 +441,11 @@ int inet6_getname(struct socket *sock, s
29625                         return -ENOTCONN;
29626                 sin->sin6_port = inet->dport;
29627                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
29628 +               /* FIXME: remap lback? */
29629                 if (np->sndflow)
29630                         sin->sin6_flowinfo = np->flow_label;
29631         } else {
29632 +               /* FIXME: remap lback? */
29633                 if (ipv6_addr_any(&np->rcv_saddr))
29634                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
29635                 else
29636 diff -Nurp linux-2.6.22.15/net/ipv6/fib6_rules.c linux-2.6.22.15-vs2.3.0.29.1/net/ipv6/fib6_rules.c
29637 --- linux-2.6.22.15/net/ipv6/fib6_rules.c       2007-07-21 18:00:27.000000000 -0400
29638 +++ linux-2.6.22.15-vs2.3.0.29.1/net/ipv6/fib6_rules.c  2007-12-09 06:44:23.000000000 -0500
29639 @@ -107,7 +107,7 @@ static int fib6_rule_action(struct fib_r
29640                     r->src.plen && !(flags & RT6_LOOKUP_F_HAS_SADDR)) {
29641                         struct in6_addr saddr;
29642                         if (ipv6_get_saddr(&rt->u.dst, &flp->fl6_dst,
29643 -                                          &saddr))
29644 +                                          &saddr, NULL))
29645                                 goto again;
29646                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
29647                                                r->src.plen))
29648 diff -Nurp linux-2.6.22.15/net/ipv6/inet6_hashtables.c linux-2.6.22.15-vs2.3.0.29.1/net/ipv6/inet6_hashtables.c
29649 --- linux-2.6.22.15/net/ipv6/inet6_hashtables.c 2007-07-21 17:58:56.000000000 -0400
29650 +++ linux-2.6.22.15-vs2.3.0.29.1/net/ipv6/inet6_hashtables.c    2007-12-09 06:44:23.000000000 -0500
29651 @@ -16,6 +16,7 @@
29652  
29653  #include <linux/module.h>
29654  #include <linux/random.h>
29655 +#include <linux/vs_inet6.h>
29656  
29657  #include <net/inet_connection_sock.h>
29658  #include <net/inet_hashtables.h>
29659 @@ -121,6 +122,9 @@ struct sock *inet6_lookup_listener(struc
29660                                 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
29661                                         continue;
29662                                 score++;
29663 +                       } else {
29664 +                               if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
29665 +                                       continue;
29666                         }
29667                         if (sk->sk_bound_dev_if) {
29668                                 if (sk->sk_bound_dev_if != dif)
29669 diff -Nurp linux-2.6.22.15/net/ipv6/ip6_output.c linux-2.6.22.15-vs2.3.0.29.1/net/ipv6/ip6_output.c
29670 --- linux-2.6.22.15/net/ipv6/ip6_output.c       2007-09-29 08:11:49.000000000 -0400
29671 +++ linux-2.6.22.15-vs2.3.0.29.1/net/ipv6/ip6_output.c  2007-12-09 06:44:23.000000000 -0500
29672 @@ -884,7 +884,7 @@ static int ip6_dst_lookup_tail(struct so
29673                 goto out_err_release;
29674  
29675         if (ipv6_addr_any(&fl->fl6_src)) {
29676 -               err = ipv6_get_saddr(*dst, &fl->fl6_dst, &fl->fl6_src);
29677 +               err = ipv6_get_saddr(*dst, &fl->fl6_dst, &fl->fl6_src, sk->sk_nx_info);
29678                 if (err)
29679                         goto out_err_release;
29680         }
29681 diff -Nurp linux-2.6.22.15/net/ipv6/Kconfig linux-2.6.22.15-vs2.3.0.29.1/net/ipv6/Kconfig
29682 --- linux-2.6.22.15/net/ipv6/Kconfig    2007-07-21 18:00:27.000000000 -0400
29683 +++ linux-2.6.22.15-vs2.3.0.29.1/net/ipv6/Kconfig       2007-12-09 06:44:23.000000000 -0500
29684 @@ -4,8 +4,8 @@
29685  
29686  #   IPv6 as module will cause a CRASH if you try to unload it
29687  config IPV6
29688 -       tristate "The IPv6 protocol"
29689 -       default m
29690 +       bool "The IPv6 protocol"
29691 +       default n
29692         ---help---
29693           This is complemental support for the IP version 6.
29694           You will still be able to do traditional IPv4 networking as well.
29695 diff -Nurp linux-2.6.22.15/net/ipv6/ndisc.c linux-2.6.22.15-vs2.3.0.29.1/net/ipv6/ndisc.c
29696 --- linux-2.6.22.15/net/ipv6/ndisc.c    2007-12-09 06:43:41.000000000 -0500
29697 +++ linux-2.6.22.15-vs2.3.0.29.1/net/ipv6/ndisc.c       2007-12-09 06:44:23.000000000 -0500
29698 @@ -531,7 +531,7 @@ static void ndisc_send_na(struct net_dev
29699                         override = 0;
29700                 in6_ifa_put(ifp);
29701         } else {
29702 -               if (ipv6_dev_get_saddr(dev, daddr, &tmpaddr))
29703 +               if (ipv6_dev_get_saddr(dev, daddr, &tmpaddr, NULL))
29704                         return;
29705                 src_addr = &tmpaddr;
29706         }
29707 diff -Nurp linux-2.6.22.15/net/ipv6/route.c linux-2.6.22.15-vs2.3.0.29.1/net/ipv6/route.c
29708 --- linux-2.6.22.15/net/ipv6/route.c    2007-07-21 18:00:27.000000000 -0400
29709 +++ linux-2.6.22.15-vs2.3.0.29.1/net/ipv6/route.c       2007-12-09 06:44:23.000000000 -0500
29710 @@ -2182,7 +2182,7 @@ static int rt6_fill_node(struct sk_buff 
29711                 NLA_PUT_U32(skb, RTA_IIF, iif);
29712         else if (dst) {
29713                 struct in6_addr saddr_buf;
29714 -               if (ipv6_get_saddr(&rt->u.dst, dst, &saddr_buf) == 0)
29715 +               if (ipv6_get_saddr(&rt->u.dst, dst, &saddr_buf, skb->sk->sk_nx_info) == 0)
29716                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
29717         }
29718  
29719 diff -Nurp linux-2.6.22.15/net/ipv6/tcp_ipv6.c linux-2.6.22.15-vs2.3.0.29.1/net/ipv6/tcp_ipv6.c
29720 --- linux-2.6.22.15/net/ipv6/tcp_ipv6.c 2007-12-09 06:43:41.000000000 -0500
29721 +++ linux-2.6.22.15-vs2.3.0.29.1/net/ipv6/tcp_ipv6.c    2007-12-09 06:44:23.000000000 -0500
29722 @@ -68,6 +68,7 @@
29723  
29724  #include <linux/crypto.h>
29725  #include <linux/scatterlist.h>
29726 +#include <linux/vs_inet6.h>
29727  
29728  /* Socket used for sending RSTs and ACKs */
29729  static struct socket *tcp6_socket;
29730 @@ -160,8 +161,15 @@ static int tcp_v6_connect(struct sock *s
29731          *      connect() to INADDR_ANY means loopback (BSD'ism).
29732          */
29733  
29734 -       if(ipv6_addr_any(&usin->sin6_addr))
29735 -               usin->sin6_addr.s6_addr[15] = 0x1;
29736 +       if(ipv6_addr_any(&usin->sin6_addr)) {
29737 +               struct nx_info *nxi =  sk->sk_nx_info;
29738 +
29739 +               if (nxi && nx_info_has_v6(nxi))
29740 +                       /* FIXME: remap lback? */
29741 +                       usin->sin6_addr = nxi->v6.ip;
29742 +               else
29743 +                       usin->sin6_addr.s6_addr[15] = 0x1;
29744 +       }
29745  
29746         addr_type = ipv6_addr_type(&usin->sin6_addr);
29747  
29748 diff -Nurp linux-2.6.22.15/net/ipv6/udp.c linux-2.6.22.15-vs2.3.0.29.1/net/ipv6/udp.c
29749 --- linux-2.6.22.15/net/ipv6/udp.c      2007-07-21 18:00:27.000000000 -0400
29750 +++ linux-2.6.22.15-vs2.3.0.29.1/net/ipv6/udp.c 2007-12-09 06:44:23.000000000 -0500
29751 @@ -48,6 +48,7 @@
29752  
29753  #include <linux/proc_fs.h>
29754  #include <linux/seq_file.h>
29755 +#include <linux/vs_inet6.h>
29756  #include "udp_impl.h"
29757  
29758  DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6) __read_mostly;
29759 @@ -82,6 +83,10 @@ static struct sock *__udp6_lib_lookup(st
29760                                 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
29761                                         continue;
29762                                 score++;
29763 +                       } else {
29764 +                               /* block non nx_info ips */
29765 +                               if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
29766 +                                       continue;
29767                         }
29768                         if (!ipv6_addr_any(&np->daddr)) {
29769                                 if (!ipv6_addr_equal(&np->daddr, saddr))
29770 diff -Nurp linux-2.6.22.15/net/ipv6/xfrm6_policy.c linux-2.6.22.15-vs2.3.0.29.1/net/ipv6/xfrm6_policy.c
29771 --- linux-2.6.22.15/net/ipv6/xfrm6_policy.c     2007-07-21 18:00:27.000000000 -0400
29772 +++ linux-2.6.22.15-vs2.3.0.29.1/net/ipv6/xfrm6_policy.c        2007-12-09 06:44:23.000000000 -0500
29773 @@ -49,7 +49,7 @@ static int xfrm6_get_saddr(xfrm_address_
29774  
29775         if (!xfrm6_dst_lookup((struct xfrm_dst **)&rt, &fl_tunnel)) {
29776                 ipv6_get_saddr(&rt->u.dst, (struct in6_addr *)&daddr->a6,
29777 -                              (struct in6_addr *)&saddr->a6);
29778 +                              (struct in6_addr *)&saddr->a6, NULL);
29779                 dst_release(&rt->u.dst);
29780                 return 0;
29781         }
29782 diff -Nurp linux-2.6.22.15/net/netlink/af_netlink.c linux-2.6.22.15-vs2.3.0.29.1/net/netlink/af_netlink.c
29783 --- linux-2.6.22.15/net/netlink/af_netlink.c    2007-12-09 06:43:53.000000000 -0500
29784 +++ linux-2.6.22.15-vs2.3.0.29.1/net/netlink/af_netlink.c       2007-12-09 06:44:23.000000000 -0500
29785 @@ -56,6 +56,9 @@
29786  #include <linux/audit.h>
29787  #include <linux/selinux.h>
29788  #include <linux/mutex.h>
29789 +#include <linux/vs_context.h>
29790 +#include <linux/vs_network.h>
29791 +#include <linux/vs_limit.h>
29792  
29793  #include <net/sock.h>
29794  #include <net/scm.h>
29795 diff -Nurp linux-2.6.22.15/net/rxrpc/Kconfig linux-2.6.22.15-vs2.3.0.29.1/net/rxrpc/Kconfig
29796 --- linux-2.6.22.15/net/rxrpc/Kconfig   2007-07-21 18:00:27.000000000 -0400
29797 +++ linux-2.6.22.15-vs2.3.0.29.1/net/rxrpc/Kconfig      2007-12-09 06:45:27.000000000 -0500
29798 @@ -4,7 +4,7 @@
29799  
29800  config AF_RXRPC
29801         tristate "RxRPC session sockets"
29802 -       depends on INET && EXPERIMENTAL
29803 +       depends on INET && EXPERIMENTAL && !VSERVER_SECURITY
29804         select CRYPTO
29805         select KEYS
29806         help
29807 diff -Nurp linux-2.6.22.15/net/sctp/ipv6.c linux-2.6.22.15-vs2.3.0.29.1/net/sctp/ipv6.c
29808 --- linux-2.6.22.15/net/sctp/ipv6.c     2007-08-11 21:54:37.000000000 -0400
29809 +++ linux-2.6.22.15-vs2.3.0.29.1/net/sctp/ipv6.c        2007-12-09 06:44:23.000000000 -0500
29810 @@ -303,7 +303,7 @@ static void sctp_v6_get_saddr(struct sct
29811                           __FUNCTION__, asoc, dst, NIP6(daddr->v6.sin6_addr));
29812  
29813         if (!asoc) {
29814 -               ipv6_get_saddr(dst, &daddr->v6.sin6_addr,&saddr->v6.sin6_addr);
29815 +               ipv6_get_saddr(dst, &daddr->v6.sin6_addr,&saddr->v6.sin6_addr, asoc->base.sk->sk_nx_info);
29816                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: " NIP6_FMT "\n",
29817                                   NIP6(saddr->v6.sin6_addr));
29818                 return;
29819 diff -Nurp linux-2.6.22.15/net/socket.c linux-2.6.22.15-vs2.3.0.29.1/net/socket.c
29820 --- linux-2.6.22.15/net/socket.c        2007-12-09 06:43:53.000000000 -0500
29821 +++ linux-2.6.22.15-vs2.3.0.29.1/net/socket.c   2007-12-09 06:44:23.000000000 -0500
29822 @@ -92,6 +92,10 @@
29823  
29824  #include <net/sock.h>
29825  #include <linux/netfilter.h>
29826 +#include <linux/vs_base.h>
29827 +#include <linux/vs_socket.h>
29828 +#include <linux/vs_inet.h>
29829 +#include <linux/vs_inet6.h>
29830  
29831  static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
29832  static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
29833 @@ -543,7 +547,7 @@ static inline int __sock_sendmsg(struct 
29834                                  struct msghdr *msg, size_t size)
29835  {
29836         struct sock_iocb *si = kiocb_to_siocb(iocb);
29837 -       int err;
29838 +       int err, len;
29839  
29840         si->sock = sock;
29841         si->scm = NULL;
29842 @@ -554,7 +558,22 @@ static inline int __sock_sendmsg(struct 
29843         if (err)
29844                 return err;
29845  
29846 -       return sock->ops->sendmsg(iocb, sock, msg, size);
29847 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
29848 +       if (sock->sk) {
29849 +               if (len == size)
29850 +                       vx_sock_send(sock->sk, size);
29851 +               else
29852 +                       vx_sock_fail(sock->sk, size);
29853 +       }
29854 +       vxdprintk(VXD_CBIT(net, 7),
29855 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
29856 +               sock, sock->sk,
29857 +               (sock->sk)?sock->sk->sk_nx_info:0,
29858 +               (sock->sk)?sock->sk->sk_vx_info:0,
29859 +               (sock->sk)?sock->sk->sk_xid:0,
29860 +               (sock->sk)?sock->sk->sk_nid:0,
29861 +               (unsigned int)size, len);
29862 +       return len;
29863  }
29864  
29865  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
29866 @@ -623,7 +642,7 @@ EXPORT_SYMBOL_GPL(__sock_recv_timestamp)
29867  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
29868                                  struct msghdr *msg, size_t size, int flags)
29869  {
29870 -       int err;
29871 +       int err, len;
29872         struct sock_iocb *si = kiocb_to_siocb(iocb);
29873  
29874         si->sock = sock;
29875 @@ -636,7 +655,18 @@ static inline int __sock_recvmsg(struct 
29876         if (err)
29877                 return err;
29878  
29879 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
29880 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
29881 +       if ((len >= 0) && sock->sk)
29882 +               vx_sock_recv(sock->sk, len);
29883 +       vxdprintk(VXD_CBIT(net, 7),
29884 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
29885 +               sock, sock->sk,
29886 +               (sock->sk)?sock->sk->sk_nx_info:0,
29887 +               (sock->sk)?sock->sk->sk_vx_info:0,
29888 +               (sock->sk)?sock->sk->sk_xid:0,
29889 +               (sock->sk)?sock->sk->sk_nid:0,
29890 +               (unsigned int)size, len);
29891 +       return len;
29892  }
29893  
29894  int sock_recvmsg(struct socket *sock, struct msghdr *msg,
29895 @@ -1087,6 +1117,13 @@ static int __sock_create(int family, int
29896         if (type < 0 || type >= SOCK_MAX)
29897                 return -EINVAL;
29898  
29899 +       if (!nx_check(0, VS_ADMIN)) {
29900 +               if (family == PF_INET && !current_nx_info_has_v4())
29901 +                       return -EAFNOSUPPORT;
29902 +               if (family == PF_INET6 && !current_nx_info_has_v6())
29903 +                       return -EAFNOSUPPORT;
29904 +       }
29905 +
29906         /* Compatibility.
29907  
29908            This uglymoron is moved from INET layer to here to avoid
29909 @@ -1204,6 +1241,7 @@ asmlinkage long sys_socket(int family, i
29910         if (retval < 0)
29911                 goto out;
29912  
29913 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
29914         retval = sock_map_fd(sock);
29915         if (retval < 0)
29916                 goto out_release;
29917 @@ -1236,10 +1274,12 @@ asmlinkage long sys_socketpair(int famil
29918         err = sock_create(family, type, protocol, &sock1);
29919         if (err < 0)
29920                 goto out;
29921 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
29922  
29923         err = sock_create(family, type, protocol, &sock2);
29924         if (err < 0)
29925                 goto out_release_1;
29926 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
29927  
29928         err = sock1->ops->socketpair(sock1, sock2);
29929         if (err < 0)
29930 diff -Nurp linux-2.6.22.15/net/sunrpc/auth.c linux-2.6.22.15-vs2.3.0.29.1/net/sunrpc/auth.c
29931 --- linux-2.6.22.15/net/sunrpc/auth.c   2007-07-21 17:59:04.000000000 -0400
29932 +++ linux-2.6.22.15-vs2.3.0.29.1/net/sunrpc/auth.c      2007-12-09 06:44:23.000000000 -0500
29933 @@ -13,6 +13,7 @@
29934  #include <linux/errno.h>
29935  #include <linux/sunrpc/clnt.h>
29936  #include <linux/spinlock.h>
29937 +#include <linux/vs_tag.h>
29938  
29939  #ifdef RPC_DEBUG
29940  # define RPCDBG_FACILITY       RPCDBG_AUTH
29941 @@ -263,6 +264,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
29942         struct auth_cred acred = {
29943                 .uid = current->fsuid,
29944                 .gid = current->fsgid,
29945 +               .tag = dx_current_tag(),
29946                 .group_info = current->group_info,
29947         };
29948         struct rpc_cred *ret;
29949 @@ -282,6 +284,7 @@ rpcauth_bindcred(struct rpc_task *task)
29950         struct auth_cred acred = {
29951                 .uid = current->fsuid,
29952                 .gid = current->fsgid,
29953 +               .tag = dx_current_tag(),
29954                 .group_info = current->group_info,
29955         };
29956         struct rpc_cred *ret;
29957 diff -Nurp linux-2.6.22.15/net/sunrpc/auth_unix.c linux-2.6.22.15-vs2.3.0.29.1/net/sunrpc/auth_unix.c
29958 --- linux-2.6.22.15/net/sunrpc/auth_unix.c      2007-07-21 17:59:04.000000000 -0400
29959 +++ linux-2.6.22.15-vs2.3.0.29.1/net/sunrpc/auth_unix.c 2007-12-09 06:44:23.000000000 -0500
29960 @@ -11,12 +11,14 @@
29961  #include <linux/module.h>
29962  #include <linux/sunrpc/clnt.h>
29963  #include <linux/sunrpc/auth.h>
29964 +#include <linux/vs_tag.h>
29965  
29966  #define NFS_NGROUPS    16
29967  
29968  struct unx_cred {
29969         struct rpc_cred         uc_base;
29970         gid_t                   uc_gid;
29971 +       tag_t                   uc_tag;
29972         gid_t                   uc_gids[NFS_NGROUPS];
29973  };
29974  #define uc_uid                 uc_base.cr_uid
29975 @@ -79,6 +81,7 @@ unx_create_cred(struct rpc_auth *auth, s
29976         if (flags & RPCAUTH_LOOKUP_ROOTCREDS) {
29977                 cred->uc_uid = 0;
29978                 cred->uc_gid = 0;
29979 +               cred->uc_tag = dx_current_tag();
29980                 cred->uc_gids[0] = NOGROUP;
29981         } else {
29982                 int groups = acred->group_info->ngroups;
29983 @@ -87,6 +90,7 @@ unx_create_cred(struct rpc_auth *auth, s
29984  
29985                 cred->uc_uid = acred->uid;
29986                 cred->uc_gid = acred->gid;
29987 +               cred->uc_tag = acred->tag;
29988                 for (i = 0; i < groups; i++)
29989                         cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
29990                 if (i < NFS_NGROUPS)
29991 @@ -118,7 +122,8 @@ unx_match(struct auth_cred *acred, struc
29992                 int groups;
29993  
29994                 if (cred->uc_uid != acred->uid
29995 -                || cred->uc_gid != acred->gid)
29996 +                || cred->uc_gid != acred->gid
29997 +                || cred->uc_tag != acred->tag)
29998                         return 0;
29999  
30000                 groups = acred->group_info->ngroups;
30001 @@ -144,7 +149,7 @@ unx_marshal(struct rpc_task *task, __be3
30002         struct rpc_clnt *clnt = task->tk_client;
30003         struct unx_cred *cred = (struct unx_cred *) task->tk_msg.rpc_cred;
30004         __be32          *base, *hold;
30005 -       int             i;
30006 +       int             i, tag;
30007  
30008         *p++ = htonl(RPC_AUTH_UNIX);
30009         base = p++;
30010 @@ -154,9 +159,12 @@ unx_marshal(struct rpc_task *task, __be3
30011          * Copy the UTS nodename captured when the client was created.
30012          */
30013         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
30014 +       tag = task->tk_client->cl_tag;
30015  
30016 -       *p++ = htonl((u32) cred->uc_uid);
30017 -       *p++ = htonl((u32) cred->uc_gid);
30018 +       *p++ = htonl((u32) TAGINO_UID(tag,
30019 +               cred->uc_uid, cred->uc_tag));
30020 +       *p++ = htonl((u32) TAGINO_GID(tag,
30021 +               cred->uc_gid, cred->uc_tag));
30022         hold = p++;
30023         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
30024                 *p++ = htonl((u32) cred->uc_gids[i]);
30025 diff -Nurp linux-2.6.22.15/net/sunrpc/clnt.c linux-2.6.22.15-vs2.3.0.29.1/net/sunrpc/clnt.c
30026 --- linux-2.6.22.15/net/sunrpc/clnt.c   2007-07-21 18:00:28.000000000 -0400
30027 +++ linux-2.6.22.15-vs2.3.0.29.1/net/sunrpc/clnt.c      2007-12-09 06:44:23.000000000 -0500
30028 @@ -30,6 +30,7 @@
30029  #include <linux/smp_lock.h>
30030  #include <linux/utsname.h>
30031  #include <linux/workqueue.h>
30032 +#include <linux/vs_cvirt.h>
30033  
30034  #include <linux/sunrpc/clnt.h>
30035  #include <linux/sunrpc/rpc_pipe_fs.h>
30036 @@ -249,7 +250,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
30037                 clnt->cl_oneshot = 1;
30038         if (args->flags & RPC_CLNT_CREATE_DISCRTRY)
30039                 clnt->cl_discrtry = 1;
30040 -
30041 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
30042 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
30043 +               clnt->cl_tag = 1; */
30044         return clnt;
30045  }
30046  EXPORT_SYMBOL_GPL(rpc_create);
30047 diff -Nurp linux-2.6.22.15/net/unix/af_unix.c linux-2.6.22.15-vs2.3.0.29.1/net/unix/af_unix.c
30048 --- linux-2.6.22.15/net/unix/af_unix.c  2007-07-21 18:00:28.000000000 -0400
30049 +++ linux-2.6.22.15-vs2.3.0.29.1/net/unix/af_unix.c     2007-12-09 06:44:23.000000000 -0500
30050 @@ -115,6 +115,8 @@
30051  #include <linux/mount.h>
30052  #include <net/checksum.h>
30053  #include <linux/security.h>
30054 +#include <linux/vs_context.h>
30055 +#include <linux/vs_limit.h>
30056  
30057  int sysctl_unix_max_dgram_qlen __read_mostly = 10;
30058  
30059 @@ -252,6 +254,8 @@ static struct sock *__unix_find_socket_b
30060         sk_for_each(s, node, &unix_socket_table[hash ^ type]) {
30061                 struct unix_sock *u = unix_sk(s);
30062  
30063 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
30064 +                       continue;
30065                 if (u->addr->len == len &&
30066                     !memcmp(u->addr->name, sunname, len))
30067                         goto found;
30068 @@ -807,7 +811,7 @@ static int unix_bind(struct socket *sock
30069                  */
30070                 mode = S_IFSOCK |
30071                        (SOCK_INODE(sock)->i_mode & ~current->fs->umask);
30072 -               err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);
30073 +               err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0, NULL);
30074                 if (err)
30075                         goto out_mknod_dput;
30076                 mutex_unlock(&nd.dentry->d_inode->i_mutex);
30077 diff -Nurp linux-2.6.22.15/net/x25/af_x25.c linux-2.6.22.15-vs2.3.0.29.1/net/x25/af_x25.c
30078 --- linux-2.6.22.15/net/x25/af_x25.c    2007-07-21 18:00:28.000000000 -0400
30079 +++ linux-2.6.22.15-vs2.3.0.29.1/net/x25/af_x25.c       2007-12-09 06:44:23.000000000 -0500
30080 @@ -500,7 +500,10 @@ static int x25_create(struct socket *soc
30081  
30082         x25 = x25_sk(sk);
30083  
30084 -       sock_init_data(sock, sk);
30085 +       sk->sk_socket = sock;
30086 +       sk->sk_type = sock->type;
30087 +       sk->sk_sleep = &sock->wait;
30088 +       sock->sk = sk;
30089  
30090         x25_init_timers(sk);
30091  
30092 diff -Nurp linux-2.6.22.15/security/commoncap.c linux-2.6.22.15-vs2.3.0.29.1/security/commoncap.c
30093 --- linux-2.6.22.15/security/commoncap.c        2007-07-21 18:00:28.000000000 -0400
30094 +++ linux-2.6.22.15-vs2.3.0.29.1/security/commoncap.c   2007-12-09 06:44:23.000000000 -0500
30095 @@ -22,10 +22,11 @@
30096  #include <linux/ptrace.h>
30097  #include <linux/xattr.h>
30098  #include <linux/hugetlb.h>
30099 +#include <linux/vs_context.h>
30100  
30101  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
30102  {
30103 -       NETLINK_CB(skb).eff_cap = current->cap_effective;
30104 +       cap_t(NETLINK_CB(skb).eff_cap) = vx_mbcap(cap_effective);
30105         return 0;
30106  }
30107  
30108 @@ -43,7 +44,7 @@ EXPORT_SYMBOL(cap_netlink_recv);
30109  int cap_capable (struct task_struct *tsk, int cap)
30110  {
30111         /* Derived from include/linux/sched.h:capable. */
30112 -       if (cap_raised(tsk->cap_effective, cap))
30113 +       if (vx_cap_raised(tsk->vx_info, tsk->cap_effective, cap))
30114                 return 0;
30115         return -EPERM;
30116  }
30117 @@ -141,7 +142,8 @@ void cap_bprm_apply_creds (struct linux_
30118         /* Derived from fs/exec.c:compute_creds. */
30119         kernel_cap_t new_permitted, working;
30120  
30121 -       new_permitted = cap_intersect (bprm->cap_permitted, cap_bset);
30122 +       new_permitted = cap_intersect (bprm->cap_permitted,
30123 +                                       vx_current_cap_bset());
30124         working = cap_intersect (bprm->cap_inheritable,
30125                                  current->cap_inheritable);
30126         new_permitted = cap_combine (new_permitted, working);
30127 @@ -310,7 +312,8 @@ void cap_task_reparent_to_init (struct t
30128  
30129  int cap_syslog (int type)
30130  {
30131 -       if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
30132 +       if ((type != 3 && type != 10) &&
30133 +               !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
30134                 return -EPERM;
30135         return 0;
30136  }
30137 diff -Nurp linux-2.6.22.15/security/dummy.c linux-2.6.22.15-vs2.3.0.29.1/security/dummy.c
30138 --- linux-2.6.22.15/security/dummy.c    2007-07-21 17:59:05.000000000 -0400
30139 +++ linux-2.6.22.15-vs2.3.0.29.1/security/dummy.c       2007-12-09 06:44:23.000000000 -0500
30140 @@ -28,6 +28,7 @@
30141  #include <linux/hugetlb.h>
30142  #include <linux/ptrace.h>
30143  #include <linux/file.h>
30144 +#include <linux/vs_context.h>
30145  
30146  static int dummy_ptrace (struct task_struct *parent, struct task_struct *child)
30147  {
30148 @@ -678,7 +679,7 @@ static int dummy_sem_semop (struct sem_a
30149  
30150  static int dummy_netlink_send (struct sock *sk, struct sk_buff *skb)
30151  {
30152 -       NETLINK_CB(skb).eff_cap = current->cap_effective;
30153 +       cap_t(NETLINK_CB(skb).eff_cap) = vx_mbcap(cap_effective);
30154         return 0;
30155  }
30156  
30157 diff -Nurp linux-2.6.22.15/security/Kconfig linux-2.6.22.15-vs2.3.0.29.1/security/Kconfig
30158 --- linux-2.6.22.15/security/Kconfig    2007-05-04 09:57:46.000000000 -0400
30159 +++ linux-2.6.22.15-vs2.3.0.29.1/security/Kconfig       2007-12-09 06:44:23.000000000 -0500
30160 @@ -6,6 +6,7 @@ menu "Security options"
30161  
30162  config KEYS
30163         bool "Enable access key retention support"
30164 +       depends on !VSERVER_SECURITY
30165         help
30166           This option provides support for retaining authentication tokens and
30167           access keys in the kernel.
30168 diff -Nurp linux-2.6.22.15/security/selinux/hooks.c linux-2.6.22.15-vs2.3.0.29.1/security/selinux/hooks.c
30169 --- linux-2.6.22.15/security/selinux/hooks.c    2007-10-29 21:18:04.000000000 -0400
30170 +++ linux-2.6.22.15-vs2.3.0.29.1/security/selinux/hooks.c       2007-12-09 06:44:23.000000000 -0500
30171 @@ -60,7 +60,6 @@
30172  #include <linux/dccp.h>
30173  #include <linux/quota.h>
30174  #include <linux/un.h>          /* for Unix socket types */
30175 -#include <net/af_unix.h>       /* for Unix socket types */
30176  #include <linux/parser.h>
30177  #include <linux/nfs_mount.h>
30178  #include <net/ipv6.h>
30179 diff -u linux-2.6.22.16-vs2.3.0.29.1/fs/ocfs2/ioctl.c linux-2.6.22.16-vs2.3.0.29.2/fs/ocfs2/ioctl.c
30180 --- linux-2.6.22.16-vs2.3.0.29.1/fs/ocfs2/ioctl.c       2008-01-15 16:18:33.000000000 +0100
30181 +++ linux-2.6.22.16-vs2.3.0.29.2/fs/ocfs2/ioctl.c       2008-01-18 12:45:12.000000000 +0100
30182 @@ -39,6 +39,7 @@
30183         return status;
30184  }
30185  
30186 +/* Called with inode->i_mutex locked */
30187  int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
30188                                 unsigned mask)
30189  {
30190 @@ -49,8 +50,6 @@
30191         unsigned oldflags;
30192         int status;
30193  
30194 -       mutex_lock(&inode->i_mutex);
30195 -
30196         status = ocfs2_meta_lock(inode, &bh, 1);
30197         if (status < 0) {
30198                 mlog_errno(status);
30199 @@ -101,8 +100,6 @@
30200  bail_unlock:
30201         ocfs2_meta_unlock(inode, 1);
30202  bail:
30203 -       mutex_unlock(&inode->i_mutex);
30204 -
30205         if (bh)
30206                 brelse(bh);
30207  
30208 @@ -110,6 +107,16 @@
30209         return status;
30210  }
30211  
30212 +static inline int ocfs2_set_inode_attr_lock(struct inode *inode,
30213 +       unsigned flags, unsigned mask)
30214 +{
30215 +       int ret;
30216 +       mutex_lock(&inode->i_mutex);
30217 +       ret = ocfs2_set_inode_attr(inode, flags, mask);
30218 +       mutex_unlock(&inode->i_mutex);
30219 +       return ret;
30220 +}
30221 +
30222  int ocfs2_ioctl(struct inode * inode, struct file * filp,
30223         unsigned int cmd, unsigned long arg)
30224  {
30225 @@ -128,7 +135,7 @@
30226                 if (get_user(flags, (int __user *) arg))
30227                         return -EFAULT;
30228  
30229 -               return ocfs2_set_inode_attr(inode, flags,
30230 +               return ocfs2_set_inode_attr_lock(inode, flags,
30231                         OCFS2_FL_MODIFIABLE);
30232         default:
30233                 return -ENOTTY;
30234 diff -u linux-2.6.22.16-vs2.3.0.29.1/kernel/signal.c linux-2.6.22.16-vs2.3.0.29.2/kernel/signal.c
30235 --- linux-2.6.22.16-vs2.3.0.29.1/kernel/signal.c        2008-01-15 16:18:34.000000000 +0100
30236 +++ linux-2.6.22.16-vs2.3.0.29.2/kernel/signal.c        2008-01-18 12:45:49.000000000 +0100
30237 @@ -1136,7 +1136,8 @@
30238                 read_lock(&tasklist_lock);
30239                 for_each_process(p) {
30240                         if (vx_check(vx_task_xid(p), VS_ADMIN_P|VS_IDENT) &&
30241 -                               p->pid > 1 && p->tgid != current->tgid) {
30242 +                               p->pid > 1 && p->tgid != current->tgid &&
30243 +                               !vx_current_initpid(p->pid)) {
30244                                 int err = group_send_sig_info(sig, info, p);
30245                                 ++count;
30246                                 if (err != -EPERM)
30247 @@ -1146,9 +1147,9 @@
30248                 read_unlock(&tasklist_lock);
30249                 ret = count ? retval : -ESRCH;
30250         } else if (pid < 0) {
30251 -               ret = kill_pgrp_info(sig, info, find_pid(-pid));
30252 +               ret = kill_pgrp_info(sig, info, find_pid(vx_rmap_pid(-pid)));
30253         } else {
30254 -               ret = kill_pid_info(sig, info, find_pid(pid));
30255 +               ret = kill_pid_info(sig, info, find_pid(vx_rmap_pid(pid)));
30256         }
30257         rcu_read_unlock();
30258         return ret;
This page took 2.67512 seconds and 3 git commands to generate.