]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- renamed to kernel-wrr.patch
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-2.6.25/arch/alpha/Kconfig linux-2.6.25-vs2.3.0.34.9/arch/alpha/Kconfig
2 --- linux-2.6.25/arch/alpha/Kconfig     2008-04-17 12:05:26.000000000 -0400
3 +++ linux-2.6.25-vs2.3.0.34.9/arch/alpha/Kconfig        2008-04-19 15:14:51.000000000 -0400
4 @@ -671,6 +671,8 @@ config DUMMY_CONSOLE
5         depends on VGA_HOSE
6         default y
7  
8 +source "kernel/vserver/Kconfig"
9 +
10  source "security/Kconfig"
11  
12  source "crypto/Kconfig"
13 diff -NurpP --minimal linux-2.6.25/arch/alpha/kernel/entry.S linux-2.6.25-vs2.3.0.34.9/arch/alpha/kernel/entry.S
14 --- linux-2.6.25/arch/alpha/kernel/entry.S      2008-04-17 11:31:21.000000000 -0400
15 +++ linux-2.6.25-vs2.3.0.34.9/arch/alpha/kernel/entry.S 2008-04-21 11:09:01.000000000 -0400
16 @@ -872,24 +872,15 @@ sys_getxgid:
17         .globl  sys_getxpid
18         .ent    sys_getxpid
19  sys_getxpid:
20 +       lda     $sp, -16($sp)
21 +       stq     $26, 0($sp)
22         .prologue 0
23 -       ldq     $2, TI_TASK($8)
24  
25 -       /* See linux/kernel/timer.c sys_getppid for discussion
26 -          about this loop.  */
27 -       ldq     $3, TASK_GROUP_LEADER($2)
28 -       ldq     $4, TASK_REAL_PARENT($3)
29 -       ldl     $0, TASK_TGID($2)
30 -1:     ldl     $1, TASK_TGID($4)
31 -#ifdef CONFIG_SMP
32 -       mov     $4, $5
33 -       mb
34 -       ldq     $3, TASK_GROUP_LEADER($2)
35 -       ldq     $4, TASK_REAL_PARENT($3)
36 -       cmpeq   $4, $5, $5
37 -       beq     $5, 1b
38 -#endif
39 -       stq     $1, 80($sp)
40 +       lda     $16, 96($sp)
41 +       jsr     $26, do_getxpid
42 +       ldq     $26, 0($sp)
43 +
44 +       lda     $sp, 16($sp)
45         ret
46  .end sys_getxpid
47  
48 diff -NurpP --minimal linux-2.6.25/arch/alpha/kernel/osf_sys.c linux-2.6.25-vs2.3.0.34.9/arch/alpha/kernel/osf_sys.c
49 --- linux-2.6.25/arch/alpha/kernel/osf_sys.c    2008-04-17 12:05:26.000000000 -0400
50 +++ linux-2.6.25-vs2.3.0.34.9/arch/alpha/kernel/osf_sys.c       2008-04-19 15:14:51.000000000 -0400
51 @@ -882,7 +882,7 @@ osf_gettimeofday(struct timeval32 __user
52  {
53         if (tv) {
54                 struct timeval ktv;
55 -               do_gettimeofday(&ktv);
56 +               vx_gettimeofday(&ktv);
57                 if (put_tv32(tv, &ktv))
58                         return -EFAULT;
59         }
60 diff -NurpP --minimal linux-2.6.25/arch/alpha/kernel/ptrace.c linux-2.6.25-vs2.3.0.34.9/arch/alpha/kernel/ptrace.c
61 --- linux-2.6.25/arch/alpha/kernel/ptrace.c     2008-04-17 11:31:21.000000000 -0400
62 +++ linux-2.6.25-vs2.3.0.34.9/arch/alpha/kernel/ptrace.c        2008-04-19 15:14:51.000000000 -0400
63 @@ -15,6 +15,7 @@
64  #include <linux/slab.h>
65  #include <linux/security.h>
66  #include <linux/signal.h>
67 +#include <linux/vs_base.h>
68  
69  #include <asm/uaccess.h>
70  #include <asm/pgtable.h>
71 diff -NurpP --minimal linux-2.6.25/arch/alpha/kernel/semaphore.c linux-2.6.25-vs2.3.0.34.9/arch/alpha/kernel/semaphore.c
72 --- linux-2.6.25/arch/alpha/kernel/semaphore.c  2008-04-17 11:31:21.000000000 -0400
73 +++ linux-2.6.25-vs2.3.0.34.9/arch/alpha/kernel/semaphore.c     2008-04-19 15:14:51.000000000 -0400
74 @@ -68,8 +68,8 @@ __down_failed(struct semaphore *sem)
75         DECLARE_WAITQUEUE(wait, tsk);
76  
77  #ifdef CONFIG_DEBUG_SEMAPHORE
78 -       printk("%s(%d): down failed(%p)\n",
79 -              tsk->comm, task_pid_nr(tsk), sem);
80 +       printk("%s(%d:#%u): down failed(%p)\n",
81 +              tsk->comm, task_pid_nr(tsk), tsk->xid, sem);
82  #endif
83  
84         tsk->state = TASK_UNINTERRUPTIBLE;
85 @@ -97,8 +97,8 @@ __down_failed(struct semaphore *sem)
86         wake_up(&sem->wait);
87  
88  #ifdef CONFIG_DEBUG_SEMAPHORE
89 -       printk("%s(%d): down acquired(%p)\n",
90 -              tsk->comm, task_pid_nr(tsk), sem);
91 +       printk("%s(%d:#%u): down acquired(%p)\n",
92 +              tsk->comm, task_pid_nr(tsk), tsk->xid, sem);
93  #endif
94  }
95  
96 @@ -110,8 +110,8 @@ __down_failed_interruptible(struct semap
97         long ret = 0;
98  
99  #ifdef CONFIG_DEBUG_SEMAPHORE
100 -       printk("%s(%d): down failed(%p)\n",
101 -              tsk->comm, task_pid_nr(tsk), sem);
102 +       printk("%s(%d:#%u): down failed(%p)\n",
103 +              tsk->comm, task_pid_nr(tsk), tsk->xid, sem);
104  #endif
105  
106         tsk->state = TASK_INTERRUPTIBLE;
107 diff -NurpP --minimal linux-2.6.25/arch/alpha/kernel/systbls.S linux-2.6.25-vs2.3.0.34.9/arch/alpha/kernel/systbls.S
108 --- linux-2.6.25/arch/alpha/kernel/systbls.S    2008-04-17 12:05:26.000000000 -0400
109 +++ linux-2.6.25-vs2.3.0.34.9/arch/alpha/kernel/systbls.S       2008-04-19 15:14:51.000000000 -0400
110 @@ -446,7 +446,7 @@ sys_call_table:
111         .quad sys_stat64                        /* 425 */
112         .quad sys_lstat64
113         .quad sys_fstat64
114 -       .quad sys_ni_syscall                    /* sys_vserver */
115 +       .quad sys_vserver                       /* sys_vserver */
116         .quad sys_ni_syscall                    /* sys_mbind */
117         .quad sys_ni_syscall                    /* sys_get_mempolicy */
118         .quad sys_ni_syscall                    /* sys_set_mempolicy */
119 diff -NurpP --minimal linux-2.6.25/arch/alpha/kernel/traps.c linux-2.6.25-vs2.3.0.34.9/arch/alpha/kernel/traps.c
120 --- linux-2.6.25/arch/alpha/kernel/traps.c      2008-04-17 11:31:21.000000000 -0400
121 +++ linux-2.6.25-vs2.3.0.34.9/arch/alpha/kernel/traps.c 2008-04-19 15:14:51.000000000 -0400
122 @@ -182,7 +182,8 @@ die_if_kernel(char * str, struct pt_regs
123  #ifdef CONFIG_SMP
124         printk("CPU %d ", hard_smp_processor_id());
125  #endif
126 -       printk("%s(%d): %s %ld\n", current->comm, task_pid_nr(current), str, err);
127 +       printk("%s(%d[#%u]): %s %ld\n", current->comm,
128 +               task_pid_nr(current), current->xid, str, err);
129         dik_show_regs(regs, r9_15);
130         add_taint(TAINT_DIE);
131         dik_show_trace((unsigned long *)(regs+1));
132 diff -NurpP --minimal linux-2.6.25/arch/alpha/mm/fault.c linux-2.6.25-vs2.3.0.34.9/arch/alpha/mm/fault.c
133 --- linux-2.6.25/arch/alpha/mm/fault.c  2008-04-17 11:31:21.000000000 -0400
134 +++ linux-2.6.25-vs2.3.0.34.9/arch/alpha/mm/fault.c     2008-04-19 15:14:51.000000000 -0400
135 @@ -193,8 +193,8 @@ do_page_fault(unsigned long address, uns
136                 down_read(&mm->mmap_sem);
137                 goto survive;
138         }
139 -       printk(KERN_ALERT "VM: killing process %s(%d)\n",
140 -              current->comm, task_pid_nr(current));
141 +       printk(KERN_ALERT "VM: killing process %s(%d:#%u)\n",
142 +              current->comm, task_pid_nr(current), current->xid);
143         if (!user_mode(regs))
144                 goto no_context;
145         do_group_exit(SIGKILL);
146 diff -NurpP --minimal linux-2.6.25/arch/arm/Kconfig linux-2.6.25-vs2.3.0.34.9/arch/arm/Kconfig
147 --- linux-2.6.25/arch/arm/Kconfig       2008-04-17 12:05:26.000000000 -0400
148 +++ linux-2.6.25-vs2.3.0.34.9/arch/arm/Kconfig  2008-04-19 15:14:51.000000000 -0400
149 @@ -1180,6 +1180,8 @@ source "fs/Kconfig"
150  
151  source "arch/arm/Kconfig.debug"
152  
153 +source "kernel/vserver/Kconfig"
154 +
155  source "security/Kconfig"
156  
157  source "crypto/Kconfig"
158 diff -NurpP --minimal linux-2.6.25/arch/arm/kernel/calls.S linux-2.6.25-vs2.3.0.34.9/arch/arm/kernel/calls.S
159 --- linux-2.6.25/arch/arm/kernel/calls.S        2008-04-17 12:05:26.000000000 -0400
160 +++ linux-2.6.25-vs2.3.0.34.9/arch/arm/kernel/calls.S   2008-04-19 15:14:51.000000000 -0400
161 @@ -322,7 +322,7 @@
162  /* 310 */      CALL(sys_request_key)
163                 CALL(sys_keyctl)
164                 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
165 -/* vserver */  CALL(sys_ni_syscall)
166 +               CALL(sys_vserver)
167                 CALL(sys_ioprio_set)
168  /* 315 */      CALL(sys_ioprio_get)
169                 CALL(sys_inotify_init)
170 diff -NurpP --minimal linux-2.6.25/arch/arm/kernel/process.c linux-2.6.25-vs2.3.0.34.9/arch/arm/kernel/process.c
171 --- linux-2.6.25/arch/arm/kernel/process.c      2008-04-17 12:05:26.000000000 -0400
172 +++ linux-2.6.25-vs2.3.0.34.9/arch/arm/kernel/process.c 2008-04-21 11:09:01.000000000 -0400
173 @@ -264,7 +264,8 @@ void __show_regs(struct pt_regs *regs)
174  void show_regs(struct pt_regs * regs)
175  {
176         printk("\n");
177 -       printk("Pid: %d, comm: %20s\n", task_pid_nr(current), current->comm);
178 +       printk("Pid: %d[#%u], comm: %20s\n",
179 +               task_pid_nr(current), current->xid, current->comm);
180         __show_regs(regs);
181         __backtrace();
182  }
183 diff -NurpP --minimal linux-2.6.25/arch/arm/kernel/traps.c linux-2.6.25-vs2.3.0.34.9/arch/arm/kernel/traps.c
184 --- linux-2.6.25/arch/arm/kernel/traps.c        2008-04-17 12:05:26.000000000 -0400
185 +++ linux-2.6.25-vs2.3.0.34.9/arch/arm/kernel/traps.c   2008-04-19 15:14:51.000000000 -0400
186 @@ -214,8 +214,8 @@ static void __die(const char *str, int e
187                str, err, ++die_counter);
188         print_modules();
189         __show_regs(regs);
190 -       printk("Process %s (pid: %d, stack limit = 0x%p)\n",
191 -               tsk->comm, task_pid_nr(tsk), thread + 1);
192 +       printk("Process %s (pid: %d:#%u, stack limit = 0x%p)\n",
193 +               tsk->comm, task_pid_nr(tsk), tsk->xid, thread + 1);
194  
195         if (!user_mode(regs) || in_interrupt()) {
196                 dump_mem("Stack: ", regs->ARM_sp,
197 diff -NurpP --minimal linux-2.6.25/arch/arm/mm/fault.c linux-2.6.25-vs2.3.0.34.9/arch/arm/mm/fault.c
198 --- linux-2.6.25/arch/arm/mm/fault.c    2008-04-17 12:05:27.000000000 -0400
199 +++ linux-2.6.25-vs2.3.0.34.9/arch/arm/mm/fault.c       2008-04-19 15:14:51.000000000 -0400
200 @@ -292,7 +292,8 @@ do_page_fault(unsigned long addr, unsign
201                  * happened to us that made us unable to handle
202                  * the page fault gracefully.
203                  */
204 -               printk("VM: killing process %s\n", tsk->comm);
205 +               printk("VM: killing process %s(%d:#%u)\n",
206 +                       tsk->comm, task_pid_nr(tsk), tsk->xid);
207                 do_group_exit(SIGKILL);
208                 return 0;
209         }
210 diff -NurpP --minimal linux-2.6.25/arch/cris/Kconfig linux-2.6.25-vs2.3.0.34.9/arch/cris/Kconfig
211 --- linux-2.6.25/arch/cris/Kconfig      2008-04-17 12:05:27.000000000 -0400
212 +++ linux-2.6.25-vs2.3.0.34.9/arch/cris/Kconfig 2008-04-19 15:14:51.000000000 -0400
213 @@ -679,6 +679,8 @@ source "drivers/usb/Kconfig"
214  
215  source "arch/cris/Kconfig.debug"
216  
217 +source "kernel/vserver/Kconfig"
218 +
219  source "security/Kconfig"
220  
221  source "crypto/Kconfig"
222 diff -NurpP --minimal linux-2.6.25/arch/frv/kernel/kernel_thread.S linux-2.6.25-vs2.3.0.34.9/arch/frv/kernel/kernel_thread.S
223 --- linux-2.6.25/arch/frv/kernel/kernel_thread.S        2007-02-04 13:44:54.000000000 -0500
224 +++ linux-2.6.25-vs2.3.0.34.9/arch/frv/kernel/kernel_thread.S   2008-04-21 11:09:01.000000000 -0400
225 @@ -37,7 +37,7 @@ kernel_thread:
226  
227         # start by forking the current process, but with shared VM
228         setlos.p        #__NR_clone,gr7         ; syscall number
229 -       ori             gr10,#CLONE_VM,gr8      ; first syscall arg     [clone_flags]
230 +       ori             gr10,#CLONE_KT,gr8      ; first syscall arg     [clone_flags]
231         sethi.p         #0xe4e4,gr9             ; second syscall arg    [newsp]
232         setlo           #0xe4e4,gr9
233         setlos.p        #0,gr10                 ; third syscall arg     [parent_tidptr]
234 diff -NurpP --minimal linux-2.6.25/arch/h8300/Kconfig linux-2.6.25-vs2.3.0.34.9/arch/h8300/Kconfig
235 --- linux-2.6.25/arch/h8300/Kconfig     2008-04-17 12:05:28.000000000 -0400
236 +++ linux-2.6.25-vs2.3.0.34.9/arch/h8300/Kconfig        2008-04-19 15:14:51.000000000 -0400
237 @@ -233,6 +233,8 @@ source "fs/Kconfig"
238  
239  source "arch/h8300/Kconfig.debug"
240  
241 +source "kernel/vserver/Kconfig"
242 +
243  source "security/Kconfig"
244  
245  source "crypto/Kconfig"
246 diff -NurpP --minimal linux-2.6.25/arch/ia64/ia32/ia32_entry.S linux-2.6.25-vs2.3.0.34.9/arch/ia64/ia32/ia32_entry.S
247 --- linux-2.6.25/arch/ia64/ia32/ia32_entry.S    2008-04-17 10:37:14.000000000 -0400
248 +++ linux-2.6.25-vs2.3.0.34.9/arch/ia64/ia32/ia32_entry.S       2008-04-19 15:14:51.000000000 -0400
249 @@ -446,7 +446,7 @@ ia32_syscall_table:
250         data8 sys_tgkill        /* 270 */
251         data8 compat_sys_utimes
252         data8 sys32_fadvise64_64
253 -       data8 sys_ni_syscall
254 +       data8 sys32_vserver
255         data8 sys_ni_syscall
256         data8 sys_ni_syscall    /* 275 */
257         data8 sys_ni_syscall
258 diff -NurpP --minimal linux-2.6.25/arch/ia64/ia32/sys_ia32.c linux-2.6.25-vs2.3.0.34.9/arch/ia64/ia32/sys_ia32.c
259 --- linux-2.6.25/arch/ia64/ia32/sys_ia32.c      2008-04-17 12:05:28.000000000 -0400
260 +++ linux-2.6.25-vs2.3.0.34.9/arch/ia64/ia32/sys_ia32.c 2008-04-19 15:14:51.000000000 -0400
261 @@ -1177,7 +1177,7 @@ sys32_gettimeofday (struct compat_timeva
262  {
263         if (tv) {
264                 struct timeval ktv;
265 -               do_gettimeofday(&ktv);
266 +               vx_gettimeofday(&ktv);
267                 if (put_tv32(tv, &ktv))
268                         return -EFAULT;
269         }
270 diff -NurpP --minimal linux-2.6.25/arch/ia64/Kconfig linux-2.6.25-vs2.3.0.34.9/arch/ia64/Kconfig
271 --- linux-2.6.25/arch/ia64/Kconfig      2008-04-17 12:05:28.000000000 -0400
272 +++ linux-2.6.25-vs2.3.0.34.9/arch/ia64/Kconfig 2008-04-19 15:14:51.000000000 -0400
273 @@ -615,6 +615,8 @@ source "arch/ia64/hp/sim/Kconfig"
274  
275  source "arch/ia64/Kconfig.debug"
276  
277 +source "kernel/vserver/Kconfig"
278 +
279  source "security/Kconfig"
280  
281  source "crypto/Kconfig"
282 diff -NurpP --minimal linux-2.6.25/arch/ia64/kernel/entry.S linux-2.6.25-vs2.3.0.34.9/arch/ia64/kernel/entry.S
283 --- linux-2.6.25/arch/ia64/kernel/entry.S       2008-04-17 12:05:28.000000000 -0400
284 +++ linux-2.6.25-vs2.3.0.34.9/arch/ia64/kernel/entry.S  2008-04-19 15:14:51.000000000 -0400
285 @@ -1547,7 +1547,7 @@ sys_call_table:
286         data8 sys_mq_notify
287         data8 sys_mq_getsetattr
288         data8 sys_kexec_load
289 -       data8 sys_ni_syscall                    // reserved for vserver
290 +       data8 sys_vserver
291         data8 sys_waitid                        // 1270
292         data8 sys_add_key
293         data8 sys_request_key
294 diff -NurpP --minimal linux-2.6.25/arch/ia64/kernel/perfmon.c linux-2.6.25-vs2.3.0.34.9/arch/ia64/kernel/perfmon.c
295 --- linux-2.6.25/arch/ia64/kernel/perfmon.c     2008-04-17 12:05:28.000000000 -0400
296 +++ linux-2.6.25-vs2.3.0.34.9/arch/ia64/kernel/perfmon.c        2008-04-19 15:14:51.000000000 -0400
297 @@ -40,6 +40,7 @@
298  #include <linux/capability.h>
299  #include <linux/rcupdate.h>
300  #include <linux/completion.h>
301 +#include <linux/vs_memory.h>
302  
303  #include <asm/errno.h>
304  #include <asm/intrinsics.h>
305 @@ -2374,7 +2375,7 @@ pfm_smpl_buffer_alloc(struct task_struct
306          */
307         insert_vm_struct(mm, vma);
308  
309 -       mm->total_vm  += size >> PAGE_SHIFT;
310 +       vx_vmpages_add(mm, size >> PAGE_SHIFT);
311         vm_stat_account(vma->vm_mm, vma->vm_flags, vma->vm_file,
312                                                         vma_pages(vma));
313         up_write(&task->mm->mmap_sem);
314 diff -NurpP --minimal linux-2.6.25/arch/ia64/kernel/process.c linux-2.6.25-vs2.3.0.34.9/arch/ia64/kernel/process.c
315 --- linux-2.6.25/arch/ia64/kernel/process.c     2008-04-17 12:05:28.000000000 -0400
316 +++ linux-2.6.25-vs2.3.0.34.9/arch/ia64/kernel/process.c        2008-04-21 11:09:01.000000000 -0400
317 @@ -105,8 +105,8 @@ show_regs (struct pt_regs *regs)
318         unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
319  
320         print_modules();
321 -       printk("\nPid: %d, CPU %d, comm: %20s\n", task_pid_nr(current),
322 -                       smp_processor_id(), current->comm);
323 +       printk("\nPid: %d[#%u], CPU %d, comm: %20s\n", task_pid_nr(current),
324 +                       current->xid, smp_processor_id(), current->comm);
325         printk("psr : %016lx ifs : %016lx ip  : [<%016lx>]    %s (%s)\n",
326                regs->cr_ipsr, regs->cr_ifs, ip, print_tainted(),
327                init_utsname()->release);
328 diff -NurpP --minimal linux-2.6.25/arch/ia64/kernel/ptrace.c linux-2.6.25-vs2.3.0.34.9/arch/ia64/kernel/ptrace.c
329 --- linux-2.6.25/arch/ia64/kernel/ptrace.c      2008-04-17 12:05:28.000000000 -0400
330 +++ linux-2.6.25-vs2.3.0.34.9/arch/ia64/kernel/ptrace.c 2008-04-19 15:14:51.000000000 -0400
331 @@ -17,6 +17,7 @@
332  #include <linux/security.h>
333  #include <linux/audit.h>
334  #include <linux/signal.h>
335 +#include <linux/vs_base.h>
336  
337  #include <asm/pgtable.h>
338  #include <asm/processor.h>
339 diff -NurpP --minimal linux-2.6.25/arch/ia64/kernel/traps.c linux-2.6.25-vs2.3.0.34.9/arch/ia64/kernel/traps.c
340 --- linux-2.6.25/arch/ia64/kernel/traps.c       2008-04-17 12:05:28.000000000 -0400
341 +++ linux-2.6.25-vs2.3.0.34.9/arch/ia64/kernel/traps.c  2008-04-21 10:33:04.000000000 -0400
342 @@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
343         put_cpu();
344  
345         if (++die.lock_owner_depth < 3) {
346 -               printk("%s[%d]: %s %ld [%d]\n",
347 -               current->comm, task_pid_nr(current), str, err, ++die_counter);
348 +               printk("%s[%d[#%u]]: %s %ld [%d]\n",
349 +                       current->comm, task_pid_nr(current), current->xid,
350 +                       str, err, ++die_counter);
351                 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
352                     != NOTIFY_STOP)
353                         show_regs(regs);
354 @@ -324,8 +325,9 @@ handle_fpu_swa (int fp_fault, struct pt_
355                         if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
356                                 last.time = current_jiffies + 5 * HZ;
357                                 printk(KERN_WARNING
358 -                                       "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
359 -                                       current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
360 +                                       "%s(%d[#%u]): floating-point assist fault at ip %016lx, isr %016lx\n",
361 +                                       current->comm, task_pid_nr(current), current->xid,
362 +                                       regs->cr_iip + ia64_psr(regs)->ri, isr);
363                         }
364                 }
365         }
366 diff -NurpP --minimal linux-2.6.25/arch/ia64/mm/fault.c linux-2.6.25-vs2.3.0.34.9/arch/ia64/mm/fault.c
367 --- linux-2.6.25/arch/ia64/mm/fault.c   2008-04-17 12:05:28.000000000 -0400
368 +++ linux-2.6.25-vs2.3.0.34.9/arch/ia64/mm/fault.c      2008-04-19 15:14:52.000000000 -0400
369 @@ -10,6 +10,7 @@
370  #include <linux/interrupt.h>
371  #include <linux/kprobes.h>
372  #include <linux/kdebug.h>
373 +#include <linux/vs_memory.h>
374  
375  #include <asm/pgtable.h>
376  #include <asm/processor.h>
377 diff -NurpP --minimal linux-2.6.25/arch/m32r/kernel/traps.c linux-2.6.25-vs2.3.0.34.9/arch/m32r/kernel/traps.c
378 --- linux-2.6.25/arch/m32r/kernel/traps.c       2008-04-17 11:31:23.000000000 -0400
379 +++ linux-2.6.25-vs2.3.0.34.9/arch/m32r/kernel/traps.c  2008-04-19 15:14:52.000000000 -0400
380 @@ -195,8 +195,9 @@ static void show_registers(struct pt_reg
381         } else {
382                 printk("SPI: %08lx\n", sp);
383         }
384 -       printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
385 -               current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
386 +       printk("Process %s (pid: %d[#%u], process nr: %d, stackpage=%08lx)",
387 +               current->comm, task_pid_nr(current), current->xid,
388 +               0xffff & i, 4096+(unsigned long)current);
389  
390         /*
391          * When in-kernel, we also print out the stack and code at the
392 diff -NurpP --minimal linux-2.6.25/arch/m68k/Kconfig linux-2.6.25-vs2.3.0.34.9/arch/m68k/Kconfig
393 --- linux-2.6.25/arch/m68k/Kconfig      2008-04-17 12:05:28.000000000 -0400
394 +++ linux-2.6.25-vs2.3.0.34.9/arch/m68k/Kconfig 2008-04-19 15:14:52.000000000 -0400
395 @@ -674,6 +674,8 @@ source "fs/Kconfig"
396  
397  source "arch/m68k/Kconfig.debug"
398  
399 +source "kernel/vserver/Kconfig"
400 +
401  source "security/Kconfig"
402  
403  source "crypto/Kconfig"
404 diff -NurpP --minimal linux-2.6.25/arch/m68k/kernel/ptrace.c linux-2.6.25-vs2.3.0.34.9/arch/m68k/kernel/ptrace.c
405 --- linux-2.6.25/arch/m68k/kernel/ptrace.c      2008-04-17 11:31:23.000000000 -0400
406 +++ linux-2.6.25-vs2.3.0.34.9/arch/m68k/kernel/ptrace.c 2008-04-19 15:14:52.000000000 -0400
407 @@ -18,6 +18,7 @@
408  #include <linux/ptrace.h>
409  #include <linux/user.h>
410  #include <linux/signal.h>
411 +#include <linux/vs_base.h>
412  
413  #include <asm/uaccess.h>
414  #include <asm/page.h>
415 @@ -269,6 +270,8 @@ long arch_ptrace(struct task_struct *chi
416                 ret = ptrace_request(child, request, addr, data);
417                 break;
418         }
419 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
420 +               goto out_tsk;
421  
422         return ret;
423  out_eio:
424 diff -NurpP --minimal linux-2.6.25/arch/m68k/kernel/traps.c linux-2.6.25-vs2.3.0.34.9/arch/m68k/kernel/traps.c
425 --- linux-2.6.25/arch/m68k/kernel/traps.c       2008-04-17 12:05:28.000000000 -0400
426 +++ linux-2.6.25-vs2.3.0.34.9/arch/m68k/kernel/traps.c  2008-04-19 15:14:52.000000000 -0400
427 @@ -898,8 +898,8 @@ void show_registers(struct pt_regs *regs
428         printk("d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
429                regs->d4, regs->d5, regs->a0, regs->a1);
430  
431 -       printk("Process %s (pid: %d, task=%p)\n",
432 -               current->comm, task_pid_nr(current), current);
433 +       printk("Process %s (pid: %d[#%u], task=%p)\n",
434 +               current->comm, task_pid_nr(current), current->xid, current);
435         addr = (unsigned long)&fp->un;
436         printk("Frame format=%X ", regs->format);
437         switch (regs->format) {
438 diff -NurpP --minimal linux-2.6.25/arch/m68knommu/Kconfig linux-2.6.25-vs2.3.0.34.9/arch/m68knommu/Kconfig
439 --- linux-2.6.25/arch/m68knommu/Kconfig 2008-04-17 12:05:28.000000000 -0400
440 +++ linux-2.6.25-vs2.3.0.34.9/arch/m68knommu/Kconfig    2008-04-19 15:14:52.000000000 -0400
441 @@ -722,6 +722,8 @@ source "fs/Kconfig"
442  
443  source "arch/m68knommu/Kconfig.debug"
444  
445 +source "kernel/vserver/Kconfig"
446 +
447  source "security/Kconfig"
448  
449  source "crypto/Kconfig"
450 diff -NurpP --minimal linux-2.6.25/arch/m68knommu/kernel/traps.c linux-2.6.25-vs2.3.0.34.9/arch/m68knommu/kernel/traps.c
451 --- linux-2.6.25/arch/m68knommu/kernel/traps.c  2008-04-17 10:37:14.000000000 -0400
452 +++ linux-2.6.25-vs2.3.0.34.9/arch/m68knommu/kernel/traps.c     2008-04-19 15:14:52.000000000 -0400
453 @@ -78,8 +78,9 @@ void die_if_kernel(char *str, struct pt_
454         printk(KERN_EMERG "d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
455                fp->d4, fp->d5, fp->a0, fp->a1);
456  
457 -       printk(KERN_EMERG "Process %s (pid: %d, stackpage=%08lx)\n",
458 -               current->comm, current->pid, PAGE_SIZE+(unsigned long)current);
459 +       printk(KERN_EMERG "Process %s (pid: %d[#%u], stackpage=%08lx)\n",
460 +               current->comm, task_pid_nr(current), current->xid,
461 +               PAGE_SIZE+(unsigned long)current);
462         show_stack(NULL, (unsigned long *)(fp + 1));
463         add_taint(TAINT_DIE);
464         do_exit(SIGSEGV);
465 diff -NurpP --minimal linux-2.6.25/arch/mips/Kconfig linux-2.6.25-vs2.3.0.34.9/arch/mips/Kconfig
466 --- linux-2.6.25/arch/mips/Kconfig      2008-04-17 12:05:28.000000000 -0400
467 +++ linux-2.6.25-vs2.3.0.34.9/arch/mips/Kconfig 2008-04-19 15:14:52.000000000 -0400
468 @@ -2099,6 +2099,8 @@ source "fs/Kconfig"
469  
470  source "arch/mips/Kconfig.debug"
471  
472 +source "kernel/vserver/Kconfig"
473 +
474  source "security/Kconfig"
475  
476  source "crypto/Kconfig"
477 diff -NurpP --minimal linux-2.6.25/arch/mips/kernel/linux32.c linux-2.6.25-vs2.3.0.34.9/arch/mips/kernel/linux32.c
478 --- linux-2.6.25/arch/mips/kernel/linux32.c     2008-04-17 12:05:29.000000000 -0400
479 +++ linux-2.6.25-vs2.3.0.34.9/arch/mips/kernel/linux32.c        2008-04-19 15:14:52.000000000 -0400
480 @@ -209,7 +209,7 @@ sys32_gettimeofday(struct compat_timeval
481  {
482         if (tv) {
483                 struct timeval ktv;
484 -               do_gettimeofday(&ktv);
485 +               vx_gettimeofday(&ktv);
486                 if (put_tv32(tv, &ktv))
487                         return -EFAULT;
488         }
489 diff -NurpP --minimal linux-2.6.25/arch/mips/kernel/ptrace.c linux-2.6.25-vs2.3.0.34.9/arch/mips/kernel/ptrace.c
490 --- linux-2.6.25/arch/mips/kernel/ptrace.c      2008-04-17 11:31:23.000000000 -0400
491 +++ linux-2.6.25-vs2.3.0.34.9/arch/mips/kernel/ptrace.c 2008-04-19 15:14:52.000000000 -0400
492 @@ -25,6 +25,7 @@
493  #include <linux/security.h>
494  #include <linux/audit.h>
495  #include <linux/seccomp.h>
496 +#include <linux/vs_base.h>
497  
498  #include <asm/byteorder.h>
499  #include <asm/cpu.h>
500 @@ -171,6 +172,9 @@ long arch_ptrace(struct task_struct *chi
501  {
502         int ret;
503  
504 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
505 +               goto out;
506 +
507         switch (request) {
508         /* when I and D space are separate, these will need to be fixed. */
509         case PTRACE_PEEKTEXT: /* read word at location addr. */
510 diff -NurpP --minimal linux-2.6.25/arch/mips/kernel/scall32-o32.S linux-2.6.25-vs2.3.0.34.9/arch/mips/kernel/scall32-o32.S
511 --- linux-2.6.25/arch/mips/kernel/scall32-o32.S 2008-04-17 12:05:29.000000000 -0400
512 +++ linux-2.6.25-vs2.3.0.34.9/arch/mips/kernel/scall32-o32.S    2008-04-19 15:14:52.000000000 -0400
513 @@ -619,7 +619,7 @@ einval:     li      v0, -EINVAL
514         sys     sys_mq_timedreceive     5
515         sys     sys_mq_notify           2       /* 4275 */
516         sys     sys_mq_getsetattr       3
517 -       sys     sys_ni_syscall          0       /* sys_vserver */
518 +       sys     sys_vserver             3
519         sys     sys_waitid              5
520         sys     sys_ni_syscall          0       /* available, was setaltroot */
521         sys     sys_add_key             5       /* 4280 */
522 diff -NurpP --minimal linux-2.6.25/arch/mips/kernel/scall64-64.S linux-2.6.25-vs2.3.0.34.9/arch/mips/kernel/scall64-64.S
523 --- linux-2.6.25/arch/mips/kernel/scall64-64.S  2008-04-17 12:05:29.000000000 -0400
524 +++ linux-2.6.25-vs2.3.0.34.9/arch/mips/kernel/scall64-64.S     2008-04-19 15:14:52.000000000 -0400
525 @@ -434,7 +434,7 @@ sys_call_table:
526         PTR     sys_mq_timedreceive
527         PTR     sys_mq_notify
528         PTR     sys_mq_getsetattr               /* 5235 */
529 -       PTR     sys_ni_syscall                  /* sys_vserver */
530 +       PTR     sys_vserver
531         PTR     sys_waitid
532         PTR     sys_ni_syscall                  /* available, was setaltroot */
533         PTR     sys_add_key
534 diff -NurpP --minimal linux-2.6.25/arch/mips/kernel/scall64-n32.S linux-2.6.25-vs2.3.0.34.9/arch/mips/kernel/scall64-n32.S
535 --- linux-2.6.25/arch/mips/kernel/scall64-n32.S 2008-04-17 12:05:29.000000000 -0400
536 +++ linux-2.6.25-vs2.3.0.34.9/arch/mips/kernel/scall64-n32.S    2008-04-19 15:14:52.000000000 -0400
537 @@ -360,7 +360,7 @@ EXPORT(sysn32_call_table)
538         PTR     compat_sys_mq_timedreceive
539         PTR     compat_sys_mq_notify
540         PTR     compat_sys_mq_getsetattr
541 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
542 +       PTR     sys32_vserver                   /* 6240 */
543         PTR     compat_sys_waitid
544         PTR     sys_ni_syscall                  /* available, was setaltroot */
545         PTR     sys_add_key
546 diff -NurpP --minimal linux-2.6.25/arch/mips/kernel/scall64-o32.S linux-2.6.25-vs2.3.0.34.9/arch/mips/kernel/scall64-o32.S
547 --- linux-2.6.25/arch/mips/kernel/scall64-o32.S 2008-04-17 12:05:29.000000000 -0400
548 +++ linux-2.6.25-vs2.3.0.34.9/arch/mips/kernel/scall64-o32.S    2008-04-19 15:14:52.000000000 -0400
549 @@ -482,7 +482,7 @@ sys_call_table:
550         PTR     compat_sys_mq_timedreceive
551         PTR     compat_sys_mq_notify            /* 4275 */
552         PTR     compat_sys_mq_getsetattr
553 -       PTR     sys_ni_syscall                  /* sys_vserver */
554 +       PTR     sys32_vserver
555         PTR     sys32_waitid
556         PTR     sys_ni_syscall                  /* available, was setaltroot */
557         PTR     sys_add_key                     /* 4280 */
558 diff -NurpP --minimal linux-2.6.25/arch/mips/kernel/traps.c linux-2.6.25-vs2.3.0.34.9/arch/mips/kernel/traps.c
559 --- linux-2.6.25/arch/mips/kernel/traps.c       2008-04-17 12:05:29.000000000 -0400
560 +++ linux-2.6.25-vs2.3.0.34.9/arch/mips/kernel/traps.c  2008-04-19 15:14:52.000000000 -0400
561 @@ -313,8 +313,9 @@ void show_registers(const struct pt_regs
562  {
563         __show_regs(regs);
564         print_modules();
565 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p)\n",
566 -               current->comm, task_pid_nr(current), current_thread_info(), current);
567 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p)\n",
568 +               current->comm, task_pid_nr(current), current->xid,
569 +               current_thread_info(), current);
570         show_stacktrace(current, regs);
571         show_code((unsigned int __user *) regs->cp0_epc);
572         printk("\n");
573 diff -NurpP --minimal linux-2.6.25/arch/mips/mm/fault.c linux-2.6.25-vs2.3.0.34.9/arch/mips/mm/fault.c
574 --- linux-2.6.25/arch/mips/mm/fault.c   2008-04-17 11:31:24.000000000 -0400
575 +++ linux-2.6.25-vs2.3.0.34.9/arch/mips/mm/fault.c      2008-04-19 15:14:52.000000000 -0400
576 @@ -178,7 +178,8 @@ out_of_memory:
577                 down_read(&mm->mmap_sem);
578                 goto survive;
579         }
580 -       printk("VM: killing process %s\n", tsk->comm);
581 +       printk("VM: killing process %s(%d:#%u)\n",
582 +               tsk->comm, tsk->pid, tsk->xid);
583         if (user_mode(regs))
584                 do_group_exit(SIGKILL);
585         goto no_context;
586 diff -NurpP --minimal linux-2.6.25/arch/parisc/Kconfig linux-2.6.25-vs2.3.0.34.9/arch/parisc/Kconfig
587 --- linux-2.6.25/arch/parisc/Kconfig    2008-04-17 12:05:29.000000000 -0400
588 +++ linux-2.6.25-vs2.3.0.34.9/arch/parisc/Kconfig       2008-04-19 15:14:52.000000000 -0400
589 @@ -278,6 +278,8 @@ source "fs/Kconfig"
590  
591  source "arch/parisc/Kconfig.debug"
592  
593 +source "kernel/vserver/Kconfig"
594 +
595  source "security/Kconfig"
596  
597  source "crypto/Kconfig"
598 diff -NurpP --minimal linux-2.6.25/arch/parisc/kernel/syscall_table.S linux-2.6.25-vs2.3.0.34.9/arch/parisc/kernel/syscall_table.S
599 --- linux-2.6.25/arch/parisc/kernel/syscall_table.S     2008-04-17 12:05:29.000000000 -0400
600 +++ linux-2.6.25-vs2.3.0.34.9/arch/parisc/kernel/syscall_table.S        2008-04-19 15:14:52.000000000 -0400
601 @@ -361,7 +361,7 @@
602         ENTRY_COMP(mbind)               /* 260 */
603         ENTRY_COMP(get_mempolicy)
604         ENTRY_COMP(set_mempolicy)
605 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
606 +       ENTRY_DIFF(vserver)
607         ENTRY_SAME(add_key)
608         ENTRY_SAME(request_key)         /* 265 */
609         ENTRY_SAME(keyctl)
610 diff -NurpP --minimal linux-2.6.25/arch/parisc/kernel/sys_parisc32.c linux-2.6.25-vs2.3.0.34.9/arch/parisc/kernel/sys_parisc32.c
611 --- linux-2.6.25/arch/parisc/kernel/sys_parisc32.c      2008-04-17 11:31:24.000000000 -0400
612 +++ linux-2.6.25-vs2.3.0.34.9/arch/parisc/kernel/sys_parisc32.c 2008-04-19 15:14:52.000000000 -0400
613 @@ -204,11 +204,11 @@ static inline long get_ts32(struct times
614  asmlinkage int
615  sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
616  {
617 -    extern void do_gettimeofday(struct timeval *tv);
618 +    extern void vx_gettimeofday(struct timeval *tv);
619  
620      if (tv) {
621             struct timeval ktv;
622 -           do_gettimeofday(&ktv);
623 +           vx_gettimeofday(&ktv);
624             if (put_compat_timeval(tv, &ktv))
625                     return -EFAULT;
626      }
627 diff -NurpP --minimal linux-2.6.25/arch/parisc/kernel/traps.c linux-2.6.25-vs2.3.0.34.9/arch/parisc/kernel/traps.c
628 --- linux-2.6.25/arch/parisc/kernel/traps.c     2008-04-17 12:05:29.000000000 -0400
629 +++ linux-2.6.25-vs2.3.0.34.9/arch/parisc/kernel/traps.c        2008-04-19 15:14:52.000000000 -0400
630 @@ -237,8 +237,9 @@ void die_if_kernel(char *str, struct pt_
631                 if (err == 0)
632                         return; /* STFU */
633  
634 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
635 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
636 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
637 +                       current->comm, task_pid_nr(current), current->xid,
638 +                       str, err, regs->iaoq[0]);
639  #ifdef PRINT_USER_FAULTS
640                 /* XXX for debugging only */
641                 show_regs(regs);
642 @@ -270,8 +271,8 @@ KERN_CRIT "                     ||     |
643                 pdc_console_restart();
644         
645         if (err)
646 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
647 -                       current->comm, task_pid_nr(current), str, err);
648 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
649 +                       current->comm, task_pid_nr(current), current->xid, str, err);
650  
651         /* Wot's wrong wif bein' racy? */
652         if (current->thread.flags & PARISC_KERNEL_DEATH) {
653 diff -NurpP --minimal linux-2.6.25/arch/parisc/mm/fault.c linux-2.6.25-vs2.3.0.34.9/arch/parisc/mm/fault.c
654 --- linux-2.6.25/arch/parisc/mm/fault.c 2008-04-17 11:31:24.000000000 -0400
655 +++ linux-2.6.25-vs2.3.0.34.9/arch/parisc/mm/fault.c    2008-04-19 15:14:52.000000000 -0400
656 @@ -210,8 +210,9 @@ bad_area:
657  
658  #ifdef PRINT_USER_FAULTS
659                 printk(KERN_DEBUG "\n");
660 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
661 -                   task_pid_nr(tsk), tsk->comm, code, address);
662 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
663 +                   "command='%s' type=%lu address=0x%08lx\n",
664 +                   task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
665                 if (vma) {
666                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
667                                         vma->vm_start, vma->vm_end);
668 @@ -261,7 +262,8 @@ no_context:
669  
670    out_of_memory:
671         up_read(&mm->mmap_sem);
672 -       printk(KERN_CRIT "VM: killing process %s\n", current->comm);
673 +       printk(KERN_CRIT "VM: killing process %s(%d:#%u)\n",
674 +               current->comm, current->pid, current->xid);
675         if (user_mode(regs))
676                 do_group_exit(SIGKILL);
677         goto no_context;
678 diff -NurpP --minimal linux-2.6.25/arch/powerpc/Kconfig linux-2.6.25-vs2.3.0.34.9/arch/powerpc/Kconfig
679 --- linux-2.6.25/arch/powerpc/Kconfig   2008-04-17 12:05:29.000000000 -0400
680 +++ linux-2.6.25-vs2.3.0.34.9/arch/powerpc/Kconfig      2008-04-19 15:14:52.000000000 -0400
681 @@ -706,6 +706,8 @@ source "lib/Kconfig"
682  
683  source "arch/powerpc/Kconfig.debug"
684  
685 +source "kernel/vserver/Kconfig"
686 +
687  source "security/Kconfig"
688  
689  config KEYS_COMPAT
690 diff -NurpP --minimal linux-2.6.25/arch/powerpc/kernel/irq.c linux-2.6.25-vs2.3.0.34.9/arch/powerpc/kernel/irq.c
691 --- linux-2.6.25/arch/powerpc/kernel/irq.c      2008-04-17 12:05:29.000000000 -0400
692 +++ linux-2.6.25-vs2.3.0.34.9/arch/powerpc/kernel/irq.c 2008-04-19 15:14:52.000000000 -0400
693 @@ -53,6 +53,7 @@
694  #include <linux/bootmem.h>
695  #include <linux/pci.h>
696  #include <linux/debugfs.h>
697 +#include <linux/vs_context.h>
698  
699  #include <asm/uaccess.h>
700  #include <asm/system.h>
701 diff -NurpP --minimal linux-2.6.25/arch/powerpc/kernel/process.c linux-2.6.25-vs2.3.0.34.9/arch/powerpc/kernel/process.c
702 --- linux-2.6.25/arch/powerpc/kernel/process.c  2008-04-17 12:05:30.000000000 -0400
703 +++ linux-2.6.25-vs2.3.0.34.9/arch/powerpc/kernel/process.c     2008-04-19 15:14:52.000000000 -0400
704 @@ -464,8 +464,9 @@ void show_regs(struct pt_regs * regs)
705  #else
706                 printk("DAR: "REG", DSISR: "REG"\n", regs->dar, regs->dsisr);
707  #endif
708 -       printk("TASK = %p[%d] '%s' THREAD: %p",
709 -              current, task_pid_nr(current), current->comm, task_thread_info(current));
710 +       printk("TASK = %p[%d,#%u] '%s' THREAD: %p",
711 +              current, task_pid_nr(current), current->xid,
712 +              current->comm, task_thread_info(current));
713  
714  #ifdef CONFIG_SMP
715         printk(" CPU: %d", raw_smp_processor_id());
716 diff -NurpP --minimal linux-2.6.25/arch/powerpc/kernel/sys_ppc32.c linux-2.6.25-vs2.3.0.34.9/arch/powerpc/kernel/sys_ppc32.c
717 --- linux-2.6.25/arch/powerpc/kernel/sys_ppc32.c        2008-04-17 11:31:24.000000000 -0400
718 +++ linux-2.6.25-vs2.3.0.34.9/arch/powerpc/kernel/sys_ppc32.c   2008-04-19 15:14:52.000000000 -0400
719 @@ -205,7 +205,7 @@ asmlinkage long compat_sys_gettimeofday(
720  {
721         if (tv) {
722                 struct timeval ktv;
723 -               do_gettimeofday(&ktv);
724 +               vx_gettimeofday(&ktv);
725                 if (put_tv32(tv, &ktv))
726                         return -EFAULT;
727         }
728 diff -NurpP --minimal linux-2.6.25/arch/powerpc/kernel/traps.c linux-2.6.25-vs2.3.0.34.9/arch/powerpc/kernel/traps.c
729 --- linux-2.6.25/arch/powerpc/kernel/traps.c    2008-04-17 12:05:30.000000000 -0400
730 +++ linux-2.6.25-vs2.3.0.34.9/arch/powerpc/kernel/traps.c       2008-04-19 15:14:52.000000000 -0400
731 @@ -941,8 +941,9 @@ void nonrecoverable_exception(struct pt_
732  
733  void trace_syscall(struct pt_regs *regs)
734  {
735 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
736 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
737 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
738 +              current, task_pid_nr(current), current->xid,
739 +              regs->nip, regs->link, regs->gpr[0],
740                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
741  }
742  
743 diff -NurpP --minimal linux-2.6.25/arch/powerpc/kernel/vdso.c linux-2.6.25-vs2.3.0.34.9/arch/powerpc/kernel/vdso.c
744 --- linux-2.6.25/arch/powerpc/kernel/vdso.c     2008-04-17 12:05:30.000000000 -0400
745 +++ linux-2.6.25-vs2.3.0.34.9/arch/powerpc/kernel/vdso.c        2008-04-19 15:14:52.000000000 -0400
746 @@ -21,6 +21,7 @@
747  #include <linux/elf.h>
748  #include <linux/security.h>
749  #include <linux/bootmem.h>
750 +#include <linux/vs_memory.h>
751  
752  #include <asm/pgtable.h>
753  #include <asm/system.h>
754 diff -NurpP --minimal linux-2.6.25/arch/powerpc/mm/fault.c linux-2.6.25-vs2.3.0.34.9/arch/powerpc/mm/fault.c
755 --- linux-2.6.25/arch/powerpc/mm/fault.c        2008-04-17 12:05:30.000000000 -0400
756 +++ linux-2.6.25-vs2.3.0.34.9/arch/powerpc/mm/fault.c   2008-04-19 15:14:52.000000000 -0400
757 @@ -378,7 +378,8 @@ out_of_memory:
758                 down_read(&mm->mmap_sem);
759                 goto survive;
760         }
761 -       printk("VM: killing process %s\n", current->comm);
762 +       printk("VM: killing process %s(%d:#%u)\n",
763 +               current->comm, current->pid, current->xid);
764         if (user_mode(regs))
765                 do_group_exit(SIGKILL);
766         return SIGKILL;
767 diff -NurpP --minimal linux-2.6.25/arch/ppc/Kconfig linux-2.6.25-vs2.3.0.34.9/arch/ppc/Kconfig
768 --- linux-2.6.25/arch/ppc/Kconfig       2008-04-17 12:05:30.000000000 -0400
769 +++ linux-2.6.25-vs2.3.0.34.9/arch/ppc/Kconfig  2008-04-19 15:14:52.000000000 -0400
770 @@ -1261,6 +1261,8 @@ source "lib/Kconfig"
771  
772  source "arch/ppc/Kconfig.debug"
773  
774 +source "kernel/vserver/Kconfig"
775 +
776  source "security/Kconfig"
777  
778  source "crypto/Kconfig"
779 diff -NurpP --minimal linux-2.6.25/arch/ppc/kernel/traps.c linux-2.6.25-vs2.3.0.34.9/arch/ppc/kernel/traps.c
780 --- linux-2.6.25/arch/ppc/kernel/traps.c        2008-04-17 12:05:30.000000000 -0400
781 +++ linux-2.6.25-vs2.3.0.34.9/arch/ppc/kernel/traps.c   2008-04-19 15:14:52.000000000 -0400
782 @@ -669,8 +669,9 @@ void nonrecoverable_exception(struct pt_
783  
784  void trace_syscall(struct pt_regs *regs)
785  {
786 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
787 -              current, current->pid, regs->nip, regs->link, regs->gpr[0],
788 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
789 +              current, current->pid, current->xid,
790 +              regs->nip, regs->link, regs->gpr[0],
791                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
792  }
793  
794 diff -NurpP --minimal linux-2.6.25/arch/ppc/mm/fault.c linux-2.6.25-vs2.3.0.34.9/arch/ppc/mm/fault.c
795 --- linux-2.6.25/arch/ppc/mm/fault.c    2008-04-17 11:31:25.000000000 -0400
796 +++ linux-2.6.25-vs2.3.0.34.9/arch/ppc/mm/fault.c       2008-04-19 15:14:52.000000000 -0400
797 @@ -295,7 +295,8 @@ out_of_memory:
798                 down_read(&mm->mmap_sem);
799                 goto survive;
800         }
801 -       printk("VM: killing process %s\n", current->comm);
802 +       printk("VM: killing process %s(%d:#%u)\n",
803 +               current->comm, current->pid, current->xid);
804         if (user_mode(regs))
805                 do_group_exit(SIGKILL);
806         return SIGKILL;
807 diff -NurpP --minimal linux-2.6.25/arch/s390/Kconfig linux-2.6.25-vs2.3.0.34.9/arch/s390/Kconfig
808 --- linux-2.6.25/arch/s390/Kconfig      2008-04-17 12:05:30.000000000 -0400
809 +++ linux-2.6.25-vs2.3.0.34.9/arch/s390/Kconfig 2008-04-19 15:14:52.000000000 -0400
810 @@ -544,6 +544,8 @@ source "fs/Kconfig"
811  
812  source "arch/s390/Kconfig.debug"
813  
814 +source "kernel/vserver/Kconfig"
815 +
816  source "security/Kconfig"
817  
818  source "crypto/Kconfig"
819 diff -NurpP --minimal linux-2.6.25/arch/s390/kernel/compat_linux.c linux-2.6.25-vs2.3.0.34.9/arch/s390/kernel/compat_linux.c
820 --- linux-2.6.25/arch/s390/kernel/compat_linux.c        2008-04-17 11:31:25.000000000 -0400
821 +++ linux-2.6.25-vs2.3.0.34.9/arch/s390/kernel/compat_linux.c   2008-04-19 15:14:52.000000000 -0400
822 @@ -567,7 +567,7 @@ asmlinkage long sys32_gettimeofday(struc
823  {
824         if (tv) {
825                 struct timeval ktv;
826 -               do_gettimeofday(&ktv);
827 +               vx_gettimeofday(&ktv);
828                 if (put_tv32(tv, &ktv))
829                         return -EFAULT;
830         }
831 diff -NurpP --minimal linux-2.6.25/arch/s390/kernel/process.c linux-2.6.25-vs2.3.0.34.9/arch/s390/kernel/process.c
832 --- linux-2.6.25/arch/s390/kernel/process.c     2008-04-17 12:05:30.000000000 -0400
833 +++ linux-2.6.25-vs2.3.0.34.9/arch/s390/kernel/process.c        2008-04-21 11:09:01.000000000 -0400
834 @@ -194,9 +194,9 @@ void show_regs(struct pt_regs *regs)
835                init_utsname()->release,
836                (int)strcspn(init_utsname()->version, " "),
837                init_utsname()->version);
838 -       printk("Process %s (pid: %d, task: %p, ksp: %p)\n",
839 -              current->comm, current->pid, current,
840 -              (void *) current->thread.ksp);
841 +       printk("Process %s (pid: %d[#%u], task: %p, ksp: %p)\n",
842 +              current->comm, current->pid, current->xid,
843 +              (void *) current, (void *) current->thread.ksp);
844         show_registers(regs);
845         /* Show stack backtrace if pt_regs is from kernel mode */
846         if (!(regs->psw.mask & PSW_MASK_PSTATE))
847 diff -NurpP --minimal linux-2.6.25/arch/s390/kernel/ptrace.c linux-2.6.25-vs2.3.0.34.9/arch/s390/kernel/ptrace.c
848 --- linux-2.6.25/arch/s390/kernel/ptrace.c      2008-04-17 12:05:30.000000000 -0400
849 +++ linux-2.6.25-vs2.3.0.34.9/arch/s390/kernel/ptrace.c 2008-04-19 15:14:52.000000000 -0400
850 @@ -33,6 +33,7 @@
851  #include <linux/security.h>
852  #include <linux/audit.h>
853  #include <linux/signal.h>
854 +#include <linux/vs_base.h>
855  
856  #include <asm/segment.h>
857  #include <asm/page.h>
858 @@ -710,7 +711,13 @@ sys_ptrace(long request, long pid, long 
859                 goto out;
860         }
861  
862 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT)) {
863 +               ret = -EPERM;
864 +               goto out_tsk;
865 +       }
866 +
867         ret = do_ptrace(child, request, addr, data);
868 +out_tsk:
869         put_task_struct(child);
870  out:
871         unlock_kernel();
872 diff -NurpP --minimal linux-2.6.25/arch/s390/kernel/syscalls.S linux-2.6.25-vs2.3.0.34.9/arch/s390/kernel/syscalls.S
873 --- linux-2.6.25/arch/s390/kernel/syscalls.S    2008-04-17 12:05:30.000000000 -0400
874 +++ linux-2.6.25-vs2.3.0.34.9/arch/s390/kernel/syscalls.S       2008-04-19 15:14:52.000000000 -0400
875 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
876  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
877  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
878  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
879 -NI_SYSCALL                                                     /* reserved for vserver */
880 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
881  SYSCALL(s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
882  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
883  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
884 diff -NurpP --minimal linux-2.6.25/arch/s390/mm/fault.c linux-2.6.25-vs2.3.0.34.9/arch/s390/mm/fault.c
885 --- linux-2.6.25/arch/s390/mm/fault.c   2008-04-17 12:05:30.000000000 -0400
886 +++ linux-2.6.25-vs2.3.0.34.9/arch/s390/mm/fault.c      2008-04-19 15:14:52.000000000 -0400
887 @@ -217,7 +217,8 @@ static int do_out_of_memory(struct pt_re
888                 down_read(&mm->mmap_sem);
889                 return 1;
890         }
891 -       printk("VM: killing process %s\n", tsk->comm);
892 +       printk("VM: killing process %s(%d:#%u)\n",
893 +               tsk->comm, tsk->pid, tsk->xid);
894         if (regs->psw.mask & PSW_MASK_PSTATE)
895                 do_group_exit(SIGKILL);
896         do_no_context(regs, error_code, address);
897 diff -NurpP --minimal linux-2.6.25/arch/sh/Kconfig linux-2.6.25-vs2.3.0.34.9/arch/sh/Kconfig
898 --- linux-2.6.25/arch/sh/Kconfig        2008-04-17 12:05:30.000000000 -0400
899 +++ linux-2.6.25-vs2.3.0.34.9/arch/sh/Kconfig   2008-04-19 15:14:52.000000000 -0400
900 @@ -913,6 +913,8 @@ source "fs/Kconfig"
901  
902  source "arch/sh/Kconfig.debug"
903  
904 +source "kernel/vserver/Kconfig"
905 +
906  source "security/Kconfig"
907  
908  source "crypto/Kconfig"
909 diff -NurpP --minimal linux-2.6.25/arch/sh/kernel/irq.c linux-2.6.25-vs2.3.0.34.9/arch/sh/kernel/irq.c
910 --- linux-2.6.25/arch/sh/kernel/irq.c   2008-04-17 12:05:30.000000000 -0400
911 +++ linux-2.6.25-vs2.3.0.34.9/arch/sh/kernel/irq.c      2008-04-19 15:14:52.000000000 -0400
912 @@ -11,6 +11,7 @@
913  #include <linux/module.h>
914  #include <linux/kernel_stat.h>
915  #include <linux/seq_file.h>
916 +#include <linux/vs_context.h>
917  #include <asm/processor.h>
918  #include <asm/machvec.h>
919  #include <asm/uaccess.h>
920 diff -NurpP --minimal linux-2.6.25/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.25-vs2.3.0.34.9/arch/sh/kernel/vsyscall/vsyscall.c
921 --- linux-2.6.25/arch/sh/kernel/vsyscall/vsyscall.c     2008-04-17 10:37:14.000000000 -0400
922 +++ linux-2.6.25-vs2.3.0.34.9/arch/sh/kernel/vsyscall/vsyscall.c        2008-04-19 15:14:52.000000000 -0400
923 @@ -19,6 +19,7 @@
924  #include <linux/elf.h>
925  #include <linux/sched.h>
926  #include <linux/err.h>
927 +#include <linux/vs_memory.h>
928  
929  /*
930   * Should the kernel map a VDSO page into processes and pass its
931 diff -NurpP --minimal linux-2.6.25/arch/sparc/Kconfig linux-2.6.25-vs2.3.0.34.9/arch/sparc/Kconfig
932 --- linux-2.6.25/arch/sparc/Kconfig     2008-04-17 12:05:30.000000000 -0400
933 +++ linux-2.6.25-vs2.3.0.34.9/arch/sparc/Kconfig        2008-04-19 15:14:52.000000000 -0400
934 @@ -330,6 +330,8 @@ source "fs/Kconfig"
935  
936  source "arch/sparc/Kconfig.debug"
937  
938 +source "kernel/vserver/Kconfig"
939 +
940  source "security/Kconfig"
941  
942  source "crypto/Kconfig"
943 diff -NurpP --minimal linux-2.6.25/arch/sparc/kernel/ptrace.c linux-2.6.25-vs2.3.0.34.9/arch/sparc/kernel/ptrace.c
944 --- linux-2.6.25/arch/sparc/kernel/ptrace.c     2008-04-17 12:05:30.000000000 -0400
945 +++ linux-2.6.25-vs2.3.0.34.9/arch/sparc/kernel/ptrace.c        2008-04-21 10:36:17.000000000 -0400
946 @@ -21,6 +21,7 @@
947  #include <linux/signal.h>
948  #include <linux/regset.h>
949  #include <linux/elf.h>
950 +#include <linux/vs_base.h>
951  
952  #include <asm/pgtable.h>
953  #include <asm/system.h>
954 @@ -270,6 +271,10 @@ static int fpregs32_set(struct task_stru
955                                          33 * sizeof(u32),
956                                          34 * sizeof(u32));
957         }
958 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT)) {
959 +               pt_error_return(regs, ESRCH);
960 +               goto out_tsk;
961 +       }
962  
963         if (!ret)
964                 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
965 diff -NurpP --minimal linux-2.6.25/arch/sparc/kernel/systbls.S linux-2.6.25-vs2.3.0.34.9/arch/sparc/kernel/systbls.S
966 --- linux-2.6.25/arch/sparc/kernel/systbls.S    2008-04-17 12:05:30.000000000 -0400
967 +++ linux-2.6.25-vs2.3.0.34.9/arch/sparc/kernel/systbls.S       2008-04-19 15:14:52.000000000 -0400
968 @@ -70,7 +70,7 @@ sys_call_table:
969  /*250*/        .long sparc_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
970  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
971  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
972 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
973 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
974  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
975  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
976  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
977 diff -NurpP --minimal linux-2.6.25/arch/sparc/kernel/traps.c linux-2.6.25-vs2.3.0.34.9/arch/sparc/kernel/traps.c
978 --- linux-2.6.25/arch/sparc/kernel/traps.c      2008-04-17 11:31:25.000000000 -0400
979 +++ linux-2.6.25-vs2.3.0.34.9/arch/sparc/kernel/traps.c 2008-04-19 15:14:52.000000000 -0400
980 @@ -99,7 +99,8 @@ void die_if_kernel(char *str, struct pt_
981  "              /_| \\__/ |_\\\n"
982  "                 \\__U_/\n");
983  
984 -       printk("%s(%d): %s [#%d]\n", current->comm, task_pid_nr(current), str, ++die_counter);
985 +       printk("%s(%d[#%u]): %s [#%d]\n", current->comm,
986 +               task_pid_nr(current), current->xid, str, ++die_counter);
987         show_regs(regs);
988         add_taint(TAINT_DIE);
989  
990 diff -NurpP --minimal linux-2.6.25/arch/sparc/mm/fault.c linux-2.6.25-vs2.3.0.34.9/arch/sparc/mm/fault.c
991 --- linux-2.6.25/arch/sparc/mm/fault.c  2008-04-17 11:31:25.000000000 -0400
992 +++ linux-2.6.25-vs2.3.0.34.9/arch/sparc/mm/fault.c     2008-04-19 15:14:52.000000000 -0400
993 @@ -367,7 +367,8 @@ no_context:
994   */
995  out_of_memory:
996         up_read(&mm->mmap_sem);
997 -       printk("VM: killing process %s\n", tsk->comm);
998 +       printk("VM: killing process %s(%d:#%u)\n",
999 +               tsk->comm, tsk->pid, tsk->xid);
1000         if (from_user)
1001                 do_group_exit(SIGKILL);
1002         goto no_context;
1003 diff -NurpP --minimal linux-2.6.25/arch/sparc64/Kconfig linux-2.6.25-vs2.3.0.34.9/arch/sparc64/Kconfig
1004 --- linux-2.6.25/arch/sparc64/Kconfig   2008-04-17 12:05:30.000000000 -0400
1005 +++ linux-2.6.25-vs2.3.0.34.9/arch/sparc64/Kconfig      2008-04-19 15:14:52.000000000 -0400
1006 @@ -471,6 +471,8 @@ source "fs/Kconfig"
1007  
1008  source "arch/sparc64/Kconfig.debug"
1009  
1010 +source "kernel/vserver/Kconfig"
1011 +
1012  source "security/Kconfig"
1013  
1014  source "crypto/Kconfig"
1015 diff -NurpP --minimal linux-2.6.25/arch/sparc64/kernel/binfmt_aout32.c linux-2.6.25-vs2.3.0.34.9/arch/sparc64/kernel/binfmt_aout32.c
1016 --- linux-2.6.25/arch/sparc64/kernel/binfmt_aout32.c    2008-04-17 12:05:30.000000000 -0400
1017 +++ linux-2.6.25-vs2.3.0.34.9/arch/sparc64/kernel/binfmt_aout32.c       2008-04-19 15:14:52.000000000 -0400
1018 @@ -27,6 +27,7 @@
1019  #include <linux/binfmts.h>
1020  #include <linux/personality.h>
1021  #include <linux/init.h>
1022 +#include <linux/vs_memory.h>
1023  
1024  #include <asm/system.h>
1025  #include <asm/uaccess.h>
1026 diff -NurpP --minimal linux-2.6.25/arch/sparc64/kernel/ptrace.c linux-2.6.25-vs2.3.0.34.9/arch/sparc64/kernel/ptrace.c
1027 --- linux-2.6.25/arch/sparc64/kernel/ptrace.c   2008-04-17 12:05:30.000000000 -0400
1028 +++ linux-2.6.25-vs2.3.0.34.9/arch/sparc64/kernel/ptrace.c      2008-04-21 10:36:34.000000000 -0400
1029 @@ -25,6 +25,7 @@
1030  #include <linux/regset.h>
1031  #include <linux/compat.h>
1032  #include <linux/elf.h>
1033 +#include <linux/vs_base.h>
1034  
1035  #include <asm/asi.h>
1036  #include <asm/pgtable.h>
1037 @@ -222,6 +223,10 @@ static int genregs64_get(struct task_str
1038                                           16 * sizeof(u64),
1039                                           32 * sizeof(u64));
1040         }
1041 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT)) {
1042 +               pt_error_return(regs, ESRCH);
1043 +               goto out_tsk;
1044 +       }
1045  
1046         if (!ret) {
1047                 /* TSTATE, TPC, TNPC */
1048 diff -NurpP --minimal linux-2.6.25/arch/sparc64/kernel/sys_sparc32.c linux-2.6.25-vs2.3.0.34.9/arch/sparc64/kernel/sys_sparc32.c
1049 --- linux-2.6.25/arch/sparc64/kernel/sys_sparc32.c      2008-04-17 12:05:30.000000000 -0400
1050 +++ linux-2.6.25-vs2.3.0.34.9/arch/sparc64/kernel/sys_sparc32.c 2008-04-19 15:14:52.000000000 -0400
1051 @@ -722,7 +722,7 @@ asmlinkage long sys32_gettimeofday(struc
1052  {
1053         if (tv) {
1054                 struct timeval ktv;
1055 -               do_gettimeofday(&ktv);
1056 +               vx_gettimeofday(&ktv);
1057                 if (put_tv32(tv, &ktv))
1058                         return -EFAULT;
1059         }
1060 diff -NurpP --minimal linux-2.6.25/arch/sparc64/kernel/systbls.S linux-2.6.25-vs2.3.0.34.9/arch/sparc64/kernel/systbls.S
1061 --- linux-2.6.25/arch/sparc64/kernel/systbls.S  2008-04-17 12:05:30.000000000 -0400
1062 +++ linux-2.6.25-vs2.3.0.34.9/arch/sparc64/kernel/systbls.S     2008-04-19 15:14:52.000000000 -0400
1063 @@ -71,7 +71,7 @@ sys_call_table32:
1064  /*250*/        .word sys32_mremap, sys32_sysctl, sys32_getsid, sys_fdatasync, sys32_nfsservctl
1065         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
1066  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
1067 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
1068 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
1069  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
1070         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
1071  /*280*/        .word sys32_tee, sys_add_key, sys_request_key, sys_keyctl, compat_sys_openat
1072 @@ -144,7 +144,7 @@ sys_call_table:
1073  /*250*/        .word sys64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
1074         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
1075  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
1076 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
1077 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
1078  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
1079         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
1080  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
1081 diff -NurpP --minimal linux-2.6.25/arch/sparc64/kernel/traps.c linux-2.6.25-vs2.3.0.34.9/arch/sparc64/kernel/traps.c
1082 --- linux-2.6.25/arch/sparc64/kernel/traps.c    2008-04-17 12:05:30.000000000 -0400
1083 +++ linux-2.6.25-vs2.3.0.34.9/arch/sparc64/kernel/traps.c       2008-04-19 15:14:52.000000000 -0400
1084 @@ -2183,7 +2183,8 @@ void die_if_kernel(char *str, struct pt_
1085  "              /_| \\__/ |_\\\n"
1086  "                 \\__U_/\n");
1087  
1088 -       printk("%s(%d): %s [#%d]\n", current->comm, task_pid_nr(current), str, ++die_counter);
1089 +       printk("%s(%d[#%u]): %s [#%d]\n", current->comm,
1090 +               task_pid_nr(current), current->xid, str, ++die_counter);
1091         notify_die(DIE_OOPS, str, regs, 0, 255, SIGSEGV);
1092         __asm__ __volatile__("flushw");
1093         __show_regs(regs);
1094 diff -NurpP --minimal linux-2.6.25/arch/sparc64/mm/fault.c linux-2.6.25-vs2.3.0.34.9/arch/sparc64/mm/fault.c
1095 --- linux-2.6.25/arch/sparc64/mm/fault.c        2008-04-17 12:05:30.000000000 -0400
1096 +++ linux-2.6.25-vs2.3.0.34.9/arch/sparc64/mm/fault.c   2008-04-19 15:14:52.000000000 -0400
1097 @@ -453,7 +453,8 @@ handle_kernel_fault:
1098  out_of_memory:
1099         insn = get_fault_insn(regs, insn);
1100         up_read(&mm->mmap_sem);
1101 -       printk("VM: killing process %s\n", current->comm);
1102 +       printk("VM: killing process %s(%d:#%u)\n",
1103 +               current->comm, current->pid, current->xid);
1104         if (!(regs->tstate & TSTATE_PRIV))
1105                 do_group_exit(SIGKILL);
1106         goto handle_kernel_fault;
1107 diff -NurpP --minimal linux-2.6.25/arch/sparc64/solaris/fs.c linux-2.6.25-vs2.3.0.34.9/arch/sparc64/solaris/fs.c
1108 --- linux-2.6.25/arch/sparc64/solaris/fs.c      2008-04-17 12:05:30.000000000 -0400
1109 +++ linux-2.6.25-vs2.3.0.34.9/arch/sparc64/solaris/fs.c 2008-04-19 15:14:52.000000000 -0400
1110 @@ -368,7 +368,7 @@ static int report_statvfs(struct vfsmoun
1111                 int j = strlen (p);
1112                 
1113                 if (j > 15) j = 15;
1114 -               if (IS_RDONLY(inode)) i = 1;
1115 +               if (IS_RDONLY(inode) || MNT_IS_RDONLY(mnt)) i = 1;
1116                 if (mnt->mnt_flags & MNT_NOSUID) i |= 2;
1117                 if (!sysv_valid_dev(inode->i_sb->s_dev))
1118                         return -EOVERFLOW;
1119 @@ -404,7 +404,7 @@ static int report_statvfs64(struct vfsmo
1120                 int j = strlen (p);
1121                 
1122                 if (j > 15) j = 15;
1123 -               if (IS_RDONLY(inode)) i = 1;
1124 +               if (IS_RDONLY(inode) || MNT_IS_RDONLY(mnt)) i = 1;
1125                 if (mnt->mnt_flags & MNT_NOSUID) i |= 2;
1126                 if (!sysv_valid_dev(inode->i_sb->s_dev))
1127                         return -EOVERFLOW;
1128 diff -NurpP --minimal linux-2.6.25/arch/um/Kconfig linux-2.6.25-vs2.3.0.34.9/arch/um/Kconfig
1129 --- linux-2.6.25/arch/um/Kconfig        2008-04-17 12:05:30.000000000 -0400
1130 +++ linux-2.6.25-vs2.3.0.34.9/arch/um/Kconfig   2008-04-19 15:14:52.000000000 -0400
1131 @@ -245,6 +245,8 @@ source "drivers/connector/Kconfig"
1132  
1133  source "fs/Kconfig"
1134  
1135 +source "kernel/vserver/Kconfig"
1136 +
1137  source "security/Kconfig"
1138  
1139  source "crypto/Kconfig"
1140 diff -NurpP --minimal linux-2.6.25/arch/um/kernel/trap.c linux-2.6.25-vs2.3.0.34.9/arch/um/kernel/trap.c
1141 --- linux-2.6.25/arch/um/kernel/trap.c  2008-04-17 12:05:30.000000000 -0400
1142 +++ linux-2.6.25-vs2.3.0.34.9/arch/um/kernel/trap.c     2008-04-19 15:14:52.000000000 -0400
1143 @@ -215,7 +215,8 @@ unsigned long segv(struct faultinfo fi, 
1144                 current->thread.arch.faultinfo = fi;
1145                 force_sig_info(SIGBUS, &si, current);
1146         } else if (err == -ENOMEM) {
1147 -               printk(KERN_INFO "VM: killing process %s\n", current->comm);
1148 +               printk(KERN_INFO "VM: killing process %s(%d:#%u)\n",
1149 +                       current->comm, task_pid_nr(current), current->xid);
1150                 do_exit(SIGKILL);
1151         } else {
1152                 BUG_ON(err != -EFAULT);
1153 diff -NurpP --minimal linux-2.6.25/arch/v850/Kconfig linux-2.6.25-vs2.3.0.34.9/arch/v850/Kconfig
1154 --- linux-2.6.25/arch/v850/Kconfig      2008-04-17 12:05:30.000000000 -0400
1155 +++ linux-2.6.25-vs2.3.0.34.9/arch/v850/Kconfig 2008-04-19 15:14:52.000000000 -0400
1156 @@ -344,6 +344,8 @@ source "drivers/usb/Kconfig"
1157  
1158  source "arch/v850/Kconfig.debug"
1159  
1160 +source "kernel/vserver/Kconfig"
1161 +
1162  source "security/Kconfig"
1163  
1164  source "crypto/Kconfig"
1165 diff -NurpP --minimal linux-2.6.25/arch/v850/kernel/ptrace.c linux-2.6.25-vs2.3.0.34.9/arch/v850/kernel/ptrace.c
1166 --- linux-2.6.25/arch/v850/kernel/ptrace.c      2008-04-17 10:37:14.000000000 -0400
1167 +++ linux-2.6.25-vs2.3.0.34.9/arch/v850/kernel/ptrace.c 2008-04-19 15:14:52.000000000 -0400
1168 @@ -23,6 +23,7 @@
1169  #include <linux/sched.h>
1170  #include <linux/ptrace.h>
1171  #include <linux/signal.h>
1172 +#include <linux/vs_base.h>
1173  
1174  #include <asm/errno.h>
1175  #include <asm/ptrace.h>
1176 @@ -116,6 +117,9 @@ long arch_ptrace(struct task_struct *chi
1177  {
1178         int rval;
1179  
1180 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
1181 +               goto out;
1182 +
1183         switch (request) {
1184                 unsigned long val;
1185  
1186 diff -NurpP --minimal linux-2.6.25/arch/x86/ia32/ia32entry.S linux-2.6.25-vs2.3.0.34.9/arch/x86/ia32/ia32entry.S
1187 --- linux-2.6.25/arch/x86/ia32/ia32entry.S      2008-04-17 12:05:30.000000000 -0400
1188 +++ linux-2.6.25-vs2.3.0.34.9/arch/x86/ia32/ia32entry.S 2008-04-22 20:07:49.000000000 -0400
1189 @@ -673,7 +673,7 @@ ia32_sys_call_table:
1190         .quad sys_tgkill                /* 270 */
1191         .quad compat_sys_utimes
1192         .quad sys32_fadvise64_64
1193 -       .quad quiet_ni_syscall  /* sys_vserver */
1194 +       .quad sys32_vserver
1195         .quad sys_mbind
1196         .quad compat_sys_get_mempolicy  /* 275 */
1197         .quad sys_set_mempolicy
1198 diff -NurpP --minimal linux-2.6.25/arch/x86/Kconfig linux-2.6.25-vs2.3.0.34.9/arch/x86/Kconfig
1199 --- linux-2.6.25/arch/x86/Kconfig       2008-04-17 12:05:30.000000000 -0400
1200 +++ linux-2.6.25-vs2.3.0.34.9/arch/x86/Kconfig  2008-04-19 15:14:52.000000000 -0400
1201 @@ -1611,6 +1611,8 @@ source "fs/Kconfig"
1202  
1203  source "arch/x86/Kconfig.debug"
1204  
1205 +source "kernel/vserver/Kconfig"
1206 +
1207  source "security/Kconfig"
1208  
1209  source "crypto/Kconfig"
1210 diff -NurpP --minimal linux-2.6.25/arch/x86/kernel/syscall_table_32.S linux-2.6.25-vs2.3.0.34.9/arch/x86/kernel/syscall_table_32.S
1211 --- linux-2.6.25/arch/x86/kernel/syscall_table_32.S     2008-04-17 12:05:30.000000000 -0400
1212 +++ linux-2.6.25-vs2.3.0.34.9/arch/x86/kernel/syscall_table_32.S        2008-04-19 15:14:52.000000000 -0400
1213 @@ -272,7 +272,7 @@ ENTRY(sys_call_table)
1214         .long sys_tgkill        /* 270 */
1215         .long sys_utimes
1216         .long sys_fadvise64_64
1217 -       .long sys_ni_syscall    /* sys_vserver */
1218 +       .long sys_vserver
1219         .long sys_mbind
1220         .long sys_get_mempolicy
1221         .long sys_set_mempolicy
1222 diff -NurpP --minimal linux-2.6.25/Documentation/vserver/debug.txt linux-2.6.25-vs2.3.0.34.9/Documentation/vserver/debug.txt
1223 --- linux-2.6.25/Documentation/vserver/debug.txt        1969-12-31 19:00:00.000000000 -0500
1224 +++ linux-2.6.25-vs2.3.0.34.9/Documentation/vserver/debug.txt   2008-04-19 15:14:51.000000000 -0400
1225 @@ -0,0 +1,154 @@
1226 +
1227 +debug_cvirt:
1228 +
1229 + 2   4 "vx_map_tgid: %p/%llx: %d -> %d"
1230 +       "vx_rmap_tgid: %p/%llx: %d -> %d"
1231 +
1232 +debug_dlim:
1233 +
1234 + 0   1 "ALLOC (%p,#%d)%c inode (%d)"
1235 +       "FREE  (%p,#%d)%c inode"
1236 + 1   2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
1237 +       "FREE  (%p,#%d)%c %lld bytes"
1238 + 2   4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
1239 + 3   8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
1240 +       "ext3_has_free_blocks(%p): free=%lu, root=%lu"
1241 +       "rcu_free_dl_info(%p)"
1242 + 4  10 "alloc_dl_info(%p,%d) = %p"
1243 +       "dealloc_dl_info(%p)"
1244 +       "get_dl_info(%p[#%d.%d])"
1245 +       "put_dl_info(%p[#%d.%d])"
1246 + 5  20 "alloc_dl_info(%p,%d)*"
1247 + 6  40 "__hash_dl_info: %p[#%d]"
1248 +       "__unhash_dl_info: %p[#%d]"
1249 + 7  80 "locate_dl_info(%p,#%d) = %p"
1250 +
1251 +debug_misc:
1252 +
1253 + 0   1 "destroy_dqhash: %p [#0x%08x] c=%d"
1254 +       "new_dqhash: %p [#0x%08x]"
1255 +       "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
1256 +       "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
1257 +       "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
1258 +       "vroot_get_real_bdev not set"
1259 + 1   2 "cow_break_link(»%s«)"
1260 +       "temp copy Â»%s«"
1261 + 2   4 "dentry_open(new): %p"
1262 +       "dentry_open(old): %p"
1263 +       "lookup_create(new): %p"
1264 +       "old path Â»%s«"
1265 +       "path_lookup(old): %d"
1266 +       "vfs_create(new): %d"
1267 +       "vfs_rename: %d"
1268 +       "vfs_sendfile: %d"
1269 + 3   8 "fput(new_file=%p[#%d])"
1270 +       "fput(old_file=%p[#%d])"
1271 + 4  10 "vx_info_kill(%p[#%d],%d,%d) = %d"
1272 +       "vx_info_kill(%p[#%d],%d,%d)*"
1273 + 5  20 "vs_reboot(%p[#%d],%d)"
1274 + 6  40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
1275 +
1276 +debug_net:
1277 +
1278 + 2   4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
1279 + 3   8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
1280 +       "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
1281 + 4  10 "ip_route_connect(%p) %p,%p;%lx"
1282 + 5  20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
1283 + 6  40 "sk,egf: %p [#%d] (from %d)"
1284 +       "sk,egn: %p [#%d] (from %d)"
1285 +       "sk,req: %p [#%d] (from %d)"
1286 +       "sk: %p [#%d] (from %d)"
1287 +       "tw: %p [#%d] (from %d)"
1288 + 7  80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
1289 +       "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
1290 +
1291 +debug_nid:
1292 +
1293 + 0   1 "__lookup_nx_info(#%u): %p[#%u]"
1294 +       "alloc_nx_info(%d) = %p"
1295 +       "create_nx_info(%d) (dynamic rejected)"
1296 +       "create_nx_info(%d) = %p (already there)"
1297 +       "create_nx_info(%d) = %p (new)"
1298 +       "dealloc_nx_info(%p)"
1299 + 1   2 "alloc_nx_info(%d)*"
1300 +       "create_nx_info(%d)*"
1301 + 2   4 "get_nx_info(%p[#%d.%d])"
1302 +       "put_nx_info(%p[#%d.%d])"
1303 + 3   8 "claim_nx_info(%p[#%d.%d.%d]) %p"
1304 +       "clr_nx_info(%p[#%d.%d])"
1305 +       "init_nx_info(%p[#%d.%d])"
1306 +       "release_nx_info(%p[#%d.%d.%d]) %p"
1307 +       "set_nx_info(%p[#%d.%d])"
1308 + 4  10 "__hash_nx_info: %p[#%d]"
1309 +       "__nx_dynamic_id: [#%d]"
1310 +       "__unhash_nx_info: %p[#%d.%d.%d]"
1311 + 5  20 "moved task %p into nxi:%p[#%d]"
1312 +       "nx_migrate_task(%p,%p[#%d.%d.%d])"
1313 +       "task_get_nx_info(%p)"
1314 + 6  40 "nx_clear_persistent(%p[#%d])"
1315 +
1316 +debug_quota:
1317 +
1318 + 0   1 "quota_sync_dqh(%p,%d) discard inode %p"
1319 + 1   2 "quota_sync_dqh(%p,%d)"
1320 +       "sync_dquots(%p,%d)"
1321 +       "sync_dquots_dqh(%p,%d)"
1322 + 3   8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
1323 +
1324 +debug_switch:
1325 +
1326 + 0   1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
1327 + 1   2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
1328 + 4  10 "%s: (%s %s) returned %s with %d"
1329 +
1330 +debug_tag:
1331 +
1332 + 7  80 "dx_parse_tag(»%s«): %d:#%d"
1333 +       "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
1334 +
1335 +debug_xid:
1336 +
1337 + 0   1 "__lookup_vx_info(#%u): %p[#%u]"
1338 +       "alloc_vx_info(%d) = %p"
1339 +       "alloc_vx_info(%d)*"
1340 +       "create_vx_info(%d) (dynamic rejected)"
1341 +       "create_vx_info(%d) = %p (already there)"
1342 +       "create_vx_info(%d) = %p (new)"
1343 +       "dealloc_vx_info(%p)"
1344 +       "loc_vx_info(%d) = %p (found)"
1345 +       "loc_vx_info(%d) = %p (new)"
1346 +       "loc_vx_info(%d) = %p (not available)"
1347 + 1   2 "create_vx_info(%d)*"
1348 +       "loc_vx_info(%d)*"
1349 + 2   4 "get_vx_info(%p[#%d.%d])"
1350 +       "put_vx_info(%p[#%d.%d])"
1351 + 3   8 "claim_vx_info(%p[#%d.%d.%d]) %p"
1352 +       "clr_vx_info(%p[#%d.%d])"
1353 +       "init_vx_info(%p[#%d.%d])"
1354 +       "release_vx_info(%p[#%d.%d.%d]) %p"
1355 +       "set_vx_info(%p[#%d.%d])"
1356 + 4  10 "__hash_vx_info: %p[#%d]"
1357 +       "__unhash_vx_info: %p[#%d.%d.%d]"
1358 +       "__vx_dynamic_id: [#%d]"
1359 + 5  20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
1360 +       "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
1361 +       "moved task %p into vxi:%p[#%d]"
1362 +       "task_get_vx_info(%p)"
1363 +       "vx_migrate_task(%p,%p[#%d.%d])"
1364 + 6  40 "vx_clear_persistent(%p[#%d])"
1365 +       "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
1366 +       "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
1367 +       "vx_set_persistent(%p[#%d])"
1368 +       "vx_set_reaper(%p[#%d],%p[#%d,%d])"
1369 + 7  80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
1370 +
1371 +
1372 +debug_limit:
1373 +
1374 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
1375 +       "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1376 +
1377 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
1378 +       "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
1379 +       "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1380 diff -NurpP --minimal linux-2.6.25/drivers/block/Kconfig linux-2.6.25-vs2.3.0.34.9/drivers/block/Kconfig
1381 --- linux-2.6.25/drivers/block/Kconfig  2008-04-17 12:05:31.000000000 -0400
1382 +++ linux-2.6.25-vs2.3.0.34.9/drivers/block/Kconfig     2008-04-19 15:14:52.000000000 -0400
1383 @@ -263,6 +263,13 @@ config BLK_DEV_CRYPTOLOOP
1384           instead, which can be configured to be on-disk compatible with the
1385           cryptoloop device.
1386  
1387 +config BLK_DEV_VROOT
1388 +       tristate "Virtual Root device support"
1389 +       depends on QUOTACTL
1390 +       ---help---
1391 +         Saying Y here will allow you to use quota/fs ioctls on a shared
1392 +         partition within a virtual server without compromising security.
1393 +
1394  config BLK_DEV_NBD
1395         tristate "Network block device support"
1396         depends on NET
1397 diff -NurpP --minimal linux-2.6.25/drivers/block/loop.c linux-2.6.25-vs2.3.0.34.9/drivers/block/loop.c
1398 --- linux-2.6.25/drivers/block/loop.c   2008-04-17 12:05:32.000000000 -0400
1399 +++ linux-2.6.25-vs2.3.0.34.9/drivers/block/loop.c      2008-04-19 15:14:52.000000000 -0400
1400 @@ -76,6 +76,7 @@
1401  #include <linux/gfp.h>
1402  #include <linux/kthread.h>
1403  #include <linux/splice.h>
1404 +#include <linux/vs_context.h>
1405  
1406  #include <asm/uaccess.h>
1407  
1408 @@ -789,6 +790,7 @@ static int loop_set_fd(struct loop_devic
1409         lo->lo_blocksize = lo_blocksize;
1410         lo->lo_device = bdev;
1411         lo->lo_flags = lo_flags;
1412 +       lo->lo_xid = vx_current_xid();
1413         lo->lo_backing_file = file;
1414         lo->transfer = transfer_none;
1415         lo->ioctl = NULL;
1416 @@ -908,6 +910,7 @@ static int loop_clr_fd(struct loop_devic
1417         lo->lo_encrypt_key_size = 0;
1418         lo->lo_flags = 0;
1419         lo->lo_thread = NULL;
1420 +       lo->lo_xid = 0;
1421         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
1422         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
1423         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
1424 @@ -929,7 +932,7 @@ loop_set_status(struct loop_device *lo, 
1425         struct loop_func_table *xfer;
1426  
1427         if (lo->lo_encrypt_key_size && lo->lo_key_owner != current->uid &&
1428 -           !capable(CAP_SYS_ADMIN))
1429 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
1430                 return -EPERM;
1431         if (lo->lo_state != Lo_bound)
1432                 return -ENXIO;
1433 @@ -1013,7 +1016,8 @@ loop_get_status(struct loop_device *lo, 
1434         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
1435         info->lo_encrypt_type =
1436                 lo->lo_encryption ? lo->lo_encryption->number : 0;
1437 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
1438 +       if (lo->lo_encrypt_key_size &&
1439 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
1440                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
1441                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
1442                        lo->lo_encrypt_key_size);
1443 @@ -1322,6 +1326,9 @@ static int lo_open(struct inode *inode, 
1444  {
1445         struct loop_device *lo = inode->i_bdev->bd_disk->private_data;
1446  
1447 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P))
1448 +               return -EACCES;
1449 +
1450         mutex_lock(&lo->lo_ctl_mutex);
1451         lo->lo_refcnt++;
1452         mutex_unlock(&lo->lo_ctl_mutex);
1453 diff -NurpP --minimal linux-2.6.25/drivers/block/Makefile linux-2.6.25-vs2.3.0.34.9/drivers/block/Makefile
1454 --- linux-2.6.25/drivers/block/Makefile 2008-04-17 12:05:31.000000000 -0400
1455 +++ linux-2.6.25-vs2.3.0.34.9/drivers/block/Makefile    2008-04-19 15:14:52.000000000 -0400
1456 @@ -29,5 +29,6 @@ obj-$(CONFIG_VIRTIO_BLK)      += virtio_blk.o
1457  obj-$(CONFIG_VIODASD)          += viodasd.o
1458  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
1459  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
1460 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
1461  
1462  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
1463 diff -NurpP --minimal linux-2.6.25/drivers/block/vroot.c linux-2.6.25-vs2.3.0.34.9/drivers/block/vroot.c
1464 --- linux-2.6.25/drivers/block/vroot.c  1969-12-31 19:00:00.000000000 -0500
1465 +++ linux-2.6.25-vs2.3.0.34.9/drivers/block/vroot.c     2008-04-19 15:14:52.000000000 -0400
1466 @@ -0,0 +1,280 @@
1467 +/*
1468 + *  linux/drivers/block/vroot.c
1469 + *
1470 + *  written by Herbert Pötzl, 9/11/2002
1471 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
1472 + *
1473 + *  based on the loop.c code by Theodore Ts'o.
1474 + *
1475 + * Copyright (C) 2002-2007 by Herbert Pötzl.
1476 + * Redistribution of this file is permitted under the
1477 + * GNU General Public License.
1478 + *
1479 + */
1480 +
1481 +#include <linux/module.h>
1482 +#include <linux/moduleparam.h>
1483 +#include <linux/file.h>
1484 +#include <linux/major.h>
1485 +#include <linux/blkdev.h>
1486 +
1487 +#include <linux/vroot.h>
1488 +#include <linux/vs_context.h>
1489 +
1490 +
1491 +static int max_vroot = 8;
1492 +
1493 +static struct vroot_device *vroot_dev;
1494 +static struct gendisk **disks;
1495 +
1496 +
1497 +static int vroot_set_dev(
1498 +       struct vroot_device *vr,
1499 +       struct file *vr_file,
1500 +       struct block_device *bdev,
1501 +       unsigned int arg)
1502 +{
1503 +       struct block_device *real_bdev;
1504 +       struct file *file;
1505 +       struct inode *inode;
1506 +       int error;
1507 +
1508 +       error = -EBUSY;
1509 +       if (vr->vr_state != Vr_unbound)
1510 +               goto out;
1511 +
1512 +       error = -EBADF;
1513 +       file = fget(arg);
1514 +       if (!file)
1515 +               goto out;
1516 +
1517 +       error = -EINVAL;
1518 +       inode = file->f_dentry->d_inode;
1519 +
1520 +
1521 +       if (S_ISBLK(inode->i_mode)) {
1522 +               real_bdev = inode->i_bdev;
1523 +               vr->vr_device = real_bdev;
1524 +               __iget(real_bdev->bd_inode);
1525 +       } else
1526 +               goto out_fput;
1527 +
1528 +       vxdprintk(VXD_CBIT(misc, 0),
1529 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
1530 +               vr->vr_number, VXD_DEV(real_bdev));
1531 +
1532 +       vr->vr_state = Vr_bound;
1533 +       error = 0;
1534 +
1535 + out_fput:
1536 +       fput(file);
1537 + out:
1538 +       return error;
1539 +}
1540 +
1541 +static int vroot_clr_dev(
1542 +       struct vroot_device *vr,
1543 +       struct file *vr_file,
1544 +       struct block_device *bdev)
1545 +{
1546 +       struct block_device *real_bdev;
1547 +
1548 +       if (vr->vr_state != Vr_bound)
1549 +               return -ENXIO;
1550 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
1551 +               return -EBUSY;
1552 +
1553 +       real_bdev = vr->vr_device;
1554 +
1555 +       vxdprintk(VXD_CBIT(misc, 0),
1556 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1557 +               vr->vr_number, VXD_DEV(real_bdev));
1558 +
1559 +       bdput(real_bdev);
1560 +       vr->vr_state = Vr_unbound;
1561 +       vr->vr_device = NULL;
1562 +       return 0;
1563 +}
1564 +
1565 +
1566 +static int vr_ioctl(struct inode *inode, struct file *file,
1567 +       unsigned int cmd, unsigned long arg)
1568 +{
1569 +       struct vroot_device *vr = inode->i_bdev->bd_disk->private_data;
1570 +       int err;
1571 +
1572 +       down(&vr->vr_ctl_mutex);
1573 +       switch (cmd) {
1574 +       case VROOT_SET_DEV:
1575 +               err = vroot_set_dev(vr, file, inode->i_bdev, arg);
1576 +               break;
1577 +       case VROOT_CLR_DEV:
1578 +               err = vroot_clr_dev(vr, file, inode->i_bdev);
1579 +               break;
1580 +       default:
1581 +               err = -EINVAL;
1582 +               break;
1583 +       }
1584 +       up(&vr->vr_ctl_mutex);
1585 +       return err;
1586 +}
1587 +
1588 +static int vr_open(struct inode *inode, struct file *file)
1589 +{
1590 +       struct vroot_device *vr = inode->i_bdev->bd_disk->private_data;
1591 +
1592 +       down(&vr->vr_ctl_mutex);
1593 +       vr->vr_refcnt++;
1594 +       up(&vr->vr_ctl_mutex);
1595 +       return 0;
1596 +}
1597 +
1598 +static int vr_release(struct inode *inode, struct file *file)
1599 +{
1600 +       struct vroot_device *vr = inode->i_bdev->bd_disk->private_data;
1601 +
1602 +       down(&vr->vr_ctl_mutex);
1603 +       --vr->vr_refcnt;
1604 +       up(&vr->vr_ctl_mutex);
1605 +       return 0;
1606 +}
1607 +
1608 +static struct block_device_operations vr_fops = {
1609 +       .owner =        THIS_MODULE,
1610 +       .open =         vr_open,
1611 +       .release =      vr_release,
1612 +       .ioctl =        vr_ioctl,
1613 +};
1614 +
1615 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1616 +{
1617 +       struct inode *inode = bdev->bd_inode;
1618 +       struct vroot_device *vr;
1619 +       struct block_device *real_bdev;
1620 +       int minor = iminor(inode);
1621 +
1622 +       vr = &vroot_dev[minor];
1623 +       real_bdev = vr->vr_device;
1624 +
1625 +       vxdprintk(VXD_CBIT(misc, 0),
1626 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1627 +               vr->vr_number, VXD_DEV(real_bdev));
1628 +
1629 +       if (vr->vr_state != Vr_bound)
1630 +               return ERR_PTR(-ENXIO);
1631 +
1632 +       __iget(real_bdev->bd_inode);
1633 +       return real_bdev;
1634 +}
1635 +
1636 +/*
1637 + * And now the modules code and kernel interface.
1638 + */
1639 +
1640 +module_param(max_vroot, int, 0);
1641 +
1642 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1643 +MODULE_LICENSE("GPL");
1644 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1645 +
1646 +MODULE_AUTHOR ("Herbert Pötzl");
1647 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1648 +
1649 +
1650 +int __init vroot_init(void)
1651 +{
1652 +       int err, i;
1653 +
1654 +       if (max_vroot < 1 || max_vroot > 256) {
1655 +               max_vroot = MAX_VROOT_DEFAULT;
1656 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1657 +                       "(must be between 1 and 256), "
1658 +                       "using default (%d)\n", max_vroot);
1659 +       }
1660 +
1661 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1662 +               return -EIO;
1663 +
1664 +       err = -ENOMEM;
1665 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1666 +       if (!vroot_dev)
1667 +               goto out_mem1;
1668 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1669 +
1670 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1671 +       if (!disks)
1672 +               goto out_mem2;
1673 +
1674 +       for (i = 0; i < max_vroot; i++) {
1675 +               disks[i] = alloc_disk(1);
1676 +               if (!disks[i])
1677 +                       goto out_mem3;
1678 +       }
1679 +
1680 +       for (i = 0; i < max_vroot; i++) {
1681 +               struct vroot_device *vr = &vroot_dev[i];
1682 +               struct gendisk *disk = disks[i];
1683 +
1684 +               memset(vr, 0, sizeof(*vr));
1685 +               init_MUTEX(&vr->vr_ctl_mutex);
1686 +               vr->vr_number = i;
1687 +               disk->major = VROOT_MAJOR;
1688 +               disk->first_minor = i;
1689 +               disk->fops = &vr_fops;
1690 +               sprintf(disk->disk_name, "vroot%d", i);
1691 +               disk->private_data = vr;
1692 +       }
1693 +
1694 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1695 +       if (err)
1696 +               goto out_mem3;
1697 +
1698 +       for (i = 0; i < max_vroot; i++)
1699 +               add_disk(disks[i]);
1700 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1701 +       return 0;
1702 +
1703 +out_mem3:
1704 +       while (i--)
1705 +               put_disk(disks[i]);
1706 +       kfree(disks);
1707 +out_mem2:
1708 +       kfree(vroot_dev);
1709 +out_mem1:
1710 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1711 +       printk(KERN_ERR "vroot: ran out of memory\n");
1712 +       return err;
1713 +}
1714 +
1715 +void vroot_exit(void)
1716 +{
1717 +       int i;
1718 +
1719 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1720 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1721 +
1722 +       for (i = 0; i < max_vroot; i++) {
1723 +               del_gendisk(disks[i]);
1724 +               put_disk(disks[i]);
1725 +       }
1726 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1727 +
1728 +       kfree(disks);
1729 +       kfree(vroot_dev);
1730 +}
1731 +
1732 +module_init(vroot_init);
1733 +module_exit(vroot_exit);
1734 +
1735 +#ifndef MODULE
1736 +
1737 +static int __init max_vroot_setup(char *str)
1738 +{
1739 +       max_vroot = simple_strtol(str, NULL, 0);
1740 +       return 1;
1741 +}
1742 +
1743 +__setup("max_vroot=", max_vroot_setup);
1744 +
1745 +#endif
1746 +
1747 diff -NurpP --minimal linux-2.6.25/drivers/char/sysrq.c linux-2.6.25-vs2.3.0.34.9/drivers/char/sysrq.c
1748 --- linux-2.6.25/drivers/char/sysrq.c   2008-04-17 11:31:27.000000000 -0400
1749 +++ linux-2.6.25-vs2.3.0.34.9/drivers/char/sysrq.c      2008-04-19 15:14:52.000000000 -0400
1750 @@ -37,6 +37,7 @@
1751  #include <linux/irq.h>
1752  #include <linux/hrtimer.h>
1753  #include <linux/oom.h>
1754 +#include <linux/vserver/debug.h>
1755  
1756  #include <asm/ptrace.h>
1757  #include <asm/irq_regs.h>
1758 @@ -310,6 +311,21 @@ static struct sysrq_key_op sysrq_unrt_op
1759         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1760  };
1761  
1762 +
1763 +#ifdef CONFIG_VSERVER_DEBUG
1764 +static void sysrq_handle_vxinfo(int key, struct tty_struct *tty)
1765 +{
1766 +       dump_vx_info_inactive((key == 'x')?0:1);
1767 +}
1768 +
1769 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1770 +       .handler        = sysrq_handle_vxinfo,
1771 +       .help_msg       = "conteXt",
1772 +       .action_msg     = "Show Context Info",
1773 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1774 +};
1775 +#endif
1776 +
1777  /* Key Operations table and lock */
1778  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1779  
1780 @@ -358,7 +374,11 @@ static struct sysrq_key_op *sysrq_key_ta
1781         /* x: May be registered on ppc/powerpc for xmon */
1782         NULL,                           /* x */
1783         NULL,                           /* y */
1784 -       NULL                            /* z */
1785 +#ifdef CONFIG_VSERVER_DEBUG
1786 +       &sysrq_showvxinfo_op,           /* z */
1787 +#else
1788 +       NULL,                           /* z */
1789 +#endif
1790  };
1791  
1792  /* key2index calculation, -1 on invalid index */
1793 @@ -370,6 +390,8 @@ static int sysrq_key_table_key2index(int
1794                 retval = key - '0';
1795         else if ((key >= 'a') && (key <= 'z'))
1796                 retval = key + 10 - 'a';
1797 +       else if ((key >= 'A') && (key <= 'Z'))
1798 +               retval = key + 10 - 'A';
1799         else
1800                 retval = -1;
1801         return retval;
1802 diff -NurpP --minimal linux-2.6.25/drivers/char/tty_io.c linux-2.6.25-vs2.3.0.34.9/drivers/char/tty_io.c
1803 --- linux-2.6.25/drivers/char/tty_io.c  2008-04-17 12:05:32.000000000 -0400
1804 +++ linux-2.6.25-vs2.3.0.34.9/drivers/char/tty_io.c     2008-04-19 15:14:52.000000000 -0400
1805 @@ -105,6 +105,7 @@
1806  
1807  #include <linux/kmod.h>
1808  #include <linux/nsproxy.h>
1809 +#include <linux/vs_pid.h>
1810  
1811  #undef TTY_DEBUG_HANGUP
1812  
1813 @@ -3142,6 +3143,7 @@ static int tiocspgrp(struct tty_struct *
1814                 return -ENOTTY;
1815         if (get_user(pgrp_nr, p))
1816                 return -EFAULT;
1817 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1818         if (pgrp_nr < 0)
1819                 return -EINVAL;
1820         rcu_read_lock();
1821 diff -NurpP --minimal linux-2.6.25/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.25-vs2.3.0.34.9/drivers/infiniband/hw/ipath/ipath_user_pages.c
1822 --- linux-2.6.25/drivers/infiniband/hw/ipath/ipath_user_pages.c 2008-04-17 10:37:17.000000000 -0400
1823 +++ linux-2.6.25-vs2.3.0.34.9/drivers/infiniband/hw/ipath/ipath_user_pages.c    2008-04-19 15:14:52.000000000 -0400
1824 @@ -33,6 +33,7 @@
1825  
1826  #include <linux/mm.h>
1827  #include <linux/device.h>
1828 +#include <linux/vs_memory.h>
1829  
1830  #include "ipath_kernel.h"
1831  
1832 @@ -61,7 +62,8 @@ static int __get_user_pages(unsigned lon
1833         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur >>
1834                 PAGE_SHIFT;
1835  
1836 -       if (num_pages > lock_limit) {
1837 +       if (num_pages > lock_limit ||
1838 +               !vx_vmlocked_avail(current->mm, num_pages)) {
1839                 ret = -ENOMEM;
1840                 goto bail;
1841         }
1842 @@ -78,7 +80,7 @@ static int __get_user_pages(unsigned lon
1843                         goto bail_release;
1844         }
1845  
1846 -       current->mm->locked_vm += num_pages;
1847 +       vx_vmlocked_add(current->mm, num_pages);
1848  
1849         ret = 0;
1850         goto bail;
1851 @@ -177,7 +179,7 @@ void ipath_release_user_pages(struct pag
1852  
1853         __ipath_release_user_pages(p, num_pages, 1);
1854  
1855 -       current->mm->locked_vm -= num_pages;
1856 +       vx_vmlocked_sub(current->mm, num_pages);
1857  
1858         up_write(&current->mm->mmap_sem);
1859  }
1860 @@ -194,7 +196,7 @@ static void user_pages_account(struct wo
1861                 container_of(_work, struct ipath_user_pages_work, work);
1862  
1863         down_write(&work->mm->mmap_sem);
1864 -       work->mm->locked_vm -= work->num_pages;
1865 +       vx_vmlocked_sub(work->mm, work->num_pages);
1866         up_write(&work->mm->mmap_sem);
1867         mmput(work->mm);
1868         kfree(work);
1869 diff -NurpP --minimal linux-2.6.25/drivers/md/dm.c linux-2.6.25-vs2.3.0.34.9/drivers/md/dm.c
1870 --- linux-2.6.25/drivers/md/dm.c        2008-04-17 12:05:33.000000000 -0400
1871 +++ linux-2.6.25-vs2.3.0.34.9/drivers/md/dm.c   2008-04-19 15:14:52.000000000 -0400
1872 @@ -22,6 +22,7 @@
1873  #include <linux/hdreg.h>
1874  #include <linux/blktrace_api.h>
1875  #include <linux/smp_lock.h>
1876 +#include <linux/vs_base.h>
1877  
1878  #define DM_MSG_PREFIX "core"
1879  
1880 @@ -91,6 +92,7 @@ struct mapped_device {
1881         rwlock_t map_lock;
1882         atomic_t holders;
1883         atomic_t open_count;
1884 +       xid_t xid;
1885  
1886         unsigned long flags;
1887  
1888 @@ -250,6 +252,7 @@ static void __exit dm_exit(void)
1889  static int dm_blk_open(struct inode *inode, struct file *file)
1890  {
1891         struct mapped_device *md;
1892 +       int ret = -ENXIO;
1893  
1894         spin_lock(&_minor_lock);
1895  
1896 @@ -258,18 +261,19 @@ static int dm_blk_open(struct inode *ino
1897                 goto out;
1898  
1899         if (test_bit(DMF_FREEING, &md->flags) ||
1900 -           test_bit(DMF_DELETING, &md->flags)) {
1901 -               md = NULL;
1902 +           test_bit(DMF_DELETING, &md->flags))
1903 +               goto out;
1904 +
1905 +       ret = -EACCES;
1906 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1907                 goto out;
1908 -       }
1909  
1910         dm_get(md);
1911         atomic_inc(&md->open_count);
1912 -
1913 +       ret = 0;
1914  out:
1915         spin_unlock(&_minor_lock);
1916 -
1917 -       return md ? 0 : -ENXIO;
1918 +       return ret;
1919  }
1920  
1921  static int dm_blk_close(struct inode *inode, struct file *file)
1922 @@ -465,6 +469,14 @@ int dm_set_geometry(struct mapped_device
1923         return 0;
1924  }
1925  
1926 +/*
1927 + * Get the xid associated with a dm device
1928 + */
1929 +xid_t dm_get_xid(struct mapped_device *md)
1930 +{
1931 +       return md->xid;
1932 +}
1933 +
1934  /*-----------------------------------------------------------------
1935   * CRUD START:
1936   *   A more elegant soln is in the works that uses the queue
1937 @@ -1022,6 +1034,7 @@ static struct mapped_device *alloc_dev(i
1938         INIT_LIST_HEAD(&md->uevent_list);
1939         spin_lock_init(&md->uevent_lock);
1940  
1941 +       md->xid = vx_current_xid();
1942         md->queue = blk_alloc_queue(GFP_KERNEL);
1943         if (!md->queue)
1944                 goto bad_queue;
1945 diff -NurpP --minimal linux-2.6.25/drivers/md/dm.h linux-2.6.25-vs2.3.0.34.9/drivers/md/dm.h
1946 --- linux-2.6.25/drivers/md/dm.h        2008-04-17 11:31:28.000000000 -0400
1947 +++ linux-2.6.25-vs2.3.0.34.9/drivers/md/dm.h   2008-04-19 15:14:52.000000000 -0400
1948 @@ -127,6 +127,8 @@ void dm_put_target_type(struct target_ty
1949  int dm_target_iterate(void (*iter_func)(struct target_type *tt,
1950                                         void *param), void *param);
1951  
1952 +xid_t dm_get_xid(struct mapped_device *md);
1953 +
1954  /*-----------------------------------------------------------------
1955   * Useful inlines.
1956   *---------------------------------------------------------------*/
1957 diff -NurpP --minimal linux-2.6.25/drivers/md/dm-ioctl.c linux-2.6.25-vs2.3.0.34.9/drivers/md/dm-ioctl.c
1958 --- linux-2.6.25/drivers/md/dm-ioctl.c  2008-04-17 12:05:33.000000000 -0400
1959 +++ linux-2.6.25-vs2.3.0.34.9/drivers/md/dm-ioctl.c     2008-04-21 10:45:53.000000000 -0400
1960 @@ -16,6 +16,7 @@
1961  #include <linux/dm-ioctl.h>
1962  #include <linux/hdreg.h>
1963  #include <linux/compat.h>
1964 +#include <linux/vs_context.h>
1965  
1966  #include <asm/uaccess.h>
1967  
1968 @@ -101,7 +102,8 @@ static struct hash_cell *__get_name_cell
1969         unsigned int h = hash_str(str);
1970  
1971         list_for_each_entry (hc, _name_buckets + h, name_list)
1972 -               if (!strcmp(hc->name, str)) {
1973 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1974 +                       !strcmp(hc->name, str)) {
1975                         dm_get(hc->md);
1976                         return hc;
1977                 }
1978 @@ -115,7 +117,8 @@ static struct hash_cell *__get_uuid_cell
1979         unsigned int h = hash_str(str);
1980  
1981         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1982 -               if (!strcmp(hc->uuid, str)) {
1983 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1984 +                       !strcmp(hc->uuid, str)) {
1985                         dm_get(hc->md);
1986                         return hc;
1987                 }
1988 @@ -352,6 +355,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
1989  
1990  static int remove_all(struct dm_ioctl *param, size_t param_size)
1991  {
1992 +       if (!vx_check(0, VS_ADMIN))
1993 +               return -EPERM;
1994 +
1995         dm_hash_remove_all(1);
1996         param->data_size = 0;
1997         return 0;
1998 @@ -399,6 +405,8 @@ static int list_devices(struct dm_ioctl 
1999          */
2000         for (i = 0; i < NUM_BUCKETS; i++) {
2001                 list_for_each_entry (hc, _name_buckets + i, name_list) {
2002 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
2003 +                               continue;
2004                         needed += sizeof(struct dm_name_list);
2005                         needed += strlen(hc->name) + 1;
2006                         needed += ALIGN_MASK;
2007 @@ -422,6 +430,8 @@ static int list_devices(struct dm_ioctl 
2008          */
2009         for (i = 0; i < NUM_BUCKETS; i++) {
2010                 list_for_each_entry (hc, _name_buckets + i, name_list) {
2011 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
2012 +                               continue;
2013                         if (old_nl)
2014                                 old_nl->next = (uint32_t) ((void *) nl -
2015                                                            (void *) old_nl);
2016 @@ -612,10 +622,11 @@ static struct hash_cell *__find_device_h
2017         if (!md)
2018                 goto out;
2019  
2020 -       mdptr = dm_get_mdptr(md);
2021 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
2022 +               mdptr = dm_get_mdptr(md);
2023 +
2024         if (!mdptr)
2025                 dm_put(md);
2026 -
2027  out:
2028         return mdptr;
2029  }
2030 @@ -1406,8 +1417,8 @@ static int ctl_ioctl(uint command, struc
2031         ioctl_fn fn = NULL;
2032         size_t param_size;
2033  
2034 -       /* only root can play with this */
2035 -       if (!capable(CAP_SYS_ADMIN))
2036 +       /* only root and certain contexts can play with this */
2037 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
2038                 return -EACCES;
2039  
2040         if (_IOC_TYPE(command) != DM_IOCTL)
2041 diff -NurpP --minimal linux-2.6.25/drivers/net/tun.c linux-2.6.25-vs2.3.0.34.9/drivers/net/tun.c
2042 --- linux-2.6.25/drivers/net/tun.c      2008-04-17 12:05:36.000000000 -0400
2043 +++ linux-2.6.25-vs2.3.0.34.9/drivers/net/tun.c 2008-04-19 15:39:04.000000000 -0400
2044 @@ -62,6 +62,7 @@
2045  #include <linux/if_ether.h>
2046  #include <linux/if_tun.h>
2047  #include <linux/crc32.h>
2048 +#include <linux/vs_network.h>
2049  #include <net/net_namespace.h>
2050  
2051  #include <asm/system.h>
2052 @@ -86,6 +87,7 @@ struct tun_struct {
2053         int                     attached;
2054         uid_t                   owner;
2055         gid_t                   group;
2056 +       nid_t                   nid;
2057  
2058         wait_queue_head_t       read_wait;
2059         struct sk_buff_head     readq;
2060 @@ -465,6 +467,7 @@ static void tun_setup(struct net_device 
2061  
2062         tun->owner = -1;
2063         tun->group = -1;
2064 +       tun->nid = current->nid;
2065  
2066         dev->open = tun_net_open;
2067         dev->hard_start_xmit = tun_net_xmit;
2068 @@ -494,6 +497,9 @@ static int tun_set_iff(struct file *file
2069  
2070         tun = tun_get_by_name(ifr->ifr_name);
2071         if (tun) {
2072 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
2073 +                       return -EPERM;
2074 +
2075                 if (tun->attached)
2076                         return -EBUSY;
2077  
2078 @@ -502,7 +508,7 @@ static int tun_set_iff(struct file *file
2079                       current->euid != tun->owner) ||
2080                      (tun->group != -1 &&
2081                       current->egid != tun->group)) &&
2082 -                    !capable(CAP_NET_ADMIN))
2083 +                    !cap_raised(current->cap_effective, CAP_NET_ADMIN))
2084                         return -EPERM;
2085         }
2086         else if (__dev_get_by_name(&init_net, ifr->ifr_name))
2087 @@ -513,7 +519,7 @@ static int tun_set_iff(struct file *file
2088  
2089                 err = -EINVAL;
2090  
2091 -               if (!capable(CAP_NET_ADMIN))
2092 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
2093                         return -EPERM;
2094  
2095                 /* Set dev type */
2096 @@ -656,6 +662,16 @@ static int tun_chr_ioctl(struct inode *i
2097                 DBG(KERN_INFO "%s: group set to %d\n", tun->dev->name, tun->group);
2098                 break;
2099  
2100 +       case TUNSETNID:
2101 +               if (!capable(CAP_CONTEXT))
2102 +                       return -EPERM;
2103 +
2104 +               /* Set nid owner of the device */
2105 +               tun->nid = (nid_t) arg;
2106 +
2107 +               DBG(KERN_INFO "%s: nid owner set to %u\n", tun->dev->name, tun->nid);
2108 +               break;
2109 +
2110         case TUNSETLINK:
2111                 /* Only allow setting the type when the interface is down */
2112                 if (tun->dev->flags & IFF_UP) {
2113 diff -NurpP --minimal linux-2.6.25/fs/attr.c linux-2.6.25-vs2.3.0.34.9/fs/attr.c
2114 --- linux-2.6.25/fs/attr.c      2008-04-17 11:31:35.000000000 -0400
2115 +++ linux-2.6.25-vs2.3.0.34.9/fs/attr.c 2008-04-19 15:14:52.000000000 -0400
2116 @@ -14,6 +14,9 @@
2117  #include <linux/fcntl.h>
2118  #include <linux/quotaops.h>
2119  #include <linux/security.h>
2120 +#include <linux/proc_fs.h>
2121 +#include <linux/devpts_fs.h>
2122 +#include <linux/vs_base.h>
2123  
2124  /* Taken over from the old code... */
2125  
2126 @@ -55,6 +58,27 @@ int inode_change_ok(struct inode *inode,
2127                 if (!is_owner_or_cap(inode))
2128                         goto error;
2129         }
2130 +
2131 +       /* Check for evil vserver activity */
2132 +       if (vx_check(0, VS_ADMIN))
2133 +               goto fine;
2134 +
2135 +       if (IS_BARRIER(inode)) {
2136 +               vxwprintk_task(1, "messing with the barrier.");
2137 +               goto error;
2138 +       }
2139 +       switch (inode->i_sb->s_magic) {
2140 +               case PROC_SUPER_MAGIC:
2141 +                       /* maybe allow that in the future? */
2142 +                       vxwprintk_task(1, "messing with the procfs.");
2143 +                       goto error;
2144 +               case DEVPTS_SUPER_MAGIC:
2145 +                       /* devpts is xid tagged */
2146 +                       if (vx_check((xid_t)inode->i_tag, VS_IDENT))
2147 +                               goto fine;
2148 +                       vxwprintk_task(1, "messing with the devpts.");
2149 +                       goto error;
2150 +       }
2151  fine:
2152         retval = 0;
2153  error:
2154 @@ -78,6 +102,8 @@ int inode_setattr(struct inode * inode, 
2155                 inode->i_uid = attr->ia_uid;
2156         if (ia_valid & ATTR_GID)
2157                 inode->i_gid = attr->ia_gid;
2158 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2159 +               inode->i_tag = attr->ia_tag;
2160         if (ia_valid & ATTR_ATIME)
2161                 inode->i_atime = timespec_trunc(attr->ia_atime,
2162                                                 inode->i_sb->s_time_gran);
2163 @@ -167,7 +193,8 @@ int notify_change(struct dentry * dentry
2164                         error = security_inode_setattr(dentry, attr);
2165                 if (!error) {
2166                         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
2167 -                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
2168 +                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
2169 +                           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag))
2170                                 error = DQUOT_TRANSFER(inode, attr) ? -EDQUOT : 0;
2171                         if (!error)
2172                                 error = inode_setattr(inode, attr);
2173 diff -NurpP --minimal linux-2.6.25/fs/binfmt_aout.c linux-2.6.25-vs2.3.0.34.9/fs/binfmt_aout.c
2174 --- linux-2.6.25/fs/binfmt_aout.c       2008-04-17 12:05:39.000000000 -0400
2175 +++ linux-2.6.25-vs2.3.0.34.9/fs/binfmt_aout.c  2008-04-19 15:14:52.000000000 -0400
2176 @@ -24,6 +24,7 @@
2177  #include <linux/binfmts.h>
2178  #include <linux/personality.h>
2179  #include <linux/init.h>
2180 +#include <linux/vs_memory.h>
2181  
2182  #include <asm/system.h>
2183  #include <asm/uaccess.h>
2184 diff -NurpP --minimal linux-2.6.25/fs/binfmt_elf.c linux-2.6.25-vs2.3.0.34.9/fs/binfmt_elf.c
2185 --- linux-2.6.25/fs/binfmt_elf.c        2008-04-17 12:05:39.000000000 -0400
2186 +++ linux-2.6.25-vs2.3.0.34.9/fs/binfmt_elf.c   2008-04-19 15:14:52.000000000 -0400
2187 @@ -39,6 +39,7 @@
2188  #include <linux/random.h>
2189  #include <linux/elf.h>
2190  #include <linux/utsname.h>
2191 +#include <linux/vs_memory.h>
2192  #include <asm/uaccess.h>
2193  #include <asm/param.h>
2194  #include <asm/page.h>
2195 diff -NurpP --minimal linux-2.6.25/fs/binfmt_flat.c linux-2.6.25-vs2.3.0.34.9/fs/binfmt_flat.c
2196 --- linux-2.6.25/fs/binfmt_flat.c       2008-04-17 12:05:39.000000000 -0400
2197 +++ linux-2.6.25-vs2.3.0.34.9/fs/binfmt_flat.c  2008-04-19 15:14:52.000000000 -0400
2198 @@ -35,6 +35,7 @@
2199  #include <linux/init.h>
2200  #include <linux/flat.h>
2201  #include <linux/syscalls.h>
2202 +#include <linux/vs_memory.h>
2203  
2204  #include <asm/byteorder.h>
2205  #include <asm/system.h>
2206 diff -NurpP --minimal linux-2.6.25/fs/binfmt_som.c linux-2.6.25-vs2.3.0.34.9/fs/binfmt_som.c
2207 --- linux-2.6.25/fs/binfmt_som.c        2008-04-17 12:05:39.000000000 -0400
2208 +++ linux-2.6.25-vs2.3.0.34.9/fs/binfmt_som.c   2008-04-19 15:14:52.000000000 -0400
2209 @@ -28,6 +28,7 @@
2210  #include <linux/shm.h>
2211  #include <linux/personality.h>
2212  #include <linux/init.h>
2213 +#include <linux/vs_memory.h>
2214  
2215  #include <asm/uaccess.h>
2216  #include <asm/pgtable.h>
2217 diff -NurpP --minimal linux-2.6.25/fs/block_dev.c linux-2.6.25-vs2.3.0.34.9/fs/block_dev.c
2218 --- linux-2.6.25/fs/block_dev.c 2008-04-17 12:05:39.000000000 -0400
2219 +++ linux-2.6.25-vs2.3.0.34.9/fs/block_dev.c    2008-04-19 15:14:52.000000000 -0400
2220 @@ -23,6 +23,7 @@
2221  #include <linux/uio.h>
2222  #include <linux/namei.h>
2223  #include <linux/log2.h>
2224 +#include <linux/vs_device.h>
2225  #include <asm/uaccess.h>
2226  #include "internal.h"
2227  
2228 @@ -388,6 +389,7 @@ struct block_device *bdget(dev_t dev)
2229                 bdev->bd_invalidated = 0;
2230                 inode->i_mode = S_IFBLK;
2231                 inode->i_rdev = dev;
2232 +               inode->i_mdev = dev;
2233                 inode->i_bdev = bdev;
2234                 inode->i_data.a_ops = &def_blk_aops;
2235                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
2236 @@ -424,6 +426,11 @@ EXPORT_SYMBOL(bdput);
2237  static struct block_device *bd_acquire(struct inode *inode)
2238  {
2239         struct block_device *bdev;
2240 +       dev_t mdev;
2241 +
2242 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
2243 +               return NULL;
2244 +       inode->i_mdev = mdev;
2245  
2246         spin_lock(&bdev_lock);
2247         bdev = inode->i_bdev;
2248 @@ -434,7 +441,7 @@ static struct block_device *bd_acquire(s
2249         }
2250         spin_unlock(&bdev_lock);
2251  
2252 -       bdev = bdget(inode->i_rdev);
2253 +       bdev = bdget(mdev);
2254         if (bdev) {
2255                 spin_lock(&bdev_lock);
2256                 if (!inode->i_bdev) {
2257 diff -NurpP --minimal linux-2.6.25/fs/char_dev.c linux-2.6.25-vs2.3.0.34.9/fs/char_dev.c
2258 --- linux-2.6.25/fs/char_dev.c  2008-04-17 12:05:39.000000000 -0400
2259 +++ linux-2.6.25-vs2.3.0.34.9/fs/char_dev.c     2008-04-29 18:44:50.000000000 -0400
2260 @@ -21,6 +21,8 @@
2261  #include <linux/cdev.h>
2262  #include <linux/mutex.h>
2263  #include <linux/backing-dev.h>
2264 +#include <linux/vs_context.h>
2265 +#include <linux/vs_device.h>
2266  
2267  #ifdef CONFIG_KMOD
2268  #include <linux/kmod.h>
2269 @@ -362,14 +364,21 @@ static int chrdev_open(struct inode *ino
2270         struct cdev *p;
2271         struct cdev *new = NULL;
2272         int ret = 0;
2273 +       dev_t mdev;
2274 +
2275 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2276 +               return -EPERM;
2277 +       inode->i_mdev = mdev;
2278  
2279         spin_lock(&cdev_lock);
2280         p = inode->i_cdev;
2281         if (!p) {
2282                 struct kobject *kobj;
2283                 int idx;
2284 +
2285                 spin_unlock(&cdev_lock);
2286 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2287 +
2288 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2289                 if (!kobj)
2290                         return -ENXIO;
2291                 new = container_of(kobj, struct cdev, kobj);
2292 diff -NurpP --minimal linux-2.6.25/fs/dcache.c linux-2.6.25-vs2.3.0.34.9/fs/dcache.c
2293 --- linux-2.6.25/fs/dcache.c    2008-04-17 12:05:39.000000000 -0400
2294 +++ linux-2.6.25-vs2.3.0.34.9/fs/dcache.c       2008-04-19 17:06:15.000000000 -0400
2295 @@ -31,6 +31,7 @@
2296  #include <linux/seqlock.h>
2297  #include <linux/swap.h>
2298  #include <linux/bootmem.h>
2299 +#include <linux/vs_limit.h>
2300  #include "internal.h"
2301  
2302  
2303 @@ -184,6 +185,7 @@ void dput(struct dentry *dentry)
2304         if (!dentry)
2305                 return;
2306  
2307 +       vx_dentry_dec(dentry);
2308  repeat:
2309         if (atomic_read(&dentry->d_count) == 1)
2310                 might_sleep();
2311 @@ -197,6 +199,8 @@ repeat:
2312                 return;
2313         }
2314  
2315 +       vx_dentry_dec(dentry);
2316 +
2317         /*
2318          * AV: ->d_delete() is _NOT_ allowed to block now.
2319          */
2320 @@ -288,6 +292,7 @@ static inline struct dentry * __dget_loc
2321  {
2322         atomic_inc(&dentry->d_count);
2323         dentry_lru_remove(dentry);
2324 +       vx_dentry_inc(dentry);
2325         return dentry;
2326  }
2327  
2328 @@ -885,6 +890,9 @@ struct dentry *d_alloc(struct dentry * p
2329         struct dentry *dentry;
2330         char *dname;
2331  
2332 +       if (!vx_dentry_avail(1))
2333 +               return NULL;
2334 +
2335         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2336         if (!dentry)
2337                 return NULL;
2338 @@ -933,6 +941,7 @@ struct dentry *d_alloc(struct dentry * p
2339         if (parent)
2340                 list_add(&dentry->d_u.d_child, &parent->d_subdirs);
2341         dentry_stat.nr_dentry++;
2342 +       vx_dentry_inc(dentry);
2343         spin_unlock(&dcache_lock);
2344  
2345         return dentry;
2346 @@ -1282,6 +1291,7 @@ struct dentry * __d_lookup(struct dentry
2347  
2348                 if (!d_unhashed(dentry)) {
2349                         atomic_inc(&dentry->d_count);
2350 +                       vx_dentry_inc(dentry);
2351                         found = dentry;
2352                 }
2353                 spin_unlock(&dentry->d_lock);
2354 diff -NurpP --minimal linux-2.6.25/fs/devpts/inode.c linux-2.6.25-vs2.3.0.34.9/fs/devpts/inode.c
2355 --- linux-2.6.25/fs/devpts/inode.c      2008-04-17 12:05:39.000000000 -0400
2356 +++ linux-2.6.25-vs2.3.0.34.9/fs/devpts/inode.c 2008-04-21 09:23:34.000000000 -0400
2357 @@ -17,15 +17,30 @@
2358  #include <linux/namei.h>
2359  #include <linux/mount.h>
2360  #include <linux/tty.h>
2361 +#include <linux/magic.h>
2362  #include <linux/devpts_fs.h>
2363  #include <linux/parser.h>
2364  #include <linux/fsnotify.h>
2365  #include <linux/seq_file.h>
2366 +#include <linux/vs_base.h>
2367  
2368 -#define DEVPTS_SUPER_MAGIC 0x1cd1
2369  
2370  #define DEVPTS_DEFAULT_MODE 0600
2371  
2372 +static int devpts_permission(struct inode *inode, int mask, struct nameidata *nd)
2373 +{
2374 +       int ret = -EACCES;
2375 +
2376 +       /* devpts is xid tagged */
2377 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2378 +               ret = generic_permission(inode, mask, NULL);
2379 +       return ret;
2380 +}
2381 +
2382 +static struct inode_operations devpts_file_inode_operations = {
2383 +       .permission     = devpts_permission,
2384 +};
2385 +
2386  static struct vfsmount *devpts_mnt;
2387  static struct dentry *devpts_root;
2388  
2389 @@ -106,6 +121,25 @@ static int devpts_show_options(struct se
2390         return 0;
2391  }
2392  
2393 +static int devpts_filter(struct dentry *de)
2394 +{
2395 +       /* devpts is xid tagged */
2396 +       return vx_check((xid_t)de->d_inode->i_tag, VS_WATCH_P | VS_IDENT);
2397 +}
2398 +
2399 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2400 +{
2401 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2402 +}
2403 +
2404 +static struct file_operations devpts_dir_operations = {
2405 +       .open           = dcache_dir_open,
2406 +       .release        = dcache_dir_close,
2407 +       .llseek         = dcache_dir_lseek,
2408 +       .read           = generic_read_dir,
2409 +       .readdir        = devpts_readdir,
2410 +};
2411 +
2412  static const struct super_operations devpts_sops = {
2413         .statfs         = simple_statfs,
2414         .remount_fs     = devpts_remount,
2415 @@ -132,8 +166,10 @@ devpts_fill_super(struct super_block *s,
2416         inode->i_uid = inode->i_gid = 0;
2417         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2418         inode->i_op = &simple_dir_inode_operations;
2419 -       inode->i_fop = &simple_dir_operations;
2420 +       inode->i_fop = &devpts_dir_operations;
2421         inode->i_nlink = 2;
2422 +       /* devpts is xid tagged */
2423 +       inode->i_tag = (tag_t)vx_current_xid();
2424  
2425         devpts_root = s->s_root = d_alloc_root(inode);
2426         if (s->s_root)
2427 @@ -191,6 +227,9 @@ int devpts_pty_new(struct tty_struct *tt
2428         inode->i_gid = config.setgid ? config.gid : current->fsgid;
2429         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2430         init_special_inode(inode, S_IFCHR|config.mode, device);
2431 +       /* devpts is xid tagged */
2432 +       inode->i_tag = (tag_t)vx_current_xid();
2433 +       inode->i_op = &devpts_file_inode_operations;
2434         inode->i_private = tty;
2435  
2436         dentry = get_node(number);
2437 diff -NurpP --minimal linux-2.6.25/fs/ecryptfs/inode.c linux-2.6.25-vs2.3.0.34.9/fs/ecryptfs/inode.c
2438 --- linux-2.6.25/fs/ecryptfs/inode.c    2008-04-17 12:05:40.000000000 -0400
2439 +++ linux-2.6.25-vs2.3.0.34.9/fs/ecryptfs/inode.c       2008-04-19 15:14:52.000000000 -0400
2440 @@ -400,7 +400,7 @@ static int ecryptfs_link(struct dentry *
2441         dget(lower_new_dentry);
2442         lower_dir_dentry = lock_parent(lower_new_dentry);
2443         rc = vfs_link(lower_old_dentry, lower_dir_dentry->d_inode,
2444 -                     lower_new_dentry);
2445 +                     lower_new_dentry, NULL);
2446         if (rc || !lower_new_dentry->d_inode)
2447                 goto out_lock;
2448         rc = ecryptfs_interpose(lower_new_dentry, new_dentry, dir->i_sb, 0);
2449 @@ -428,7 +428,7 @@ static int ecryptfs_unlink(struct inode 
2450         struct inode *lower_dir_inode = ecryptfs_inode_to_lower(dir);
2451  
2452         lock_parent(lower_dentry);
2453 -       rc = vfs_unlink(lower_dir_inode, lower_dentry);
2454 +       rc = vfs_unlink(lower_dir_inode, lower_dentry, NULL);
2455         if (rc) {
2456                 printk(KERN_ERR "Error in vfs_unlink; rc = [%d]\n", rc);
2457                 goto out_unlock;
2458 @@ -466,7 +466,7 @@ static int ecryptfs_symlink(struct inode
2459                 goto out_lock;
2460         }
2461         rc = vfs_symlink(lower_dir_dentry->d_inode, lower_dentry,
2462 -                        encoded_symname, mode);
2463 +                        encoded_symname, mode, NULL);
2464         kfree(encoded_symname);
2465         if (rc || !lower_dentry->d_inode)
2466                 goto out_lock;
2467 @@ -491,7 +491,7 @@ static int ecryptfs_mkdir(struct inode *
2468  
2469         lower_dentry = ecryptfs_dentry_to_lower(dentry);
2470         lower_dir_dentry = lock_parent(lower_dentry);
2471 -       rc = vfs_mkdir(lower_dir_dentry->d_inode, lower_dentry, mode);
2472 +       rc = vfs_mkdir(lower_dir_dentry->d_inode, lower_dentry, mode, NULL);
2473         if (rc || !lower_dentry->d_inode)
2474                 goto out;
2475         rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0);
2476 @@ -517,7 +517,7 @@ static int ecryptfs_rmdir(struct inode *
2477         dget(dentry);
2478         lower_dir_dentry = lock_parent(lower_dentry);
2479         dget(lower_dentry);
2480 -       rc = vfs_rmdir(lower_dir_dentry->d_inode, lower_dentry);
2481 +       rc = vfs_rmdir(lower_dir_dentry->d_inode, lower_dentry, NULL);
2482         dput(lower_dentry);
2483         if (!rc)
2484                 d_delete(lower_dentry);
2485 @@ -539,7 +539,7 @@ ecryptfs_mknod(struct inode *dir, struct
2486  
2487         lower_dentry = ecryptfs_dentry_to_lower(dentry);
2488         lower_dir_dentry = lock_parent(lower_dentry);
2489 -       rc = vfs_mknod(lower_dir_dentry->d_inode, lower_dentry, mode, dev);
2490 +       rc = vfs_mknod(lower_dir_dentry->d_inode, lower_dentry, mode, dev, NULL);
2491         if (rc || !lower_dentry->d_inode)
2492                 goto out;
2493         rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0);
2494 diff -NurpP --minimal linux-2.6.25/fs/exec.c linux-2.6.25-vs2.3.0.34.9/fs/exec.c
2495 --- linux-2.6.25/fs/exec.c      2008-04-17 12:05:40.000000000 -0400
2496 +++ linux-2.6.25-vs2.3.0.34.9/fs/exec.c 2008-04-19 15:14:52.000000000 -0400
2497 @@ -249,7 +249,9 @@ static int __bprm_mm_init(struct linux_b
2498                 goto err;
2499         }
2500  
2501 -       mm->stack_vm = mm->total_vm = 1;
2502 +       mm->total_vm = 0;
2503 +       vx_vmpages_inc(mm);
2504 +       mm->stack_vm = 1;
2505         up_write(&mm->mmap_sem);
2506  
2507         bprm->p = vma->vm_end - sizeof(void *);
2508 @@ -1452,7 +1454,7 @@ static int format_corename(char *corenam
2509                         /* UNIX time of coredump */
2510                         case 't': {
2511                                 struct timeval tv;
2512 -                               do_gettimeofday(&tv);
2513 +                               vx_gettimeofday(&tv);
2514                                 rc = snprintf(out_ptr, out_end - out_ptr,
2515                                               "%lu", tv.tv_sec);
2516                                 if (rc > out_end - out_ptr)
2517 diff -NurpP --minimal linux-2.6.25/fs/ext2/balloc.c linux-2.6.25-vs2.3.0.34.9/fs/ext2/balloc.c
2518 --- linux-2.6.25/fs/ext2/balloc.c       2008-04-17 12:05:40.000000000 -0400
2519 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext2/balloc.c  2008-04-19 15:14:52.000000000 -0400
2520 @@ -16,6 +16,8 @@
2521  #include <linux/sched.h>
2522  #include <linux/buffer_head.h>
2523  #include <linux/capability.h>
2524 +#include <linux/vs_dlimit.h>
2525 +#include <linux/vs_tag.h>
2526  
2527  /*
2528   * balloc.c contains the blocks allocation and deallocation routines
2529 @@ -569,6 +571,7 @@ do_more:
2530         }
2531  error_return:
2532         brelse(bitmap_bh);
2533 +       DLIMIT_FREE_BLOCK(inode, freed);
2534         release_blocks(sb, freed);
2535         DQUOT_FREE_BLOCK(inode, freed);
2536  }
2537 @@ -701,7 +704,6 @@ ext2_try_to_allocate(struct super_block 
2538                         start = 0;
2539                 end = EXT2_BLOCKS_PER_GROUP(sb);
2540         }
2541 -
2542         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2543  
2544  repeat:
2545 @@ -1251,6 +1253,11 @@ ext2_fsblk_t ext2_new_blocks(struct inod
2546                 *errp = -EDQUOT;
2547                 return 0;
2548         }
2549 +       if (DLIMIT_ALLOC_BLOCK(inode, num)) {
2550 +               *errp = -ENOSPC;
2551 +               DQUOT_FREE_BLOCK(inode, num);
2552 +               return 0;
2553 +       }
2554  
2555         sbi = EXT2_SB(sb);
2556         es = EXT2_SB(sb)->s_es;
2557 @@ -1403,6 +1410,7 @@ allocated:
2558  
2559         *errp = 0;
2560         brelse(bitmap_bh);
2561 +       DLIMIT_FREE_BLOCK(inode, *count-num);
2562         DQUOT_FREE_BLOCK(inode, *count-num);
2563         *count = num;
2564         return ret_block;
2565 @@ -1413,8 +1421,10 @@ out:
2566         /*
2567          * Undo the block allocation
2568          */
2569 -       if (!performed_allocation)
2570 +       if (!performed_allocation) {
2571 +               DLIMIT_FREE_BLOCK(inode, *count);
2572                 DQUOT_FREE_BLOCK(inode, *count);
2573 +       }
2574         brelse(bitmap_bh);
2575         return 0;
2576  }
2577 diff -NurpP --minimal linux-2.6.25/fs/ext2/ext2.h linux-2.6.25-vs2.3.0.34.9/fs/ext2/ext2.h
2578 --- linux-2.6.25/fs/ext2/ext2.h 2008-04-17 12:05:40.000000000 -0400
2579 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext2/ext2.h    2008-04-19 15:14:52.000000000 -0400
2580 @@ -168,6 +168,7 @@ extern const struct file_operations ext2
2581  extern const struct address_space_operations ext2_aops;
2582  extern const struct address_space_operations ext2_aops_xip;
2583  extern const struct address_space_operations ext2_nobh_aops;
2584 +extern int ext2_sync_flags(struct inode *inode);
2585  
2586  /* namei.c */
2587  extern const struct inode_operations ext2_dir_inode_operations;
2588 diff -NurpP --minimal linux-2.6.25/fs/ext2/file.c linux-2.6.25-vs2.3.0.34.9/fs/ext2/file.c
2589 --- linux-2.6.25/fs/ext2/file.c 2008-04-17 12:05:40.000000000 -0400
2590 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext2/file.c    2008-04-19 15:14:52.000000000 -0400
2591 @@ -86,4 +86,5 @@ const struct inode_operations ext2_file_
2592  #endif
2593         .setattr        = ext2_setattr,
2594         .permission     = ext2_permission,
2595 +       .sync_flags     = ext2_sync_flags,
2596  };
2597 diff -NurpP --minimal linux-2.6.25/fs/ext2/ialloc.c linux-2.6.25-vs2.3.0.34.9/fs/ext2/ialloc.c
2598 --- linux-2.6.25/fs/ext2/ialloc.c       2008-04-17 11:31:35.000000000 -0400
2599 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext2/ialloc.c  2008-04-19 15:14:52.000000000 -0400
2600 @@ -17,6 +17,8 @@
2601  #include <linux/backing-dev.h>
2602  #include <linux/buffer_head.h>
2603  #include <linux/random.h>
2604 +#include <linux/vs_dlimit.h>
2605 +#include <linux/vs_tag.h>
2606  #include "ext2.h"
2607  #include "xattr.h"
2608  #include "acl.h"
2609 @@ -125,6 +127,7 @@ void ext2_free_inode (struct inode * ino
2610                 ext2_xattr_delete_inode(inode);
2611                 DQUOT_FREE_INODE(inode);
2612                 DQUOT_DROP(inode);
2613 +               DLIMIT_FREE_INODE(inode);
2614         }
2615  
2616         es = EXT2_SB(sb)->s_es;
2617 @@ -456,6 +459,11 @@ struct inode *ext2_new_inode(struct inod
2618         if (!inode)
2619                 return ERR_PTR(-ENOMEM);
2620  
2621 +       inode->i_tag = dx_current_fstag(sb);
2622 +       if (DLIMIT_ALLOC_INODE(inode)) {
2623 +               err = -ENOSPC;
2624 +               goto fail_dlim;
2625 +       }
2626         ei = EXT2_I(inode);
2627         sbi = EXT2_SB(sb);
2628         es = sbi->s_es;
2629 @@ -569,7 +577,8 @@ got:
2630         inode->i_blocks = 0;
2631         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
2632         memset(ei->i_data, 0, sizeof(ei->i_data));
2633 -       ei->i_flags = EXT2_I(dir)->i_flags & ~EXT2_BTREE_FL;
2634 +       ei->i_flags = EXT2_I(dir)->i_flags &
2635 +               ~(EXT2_BTREE_FL|EXT2_IUNLINK_FL|EXT2_BARRIER_FL);
2636         if (S_ISLNK(mode))
2637                 ei->i_flags &= ~(EXT2_IMMUTABLE_FL|EXT2_APPEND_FL);
2638         /* dirsync is only applied to directories */
2639 @@ -614,12 +623,15 @@ fail_free_drop:
2640  
2641  fail_drop:
2642         DQUOT_DROP(inode);
2643 +       DLIMIT_FREE_INODE(inode);
2644         inode->i_flags |= S_NOQUOTA;
2645         inode->i_nlink = 0;
2646         iput(inode);
2647         return ERR_PTR(err);
2648  
2649  fail:
2650 +       DLIMIT_FREE_INODE(inode);
2651 +fail_dlim:
2652         make_bad_inode(inode);
2653         iput(inode);
2654         return ERR_PTR(err);
2655 diff -NurpP --minimal linux-2.6.25/fs/ext2/inode.c linux-2.6.25-vs2.3.0.34.9/fs/ext2/inode.c
2656 --- linux-2.6.25/fs/ext2/inode.c        2008-04-17 12:05:40.000000000 -0400
2657 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext2/inode.c   2008-04-21 10:14:57.000000000 -0400
2658 @@ -31,6 +31,7 @@
2659  #include <linux/writeback.h>
2660  #include <linux/buffer_head.h>
2661  #include <linux/mpage.h>
2662 +#include <linux/vs_tag.h>
2663  #include "ext2.h"
2664  #include "acl.h"
2665  #include "xip.h"
2666 @@ -1011,7 +1012,7 @@ void ext2_truncate(struct inode *inode)
2667                 return;
2668         if (ext2_inode_is_fast_symlink(inode))
2669                 return;
2670 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2671 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2672                 return;
2673  
2674         blocksize = inode->i_sb->s_blocksize;
2675 @@ -1149,13 +1150,20 @@ void ext2_set_inode_flags(struct inode *
2676  {
2677         unsigned int flags = EXT2_I(inode)->i_flags;
2678  
2679 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2680 +       inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
2681 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2682 +
2683 +       if (flags & EXT2_IMMUTABLE_FL)
2684 +               inode->i_flags |= S_IMMUTABLE;
2685 +       if (flags & EXT2_IUNLINK_FL)
2686 +               inode->i_flags |= S_IUNLINK;
2687 +       if (flags & EXT2_BARRIER_FL)
2688 +               inode->i_flags |= S_BARRIER;
2689 +
2690         if (flags & EXT2_SYNC_FL)
2691                 inode->i_flags |= S_SYNC;
2692         if (flags & EXT2_APPEND_FL)
2693                 inode->i_flags |= S_APPEND;
2694 -       if (flags & EXT2_IMMUTABLE_FL)
2695 -               inode->i_flags |= S_IMMUTABLE;
2696         if (flags & EXT2_NOATIME_FL)
2697                 inode->i_flags |= S_NOATIME;
2698         if (flags & EXT2_DIRSYNC_FL)
2699 @@ -1181,6 +1189,30 @@ void ext2_get_inode_flags(struct ext2_in
2700                 ei->i_flags |= EXT2_DIRSYNC_FL;
2701  }
2702  
2703 +int ext2_sync_flags(struct inode *inode)
2704 +{
2705 +       unsigned int oldflags, newflags;
2706 +
2707 +       oldflags = EXT2_I(inode)->i_flags;
2708 +       newflags = oldflags & ~(EXT2_IMMUTABLE_FL |
2709 +               EXT2_IUNLINK_FL | EXT2_BARRIER_FL);
2710 +
2711 +       if (IS_IMMUTABLE(inode))
2712 +               newflags |= EXT2_IMMUTABLE_FL;
2713 +       if (IS_IUNLINK(inode))
2714 +               newflags |= EXT2_IUNLINK_FL;
2715 +       if (IS_BARRIER(inode))
2716 +               newflags |= EXT2_BARRIER_FL;
2717 +
2718 +       if (oldflags ^ newflags) {
2719 +               EXT2_I(inode)->i_flags = newflags;
2720 +               inode->i_ctime = CURRENT_TIME;
2721 +               mark_inode_dirty(inode);
2722 +       }
2723 +       return 0;
2724 +}
2725 +
2726 +
2727  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2728  {
2729         struct ext2_inode_info *ei;
2730 @@ -1188,6 +1220,8 @@ struct inode *ext2_iget (struct super_bl
2731         struct ext2_inode *raw_inode;
2732         struct inode *inode;
2733         long ret = -EIO;
2734 +       uid_t uid;
2735 +       gid_t gid;
2736         int n;
2737  
2738         inode = iget_locked(sb, ino);
2739 @@ -1210,12 +1244,17 @@ struct inode *ext2_iget (struct super_bl
2740         }
2741  
2742         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2743 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2744 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2745 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2746 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2747         if (!(test_opt (inode->i_sb, NO_UID32))) {
2748 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2749 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2750 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2751 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2752         }
2753 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2754 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2755 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2756 +               le16_to_cpu(raw_inode->i_raw_tag));
2757 +
2758         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2759         inode->i_size = le32_to_cpu(raw_inode->i_size);
2760         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2761 @@ -1311,8 +1350,8 @@ static int ext2_update_inode(struct inod
2762         struct ext2_inode_info *ei = EXT2_I(inode);
2763         struct super_block *sb = inode->i_sb;
2764         ino_t ino = inode->i_ino;
2765 -       uid_t uid = inode->i_uid;
2766 -       gid_t gid = inode->i_gid;
2767 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2768 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2769         struct buffer_head * bh;
2770         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2771         int n;
2772 @@ -1348,6 +1387,9 @@ static int ext2_update_inode(struct inod
2773                 raw_inode->i_uid_high = 0;
2774                 raw_inode->i_gid_high = 0;
2775         }
2776 +#ifdef CONFIG_TAGGING_INTERN
2777 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2778 +#endif
2779         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2780         raw_inode->i_size = cpu_to_le32(inode->i_size);
2781         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2782 @@ -1434,7 +1476,8 @@ int ext2_setattr(struct dentry *dentry, 
2783         if (error)
2784                 return error;
2785         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2786 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2787 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2788 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2789                 error = DQUOT_TRANSFER(inode, iattr) ? -EDQUOT : 0;
2790                 if (error)
2791                         return error;
2792 diff -NurpP --minimal linux-2.6.25/fs/ext2/ioctl.c linux-2.6.25-vs2.3.0.34.9/fs/ext2/ioctl.c
2793 --- linux-2.6.25/fs/ext2/ioctl.c        2008-04-17 12:05:40.000000000 -0400
2794 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext2/ioctl.c   2008-04-19 15:14:52.000000000 -0400
2795 @@ -13,6 +13,7 @@
2796  #include <linux/sched.h>
2797  #include <linux/compat.h>
2798  #include <linux/smp_lock.h>
2799 +#include <linux/mount.h>
2800  #include <asm/current.h>
2801  #include <asm/uaccess.h>
2802  
2803 @@ -34,7 +35,8 @@ long ext2_ioctl(struct file *filp, unsig
2804         case EXT2_IOC_SETFLAGS: {
2805                 unsigned int oldflags;
2806  
2807 -               if (IS_RDONLY(inode))
2808 +               if (IS_RDONLY(inode) ||
2809 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
2810                         return -EROFS;
2811  
2812                 if (!is_owner_or_cap(inode))
2813 @@ -60,7 +62,9 @@ long ext2_ioctl(struct file *filp, unsig
2814                  *
2815                  * This test looks nicer. Thanks to Pauline Middelink
2816                  */
2817 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2818 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2819 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2820 +                       EXT2_IMMUTABLE_FL | EXT2_IUNLINK_FL))) {
2821                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2822                                 mutex_unlock(&inode->i_mutex);
2823                                 return -EPERM;
2824 @@ -82,7 +86,8 @@ long ext2_ioctl(struct file *filp, unsig
2825         case EXT2_IOC_SETVERSION:
2826                 if (!is_owner_or_cap(inode))
2827                         return -EPERM;
2828 -               if (IS_RDONLY(inode))
2829 +               if (IS_RDONLY(inode) ||
2830 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
2831                         return -EROFS;
2832                 if (get_user(inode->i_generation, (int __user *) arg))
2833                         return -EFAULT; 
2834 diff -NurpP --minimal linux-2.6.25/fs/ext2/namei.c linux-2.6.25-vs2.3.0.34.9/fs/ext2/namei.c
2835 --- linux-2.6.25/fs/ext2/namei.c        2008-04-17 12:05:40.000000000 -0400
2836 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext2/namei.c   2008-04-21 10:12:49.000000000 -0400
2837 @@ -31,6 +31,7 @@
2838   */
2839  
2840  #include <linux/pagemap.h>
2841 +#include <linux/vs_tag.h>
2842  #include "ext2.h"
2843  #include "xattr.h"
2844  #include "acl.h"
2845 @@ -66,6 +67,7 @@ static struct dentry *ext2_lookup(struct
2846                 inode = ext2_iget(dir->i_sb, ino);
2847                 if (IS_ERR(inode))
2848                         return ERR_CAST(inode);
2849 +               dx_propagate_tag(nd, inode);
2850         }
2851         return d_splice_alias(inode, dentry);
2852  }
2853 @@ -391,6 +393,7 @@ const struct inode_operations ext2_dir_i
2854  #endif
2855         .setattr        = ext2_setattr,
2856         .permission     = ext2_permission,
2857 +       .sync_flags     = ext2_sync_flags,
2858  };
2859  
2860  const struct inode_operations ext2_special_inode_operations = {
2861 @@ -402,4 +405,5 @@ const struct inode_operations ext2_speci
2862  #endif
2863         .setattr        = ext2_setattr,
2864         .permission     = ext2_permission,
2865 +       .sync_flags     = ext2_sync_flags,
2866  };
2867 diff -NurpP --minimal linux-2.6.25/fs/ext2/super.c linux-2.6.25-vs2.3.0.34.9/fs/ext2/super.c
2868 --- linux-2.6.25/fs/ext2/super.c        2008-04-17 12:05:40.000000000 -0400
2869 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext2/super.c   2008-04-19 15:14:52.000000000 -0400
2870 @@ -390,7 +390,8 @@ enum {
2871         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2872         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2873         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2874 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2875 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2876 +       Opt_tag, Opt_notag, Opt_tagid
2877  };
2878  
2879  static match_table_t tokens = {
2880 @@ -418,6 +419,9 @@ static match_table_t tokens = {
2881         {Opt_acl, "acl"},
2882         {Opt_noacl, "noacl"},
2883         {Opt_xip, "xip"},
2884 +       {Opt_tag, "tag"},
2885 +       {Opt_notag, "notag"},
2886 +       {Opt_tagid, "tagid=%u"},
2887         {Opt_grpquota, "grpquota"},
2888         {Opt_ignore, "noquota"},
2889         {Opt_quota, "quota"},
2890 @@ -488,6 +492,20 @@ static int parse_options (char * options
2891                 case Opt_nouid32:
2892                         set_opt (sbi->s_mount_opt, NO_UID32);
2893                         break;
2894 +#ifndef CONFIG_TAGGING_NONE
2895 +               case Opt_tag:
2896 +                       set_opt (sbi->s_mount_opt, TAGGED);
2897 +                       break;
2898 +               case Opt_notag:
2899 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2900 +                       break;
2901 +#endif
2902 +#ifdef CONFIG_PROPAGATE
2903 +               case Opt_tagid:
2904 +                       /* use args[0] */
2905 +                       set_opt (sbi->s_mount_opt, TAGGED);
2906 +                       break;
2907 +#endif
2908                 case Opt_nocheck:
2909                         clear_opt (sbi->s_mount_opt, CHECK);
2910                         break;
2911 @@ -831,6 +849,8 @@ static int ext2_fill_super(struct super_
2912         if (!parse_options ((char *) data, sbi))
2913                 goto failed_mount;
2914  
2915 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2916 +               sb->s_flags |= MS_TAGGED;
2917         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2918                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2919                  MS_POSIXACL : 0);
2920 @@ -1164,6 +1184,13 @@ static int ext2_remount (struct super_bl
2921                 goto restore_opts;
2922         }
2923  
2924 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2925 +               !(sb->s_flags & MS_TAGGED)) {
2926 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2927 +                      sb->s_id);
2928 +               return -EINVAL;
2929 +       }
2930 +
2931         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2932                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2933  
2934 diff -NurpP --minimal linux-2.6.25/fs/ext2/symlink.c linux-2.6.25-vs2.3.0.34.9/fs/ext2/symlink.c
2935 --- linux-2.6.25/fs/ext2/symlink.c      2008-04-17 10:32:27.000000000 -0400
2936 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext2/symlink.c 2008-04-19 15:14:52.000000000 -0400
2937 @@ -38,6 +38,7 @@ const struct inode_operations ext2_symli
2938         .listxattr      = ext2_listxattr,
2939         .removexattr    = generic_removexattr,
2940  #endif
2941 +       .sync_flags     = ext2_sync_flags,
2942  };
2943   
2944  const struct inode_operations ext2_fast_symlink_inode_operations = {
2945 @@ -49,4 +50,5 @@ const struct inode_operations ext2_fast_
2946         .listxattr      = ext2_listxattr,
2947         .removexattr    = generic_removexattr,
2948  #endif
2949 +       .sync_flags     = ext2_sync_flags,
2950  };
2951 diff -NurpP --minimal linux-2.6.25/fs/ext2/xattr.c linux-2.6.25-vs2.3.0.34.9/fs/ext2/xattr.c
2952 --- linux-2.6.25/fs/ext2/xattr.c        2008-04-17 12:05:40.000000000 -0400
2953 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext2/xattr.c   2008-04-19 15:14:52.000000000 -0400
2954 @@ -60,6 +60,7 @@
2955  #include <linux/mbcache.h>
2956  #include <linux/quotaops.h>
2957  #include <linux/rwsem.h>
2958 +#include <linux/vs_dlimit.h>
2959  #include "ext2.h"
2960  #include "xattr.h"
2961  #include "acl.h"
2962 @@ -641,8 +642,12 @@ ext2_xattr_set2(struct inode *inode, str
2963                                    the inode.  */
2964                                 ea_bdebug(new_bh, "reusing block");
2965  
2966 +                               error = -ENOSPC;
2967 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
2968 +                                       goto cleanup;
2969                                 error = -EDQUOT;
2970                                 if (DQUOT_ALLOC_BLOCK(inode, 1)) {
2971 +                                       DLIMIT_FREE_BLOCK(inode, 1);
2972                                         unlock_buffer(new_bh);
2973                                         goto cleanup;
2974                                 }
2975 @@ -735,6 +740,7 @@ ext2_xattr_set2(struct inode *inode, str
2976                                 le32_to_cpu(HDR(old_bh)->h_refcount) - 1);
2977                         if (ce)
2978                                 mb_cache_entry_release(ce);
2979 +                       DLIMIT_FREE_BLOCK(inode, 1);
2980                         DQUOT_FREE_BLOCK(inode, 1);
2981                         mark_buffer_dirty(old_bh);
2982                         ea_bdebug(old_bh, "refcount now=%d",
2983 @@ -799,6 +805,7 @@ ext2_xattr_delete_inode(struct inode *in
2984                 mark_buffer_dirty(bh);
2985                 if (IS_SYNC(inode))
2986                         sync_dirty_buffer(bh);
2987 +               DLIMIT_FREE_BLOCK(inode, 1);
2988                 DQUOT_FREE_BLOCK(inode, 1);
2989         }
2990         EXT2_I(inode)->i_file_acl = 0;
2991 diff -NurpP --minimal linux-2.6.25/fs/ext3/balloc.c linux-2.6.25-vs2.3.0.34.9/fs/ext3/balloc.c
2992 --- linux-2.6.25/fs/ext3/balloc.c       2008-04-17 12:05:40.000000000 -0400
2993 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext3/balloc.c  2008-04-19 15:14:52.000000000 -0400
2994 @@ -19,6 +19,8 @@
2995  #include <linux/ext3_jbd.h>
2996  #include <linux/quotaops.h>
2997  #include <linux/buffer_head.h>
2998 +#include <linux/vs_dlimit.h>
2999 +#include <linux/vs_tag.h>
3000  
3001  /*
3002   * balloc.c contains the blocks allocation and deallocation routines
3003 @@ -675,8 +677,10 @@ void ext3_free_blocks(handle_t *handle, 
3004                 return;
3005         }
3006         ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
3007 -       if (dquot_freed_blocks)
3008 +       if (dquot_freed_blocks) {
3009 +               DLIMIT_FREE_BLOCK(inode, dquot_freed_blocks);
3010                 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
3011 +       }
3012         return;
3013  }
3014  
3015 @@ -1415,18 +1419,33 @@ out:
3016   *
3017   * Check if filesystem has at least 1 free block available for allocation.
3018   */
3019 -static int ext3_has_free_blocks(struct ext3_sb_info *sbi)
3020 +static int ext3_has_free_blocks(struct super_block *sb)
3021  {
3022 -       ext3_fsblk_t free_blocks, root_blocks;
3023 +       struct ext3_sb_info *sbi = EXT3_SB(sb);
3024 +       unsigned long long free_blocks, root_blocks;
3025 +       int cond;
3026  
3027         free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
3028         root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
3029 -       if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
3030 +
3031 +       vxdprintk(VXD_CBIT(dlim, 3),
3032 +               "ext3_has_free_blocks(%p): free=%llu, root=%llu",
3033 +               sb, free_blocks, root_blocks);
3034 +
3035 +       DLIMIT_ADJUST_BLOCK(sb, dx_current_tag(), &free_blocks, &root_blocks);
3036 +
3037 +       cond = (free_blocks < root_blocks + 1 &&
3038 +               !capable(CAP_SYS_RESOURCE) &&
3039                 sbi->s_resuid != current->fsuid &&
3040 -               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
3041 -               return 0;
3042 -       }
3043 -       return 1;
3044 +               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)));
3045 +
3046 +       vxdprintk(VXD_CBIT(dlim, 3),
3047 +               "ext3_has_free_blocks(%p): %llu<%llu+1, %c, %u!=%u r=%d",
3048 +               sb, free_blocks, root_blocks,
3049 +               !capable(CAP_SYS_RESOURCE)?'1':'0',
3050 +               sbi->s_resuid, current->fsuid, cond?0:1);
3051 +
3052 +       return (cond ? 0 : 1);
3053  }
3054  
3055  /**
3056 @@ -1443,7 +1462,7 @@ static int ext3_has_free_blocks(struct e
3057   */
3058  int ext3_should_retry_alloc(struct super_block *sb, int *retries)
3059  {
3060 -       if (!ext3_has_free_blocks(EXT3_SB(sb)) || (*retries)++ > 3)
3061 +       if (!ext3_has_free_blocks(sb) || (*retries)++ > 3)
3062                 return 0;
3063  
3064         jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id);
3065 @@ -1506,6 +1525,8 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
3066                 *errp = -EDQUOT;
3067                 return 0;
3068         }
3069 +       if (DLIMIT_ALLOC_BLOCK(inode, num))
3070 +           goto out_dlimit;
3071  
3072         sbi = EXT3_SB(sb);
3073         es = EXT3_SB(sb)->s_es;
3074 @@ -1522,7 +1543,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
3075         if (block_i && ((windowsz = block_i->rsv_window_node.rsv_goal_size) > 0))
3076                 my_rsv = &block_i->rsv_window_node;
3077  
3078 -       if (!ext3_has_free_blocks(sbi)) {
3079 +       if (!ext3_has_free_blocks(sb)) {
3080                 *errp = -ENOSPC;
3081                 goto out;
3082         }
3083 @@ -1710,12 +1731,16 @@ allocated:
3084         *errp = 0;
3085         brelse(bitmap_bh);
3086         DQUOT_FREE_BLOCK(inode, *count-num);
3087 +       DLIMIT_FREE_BLOCK(inode, *count-num);
3088         *count = num;
3089         return ret_block;
3090  
3091  io_error:
3092         *errp = -EIO;
3093  out:
3094 +       if (!performed_allocation)
3095 +               DLIMIT_FREE_BLOCK(inode, *count);
3096 +out_dlimit:
3097         if (fatal) {
3098                 *errp = fatal;
3099                 ext3_std_error(sb, fatal);
3100 diff -NurpP --minimal linux-2.6.25/fs/ext3/file.c linux-2.6.25-vs2.3.0.34.9/fs/ext3/file.c
3101 --- linux-2.6.25/fs/ext3/file.c 2008-04-17 10:37:23.000000000 -0400
3102 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext3/file.c    2008-04-19 15:14:52.000000000 -0400
3103 @@ -134,5 +134,6 @@ const struct inode_operations ext3_file_
3104         .removexattr    = generic_removexattr,
3105  #endif
3106         .permission     = ext3_permission,
3107 +       .sync_flags     = ext3_sync_flags,
3108  };
3109  
3110 diff -NurpP --minimal linux-2.6.25/fs/ext3/ialloc.c linux-2.6.25-vs2.3.0.34.9/fs/ext3/ialloc.c
3111 --- linux-2.6.25/fs/ext3/ialloc.c       2008-04-17 12:05:40.000000000 -0400
3112 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext3/ialloc.c  2008-04-19 15:14:52.000000000 -0400
3113 @@ -23,6 +23,8 @@
3114  #include <linux/buffer_head.h>
3115  #include <linux/random.h>
3116  #include <linux/bitops.h>
3117 +#include <linux/vs_dlimit.h>
3118 +#include <linux/vs_tag.h>
3119  
3120  #include <asm/byteorder.h>
3121  
3122 @@ -127,6 +129,7 @@ void ext3_free_inode (handle_t *handle, 
3123         ext3_xattr_delete_inode(handle, inode);
3124         DQUOT_FREE_INODE(inode);
3125         DQUOT_DROP(inode);
3126 +       DLIMIT_FREE_INODE(inode);
3127  
3128         is_directory = S_ISDIR(inode->i_mode);
3129  
3130 @@ -440,6 +443,12 @@ struct inode *ext3_new_inode(handle_t *h
3131         inode = new_inode(sb);
3132         if (!inode)
3133                 return ERR_PTR(-ENOMEM);
3134 +
3135 +       inode->i_tag = dx_current_fstag(sb);
3136 +       if (DLIMIT_ALLOC_INODE(inode)) {
3137 +               err = -ENOSPC;
3138 +               goto out_dlimit;
3139 +       }
3140         ei = EXT3_I(inode);
3141  
3142         sbi = EXT3_SB(sb);
3143 @@ -559,7 +568,8 @@ got:
3144         ei->i_dir_start_lookup = 0;
3145         ei->i_disksize = 0;
3146  
3147 -       ei->i_flags = EXT3_I(dir)->i_flags & ~EXT3_INDEX_FL;
3148 +       ei->i_flags = EXT3_I(dir)->i_flags &
3149 +               ~(EXT3_INDEX_FL|EXT3_IUNLINK_FL|EXT3_BARRIER_FL);
3150         if (S_ISLNK(mode))
3151                 ei->i_flags &= ~(EXT3_IMMUTABLE_FL|EXT3_APPEND_FL);
3152         /* dirsync only applies to directories */
3153 @@ -614,6 +624,8 @@ got:
3154  fail:
3155         ext3_std_error(sb, err);
3156  out:
3157 +       DLIMIT_FREE_INODE(inode);
3158 +out_dlimit:
3159         iput(inode);
3160         ret = ERR_PTR(err);
3161  really_out:
3162 @@ -625,6 +637,7 @@ fail_free_drop:
3163  
3164  fail_drop:
3165         DQUOT_DROP(inode);
3166 +       DLIMIT_FREE_INODE(inode);
3167         inode->i_flags |= S_NOQUOTA;
3168         inode->i_nlink = 0;
3169         iput(inode);
3170 diff -NurpP --minimal linux-2.6.25/fs/ext3/inode.c linux-2.6.25-vs2.3.0.34.9/fs/ext3/inode.c
3171 --- linux-2.6.25/fs/ext3/inode.c        2008-04-17 12:05:40.000000000 -0400
3172 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext3/inode.c   2008-04-20 13:25:49.000000000 -0400
3173 @@ -36,6 +36,7 @@
3174  #include <linux/mpage.h>
3175  #include <linux/uio.h>
3176  #include <linux/bio.h>
3177 +#include <linux/vs_tag.h>
3178  #include "xattr.h"
3179  #include "acl.h"
3180  
3181 @@ -2300,7 +2301,7 @@ void ext3_truncate(struct inode *inode)
3182                 return;
3183         if (ext3_inode_is_fast_symlink(inode))
3184                 return;
3185 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3186 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3187                 return;
3188  
3189         /*
3190 @@ -2622,13 +2623,20 @@ void ext3_set_inode_flags(struct inode *
3191  {
3192         unsigned int flags = EXT3_I(inode)->i_flags;
3193  
3194 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3195 +       inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
3196 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3197 +
3198 +       if (flags & EXT3_IMMUTABLE_FL)
3199 +               inode->i_flags |= S_IMMUTABLE;
3200 +       if (flags & EXT3_IUNLINK_FL)
3201 +               inode->i_flags |= S_IUNLINK;
3202 +       if (flags & EXT3_BARRIER_FL)
3203 +               inode->i_flags |= S_BARRIER;
3204 +
3205         if (flags & EXT3_SYNC_FL)
3206                 inode->i_flags |= S_SYNC;
3207         if (flags & EXT3_APPEND_FL)
3208                 inode->i_flags |= S_APPEND;
3209 -       if (flags & EXT3_IMMUTABLE_FL)
3210 -               inode->i_flags |= S_IMMUTABLE;
3211         if (flags & EXT3_NOATIME_FL)
3212                 inode->i_flags |= S_NOATIME;
3213         if (flags & EXT3_DIRSYNC_FL)
3214 @@ -2654,6 +2662,45 @@ void ext3_get_inode_flags(struct ext3_in
3215                 ei->i_flags |= EXT3_DIRSYNC_FL;
3216  }
3217  
3218 +int ext3_sync_flags(struct inode *inode)
3219 +{
3220 +       unsigned int oldflags, newflags;
3221 +       int err = 0;
3222 +
3223 +       oldflags = EXT3_I(inode)->i_flags;
3224 +       newflags = oldflags & ~(EXT3_IMMUTABLE_FL |
3225 +               EXT3_IUNLINK_FL | EXT3_BARRIER_FL);
3226 +
3227 +       if (IS_IMMUTABLE(inode))
3228 +               newflags |= EXT3_IMMUTABLE_FL;
3229 +       if (IS_IUNLINK(inode))
3230 +               newflags |= EXT3_IUNLINK_FL;
3231 +       if (IS_BARRIER(inode))
3232 +               newflags |= EXT3_BARRIER_FL;
3233 +
3234 +       if (oldflags ^ newflags) {
3235 +               handle_t *handle;
3236 +               struct ext3_iloc iloc;
3237 +
3238 +               handle = ext3_journal_start(inode, 1);
3239 +               if (IS_ERR(handle))
3240 +                       return PTR_ERR(handle);
3241 +               if (IS_SYNC(inode))
3242 +                       handle->h_sync = 1;
3243 +               err = ext3_reserve_inode_write(handle, inode, &iloc);
3244 +               if (err)
3245 +                       goto flags_err;
3246 +
3247 +               EXT3_I(inode)->i_flags = newflags;
3248 +               inode->i_ctime = CURRENT_TIME;
3249 +
3250 +               err = ext3_mark_iloc_dirty(handle, inode, &iloc);
3251 +       flags_err:
3252 +               ext3_journal_stop(handle);
3253 +       }
3254 +       return err;
3255 +}
3256 +
3257  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
3258  {
3259         struct ext3_iloc iloc;
3260 @@ -2663,6 +2710,8 @@ struct inode *ext3_iget(struct super_blo
3261         struct inode *inode;
3262         long ret;
3263         int block;
3264 +       uid_t uid;
3265 +       gid_t gid;
3266  
3267         inode = iget_locked(sb, ino);
3268         if (!inode)
3269 @@ -2683,12 +2732,17 @@ struct inode *ext3_iget(struct super_blo
3270         bh = iloc.bh;
3271         raw_inode = ext3_raw_inode(&iloc);
3272         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3273 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3274 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3275 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3276 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3277         if(!(test_opt (inode->i_sb, NO_UID32))) {
3278 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3279 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3280 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3281 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3282         }
3283 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3284 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3285 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3286 +               le16_to_cpu(raw_inode->i_raw_tag));
3287 +
3288         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3289         inode->i_size = le32_to_cpu(raw_inode->i_size);
3290         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3291 @@ -2817,6 +2871,8 @@ static int ext3_do_update_inode(handle_t
3292         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
3293         struct ext3_inode_info *ei = EXT3_I(inode);
3294         struct buffer_head *bh = iloc->bh;
3295 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3296 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3297         int err = 0, rc, block;
3298  
3299         /* For fields not not tracking in the in-memory inode,
3300 @@ -2827,29 +2883,32 @@ static int ext3_do_update_inode(handle_t
3301         ext3_get_inode_flags(ei);
3302         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3303         if(!(test_opt(inode->i_sb, NO_UID32))) {
3304 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3305 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3306 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3307 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3308  /*
3309   * Fix up interoperability with old kernels. Otherwise, old inodes get
3310   * re-used with the upper 16 bits of the uid/gid intact
3311   */
3312                 if(!ei->i_dtime) {
3313                         raw_inode->i_uid_high =
3314 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3315 +                               cpu_to_le16(high_16_bits(uid));
3316                         raw_inode->i_gid_high =
3317 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3318 +                               cpu_to_le16(high_16_bits(gid));
3319                 } else {
3320                         raw_inode->i_uid_high = 0;
3321                         raw_inode->i_gid_high = 0;
3322                 }
3323         } else {
3324                 raw_inode->i_uid_low =
3325 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3326 +                       cpu_to_le16(fs_high2lowuid(uid));
3327                 raw_inode->i_gid_low =
3328 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3329 +                       cpu_to_le16(fs_high2lowgid(gid));
3330                 raw_inode->i_uid_high = 0;
3331                 raw_inode->i_gid_high = 0;
3332         }
3333 +#ifdef CONFIG_TAGGING_INTERN
3334 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3335 +#endif
3336         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3337         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
3338         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3339 @@ -3002,7 +3061,8 @@ int ext3_setattr(struct dentry *dentry, 
3340                 return error;
3341  
3342         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3343 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3344 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3345 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3346                 handle_t *handle;
3347  
3348                 /* (user+group)*(old+new) structure, inode write (sb,
3349 @@ -3024,6 +3084,8 @@ int ext3_setattr(struct dentry *dentry, 
3350                         inode->i_uid = attr->ia_uid;
3351                 if (attr->ia_valid & ATTR_GID)
3352                         inode->i_gid = attr->ia_gid;
3353 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3354 +                       inode->i_tag = attr->ia_tag;
3355                 error = ext3_mark_inode_dirty(handle, inode);
3356                 ext3_journal_stop(handle);
3357         }
3358 diff -NurpP --minimal linux-2.6.25/fs/ext3/ioctl.c linux-2.6.25-vs2.3.0.34.9/fs/ext3/ioctl.c
3359 --- linux-2.6.25/fs/ext3/ioctl.c        2008-04-17 11:31:35.000000000 -0400
3360 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext3/ioctl.c   2008-04-19 15:14:52.000000000 -0400
3361 @@ -8,6 +8,7 @@
3362   */
3363  
3364  #include <linux/fs.h>
3365 +#include <linux/mount.h>
3366  #include <linux/jbd.h>
3367  #include <linux/capability.h>
3368  #include <linux/ext3_fs.h>
3369 @@ -15,6 +16,7 @@
3370  #include <linux/time.h>
3371  #include <linux/compat.h>
3372  #include <linux/smp_lock.h>
3373 +#include <linux/vs_tag.h>
3374  #include <asm/uaccess.h>
3375  
3376  int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
3377 @@ -38,7 +40,8 @@ int ext3_ioctl (struct inode * inode, st
3378                 unsigned int oldflags;
3379                 unsigned int jflag;
3380  
3381 -               if (IS_RDONLY(inode))
3382 +               if (IS_RDONLY(inode) ||
3383 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
3384                         return -EROFS;
3385  
3386                 if (!is_owner_or_cap(inode))
3387 @@ -67,7 +70,9 @@ int ext3_ioctl (struct inode * inode, st
3388                  *
3389                  * This test looks nicer. Thanks to Pauline Middelink
3390                  */
3391 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
3392 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
3393 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
3394 +                       EXT3_IMMUTABLE_FL | EXT3_IUNLINK_FL))) {
3395                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3396                                 mutex_unlock(&inode->i_mutex);
3397                                 return -EPERM;
3398 @@ -129,7 +134,8 @@ flags_err:
3399  
3400                 if (!is_owner_or_cap(inode))
3401                         return -EPERM;
3402 -               if (IS_RDONLY(inode))
3403 +               if (IS_RDONLY(inode) ||
3404 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
3405                         return -EROFS;
3406                 if (get_user(generation, (int __user *) arg))
3407                         return -EFAULT;
3408 @@ -183,7 +189,8 @@ flags_err:
3409                 if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode))
3410                         return -ENOTTY;
3411  
3412 -               if (IS_RDONLY(inode))
3413 +               if (IS_RDONLY(inode) ||
3414 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
3415                         return -EROFS;
3416  
3417                 if (!is_owner_or_cap(inode))
3418 @@ -218,7 +225,8 @@ flags_err:
3419                 if (!capable(CAP_SYS_RESOURCE))
3420                         return -EPERM;
3421  
3422 -               if (IS_RDONLY(inode))
3423 +               if (IS_RDONLY(inode) ||
3424 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
3425                         return -EROFS;
3426  
3427                 if (get_user(n_blocks_count, (__u32 __user *)arg))
3428 @@ -239,7 +247,8 @@ flags_err:
3429                 if (!capable(CAP_SYS_RESOURCE))
3430                         return -EPERM;
3431  
3432 -               if (IS_RDONLY(inode))
3433 +               if (IS_RDONLY(inode) ||
3434 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
3435                         return -EROFS;
3436  
3437                 if (copy_from_user(&input, (struct ext3_new_group_input __user *)arg,
3438 diff -NurpP --minimal linux-2.6.25/fs/ext3/namei.c linux-2.6.25-vs2.3.0.34.9/fs/ext3/namei.c
3439 --- linux-2.6.25/fs/ext3/namei.c        2008-04-17 12:05:40.000000000 -0400
3440 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext3/namei.c   2008-04-19 15:14:52.000000000 -0400
3441 @@ -36,6 +36,7 @@
3442  #include <linux/quotaops.h>
3443  #include <linux/buffer_head.h>
3444  #include <linux/bio.h>
3445 +#include <linux/vs_tag.h>
3446  
3447  #include "namei.h"
3448  #include "xattr.h"
3449 @@ -907,6 +908,7 @@ restart:
3450                                 if (bh)
3451                                         ll_rw_block(READ_META, 1, &bh);
3452                         }
3453 +               dx_propagate_tag(nd, inode);
3454                 }
3455                 if ((bh = bh_use[ra_ptr++]) == NULL)
3456                         goto next;
3457 @@ -2417,6 +2419,7 @@ const struct inode_operations ext3_dir_i
3458         .removexattr    = generic_removexattr,
3459  #endif
3460         .permission     = ext3_permission,
3461 +       .sync_flags     = ext3_sync_flags,
3462  };
3463  
3464  const struct inode_operations ext3_special_inode_operations = {
3465 @@ -2428,4 +2431,5 @@ const struct inode_operations ext3_speci
3466         .removexattr    = generic_removexattr,
3467  #endif
3468         .permission     = ext3_permission,
3469 +       .sync_flags     = ext3_sync_flags,
3470  };
3471 diff -NurpP --minimal linux-2.6.25/fs/ext3/super.c linux-2.6.25-vs2.3.0.34.9/fs/ext3/super.c
3472 --- linux-2.6.25/fs/ext3/super.c        2008-04-17 12:05:40.000000000 -0400
3473 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext3/super.c   2008-04-20 13:26:55.000000000 -0400
3474 @@ -756,7 +756,7 @@ enum {
3475         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
3476         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
3477         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
3478 -       Opt_grpquota
3479 +       Opt_grpquota, Opt_tag, Opt_notag, Opt_tagid
3480  };
3481  
3482  static match_table_t tokens = {
3483 @@ -807,6 +807,9 @@ static match_table_t tokens = {
3484         {Opt_usrquota, "usrquota"},
3485         {Opt_barrier, "barrier=%u"},
3486         {Opt_resize, "resize"},
3487 +       {Opt_tag, "tag"},
3488 +       {Opt_notag, "notag"},
3489 +       {Opt_tagid, "tagid=%u"},
3490         {Opt_err, NULL},
3491  };
3492  
3493 @@ -899,6 +902,20 @@ static int parse_options (char *options,
3494                 case Opt_nouid32:
3495                         set_opt (sbi->s_mount_opt, NO_UID32);
3496                         break;
3497 +#ifndef CONFIG_TAGGING_NONE
3498 +               case Opt_tag:
3499 +                       set_opt (sbi->s_mount_opt, TAGGED);
3500 +                       break;
3501 +               case Opt_notag:
3502 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3503 +                       break;
3504 +#endif
3505 +#ifdef CONFIG_PROPAGATE
3506 +               case Opt_tagid:
3507 +                       /* use args[0] */
3508 +                       set_opt (sbi->s_mount_opt, TAGGED);
3509 +                       break;
3510 +#endif
3511                 case Opt_nocheck:
3512                         clear_opt (sbi->s_mount_opt, CHECK);
3513                         break;
3514 @@ -1591,6 +1608,9 @@ static int ext3_fill_super (struct super
3515                             NULL, 0))
3516                 goto failed_mount;
3517  
3518 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
3519 +               sb->s_flags |= MS_TAGGED;
3520 +
3521         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3522                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3523  
3524 @@ -2428,6 +2448,12 @@ static int ext3_remount (struct super_bl
3525  
3526         if (sbi->s_mount_opt & EXT3_MOUNT_ABORT)
3527                 ext3_abort(sb, __FUNCTION__, "Abort forced by user");
3528 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
3529 +               !(sb->s_flags & MS_TAGGED)) {
3530 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
3531 +                       sb->s_id);
3532 +               return -EINVAL;
3533 +       }
3534  
3535         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3536                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3537 diff -NurpP --minimal linux-2.6.25/fs/ext3/symlink.c linux-2.6.25-vs2.3.0.34.9/fs/ext3/symlink.c
3538 --- linux-2.6.25/fs/ext3/symlink.c      2008-04-17 10:32:27.000000000 -0400
3539 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext3/symlink.c 2008-04-19 15:14:52.000000000 -0400
3540 @@ -40,6 +40,7 @@ const struct inode_operations ext3_symli
3541         .listxattr      = ext3_listxattr,
3542         .removexattr    = generic_removexattr,
3543  #endif
3544 +       .sync_flags     = ext3_sync_flags,
3545  };
3546  
3547  const struct inode_operations ext3_fast_symlink_inode_operations = {
3548 @@ -51,4 +52,5 @@ const struct inode_operations ext3_fast_
3549         .listxattr      = ext3_listxattr,
3550         .removexattr    = generic_removexattr,
3551  #endif
3552 +       .sync_flags     = ext3_sync_flags,
3553  };
3554 diff -NurpP --minimal linux-2.6.25/fs/ext3/xattr.c linux-2.6.25-vs2.3.0.34.9/fs/ext3/xattr.c
3555 --- linux-2.6.25/fs/ext3/xattr.c        2008-04-17 12:05:40.000000000 -0400
3556 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext3/xattr.c   2008-04-19 15:14:52.000000000 -0400
3557 @@ -58,6 +58,7 @@
3558  #include <linux/mbcache.h>
3559  #include <linux/quotaops.h>
3560  #include <linux/rwsem.h>
3561 +#include <linux/vs_dlimit.h>
3562  #include "xattr.h"
3563  #include "acl.h"
3564  
3565 @@ -496,6 +497,7 @@ ext3_xattr_release_block(handle_t *handl
3566                 error = ext3_journal_dirty_metadata(handle, bh);
3567                 if (IS_SYNC(inode))
3568                         handle->h_sync = 1;
3569 +                       DLIMIT_FREE_BLOCK(inode, 1);
3570                 DQUOT_FREE_BLOCK(inode, 1);
3571                 ea_bdebug(bh, "refcount now=%d; releasing",
3572                           le32_to_cpu(BHDR(bh)->h_refcount));
3573 @@ -769,11 +771,14 @@ inserted:
3574                         if (new_bh == bs->bh)
3575                                 ea_bdebug(new_bh, "keeping");
3576                         else {
3577 +                               error = -ENOSPC;
3578 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
3579 +                                       goto cleanup;
3580                                 /* The old block is released after updating
3581                                    the inode. */
3582                                 error = -EDQUOT;
3583                                 if (DQUOT_ALLOC_BLOCK(inode, 1))
3584 -                                       goto cleanup;
3585 +                                       goto cleanup_dlimit;
3586                                 error = ext3_journal_get_write_access(handle,
3587                                                                       new_bh);
3588                                 if (error)
3589 @@ -849,6 +854,8 @@ cleanup:
3590  
3591  cleanup_dquot:
3592         DQUOT_FREE_BLOCK(inode, 1);
3593 +cleanup_dlimit:
3594 +       DLIMIT_FREE_BLOCK(inode, 1);
3595         goto cleanup;
3596  
3597  bad_block:
3598 diff -NurpP --minimal linux-2.6.25/fs/ext4/balloc.c linux-2.6.25-vs2.3.0.34.9/fs/ext4/balloc.c
3599 --- linux-2.6.25/fs/ext4/balloc.c       2008-04-17 12:05:40.000000000 -0400
3600 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext4/balloc.c  2008-04-21 10:23:33.000000000 -0400
3601 @@ -19,6 +19,8 @@
3602  #include <linux/ext4_jbd2.h>
3603  #include <linux/quotaops.h>
3604  #include <linux/buffer_head.h>
3605 +#include <linux/vs_dlimit.h>
3606 +#include <linux/vs_tag.h>
3607  
3608  #include "group.h"
3609  /*
3610 @@ -810,8 +812,10 @@ void ext4_free_blocks(handle_t *handle, 
3611         else
3612                 ext4_mb_free_blocks(handle, inode, block, count,
3613                                                 metadata, &dquot_freed_blocks);
3614 -       if (dquot_freed_blocks)
3615 +       if (dquot_freed_blocks) {
3616 +               DLIMIT_FREE_BLOCK(inode, dquot_freed_blocks);
3617                 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
3618 +       }
3619         return;
3620  }
3621  
3622 @@ -1551,18 +1555,33 @@ out:
3623   *
3624   * Check if filesystem has at least 1 free block available for allocation.
3625   */
3626 -static int ext4_has_free_blocks(struct ext4_sb_info *sbi)
3627 +static int ext4_has_free_blocks(struct super_block *sb)
3628  {
3629 +       struct ext4_sb_info *sbi = EXT4_SB(sb);
3630         ext4_fsblk_t free_blocks, root_blocks;
3631 +       int cond;
3632  
3633         free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
3634         root_blocks = ext4_r_blocks_count(sbi->s_es);
3635 -       if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
3636 +
3637 +       vxdprintk(VXD_CBIT(dlim, 3),
3638 +               "ext4_has_free_blocks(%p): free=%llu, root=%llu",
3639 +               sb, free_blocks, root_blocks);
3640 +
3641 +       DLIMIT_ADJUST_BLOCK(sb, dx_current_tag(), &free_blocks, &root_blocks);
3642 +
3643 +       cond = (free_blocks < root_blocks + 1 &&
3644 +               !capable(CAP_SYS_RESOURCE) &&
3645                 sbi->s_resuid != current->fsuid &&
3646 -               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
3647 -               return 0;
3648 -       }
3649 -       return 1;
3650 +               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)));
3651 +
3652 +       vxdprintk(VXD_CBIT(dlim, 3),
3653 +               "ext4_has_free_blocks(%p): %llu<%llu+1, %c, %u!=%u r=%d",
3654 +               sb, free_blocks, root_blocks,
3655 +               !capable(CAP_SYS_RESOURCE)?'1':'0',
3656 +               sbi->s_resuid, current->fsuid, cond?0:1);
3657 +
3658 +       return (cond ? 0 : 1);
3659  }
3660  
3661  /**
3662 @@ -1579,7 +1598,7 @@ static int ext4_has_free_blocks(struct e
3663   */
3664  int ext4_should_retry_alloc(struct super_block *sb, int *retries)
3665  {
3666 -       if (!ext4_has_free_blocks(EXT4_SB(sb)) || (*retries)++ > 3)
3667 +       if (!ext4_has_free_blocks(sb) || (*retries)++ > 3)
3668                 return 0;
3669  
3670         jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id);
3671 @@ -1639,6 +1658,8 @@ ext4_fsblk_t ext4_new_blocks_old(handle_
3672                 *errp = -EDQUOT;
3673                 return 0;
3674         }
3675 +       if (DLIMIT_ALLOC_BLOCK(inode, num))
3676 +           goto out_dlimit;
3677  
3678         sbi = EXT4_SB(sb);
3679         es = EXT4_SB(sb)->s_es;
3680 @@ -1655,7 +1676,7 @@ ext4_fsblk_t ext4_new_blocks_old(handle_
3681         if (block_i && ((windowsz = block_i->rsv_window_node.rsv_goal_size) > 0))
3682                 my_rsv = &block_i->rsv_window_node;
3683  
3684 -       if (!ext4_has_free_blocks(sbi)) {
3685 +       if (!ext4_has_free_blocks(sb)) {
3686                 *errp = -ENOSPC;
3687                 goto out;
3688         }
3689 @@ -1841,12 +1862,16 @@ allocated:
3690         *errp = 0;
3691         brelse(bitmap_bh);
3692         DQUOT_FREE_BLOCK(inode, *count-num);
3693 +       DLIMIT_FREE_BLOCK(inode, *count-num);
3694         *count = num;
3695         return ret_block;
3696  
3697  io_error:
3698         *errp = -EIO;
3699  out:
3700 +       if (!performed_allocation)
3701 +               DLIMIT_FREE_BLOCK(inode, *count);
3702 +out_dlimit:
3703         if (fatal) {
3704                 *errp = fatal;
3705                 ext4_std_error(sb, fatal);
3706 diff -NurpP --minimal linux-2.6.25/fs/ext4/file.c linux-2.6.25-vs2.3.0.34.9/fs/ext4/file.c
3707 --- linux-2.6.25/fs/ext4/file.c 2008-04-17 12:05:40.000000000 -0400
3708 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext4/file.c    2008-04-19 15:14:52.000000000 -0400
3709 @@ -152,5 +152,6 @@ const struct inode_operations ext4_file_
3710  #endif
3711         .permission     = ext4_permission,
3712         .fallocate      = ext4_fallocate,
3713 +       .sync_flags     = ext4_sync_flags,
3714  };
3715  
3716 diff -NurpP --minimal linux-2.6.25/fs/ext4/ialloc.c linux-2.6.25-vs2.3.0.34.9/fs/ext4/ialloc.c
3717 --- linux-2.6.25/fs/ext4/ialloc.c       2008-04-17 12:05:40.000000000 -0400
3718 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext4/ialloc.c  2008-04-21 10:29:28.000000000 -0400
3719 @@ -24,6 +24,8 @@
3720  #include <linux/random.h>
3721  #include <linux/bitops.h>
3722  #include <linux/blkdev.h>
3723 +#include <linux/vs_dlimit.h>
3724 +#include <linux/vs_tag.h>
3725  #include <asm/byteorder.h>
3726  
3727  #include "xattr.h"
3728 @@ -186,6 +188,7 @@ void ext4_free_inode (handle_t *handle, 
3729         ext4_xattr_delete_inode(handle, inode);
3730         DQUOT_FREE_INODE(inode);
3731         DQUOT_DROP(inode);
3732 +       DLIMIT_FREE_INODE(inode);
3733  
3734         is_directory = S_ISDIR(inode->i_mode);
3735  
3736 @@ -513,6 +516,12 @@ struct inode *ext4_new_inode(handle_t *h
3737         inode = new_inode(sb);
3738         if (!inode)
3739                 return ERR_PTR(-ENOMEM);
3740 +
3741 +       inode->i_tag = dx_current_fstag(sb);
3742 +       if (DLIMIT_ALLOC_INODE(inode)) {
3743 +               err = -ENOSPC;
3744 +               goto out_dlimit;
3745 +       }
3746         ei = EXT4_I(inode);
3747  
3748         sbi = EXT4_SB(sb);
3749 @@ -707,7 +716,8 @@ got:
3750          * newly created directory and file only if -o extent mount option is
3751          * specified
3752          */
3753 -       ei->i_flags = EXT4_I(dir)->i_flags & ~(EXT4_INDEX_FL|EXT4_EXTENTS_FL);
3754 +       ei->i_flags = EXT4_I(dir)->i_flags &
3755 +               ~(EXT4_INDEX_FL|EXT4_EXTENTS_FL|EXT4_IUNLINK_FL|EXT4_BARRIER_FL);
3756         if (S_ISLNK(mode))
3757                 ei->i_flags &= ~(EXT4_IMMUTABLE_FL|EXT4_APPEND_FL);
3758         /* dirsync only applies to directories */
3759 @@ -766,6 +776,8 @@ got:
3760  fail:
3761         ext4_std_error(sb, err);
3762  out:
3763 +       DLIMIT_FREE_INODE(inode);
3764 +out_dlimit:
3765         iput(inode);
3766         ret = ERR_PTR(err);
3767  really_out:
3768 @@ -777,6 +789,7 @@ fail_free_drop:
3769  
3770  fail_drop:
3771         DQUOT_DROP(inode);
3772 +       DLIMIT_FREE_INODE(inode);
3773         inode->i_flags |= S_NOQUOTA;
3774         inode->i_nlink = 0;
3775         iput(inode);
3776 diff -NurpP --minimal linux-2.6.25/fs/ext4/inode.c linux-2.6.25-vs2.3.0.34.9/fs/ext4/inode.c
3777 --- linux-2.6.25/fs/ext4/inode.c        2008-04-17 12:05:40.000000000 -0400
3778 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext4/inode.c   2008-04-21 10:20:53.000000000 -0400
3779 @@ -36,6 +36,7 @@
3780  #include <linux/mpage.h>
3781  #include <linux/uio.h>
3782  #include <linux/bio.h>
3783 +#include <linux/vs_tag.h>
3784  #include "xattr.h"
3785  #include "acl.h"
3786  
3787 @@ -2342,7 +2343,7 @@ void ext4_truncate(struct inode *inode)
3788                 return;
3789         if (ext4_inode_is_fast_symlink(inode))
3790                 return;
3791 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3792 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3793                 return;
3794  
3795         /*
3796 @@ -2671,13 +2672,20 @@ void ext4_set_inode_flags(struct inode *
3797  {
3798         unsigned int flags = EXT4_I(inode)->i_flags;
3799  
3800 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3801 +       inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
3802 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3803 +
3804 +       if (flags & EXT4_IMMUTABLE_FL)
3805 +               inode->i_flags |= S_IMMUTABLE;
3806 +       if (flags & EXT4_IUNLINK_FL)
3807 +               inode->i_flags |= S_IUNLINK;
3808 +       if (flags & EXT4_BARRIER_FL)
3809 +               inode->i_flags |= S_BARRIER;
3810 +
3811         if (flags & EXT4_SYNC_FL)
3812                 inode->i_flags |= S_SYNC;
3813         if (flags & EXT4_APPEND_FL)
3814                 inode->i_flags |= S_APPEND;
3815 -       if (flags & EXT4_IMMUTABLE_FL)
3816 -               inode->i_flags |= S_IMMUTABLE;
3817         if (flags & EXT4_NOATIME_FL)
3818                 inode->i_flags |= S_NOATIME;
3819         if (flags & EXT4_DIRSYNC_FL)
3820 @@ -2702,6 +2710,46 @@ void ext4_get_inode_flags(struct ext4_in
3821         if (flags & S_DIRSYNC)
3822                 ei->i_flags |= EXT4_DIRSYNC_FL;
3823  }
3824 +
3825 +int ext4_sync_flags(struct inode *inode)
3826 +{
3827 +       unsigned int oldflags, newflags;
3828 +       int err = 0;
3829 +
3830 +       oldflags = EXT4_I(inode)->i_flags;
3831 +       newflags = oldflags & ~(EXT4_IMMUTABLE_FL |
3832 +               EXT4_IUNLINK_FL | EXT4_BARRIER_FL);
3833 +
3834 +       if (IS_IMMUTABLE(inode))
3835 +               newflags |= EXT4_IMMUTABLE_FL;
3836 +       if (IS_IUNLINK(inode))
3837 +               newflags |= EXT4_IUNLINK_FL;
3838 +       if (IS_BARRIER(inode))
3839 +               newflags |= EXT4_BARRIER_FL;
3840 +
3841 +       if (oldflags ^ newflags) {
3842 +               handle_t *handle;
3843 +               struct ext4_iloc iloc;
3844 +
3845 +               handle = ext4_journal_start(inode, 1);
3846 +               if (IS_ERR(handle))
3847 +                       return PTR_ERR(handle);
3848 +               if (IS_SYNC(inode))
3849 +                       handle->h_sync = 1;
3850 +               err = ext4_reserve_inode_write(handle, inode, &iloc);
3851 +               if (err)
3852 +                       goto flags_err;
3853 +
3854 +               EXT4_I(inode)->i_flags = newflags;
3855 +               inode->i_ctime = CURRENT_TIME;
3856 +
3857 +               err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3858 +       flags_err:
3859 +               ext4_journal_stop(handle);
3860 +       }
3861 +       return err;
3862 +}
3863 +
3864  static blkcnt_t ext4_inode_blocks(struct ext4_inode *raw_inode,
3865                                         struct ext4_inode_info *ei)
3866  {
3867 @@ -2734,6 +2782,8 @@ struct inode *ext4_iget(struct super_blo
3868         struct inode *inode;
3869         long ret;
3870         int block;
3871 +       uid_t uid;
3872 +       gid_t gid;
3873  
3874         inode = iget_locked(sb, ino);
3875         if (!inode)
3876 @@ -2754,12 +2804,17 @@ struct inode *ext4_iget(struct super_blo
3877         bh = iloc.bh;
3878         raw_inode = ext4_raw_inode(&iloc);
3879         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3880 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3881 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3882 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3883 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3884         if(!(test_opt (inode->i_sb, NO_UID32))) {
3885 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3886 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3887 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3888 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3889         }
3890 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3891 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3892 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3893 +               le16_to_cpu(raw_inode->i_raw_tag));
3894 +
3895         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3896  
3897         ei->i_state = 0;
3898 @@ -2933,6 +2988,8 @@ static int ext4_do_update_inode(handle_t
3899         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3900         struct ext4_inode_info *ei = EXT4_I(inode);
3901         struct buffer_head *bh = iloc->bh;
3902 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3903 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3904         int err = 0, rc, block;
3905  
3906         /* For fields not not tracking in the in-memory inode,
3907 @@ -2943,29 +3000,32 @@ static int ext4_do_update_inode(handle_t
3908         ext4_get_inode_flags(ei);
3909         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3910         if(!(test_opt(inode->i_sb, NO_UID32))) {
3911 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3912 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3913 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3914 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3915  /*
3916   * Fix up interoperability with old kernels. Otherwise, old inodes get
3917   * re-used with the upper 16 bits of the uid/gid intact
3918   */
3919                 if(!ei->i_dtime) {
3920                         raw_inode->i_uid_high =
3921 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3922 +                               cpu_to_le16(high_16_bits(uid));
3923                         raw_inode->i_gid_high =
3924 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3925 +                               cpu_to_le16(high_16_bits(gid));
3926                 } else {
3927                         raw_inode->i_uid_high = 0;
3928                         raw_inode->i_gid_high = 0;
3929                 }
3930         } else {
3931                 raw_inode->i_uid_low =
3932 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3933 +                       cpu_to_le16(fs_high2lowuid(uid));
3934                 raw_inode->i_gid_low =
3935 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3936 +                       cpu_to_le16(fs_high2lowgid(gid));
3937                 raw_inode->i_uid_high = 0;
3938                 raw_inode->i_gid_high = 0;
3939         }
3940 +#ifdef CONFIG_TAGGING_INTERN
3941 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3942 +#endif
3943         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3944  
3945         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3946 @@ -3121,7 +3181,8 @@ int ext4_setattr(struct dentry *dentry, 
3947                 return error;
3948  
3949         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3950 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3951 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3952 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3953                 handle_t *handle;
3954  
3955                 /* (user+group)*(old+new) structure, inode write (sb,
3956 @@ -3143,6 +3204,8 @@ int ext4_setattr(struct dentry *dentry, 
3957                         inode->i_uid = attr->ia_uid;
3958                 if (attr->ia_valid & ATTR_GID)
3959                         inode->i_gid = attr->ia_gid;
3960 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3961 +                       inode->i_tag = attr->ia_tag;
3962                 error = ext4_mark_inode_dirty(handle, inode);
3963                 ext4_journal_stop(handle);
3964         }
3965 diff -NurpP --minimal linux-2.6.25/fs/ext4/ioctl.c linux-2.6.25-vs2.3.0.34.9/fs/ext4/ioctl.c
3966 --- linux-2.6.25/fs/ext4/ioctl.c        2008-04-17 12:05:40.000000000 -0400
3967 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext4/ioctl.c   2008-04-19 15:14:52.000000000 -0400
3968 @@ -8,6 +8,7 @@
3969   */
3970  
3971  #include <linux/fs.h>
3972 +#include <linux/mount.h>
3973  #include <linux/jbd2.h>
3974  #include <linux/capability.h>
3975  #include <linux/ext4_fs.h>
3976 @@ -15,6 +16,7 @@
3977  #include <linux/time.h>
3978  #include <linux/compat.h>
3979  #include <linux/smp_lock.h>
3980 +#include <linux/vs_tag.h>
3981  #include <asm/uaccess.h>
3982  
3983  int ext4_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
3984 @@ -38,7 +40,8 @@ int ext4_ioctl (struct inode * inode, st
3985                 unsigned int oldflags;
3986                 unsigned int jflag;
3987  
3988 -               if (IS_RDONLY(inode))
3989 +               if (IS_RDONLY(inode) ||
3990 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
3991                         return -EROFS;
3992  
3993                 if (!is_owner_or_cap(inode))
3994 @@ -67,7 +70,9 @@ int ext4_ioctl (struct inode * inode, st
3995                  *
3996                  * This test looks nicer. Thanks to Pauline Middelink
3997                  */
3998 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3999 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
4000 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
4001 +                       EXT4_IMMUTABLE_FL | EXT4_IUNLINK_FL))) {
4002                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4003                                 mutex_unlock(&inode->i_mutex);
4004                                 return -EPERM;
4005 @@ -129,7 +134,8 @@ flags_err:
4006  
4007                 if (!is_owner_or_cap(inode))
4008                         return -EPERM;
4009 -               if (IS_RDONLY(inode))
4010 +               if (IS_RDONLY(inode) ||
4011 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4012                         return -EROFS;
4013                 if (get_user(generation, (int __user *) arg))
4014                         return -EFAULT;
4015 @@ -183,7 +189,8 @@ flags_err:
4016                 if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode))
4017                         return -ENOTTY;
4018  
4019 -               if (IS_RDONLY(inode))
4020 +               if (IS_RDONLY(inode) ||
4021 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4022                         return -EROFS;
4023  
4024                 if (!is_owner_or_cap(inode))
4025 @@ -218,7 +225,8 @@ flags_err:
4026                 if (!capable(CAP_SYS_RESOURCE))
4027                         return -EPERM;
4028  
4029 -               if (IS_RDONLY(inode))
4030 +               if (IS_RDONLY(inode) ||
4031 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4032                         return -EROFS;
4033  
4034                 if (get_user(n_blocks_count, (__u32 __user *)arg))
4035 @@ -239,7 +247,8 @@ flags_err:
4036                 if (!capable(CAP_SYS_RESOURCE))
4037                         return -EPERM;
4038  
4039 -               if (IS_RDONLY(inode))
4040 +               if (IS_RDONLY(inode) ||
4041 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4042                         return -EROFS;
4043  
4044                 if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg,
4045 diff -NurpP --minimal linux-2.6.25/fs/ext4/namei.c linux-2.6.25-vs2.3.0.34.9/fs/ext4/namei.c
4046 --- linux-2.6.25/fs/ext4/namei.c        2008-04-17 12:05:40.000000000 -0400
4047 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext4/namei.c   2008-04-19 15:14:52.000000000 -0400
4048 @@ -36,6 +36,7 @@
4049  #include <linux/quotaops.h>
4050  #include <linux/buffer_head.h>
4051  #include <linux/bio.h>
4052 +#include <linux/vs_tag.h>
4053  
4054  #include "namei.h"
4055  #include "xattr.h"
4056 @@ -908,6 +909,7 @@ restart:
4057                                 if (bh)
4058                                         ll_rw_block(READ_META, 1, &bh);
4059                         }
4060 +               dx_propagate_tag(nd, inode);
4061                 }
4062                 if ((bh = bh_use[ra_ptr++]) == NULL)
4063                         goto next;
4064 @@ -2448,6 +2450,7 @@ const struct inode_operations ext4_dir_i
4065         .removexattr    = generic_removexattr,
4066  #endif
4067         .permission     = ext4_permission,
4068 +       .sync_flags     = ext4_sync_flags,
4069  };
4070  
4071  const struct inode_operations ext4_special_inode_operations = {
4072 @@ -2459,4 +2462,5 @@ const struct inode_operations ext4_speci
4073         .removexattr    = generic_removexattr,
4074  #endif
4075         .permission     = ext4_permission,
4076 +       .sync_flags     = ext4_sync_flags,
4077  };
4078 diff -NurpP --minimal linux-2.6.25/fs/ext4/super.c linux-2.6.25-vs2.3.0.34.9/fs/ext4/super.c
4079 --- linux-2.6.25/fs/ext4/super.c        2008-04-17 12:05:40.000000000 -0400
4080 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext4/super.c   2008-04-21 10:31:22.000000000 -0400
4081 @@ -887,6 +887,7 @@ enum {
4082         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
4083         Opt_grpquota, Opt_extents, Opt_noextents, Opt_i_version,
4084         Opt_mballoc, Opt_nomballoc, Opt_stripe,
4085 +       Opt_tag, Opt_notag, Opt_tagid
4086  };
4087  
4088  static match_table_t tokens = {
4089 @@ -944,8 +945,11 @@ static match_table_t tokens = {
4090         {Opt_mballoc, "mballoc"},
4091         {Opt_nomballoc, "nomballoc"},
4092         {Opt_stripe, "stripe=%u"},
4093 -       {Opt_err, NULL},
4094         {Opt_resize, "resize"},
4095 +       {Opt_tag, "tag"},
4096 +       {Opt_notag, "notag"},
4097 +       {Opt_tagid, "tagid=%u"},
4098 +       {Opt_err, NULL},
4099  };
4100  
4101  static ext4_fsblk_t get_sb_block(void **data)
4102 @@ -1037,6 +1041,20 @@ static int parse_options (char *options,
4103                 case Opt_nouid32:
4104                         set_opt (sbi->s_mount_opt, NO_UID32);
4105                         break;
4106 +#ifndef CONFIG_TAGGING_NONE
4107 +               case Opt_tag:
4108 +                       set_opt (sbi->s_mount_opt, TAGGED);
4109 +                       break;
4110 +               case Opt_notag:
4111 +                       clear_opt (sbi->s_mount_opt, TAGGED);
4112 +                       break;
4113 +#endif
4114 +#ifdef CONFIG_PROPAGATE
4115 +               case Opt_tagid:
4116 +                       /* use args[0] */
4117 +                       set_opt (sbi->s_mount_opt, TAGGED);
4118 +                       break;
4119 +#endif
4120                 case Opt_nocheck:
4121                         clear_opt (sbi->s_mount_opt, CHECK);
4122                         break;
4123 @@ -1909,6 +1927,9 @@ static int ext4_fill_super (struct super
4124                             NULL, 0))
4125                 goto failed_mount;
4126  
4127 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
4128 +               sb->s_flags |= MS_TAGGED;
4129 +
4130         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4131                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
4132  
4133 @@ -2828,6 +2849,12 @@ static int ext4_remount (struct super_bl
4134  
4135         if (sbi->s_mount_opt & EXT4_MOUNT_ABORT)
4136                 ext4_abort(sb, __FUNCTION__, "Abort forced by user");
4137 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
4138 +               !(sb->s_flags & MS_TAGGED)) {
4139 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
4140 +                       sb->s_id);
4141 +               return -EINVAL;
4142 +       }
4143  
4144         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4145                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
4146 diff -NurpP --minimal linux-2.6.25/fs/ext4/symlink.c linux-2.6.25-vs2.3.0.34.9/fs/ext4/symlink.c
4147 --- linux-2.6.25/fs/ext4/symlink.c      2008-04-17 10:32:27.000000000 -0400
4148 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext4/symlink.c 2008-04-19 15:14:52.000000000 -0400
4149 @@ -40,6 +40,7 @@ const struct inode_operations ext4_symli
4150         .listxattr      = ext4_listxattr,
4151         .removexattr    = generic_removexattr,
4152  #endif
4153 +       .sync_flags     = ext4_sync_flags,
4154  };
4155  
4156  const struct inode_operations ext4_fast_symlink_inode_operations = {
4157 @@ -51,4 +52,5 @@ const struct inode_operations ext4_fast_
4158         .listxattr      = ext4_listxattr,
4159         .removexattr    = generic_removexattr,
4160  #endif
4161 +       .sync_flags     = ext4_sync_flags,
4162  };
4163 diff -NurpP --minimal linux-2.6.25/fs/ext4/xattr.c linux-2.6.25-vs2.3.0.34.9/fs/ext4/xattr.c
4164 --- linux-2.6.25/fs/ext4/xattr.c        2008-04-17 12:05:40.000000000 -0400
4165 +++ linux-2.6.25-vs2.3.0.34.9/fs/ext4/xattr.c   2008-04-19 15:14:52.000000000 -0400
4166 @@ -58,6 +58,7 @@
4167  #include <linux/mbcache.h>
4168  #include <linux/quotaops.h>
4169  #include <linux/rwsem.h>
4170 +#include <linux/vs_dlimit.h>
4171  #include "xattr.h"
4172  #include "acl.h"
4173  
4174 @@ -489,6 +490,7 @@ ext4_xattr_release_block(handle_t *handl
4175                 error = ext4_journal_dirty_metadata(handle, bh);
4176                 if (IS_SYNC(inode))
4177                         handle->h_sync = 1;
4178 +                       DLIMIT_FREE_BLOCK(inode, 1);
4179                 DQUOT_FREE_BLOCK(inode, 1);
4180                 ea_bdebug(bh, "refcount now=%d; releasing",
4181                           le32_to_cpu(BHDR(bh)->h_refcount));
4182 @@ -779,11 +781,14 @@ inserted:
4183                         if (new_bh == bs->bh)
4184                                 ea_bdebug(new_bh, "keeping");
4185                         else {
4186 +                               error = -ENOSPC;
4187 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
4188 +                                       goto cleanup;
4189                                 /* The old block is released after updating
4190                                    the inode. */
4191                                 error = -EDQUOT;
4192                                 if (DQUOT_ALLOC_BLOCK(inode, 1))
4193 -                                       goto cleanup;
4194 +                                       goto cleanup_dlimit;
4195                                 error = ext4_journal_get_write_access(handle,
4196                                                                       new_bh);
4197                                 if (error)
4198 @@ -860,6 +865,8 @@ cleanup:
4199  
4200  cleanup_dquot:
4201         DQUOT_FREE_BLOCK(inode, 1);
4202 +cleanup_dlimit:
4203 +       DLIMIT_FREE_BLOCK(inode, 1);
4204         goto cleanup;
4205  
4206  bad_block:
4207 diff -NurpP --minimal linux-2.6.25/fs/fcntl.c linux-2.6.25-vs2.3.0.34.9/fs/fcntl.c
4208 --- linux-2.6.25/fs/fcntl.c     2008-04-17 12:05:40.000000000 -0400
4209 +++ linux-2.6.25-vs2.3.0.34.9/fs/fcntl.c        2008-04-19 15:14:52.000000000 -0400
4210 @@ -19,6 +19,7 @@
4211  #include <linux/signal.h>
4212  #include <linux/rcupdate.h>
4213  #include <linux/pid_namespace.h>
4214 +#include <linux/vs_limit.h>
4215  
4216  #include <asm/poll.h>
4217  #include <asm/siginfo.h>
4218 @@ -85,6 +86,8 @@ repeat:
4219         error = -EMFILE;
4220         if (newfd >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
4221                 goto out;
4222 +       if (!vx_files_avail(1))
4223 +               goto out;
4224  
4225         error = expand_files(files, newfd);
4226         if (error < 0)
4227 @@ -128,6 +131,7 @@ static int dupfd(struct file *file, unsi
4228                 else
4229                         FD_CLR(fd, fdt->close_on_exec);
4230                 spin_unlock(&files->file_lock);
4231 +               vx_openfd_inc(fd);
4232                 fd_install(fd, file);
4233         } else {
4234                 spin_unlock(&files->file_lock);
4235 @@ -180,6 +184,9 @@ asmlinkage long sys_dup2(unsigned int ol
4236  
4237         if (tofree)
4238                 filp_close(tofree, files);
4239 +       else
4240 +               vx_openfd_inc(newfd);   /* fd was unused */
4241 +
4242         err = newfd;
4243  out:
4244         return err;
4245 diff -NurpP --minimal linux-2.6.25/fs/file_table.c linux-2.6.25-vs2.3.0.34.9/fs/file_table.c
4246 --- linux-2.6.25/fs/file_table.c        2008-04-17 12:05:40.000000000 -0400
4247 +++ linux-2.6.25-vs2.3.0.34.9/fs/file_table.c   2008-04-19 15:14:52.000000000 -0400
4248 @@ -20,6 +20,8 @@
4249  #include <linux/fsnotify.h>
4250  #include <linux/sysctl.h>
4251  #include <linux/percpu_counter.h>
4252 +#include <linux/vs_limit.h>
4253 +#include <linux/vs_context.h>
4254  
4255  #include <asm/atomic.h>
4256  
4257 @@ -124,6 +126,8 @@ struct file *get_empty_filp(void)
4258         f->f_gid = tsk->fsgid;
4259         eventpoll_init_file(f);
4260         /* f->f_version: 0 */
4261 +       f->f_xid = vx_current_xid();
4262 +       vx_files_inc(f);
4263         return f;
4264  
4265  over:
4266 @@ -239,6 +243,8 @@ void __fput(struct file *file)
4267         if (file->f_mode & FMODE_WRITE)
4268                 put_write_access(inode);
4269         put_pid(file->f_owner.pid);
4270 +       vx_files_dec(file);
4271 +       file->f_xid = 0;
4272         file_kill(file);
4273         file->f_path.dentry = NULL;
4274         file->f_path.mnt = NULL;
4275 @@ -304,6 +310,8 @@ void put_filp(struct file *file)
4276  {
4277         if (atomic_dec_and_test(&file->f_count)) {
4278                 security_file_free(file);
4279 +               vx_files_dec(file);
4280 +               file->f_xid = 0;
4281                 file_kill(file);
4282                 file_free(file);
4283         }
4284 diff -NurpP --minimal linux-2.6.25/fs/hfsplus/ioctl.c linux-2.6.25-vs2.3.0.34.9/fs/hfsplus/ioctl.c
4285 --- linux-2.6.25/fs/hfsplus/ioctl.c     2008-04-17 10:37:23.000000000 -0400
4286 +++ linux-2.6.25-vs2.3.0.34.9/fs/hfsplus/ioctl.c        2008-04-19 15:14:52.000000000 -0400
4287 @@ -16,6 +16,7 @@
4288  #include <linux/fs.h>
4289  #include <linux/sched.h>
4290  #include <linux/xattr.h>
4291 +#include <linux/mount.h>
4292  #include <asm/uaccess.h>
4293  #include "hfsplus_fs.h"
4294  
4295 @@ -35,7 +36,8 @@ int hfsplus_ioctl(struct inode *inode, s
4296                         flags |= FS_NODUMP_FL; /* EXT2_NODUMP_FL */
4297                 return put_user(flags, (int __user *)arg);
4298         case HFSPLUS_IOC_EXT2_SETFLAGS: {
4299 -               if (IS_RDONLY(inode))
4300 +               if (IS_RDONLY(inode) ||
4301 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4302                         return -EROFS;
4303  
4304                 if (!is_owner_or_cap(inode))
4305 diff -NurpP --minimal linux-2.6.25/fs/inode.c linux-2.6.25-vs2.3.0.34.9/fs/inode.c
4306 --- linux-2.6.25/fs/inode.c     2008-04-17 12:05:40.000000000 -0400
4307 +++ linux-2.6.25-vs2.3.0.34.9/fs/inode.c        2008-04-19 15:14:52.000000000 -0400
4308 @@ -124,6 +124,9 @@ static struct inode *alloc_inode(struct 
4309                 struct address_space * const mapping = &inode->i_data;
4310  
4311                 inode->i_sb = sb;
4312 +
4313 +               /* essential because of inode slab reuse */
4314 +               inode->i_tag = 0;
4315                 inode->i_blkbits = sb->s_blocksize_bits;
4316                 inode->i_flags = 0;
4317                 atomic_set(&inode->i_count, 1);
4318 @@ -142,6 +145,7 @@ static struct inode *alloc_inode(struct 
4319                 inode->i_bdev = NULL;
4320                 inode->i_cdev = NULL;
4321                 inode->i_rdev = 0;
4322 +               inode->i_mdev = 0;
4323                 inode->dirtied_when = 0;
4324                 if (security_inode_alloc(inode)) {
4325                         if (inode->i_sb->s_op->destroy_inode)
4326 @@ -246,6 +250,8 @@ void __iget(struct inode * inode)
4327         inodes_stat.nr_unused--;
4328  }
4329  
4330 +EXPORT_SYMBOL_GPL(__iget);
4331 +
4332  /**
4333   * clear_inode - clear an inode
4334   * @inode: inode to clear
4335 @@ -1434,9 +1440,11 @@ void init_special_inode(struct inode *in
4336         if (S_ISCHR(mode)) {
4337                 inode->i_fop = &def_chr_fops;
4338                 inode->i_rdev = rdev;
4339 +               inode->i_mdev = rdev;
4340         } else if (S_ISBLK(mode)) {
4341                 inode->i_fop = &def_blk_fops;
4342                 inode->i_rdev = rdev;
4343 +               inode->i_mdev = rdev;
4344         } else if (S_ISFIFO(mode))
4345                 inode->i_fop = &def_fifo_fops;
4346         else if (S_ISSOCK(mode))
4347 diff -NurpP --minimal linux-2.6.25/fs/ioctl.c linux-2.6.25-vs2.3.0.34.9/fs/ioctl.c
4348 --- linux-2.6.25/fs/ioctl.c     2008-04-17 12:05:40.000000000 -0400
4349 +++ linux-2.6.25-vs2.3.0.34.9/fs/ioctl.c        2008-04-21 09:25:46.000000000 -0400
4350 @@ -13,6 +13,9 @@
4351  #include <linux/security.h>
4352  #include <linux/module.h>
4353  #include <linux/uaccess.h>
4354 +#include <linux/proc_fs.h>
4355 +#include <linux/vserver/inode.h>
4356 +#include <linux/vs_tag.h>
4357  
4358  #include <asm/ioctls.h>
4359  
4360 diff -NurpP --minimal linux-2.6.25/fs/ioprio.c linux-2.6.25-vs2.3.0.34.9/fs/ioprio.c
4361 --- linux-2.6.25/fs/ioprio.c    2008-04-17 12:05:40.000000000 -0400
4362 +++ linux-2.6.25-vs2.3.0.34.9/fs/ioprio.c       2008-04-19 15:14:52.000000000 -0400
4363 @@ -26,6 +26,7 @@
4364  #include <linux/syscalls.h>
4365  #include <linux/security.h>
4366  #include <linux/pid_namespace.h>
4367 +#include <linux/vs_base.h>
4368  
4369  static int set_task_ioprio(struct task_struct *task, int ioprio)
4370  {
4371 @@ -116,6 +117,8 @@ asmlinkage long sys_ioprio_set(int which
4372                         else
4373                                 pgrp = find_vpid(who);
4374                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
4375 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4376 +                                       continue;
4377                                 ret = set_task_ioprio(p, ioprio);
4378                                 if (ret)
4379                                         break;
4380 @@ -205,6 +208,8 @@ asmlinkage long sys_ioprio_get(int which
4381                         else
4382                                 pgrp = find_vpid(who);
4383                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
4384 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4385 +                                       continue;
4386                                 tmpio = get_task_ioprio(p);
4387                                 if (tmpio < 0)
4388                                         continue;
4389 diff -NurpP --minimal linux-2.6.25/fs/jfs/acl.c linux-2.6.25-vs2.3.0.34.9/fs/jfs/acl.c
4390 --- linux-2.6.25/fs/jfs/acl.c   2007-02-04 13:44:54.000000000 -0500
4391 +++ linux-2.6.25-vs2.3.0.34.9/fs/jfs/acl.c      2008-04-19 15:14:52.000000000 -0400
4392 @@ -232,7 +232,8 @@ int jfs_setattr(struct dentry *dentry, s
4393                 return rc;
4394  
4395         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
4396 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
4397 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
4398 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
4399                 if (DQUOT_TRANSFER(inode, iattr))
4400                         return -EDQUOT;
4401         }
4402 diff -NurpP --minimal linux-2.6.25/fs/jfs/file.c linux-2.6.25-vs2.3.0.34.9/fs/jfs/file.c
4403 --- linux-2.6.25/fs/jfs/file.c  2008-04-17 12:05:40.000000000 -0400
4404 +++ linux-2.6.25-vs2.3.0.34.9/fs/jfs/file.c     2008-04-19 15:14:52.000000000 -0400
4405 @@ -98,6 +98,7 @@ const struct inode_operations jfs_file_i
4406         .setattr        = jfs_setattr,
4407         .permission     = jfs_permission,
4408  #endif
4409 +       .sync_flags     = jfs_sync_flags,
4410  };
4411  
4412  const struct file_operations jfs_file_operations = {
4413 diff -NurpP --minimal linux-2.6.25/fs/jfs/inode.c linux-2.6.25-vs2.3.0.34.9/fs/jfs/inode.c
4414 --- linux-2.6.25/fs/jfs/inode.c 2008-04-17 12:05:40.000000000 -0400
4415 +++ linux-2.6.25-vs2.3.0.34.9/fs/jfs/inode.c    2008-04-19 15:14:52.000000000 -0400
4416 @@ -22,6 +22,7 @@
4417  #include <linux/buffer_head.h>
4418  #include <linux/pagemap.h>
4419  #include <linux/quotaops.h>
4420 +#include <linux/vs_dlimit.h>
4421  #include "jfs_incore.h"
4422  #include "jfs_inode.h"
4423  #include "jfs_filsys.h"
4424 @@ -155,6 +156,7 @@ void jfs_delete_inode(struct inode *inod
4425                 DQUOT_INIT(inode);
4426                 DQUOT_FREE_INODE(inode);
4427                 DQUOT_DROP(inode);
4428 +               DLIMIT_FREE_INODE(inode);
4429         }
4430  
4431         clear_inode(inode);
4432 diff -NurpP --minimal linux-2.6.25/fs/jfs/ioctl.c linux-2.6.25-vs2.3.0.34.9/fs/jfs/ioctl.c
4433 --- linux-2.6.25/fs/jfs/ioctl.c 2008-04-17 12:05:40.000000000 -0400
4434 +++ linux-2.6.25-vs2.3.0.34.9/fs/jfs/ioctl.c    2008-04-21 09:25:22.000000000 -0400
4435 @@ -10,6 +10,7 @@
4436  #include <linux/capability.h>
4437  #include <linux/time.h>
4438  #include <linux/sched.h>
4439 +#include <linux/mount.h>
4440  #include <asm/current.h>
4441  #include <asm/uaccess.h>
4442  
4443 @@ -66,7 +67,8 @@ long jfs_ioctl(struct file *filp, unsign
4444         case JFS_IOC_SETFLAGS: {
4445                 unsigned int oldflags;
4446  
4447 -               if (IS_RDONLY(inode))
4448 +               if (IS_RDONLY(inode) ||
4449 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4450                         return -EROFS;
4451  
4452                 if (!is_owner_or_cap(inode))
4453 @@ -94,8 +96,8 @@ long jfs_ioctl(struct file *filp, unsign
4454                  * the relevant capability.
4455                  */
4456                 if ((oldflags & JFS_IMMUTABLE_FL) ||
4457 -                       ((flags ^ oldflags) &
4458 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
4459 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
4460 +                       JFS_IMMUTABLE_FL | JFS_IUNLINK_FL))) {
4461                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4462                                 mutex_unlock(&inode->i_mutex);
4463                                 return -EPERM;
4464 diff -NurpP --minimal linux-2.6.25/fs/jfs/jfs_dinode.h linux-2.6.25-vs2.3.0.34.9/fs/jfs/jfs_dinode.h
4465 --- linux-2.6.25/fs/jfs/jfs_dinode.h    2008-04-17 12:05:40.000000000 -0400
4466 +++ linux-2.6.25-vs2.3.0.34.9/fs/jfs/jfs_dinode.h       2008-04-19 15:14:52.000000000 -0400
4467 @@ -162,9 +162,12 @@ struct dinode {
4468  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
4469  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
4470  
4471 -#define JFS_FL_USER_VISIBLE    0x03F80000
4472 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
4473 +#define JFS_IUNLINK_FL         0x08000000 /* Immutable unlink */
4474 +
4475 +#define JFS_FL_USER_VISIBLE    0x0FF80000
4476  #define JFS_FL_USER_MODIFIABLE 0x03F80000
4477 -#define JFS_FL_INHERIT         0x03C80000
4478 +#define JFS_FL_INHERIT         0x0BC80000
4479  
4480  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
4481  #define JFS_IOC_GETFLAGS       _IOR('f', 1, long)
4482 diff -NurpP --minimal linux-2.6.25/fs/jfs/jfs_dtree.c linux-2.6.25-vs2.3.0.34.9/fs/jfs/jfs_dtree.c
4483 --- linux-2.6.25/fs/jfs/jfs_dtree.c     2008-04-17 12:05:40.000000000 -0400
4484 +++ linux-2.6.25-vs2.3.0.34.9/fs/jfs/jfs_dtree.c        2008-04-19 15:14:52.000000000 -0400
4485 @@ -102,6 +102,7 @@
4486  
4487  #include <linux/fs.h>
4488  #include <linux/quotaops.h>
4489 +#include <linux/vs_dlimit.h>
4490  #include "jfs_incore.h"
4491  #include "jfs_superblock.h"
4492  #include "jfs_filsys.h"
4493 @@ -383,10 +384,10 @@ static u32 add_index(tid_t tid, struct i
4494                  */
4495                 if (DQUOT_ALLOC_BLOCK(ip, sbi->nbperpage))
4496                         goto clean_up;
4497 -               if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr)) {
4498 -                       DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
4499 -                       goto clean_up;
4500 -               }
4501 +               if (DLIMIT_ALLOC_BLOCK(ip, sbi->nbperpage))
4502 +                       goto clean_up_dquot;
4503 +               if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr))
4504 +                       goto clean_up_dlimit;
4505  
4506                 /*
4507                  * Save the table, we're going to overwrite it with the
4508 @@ -480,6 +481,12 @@ static u32 add_index(tid_t tid, struct i
4509  
4510         return index;
4511  
4512 +      clean_up_dlimit:
4513 +       DLIMIT_FREE_BLOCK(ip, sbi->nbperpage);
4514 +
4515 +      clean_up_dquot:
4516 +       DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
4517 +
4518        clean_up:
4519  
4520         jfs_ip->next_index--;
4521 @@ -951,6 +958,7 @@ static int dtSplitUp(tid_t tid,
4522         struct tlock *tlck;
4523         struct lv *lv;
4524         int quota_allocation = 0;
4525 +       int dlimit_allocation = 0;
4526  
4527         /* get split page */
4528         smp = split->mp;
4529 @@ -1033,6 +1041,12 @@ static int dtSplitUp(tid_t tid,
4530                 }
4531                 quota_allocation += n;
4532  
4533 +               if (DLIMIT_ALLOC_BLOCK(ip, n)) {
4534 +                       rc = -ENOSPC;
4535 +                       goto extendOut;
4536 +               }
4537 +               dlimit_allocation += n;
4538 +
4539                 if ((rc = dbReAlloc(sbi->ipbmap, xaddr, (s64) xlen,
4540                                     (s64) n, &nxaddr)))
4541                         goto extendOut;
4542 @@ -1306,6 +1320,9 @@ static int dtSplitUp(tid_t tid,
4543        freeKeyName:
4544         kfree(key.name);
4545  
4546 +       /* Rollback dlimit allocation */
4547 +       if (rc && dlimit_allocation)
4548 +               DLIMIT_FREE_BLOCK(ip, dlimit_allocation);
4549         /* Rollback quota allocation */
4550         if (rc && quota_allocation)
4551                 DQUOT_FREE_BLOCK(ip, quota_allocation);
4552 @@ -1373,6 +1390,12 @@ static int dtSplitPage(tid_t tid, struct
4553                 release_metapage(rmp);
4554                 return -EDQUOT;
4555         }
4556 +       /* Allocate blocks to dlimit. */
4557 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4558 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
4559 +               release_metapage(rmp);
4560 +               return -ENOSPC;
4561 +       }
4562  
4563         jfs_info("dtSplitPage: ip:0x%p smp:0x%p rmp:0x%p", ip, smp, rmp);
4564  
4565 @@ -1920,6 +1943,12 @@ static int dtSplitRoot(tid_t tid,
4566                 release_metapage(rmp);
4567                 return -EDQUOT;
4568         }
4569 +       /* Allocate blocks to dlimit. */
4570 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4571 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
4572 +               release_metapage(rmp);
4573 +               return -ENOSPC;
4574 +       }
4575  
4576         BT_MARK_DIRTY(rmp, ip);
4577         /*
4578 @@ -2286,6 +2315,8 @@ static int dtDeleteUp(tid_t tid, struct 
4579  
4580         xlen = lengthPXD(&fp->header.self);
4581  
4582 +       /* Free dlimit allocation. */
4583 +       DLIMIT_FREE_BLOCK(ip, xlen);
4584         /* Free quota allocation. */
4585         DQUOT_FREE_BLOCK(ip, xlen);
4586  
4587 @@ -2362,6 +2393,8 @@ static int dtDeleteUp(tid_t tid, struct 
4588  
4589                                 xlen = lengthPXD(&p->header.self);
4590  
4591 +                               /* Free dlimit allocation */
4592 +                               DLIMIT_FREE_BLOCK(ip, xlen);
4593                                 /* Free quota allocation */
4594                                 DQUOT_FREE_BLOCK(ip, xlen);
4595  
4596 diff -NurpP --minimal linux-2.6.25/fs/jfs/jfs_extent.c linux-2.6.25-vs2.3.0.34.9/fs/jfs/jfs_extent.c
4597 --- linux-2.6.25/fs/jfs/jfs_extent.c    2008-04-17 10:37:23.000000000 -0400
4598 +++ linux-2.6.25-vs2.3.0.34.9/fs/jfs/jfs_extent.c       2008-04-19 15:14:52.000000000 -0400
4599 @@ -18,6 +18,7 @@
4600  
4601  #include <linux/fs.h>
4602  #include <linux/quotaops.h>
4603 +#include <linux/vs_dlimit.h>
4604  #include "jfs_incore.h"
4605  #include "jfs_inode.h"
4606  #include "jfs_superblock.h"
4607 @@ -147,6 +148,14 @@ extAlloc(struct inode *ip, s64 xlen, s64
4608                 return -EDQUOT;
4609         }
4610  
4611 +       /* Allocate blocks to dlimit. */
4612 +       if (DLIMIT_ALLOC_BLOCK(ip, nxlen)) {
4613 +               DQUOT_FREE_BLOCK(ip, nxlen);
4614 +               dbFree(ip, nxaddr, (s64) nxlen);
4615 +               mutex_unlock(&JFS_IP(ip)->commit_mutex);
4616 +               return -ENOSPC;
4617 +       }
4618 +
4619         /* determine the value of the extent flag */
4620         xflag = abnr ? XAD_NOTRECORDED : 0;
4621  
4622 @@ -164,6 +173,7 @@ extAlloc(struct inode *ip, s64 xlen, s64
4623          */
4624         if (rc) {
4625                 dbFree(ip, nxaddr, nxlen);
4626 +               DLIMIT_FREE_BLOCK(ip, nxlen);
4627                 DQUOT_FREE_BLOCK(ip, nxlen);
4628                 mutex_unlock(&JFS_IP(ip)->commit_mutex);
4629                 return (rc);
4630 @@ -261,6 +271,13 @@ int extRealloc(struct inode *ip, s64 nxl
4631                 mutex_unlock(&JFS_IP(ip)->commit_mutex);
4632                 return -EDQUOT;
4633         }
4634 +       /* Allocate blocks to dlimit. */
4635 +       if (DLIMIT_ALLOC_BLOCK(ip, nxlen)) {
4636 +               DQUOT_FREE_BLOCK(ip, nxlen);
4637 +               dbFree(ip, nxaddr, (s64) nxlen);
4638 +               up(&JFS_IP(ip)->commit_sem);
4639 +               return -ENOSPC;
4640 +       }
4641  
4642         delta = nxlen - xlen;
4643  
4644 @@ -297,6 +314,7 @@ int extRealloc(struct inode *ip, s64 nxl
4645                 /* extend the extent */
4646                 if ((rc = xtExtend(0, ip, xoff + xlen, (int) nextend, 0))) {
4647                         dbFree(ip, xaddr + xlen, delta);
4648 +                       DLIMIT_FREE_BLOCK(ip, nxlen);
4649                         DQUOT_FREE_BLOCK(ip, nxlen);
4650                         goto exit;
4651                 }
4652 @@ -308,6 +326,7 @@ int extRealloc(struct inode *ip, s64 nxl
4653                  */
4654                 if ((rc = xtTailgate(0, ip, xoff, (int) ntail, nxaddr, 0))) {
4655                         dbFree(ip, nxaddr, nxlen);
4656 +                       DLIMIT_FREE_BLOCK(ip, nxlen);
4657                         DQUOT_FREE_BLOCK(ip, nxlen);
4658                         goto exit;
4659                 }
4660 diff -NurpP --minimal linux-2.6.25/fs/jfs/jfs_filsys.h linux-2.6.25-vs2.3.0.34.9/fs/jfs/jfs_filsys.h
4661 --- linux-2.6.25/fs/jfs/jfs_filsys.h    2008-04-17 10:37:23.000000000 -0400
4662 +++ linux-2.6.25-vs2.3.0.34.9/fs/jfs/jfs_filsys.h       2008-04-19 15:14:52.000000000 -0400
4663 @@ -263,6 +263,7 @@
4664  #define JFS_NAME_MAX   255
4665  #define JFS_PATH_MAX   BPSIZE
4666  
4667 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
4668  
4669  /*
4670   *     file system state (superblock state)
4671 diff -NurpP --minimal linux-2.6.25/fs/jfs/jfs_imap.c linux-2.6.25-vs2.3.0.34.9/fs/jfs/jfs_imap.c
4672 --- linux-2.6.25/fs/jfs/jfs_imap.c      2008-04-17 12:05:40.000000000 -0400
4673 +++ linux-2.6.25-vs2.3.0.34.9/fs/jfs/jfs_imap.c 2008-04-19 15:14:52.000000000 -0400
4674 @@ -45,6 +45,7 @@
4675  #include <linux/buffer_head.h>
4676  #include <linux/pagemap.h>
4677  #include <linux/quotaops.h>
4678 +#include <linux/vs_tag.h>
4679  
4680  #include "jfs_incore.h"
4681  #include "jfs_inode.h"
4682 @@ -3061,6 +3062,8 @@ static int copy_from_dinode(struct dinod
4683  {
4684         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
4685         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
4686 +       uid_t uid;
4687 +       gid_t gid;
4688  
4689         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
4690         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
4691 @@ -3081,14 +3084,18 @@ static int copy_from_dinode(struct dinod
4692         }
4693         ip->i_nlink = le32_to_cpu(dip->di_nlink);
4694  
4695 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
4696 +       uid = le32_to_cpu(dip->di_uid);
4697 +       gid = le32_to_cpu(dip->di_gid);
4698 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
4699 +
4700 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
4701         if (sbi->uid == -1)
4702                 ip->i_uid = jfs_ip->saved_uid;
4703         else {
4704                 ip->i_uid = sbi->uid;
4705         }
4706  
4707 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
4708 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
4709         if (sbi->gid == -1)
4710                 ip->i_gid = jfs_ip->saved_gid;
4711         else {
4712 @@ -3153,14 +3160,12 @@ static void copy_to_dinode(struct dinode
4713         dip->di_size = cpu_to_le64(ip->i_size);
4714         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
4715         dip->di_nlink = cpu_to_le32(ip->i_nlink);
4716 -       if (sbi->uid == -1)
4717 -               dip->di_uid = cpu_to_le32(ip->i_uid);
4718 -       else
4719 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
4720 -       if (sbi->gid == -1)
4721 -               dip->di_gid = cpu_to_le32(ip->i_gid);
4722 -       else
4723 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
4724 +
4725 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
4726 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
4727 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
4728 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
4729 +
4730         jfs_get_inode_flags(jfs_ip);
4731         /*
4732          * mode2 is only needed for storing the higher order bits.
4733 diff -NurpP --minimal linux-2.6.25/fs/jfs/jfs_inode.c linux-2.6.25-vs2.3.0.34.9/fs/jfs/jfs_inode.c
4734 --- linux-2.6.25/fs/jfs/jfs_inode.c     2008-04-17 10:33:02.000000000 -0400
4735 +++ linux-2.6.25-vs2.3.0.34.9/fs/jfs/jfs_inode.c        2008-04-19 15:14:52.000000000 -0400
4736 @@ -18,6 +18,8 @@
4737  
4738  #include <linux/fs.h>
4739  #include <linux/quotaops.h>
4740 +#include <linux/vs_dlimit.h>
4741 +#include <linux/vs_tag.h>
4742  #include "jfs_incore.h"
4743  #include "jfs_inode.h"
4744  #include "jfs_filsys.h"
4745 @@ -30,19 +32,47 @@ void jfs_set_inode_flags(struct inode *i
4746  {
4747         unsigned int flags = JFS_IP(inode)->mode2;
4748  
4749 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
4750 -               S_NOATIME | S_DIRSYNC | S_SYNC);
4751 +       inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
4752 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4753  
4754         if (flags & JFS_IMMUTABLE_FL)
4755                 inode->i_flags |= S_IMMUTABLE;
4756 +       if (flags & JFS_IUNLINK_FL)
4757 +               inode->i_flags |= S_IUNLINK;
4758 +       if (flags & JFS_BARRIER_FL)
4759 +               inode->i_flags |= S_BARRIER;
4760 +
4761 +       if (flags & JFS_SYNC_FL)
4762 +               inode->i_flags |= S_SYNC;
4763         if (flags & JFS_APPEND_FL)
4764                 inode->i_flags |= S_APPEND;
4765         if (flags & JFS_NOATIME_FL)
4766                 inode->i_flags |= S_NOATIME;
4767         if (flags & JFS_DIRSYNC_FL)
4768                 inode->i_flags |= S_DIRSYNC;
4769 -       if (flags & JFS_SYNC_FL)
4770 -               inode->i_flags |= S_SYNC;
4771 +}
4772 +
4773 +int jfs_sync_flags(struct inode *inode)
4774 +{
4775 +       unsigned int oldflags, newflags;
4776 +
4777 +       oldflags = JFS_IP(inode)->mode2;
4778 +       newflags = oldflags & ~(JFS_IMMUTABLE_FL |
4779 +               JFS_IUNLINK_FL | JFS_BARRIER_FL);
4780 +
4781 +       if (IS_IMMUTABLE(inode))
4782 +               newflags |= JFS_IMMUTABLE_FL;
4783 +       if (IS_IUNLINK(inode))
4784 +               newflags |= JFS_IUNLINK_FL;
4785 +       if (IS_BARRIER(inode))
4786 +               newflags |= JFS_BARRIER_FL;
4787 +
4788 +       if (oldflags ^ newflags) {
4789 +               JFS_IP(inode)->mode2 = newflags;
4790 +               inode->i_ctime = CURRENT_TIME;
4791 +               mark_inode_dirty(inode);
4792 +       }
4793 +       return 0;
4794  }
4795  
4796  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
4797 @@ -108,10 +138,17 @@ struct inode *ialloc(struct inode *paren
4798         jfs_inode->saved_uid = inode->i_uid;
4799         jfs_inode->saved_gid = inode->i_gid;
4800  
4801 +       inode->i_tag = dx_current_fstag(sb);
4802 +       if (DLIMIT_ALLOC_INODE(inode)) {
4803 +               iput(inode);
4804 +               return ERR_PTR(-ENOSPC);
4805 +       }
4806 +
4807         /*
4808          * Allocate inode to quota.
4809          */
4810         if (DQUOT_ALLOC_INODE(inode)) {
4811 +               DLIMIT_FREE_INODE(inode);
4812                 DQUOT_DROP(inode);
4813                 inode->i_flags |= S_NOQUOTA;
4814                 inode->i_nlink = 0;
4815 diff -NurpP --minimal linux-2.6.25/fs/jfs/jfs_inode.h linux-2.6.25-vs2.3.0.34.9/fs/jfs/jfs_inode.h
4816 --- linux-2.6.25/fs/jfs/jfs_inode.h     2008-04-17 12:05:40.000000000 -0400
4817 +++ linux-2.6.25-vs2.3.0.34.9/fs/jfs/jfs_inode.h        2008-04-19 15:14:52.000000000 -0400
4818 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4819  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4820         int fh_len, int fh_type);
4821  extern void jfs_set_inode_flags(struct inode *);
4822 +extern int jfs_sync_flags(struct inode *);
4823  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4824  
4825  extern const struct address_space_operations jfs_aops;
4826 diff -NurpP --minimal linux-2.6.25/fs/jfs/jfs_xtree.c linux-2.6.25-vs2.3.0.34.9/fs/jfs/jfs_xtree.c
4827 --- linux-2.6.25/fs/jfs/jfs_xtree.c     2008-04-17 12:05:40.000000000 -0400
4828 +++ linux-2.6.25-vs2.3.0.34.9/fs/jfs/jfs_xtree.c        2008-04-19 15:14:52.000000000 -0400
4829 @@ -21,6 +21,7 @@
4830  
4831  #include <linux/fs.h>
4832  #include <linux/quotaops.h>
4833 +#include <linux/vs_dlimit.h>
4834  #include "jfs_incore.h"
4835  #include "jfs_filsys.h"
4836  #include "jfs_metapage.h"
4837 @@ -846,7 +847,12 @@ int xtInsert(tid_t tid,            /* transaction 
4838                         hint = 0;
4839                 if ((rc = DQUOT_ALLOC_BLOCK(ip, xlen)))
4840                         goto out;
4841 +               if ((rc = DLIMIT_ALLOC_BLOCK(ip, xlen))) {
4842 +                       DQUOT_FREE_BLOCK(ip, xlen);
4843 +                       goto out;
4844 +               }
4845                 if ((rc = dbAlloc(ip, hint, (s64) xlen, &xaddr))) {
4846 +                       DLIMIT_FREE_BLOCK(ip, xlen);
4847                         DQUOT_FREE_BLOCK(ip, xlen);
4848                         goto out;
4849                 }
4850 @@ -876,6 +882,7 @@ int xtInsert(tid_t tid,             /* transaction 
4851                         /* undo data extent allocation */
4852                         if (*xaddrp == 0) {
4853                                 dbFree(ip, xaddr, (s64) xlen);
4854 +                               DLIMIT_FREE_BLOCK(ip, xlen);
4855                                 DQUOT_FREE_BLOCK(ip, xlen);
4856                         }
4857                         return rc;
4858 @@ -1236,6 +1243,7 @@ xtSplitPage(tid_t tid, struct inode *ip,
4859         struct tlock *tlck;
4860         struct xtlock *sxtlck = NULL, *rxtlck = NULL;
4861         int quota_allocation = 0;
4862 +       int dlimit_allocation = 0;
4863  
4864         smp = split->mp;
4865         sp = XT_PAGE(ip, smp);
4866 @@ -1255,6 +1263,13 @@ xtSplitPage(tid_t tid, struct inode *ip,
4867  
4868         quota_allocation += lengthPXD(pxd);
4869  
4870 +       /* Allocate blocks to dlimit. */
4871 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4872 +              rc = -ENOSPC;
4873 +              goto clean_up;
4874 +       }
4875 +       dlimit_allocation += lengthPXD(pxd);
4876 +
4877         /*
4878          * allocate the new right page for the split
4879          */
4880 @@ -1456,6 +1471,9 @@ xtSplitPage(tid_t tid, struct inode *ip,
4881  
4882        clean_up:
4883  
4884 +       /* Rollback dlimit allocation. */
4885 +       if (dlimit_allocation)
4886 +               DLIMIT_FREE_BLOCK(ip, dlimit_allocation);
4887         /* Rollback quota allocation. */
4888         if (quota_allocation)
4889                 DQUOT_FREE_BLOCK(ip, quota_allocation);
4890 @@ -1519,6 +1537,12 @@ xtSplitRoot(tid_t tid,
4891                 release_metapage(rmp);
4892                 return -EDQUOT;
4893         }
4894 +       /* Allocate blocks to dlimit. */
4895 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4896 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
4897 +               release_metapage(rmp);
4898 +               return -ENOSPC;
4899 +       }
4900  
4901         jfs_info("xtSplitRoot: ip:0x%p rmp:0x%p", ip, rmp);
4902  
4903 @@ -3948,6 +3972,8 @@ s64 xtTruncate(tid_t tid, struct inode *
4904         else
4905                 ip->i_size = newsize;
4906  
4907 +       /* update dlimit allocation to reflect freed blocks */
4908 +       DLIMIT_FREE_BLOCK(ip, nfreed);
4909         /* update quota allocation to reflect freed blocks */
4910         DQUOT_FREE_BLOCK(ip, nfreed);
4911  
4912 diff -NurpP --minimal linux-2.6.25/fs/jfs/namei.c linux-2.6.25-vs2.3.0.34.9/fs/jfs/namei.c
4913 --- linux-2.6.25/fs/jfs/namei.c 2008-04-17 12:05:40.000000000 -0400
4914 +++ linux-2.6.25-vs2.3.0.34.9/fs/jfs/namei.c    2008-04-19 15:14:52.000000000 -0400
4915 @@ -21,6 +21,7 @@
4916  #include <linux/ctype.h>
4917  #include <linux/quotaops.h>
4918  #include <linux/exportfs.h>
4919 +#include <linux/vs_tag.h>
4920  #include "jfs_incore.h"
4921  #include "jfs_superblock.h"
4922  #include "jfs_inode.h"
4923 @@ -1468,6 +1469,7 @@ static struct dentry *jfs_lookup(struct 
4924                 return ERR_CAST(ip);
4925         }
4926  
4927 +       dx_propagate_tag(nd, ip);
4928         dentry = d_splice_alias(ip, dentry);
4929  
4930         if (dentry && (JFS_SBI(dip->i_sb)->mntflag & JFS_OS2))
4931 @@ -1550,6 +1552,7 @@ const struct inode_operations jfs_dir_in
4932         .setattr        = jfs_setattr,
4933         .permission     = jfs_permission,
4934  #endif
4935 +       .sync_flags     = jfs_sync_flags,
4936  };
4937  
4938  const struct file_operations jfs_dir_operations = {
4939 diff -NurpP --minimal linux-2.6.25/fs/jfs/super.c linux-2.6.25-vs2.3.0.34.9/fs/jfs/super.c
4940 --- linux-2.6.25/fs/jfs/super.c 2008-04-17 12:05:40.000000000 -0400
4941 +++ linux-2.6.25-vs2.3.0.34.9/fs/jfs/super.c    2008-04-19 15:14:52.000000000 -0400
4942 @@ -195,7 +195,8 @@ static void jfs_put_super(struct super_b
4943  enum {
4944         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4945         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4946 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4947 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4948 +       Opt_tag, Opt_notag, Opt_tagid
4949  };
4950  
4951  static match_table_t tokens = {
4952 @@ -205,6 +206,10 @@ static match_table_t tokens = {
4953         {Opt_resize, "resize=%u"},
4954         {Opt_resize_nosize, "resize"},
4955         {Opt_errors, "errors=%s"},
4956 +       {Opt_tag, "tag"},
4957 +       {Opt_notag, "notag"},
4958 +       {Opt_tagid, "tagid=%u"},
4959 +       {Opt_tag, "tagxid"},
4960         {Opt_ignore, "noquota"},
4961         {Opt_ignore, "quota"},
4962         {Opt_usrquota, "usrquota"},
4963 @@ -339,6 +344,20 @@ static int parse_options(char *options, 
4964                         }
4965                         break;
4966                 }
4967 +#ifndef CONFIG_TAGGING_NONE
4968 +               case Opt_tag:
4969 +                       *flag |= JFS_TAGGED;
4970 +                       break;
4971 +               case Opt_notag:
4972 +                       *flag &= JFS_TAGGED;
4973 +                       break;
4974 +#endif
4975 +#ifdef CONFIG_PROPAGATE
4976 +               case Opt_tagid:
4977 +                       /* use args[0] */
4978 +                       *flag |= JFS_TAGGED;
4979 +                       break;
4980 +#endif
4981                 default:
4982                         printk("jfs: Unrecognized mount option \"%s\" "
4983                                         " or missing value\n", p);
4984 @@ -369,6 +388,13 @@ static int jfs_remount(struct super_bloc
4985         if (!parse_options(data, sb, &newLVSize, &flag)) {
4986                 return -EINVAL;
4987         }
4988 +
4989 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4990 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4991 +                       sb->s_id);
4992 +               return -EINVAL;
4993 +       }
4994 +
4995         if (newLVSize) {
4996                 if (sb->s_flags & MS_RDONLY) {
4997                         printk(KERN_ERR
4998 @@ -440,6 +466,9 @@ static int jfs_fill_super(struct super_b
4999  #ifdef CONFIG_JFS_POSIX_ACL
5000         sb->s_flags |= MS_POSIXACL;
5001  #endif
5002 +       /* map mount option tagxid */
5003 +       if (sbi->flag & JFS_TAGGED)
5004 +               sb->s_flags |= MS_TAGGED;
5005  
5006         if (newLVSize) {
5007                 printk(KERN_ERR "resize option for remount only\n");
5008 diff -NurpP --minimal linux-2.6.25/fs/jfs/xattr.c linux-2.6.25-vs2.3.0.34.9/fs/jfs/xattr.c
5009 --- linux-2.6.25/fs/jfs/xattr.c 2008-04-17 10:37:23.000000000 -0400
5010 +++ linux-2.6.25-vs2.3.0.34.9/fs/jfs/xattr.c    2008-04-19 15:14:52.000000000 -0400
5011 @@ -23,6 +23,7 @@
5012  #include <linux/posix_acl_xattr.h>
5013  #include <linux/quotaops.h>
5014  #include <linux/security.h>
5015 +#include <linux/vs_dlimit.h>
5016  #include "jfs_incore.h"
5017  #include "jfs_superblock.h"
5018  #include "jfs_dmap.h"
5019 @@ -263,9 +264,16 @@ static int ea_write(struct inode *ip, st
5020         if (DQUOT_ALLOC_BLOCK(ip, nblocks)) {
5021                 return -EDQUOT;
5022         }
5023 +       /* Allocate new blocks to dlimit. */
5024 +       if (DLIMIT_ALLOC_BLOCK(ip, nblocks)) {
5025 +               DQUOT_FREE_BLOCK(ip, nblocks);
5026 +               return -ENOSPC;
5027 +       }
5028  
5029         rc = dbAlloc(ip, INOHINT(ip), nblocks, &blkno);
5030         if (rc) {
5031 +               /*Rollback dlimit allocation. */
5032 +               DLIMIT_FREE_BLOCK(ip, nblocks);
5033                 /*Rollback quota allocation. */
5034                 DQUOT_FREE_BLOCK(ip, nblocks);
5035                 return rc;
5036 @@ -332,6 +340,8 @@ static int ea_write(struct inode *ip, st
5037  
5038        failed:
5039         /* Rollback quota allocation. */
5040 +       DLIMIT_FREE_BLOCK(ip, nblocks);
5041 +       /* Rollback quota allocation. */
5042         DQUOT_FREE_BLOCK(ip, nblocks);
5043  
5044         dbFree(ip, blkno, nblocks);
5045 @@ -468,6 +478,7 @@ static int ea_get(struct inode *inode, s
5046         s64 blkno;
5047         int rc;
5048         int quota_allocation = 0;
5049 +       int dlimit_allocation = 0;
5050  
5051         /* When fsck.jfs clears a bad ea, it doesn't clear the size */
5052         if (ji->ea.flag == 0)
5053 @@ -543,6 +554,12 @@ static int ea_get(struct inode *inode, s
5054  
5055                 quota_allocation = blocks_needed;
5056  
5057 +               /* Allocate new blocks to dlimit. */
5058 +               rc = -ENOSPC;
5059 +               if (DLIMIT_ALLOC_BLOCK(inode, blocks_needed))
5060 +                       goto clean_up;
5061 +               dlimit_allocation = blocks_needed;
5062 +
5063                 rc = dbAlloc(inode, INOHINT(inode), (s64) blocks_needed,
5064                              &blkno);
5065                 if (rc)
5066 @@ -600,6 +617,9 @@ static int ea_get(struct inode *inode, s
5067         return ea_size;
5068  
5069        clean_up:
5070 +       /* Rollback dlimit allocation */
5071 +       if (dlimit_allocation)
5072 +               DLIMIT_FREE_BLOCK(inode, dlimit_allocation);
5073         /* Rollback quota allocation */
5074         if (quota_allocation)
5075                 DQUOT_FREE_BLOCK(inode, quota_allocation);
5076 @@ -676,8 +696,10 @@ static int ea_put(tid_t tid, struct inod
5077         }
5078  
5079         /* If old blocks exist, they must be removed from quota allocation. */
5080 -       if (old_blocks)
5081 +       if (old_blocks) {
5082 +               DLIMIT_FREE_BLOCK(inode, old_blocks);
5083                 DQUOT_FREE_BLOCK(inode, old_blocks);
5084 +       }
5085  
5086         inode->i_ctime = CURRENT_TIME;
5087  
5088 diff -NurpP --minimal linux-2.6.25/fs/libfs.c linux-2.6.25-vs2.3.0.34.9/fs/libfs.c
5089 --- linux-2.6.25/fs/libfs.c     2008-04-17 12:05:40.000000000 -0400
5090 +++ linux-2.6.25-vs2.3.0.34.9/fs/libfs.c        2008-04-19 15:14:52.000000000 -0400
5091 @@ -125,7 +125,8 @@ static inline unsigned char dt_type(stru
5092   * both impossible due to the lock on directory.
5093   */
5094  
5095 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
5096 +static inline int do_dcache_readdir_filter(struct file *filp,
5097 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
5098  {
5099         struct dentry *dentry = filp->f_path.dentry;
5100         struct dentry *cursor = filp->private_data;
5101 @@ -158,6 +159,8 @@ int dcache_readdir(struct file * filp, v
5102                                 next = list_entry(p, struct dentry, d_u.d_child);
5103                                 if (d_unhashed(next) || !next->d_inode)
5104                                         continue;
5105 +                               if (filter && !filter(next))
5106 +                                       continue;
5107  
5108                                 spin_unlock(&dcache_lock);
5109                                 if (filldir(dirent, next->d_name.name, 
5110 @@ -176,6 +179,18 @@ int dcache_readdir(struct file * filp, v
5111         return 0;
5112  }
5113  
5114 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
5115 +{
5116 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
5117 +}
5118 +
5119 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
5120 +       int (*filter)(struct dentry *))
5121 +{
5122 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
5123 +}
5124 +
5125 +
5126  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
5127  {
5128         return -EISDIR;
5129 @@ -778,6 +793,7 @@ EXPORT_SYMBOL(dcache_dir_close);
5130  EXPORT_SYMBOL(dcache_dir_lseek);
5131  EXPORT_SYMBOL(dcache_dir_open);
5132  EXPORT_SYMBOL(dcache_readdir);
5133 +EXPORT_SYMBOL(dcache_readdir_filter);
5134  EXPORT_SYMBOL(generic_read_dir);
5135  EXPORT_SYMBOL(get_sb_pseudo);
5136  EXPORT_SYMBOL(simple_write_begin);
5137 diff -NurpP --minimal linux-2.6.25/fs/locks.c linux-2.6.25-vs2.3.0.34.9/fs/locks.c
5138 --- linux-2.6.25/fs/locks.c     2008-04-17 12:05:40.000000000 -0400
5139 +++ linux-2.6.25-vs2.3.0.34.9/fs/locks.c        2008-04-22 20:05:36.000000000 -0400
5140 @@ -126,6 +126,8 @@
5141  #include <linux/time.h>
5142  #include <linux/rcupdate.h>
5143  #include <linux/pid_namespace.h>
5144 +#include <linux/vs_base.h>
5145 +#include <linux/vs_limit.h>
5146  
5147  #include <asm/semaphore.h>
5148  #include <asm/uaccess.h>
5149 @@ -148,6 +150,8 @@ static struct kmem_cache *filelock_cache
5150  /* Allocate an empty lock structure. */
5151  static struct file_lock *locks_alloc_lock(void)
5152  {
5153 +       if (!vx_locks_avail(1))
5154 +               return NULL;
5155         return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
5156  }
5157  
5158 @@ -173,6 +177,7 @@ static void locks_free_lock(struct file_
5159         BUG_ON(!list_empty(&fl->fl_block));
5160         BUG_ON(!list_empty(&fl->fl_link));
5161  
5162 +       vx_locks_dec(fl);
5163         locks_release_private(fl);
5164         kmem_cache_free(filelock_cache, fl);
5165  }
5166 @@ -193,6 +198,7 @@ void locks_init_lock(struct file_lock *f
5167         fl->fl_start = fl->fl_end = 0;
5168         fl->fl_ops = NULL;
5169         fl->fl_lmops = NULL;
5170 +       fl->fl_xid = -1;
5171  }
5172  
5173  EXPORT_SYMBOL(locks_init_lock);
5174 @@ -246,6 +252,7 @@ void locks_copy_lock(struct file_lock *n
5175         new->fl_file = fl->fl_file;
5176         new->fl_ops = fl->fl_ops;
5177         new->fl_lmops = fl->fl_lmops;
5178 +       new->fl_xid = fl->fl_xid;
5179  
5180         locks_copy_private(new, fl);
5181  }
5182 @@ -284,6 +291,11 @@ static int flock_make_lock(struct file *
5183         fl->fl_flags = FL_FLOCK;
5184         fl->fl_type = type;
5185         fl->fl_end = OFFSET_MAX;
5186 +
5187 +       vxd_assert(filp->f_xid == vx_current_xid(),
5188 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
5189 +       fl->fl_xid = filp->f_xid;
5190 +       vx_locks_inc(fl);
5191         
5192         *lock = fl;
5193         return 0;
5194 @@ -449,6 +461,7 @@ static int lease_init(struct file *filp,
5195  
5196         fl->fl_owner = current->files;
5197         fl->fl_pid = current->tgid;
5198 +       fl->fl_xid = vx_current_xid();
5199  
5200         fl->fl_file = filp;
5201         fl->fl_flags = FL_LEASE;
5202 @@ -468,6 +481,11 @@ static struct file_lock *lease_alloc(str
5203         if (fl == NULL)
5204                 return ERR_PTR(error);
5205  
5206 +       fl->fl_xid = vx_current_xid();
5207 +       if (filp)
5208 +               vxd_assert(filp->f_xid == fl->fl_xid,
5209 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
5210 +       vx_locks_inc(fl);
5211         error = lease_init(filp, type, fl);
5212         if (error) {
5213                 locks_free_lock(fl);
5214 @@ -774,6 +792,7 @@ static int flock_lock_file(struct file *
5215         if (found)
5216                 cond_resched();
5217  
5218 +       new_fl->fl_xid = -1;
5219  find_conflict:
5220         for_each_lock(inode, before) {
5221                 struct file_lock *fl = *before;
5222 @@ -792,6 +811,7 @@ find_conflict:
5223                 goto out;
5224         locks_copy_lock(new_fl, request);
5225         locks_insert_lock(before, new_fl);
5226 +       vx_locks_inc(new_fl);
5227         new_fl = NULL;
5228         error = 0;
5229  
5230 @@ -802,7 +822,8 @@ out:
5231         return error;
5232  }
5233  
5234 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
5235 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
5236 +       struct file_lock *conflock, xid_t xid)
5237  {
5238         struct file_lock *fl;
5239         struct file_lock *new_fl = NULL;
5240 @@ -812,6 +833,8 @@ static int __posix_lock_file(struct inod
5241         struct file_lock **before;
5242         int error, added = 0;
5243  
5244 +       vxd_assert(xid == vx_current_xid(),
5245 +               "xid(%d) == current(%d)", xid, vx_current_xid());
5246         /*
5247          * We may need two file_lock structures for this operation,
5248          * so we get them in advance to avoid races.
5249 @@ -822,7 +845,11 @@ static int __posix_lock_file(struct inod
5250             (request->fl_type != F_UNLCK ||
5251              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
5252                 new_fl = locks_alloc_lock();
5253 +               new_fl->fl_xid = xid;
5254 +               vx_locks_inc(new_fl);
5255                 new_fl2 = locks_alloc_lock();
5256 +               new_fl2->fl_xid = xid;
5257 +               vx_locks_inc(new_fl2);
5258         }
5259  
5260         lock_kernel();
5261 @@ -1021,7 +1048,8 @@ static int __posix_lock_file(struct inod
5262  int posix_lock_file(struct file *filp, struct file_lock *fl,
5263                         struct file_lock *conflock)
5264  {
5265 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
5266 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
5267 +               fl, conflock, filp->f_xid);
5268  }
5269  EXPORT_SYMBOL(posix_lock_file);
5270  
5271 @@ -1111,7 +1139,7 @@ int locks_mandatory_area(int read_write,
5272         fl.fl_end = offset + count - 1;
5273  
5274         for (;;) {
5275 -               error = __posix_lock_file(inode, &fl, NULL);
5276 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
5277                 if (error != -EAGAIN)
5278                         break;
5279                 if (!(fl.fl_flags & FL_SLEEP))
5280 @@ -1425,6 +1453,7 @@ int generic_setlease(struct file *filp, 
5281  
5282         locks_copy_lock(new_fl, lease);
5283         locks_insert_lock(before, new_fl);
5284 +       vx_locks_inc(new_fl);
5285  
5286         *flp = new_fl;
5287         return 0;
5288 @@ -1755,6 +1784,11 @@ int fcntl_setlk(unsigned int fd, struct 
5289         if (file_lock == NULL)
5290                 return -ENOLCK;
5291  
5292 +       vxd_assert(filp->f_xid == vx_current_xid(),
5293 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
5294 +       file_lock->fl_xid = filp->f_xid;
5295 +       vx_locks_inc(file_lock);
5296 +
5297         /*
5298          * This might block, so we do it before checking the inode.
5299          */
5300 @@ -1883,6 +1917,11 @@ int fcntl_setlk64(unsigned int fd, struc
5301         if (file_lock == NULL)
5302                 return -ENOLCK;
5303  
5304 +       vxd_assert(filp->f_xid == vx_current_xid(),
5305 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
5306 +       file_lock->fl_xid = filp->f_xid;
5307 +       vx_locks_inc(file_lock);
5308 +
5309         /*
5310          * This might block, so we do it before checking the inode.
5311          */
5312 @@ -2163,8 +2202,11 @@ static int locks_show(struct seq_file *f
5313  
5314         lock_get_status(f, fl, (long)f->private, "");
5315  
5316 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
5317 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
5318 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
5319 +                       continue;
5320                 lock_get_status(f, bfl, (long)f->private, " ->");
5321 +       }
5322  
5323         f->private++;
5324         return 0;
5325 diff -NurpP --minimal linux-2.6.25/fs/namei.c linux-2.6.25-vs2.3.0.34.9/fs/namei.c
5326 --- linux-2.6.25/fs/namei.c     2008-04-17 12:05:40.000000000 -0400
5327 +++ linux-2.6.25-vs2.3.0.34.9/fs/namei.c        2008-04-22 19:23:22.000000000 -0400
5328 @@ -30,6 +30,13 @@
5329  #include <linux/capability.h>
5330  #include <linux/file.h>
5331  #include <linux/fcntl.h>
5332 +#include <linux/proc_fs.h>
5333 +#include <linux/vserver/inode.h>
5334 +#include <linux/vs_base.h>
5335 +#include <linux/vs_tag.h>
5336 +#include <linux/vs_cowbl.h>
5337 +#include <linux/vs_device.h>
5338 +#include <linux/vs_context.h>
5339  #include <asm/namei.h>
5340  #include <asm/uaccess.h>
5341  
5342 @@ -225,6 +232,28 @@ int generic_permission(struct inode *ino
5343         return -EACCES;
5344  }
5345  
5346 +static inline int dx_barrier(struct inode *inode)
5347 +{
5348 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN)) {
5349 +               vxwprintk_task(1, "did hit the barrier.");
5350 +               return 1;
5351 +       }
5352 +       return 0;
5353 +}
5354 +
5355 +static inline int dx_permission(struct inode *inode, int mask, struct nameidata *nd)
5356 +{
5357 +       if (dx_barrier(inode))
5358 +               return -EACCES;
5359 +       if (dx_notagcheck(nd) ||
5360 +           dx_check(inode->i_tag, DX_HOSTID|DX_ADMIN|DX_WATCH|DX_IDENT))
5361 +               return 0;
5362 +
5363 +       vxwprintk_task(1, "denied access to %p[#%d,%lu] Â»%s«.",
5364 +               inode, inode->i_tag, inode->i_ino, vxd_cond_path(nd));
5365 +       return -EACCES;
5366 +}
5367 +
5368  int permission(struct inode *inode, int mask, struct nameidata *nd)
5369  {
5370         int retval, submask;
5371 @@ -239,14 +268,14 @@ int permission(struct inode *inode, int 
5372                 /*
5373                  * Nobody gets write access to a read-only fs.
5374                  */
5375 -               if (IS_RDONLY(inode) &&
5376 +               if ((IS_RDONLY(inode) || (nd && MNT_IS_RDONLY(nd->path.mnt))) &&
5377                     (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)))
5378                         return -EROFS;
5379  
5380                 /*
5381                  * Nobody gets write access to an immutable file.
5382                  */
5383 -               if (IS_IMMUTABLE(inode))
5384 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
5385                         return -EACCES;
5386         }
5387  
5388 @@ -261,6 +290,11 @@ int permission(struct inode *inode, int 
5389  
5390         /* Ordinary permission routines do not understand MAY_APPEND. */
5391         submask = mask & ~MAY_APPEND;
5392 +       if ((inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC) &&
5393 +               (inode->i_sb->s_magic != PROC_SUPER_MAGIC) &&
5394 +               (retval = dx_permission(inode, mask, nd)))
5395 +               return retval;
5396 +
5397         if (inode->i_op && inode->i_op->permission) {
5398                 retval = inode->i_op->permission(inode, submask, nd);
5399                 if (!retval) {
5400 @@ -459,6 +493,8 @@ static int exec_permission_lite(struct i
5401  {
5402         umode_t mode = inode->i_mode;
5403  
5404 +       if (dx_barrier(inode))
5405 +               return -EACCES;
5406         if (inode->i_op && inode->i_op->permission)
5407                 return -EAGAIN;
5408  
5409 @@ -789,7 +825,8 @@ static __always_inline void follow_dotdo
5410                 if (nd->path.dentry == fs->root.dentry &&
5411                     nd->path.mnt == fs->root.mnt) {
5412                          read_unlock(&fs->lock);
5413 -                       break;
5414 +                       /* for sane '/' avoid follow_mount() */
5415 +                       return;
5416                 }
5417                  read_unlock(&fs->lock);
5418                 spin_lock(&dcache_lock);
5419 @@ -826,16 +863,39 @@ static int do_lookup(struct nameidata *n
5420  {
5421         struct vfsmount *mnt = nd->path.mnt;
5422         struct dentry *dentry = __d_lookup(nd->path.dentry, name);
5423 +       struct inode *inode;
5424  
5425         if (!dentry)
5426                 goto need_lookup;
5427         if (dentry->d_op && dentry->d_op->d_revalidate)
5428                 goto need_revalidate;
5429 +       inode = dentry->d_inode;
5430 +       if (!inode)
5431 +               goto done;
5432 +
5433 +       if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
5434 +               struct proc_dir_entry *de = PDE(inode);
5435 +
5436 +               if (de && !vx_hide_check(0, de->vx_flags))
5437 +                       goto hidden;
5438 +       } else if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
5439 +               if (!vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
5440 +                       goto hidden;
5441 +       } else {
5442 +               if (!dx_notagcheck(nd) && !dx_check(inode->i_tag,
5443 +                       DX_WATCH | DX_ADMIN | DX_HOSTID | DX_IDENT))
5444 +                       goto hidden;
5445 +       }
5446  done:
5447         path->mnt = mnt;
5448         path->dentry = dentry;
5449         __follow_mount(path);
5450         return 0;
5451 +hidden:
5452 +       vxwprintk_task(1, "did lookup hidden %p[#%d,%lu] Â»%s«.",
5453 +               inode, inode->i_tag, inode->i_ino, vxd_path(path));
5454 +       dput(dentry);
5455 +       return -ENOENT;
5456  
5457  need_lookup:
5458         dentry = real_lookup(nd->path.dentry, name, nd);
5459 @@ -1464,7 +1524,8 @@ static inline int check_sticky(struct in
5460   * 10. We don't allow removal of NFS sillyrenamed files; it's handled by
5461   *     nfs_async_unlink().
5462   */
5463 -static int may_delete(struct inode *dir,struct dentry *victim,int isdir)
5464 +static int may_delete(struct inode *dir, struct dentry *victim,
5465 +       int isdir, struct nameidata *nd)
5466  {
5467         int error;
5468  
5469 @@ -1474,13 +1535,13 @@ static int may_delete(struct inode *dir,
5470         BUG_ON(victim->d_parent->d_inode != dir);
5471         audit_inode_child(victim->d_name.name, victim, dir);
5472  
5473 -       error = permission(dir,MAY_WRITE | MAY_EXEC, NULL);
5474 +       error = permission(dir,MAY_WRITE | MAY_EXEC, nd);
5475         if (error)
5476                 return error;
5477         if (IS_APPEND(dir))
5478                 return -EPERM;
5479         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
5480 -           IS_IMMUTABLE(victim->d_inode))
5481 +               IS_IXORUNLINK(victim->d_inode))
5482                 return -EPERM;
5483         if (isdir) {
5484                 if (!S_ISDIR(victim->d_inode->i_mode))
5485 @@ -1626,6 +1687,14 @@ int may_open(struct nameidata *nd, int a
5486         } else if (IS_RDONLY(inode) && (acc_mode & MAY_WRITE))
5487                 return -EROFS;
5488  
5489 +#ifdef CONFIG_VSERVER_COWBL
5490 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
5491 +               if (IS_COW_LINK(inode))
5492 +                       return -EMLINK;
5493 +               inode->i_flags &= ~(S_IUNLINK|S_IMMUTABLE);
5494 +               mark_inode_dirty(inode);
5495 +       }
5496 +#endif
5497         error = vfs_permission(nd, acc_mode);
5498         if (error)
5499                 return error;
5500 @@ -1717,6 +1786,11 @@ int open_namei(int dfd, const char *path
5501         struct dentry *dir;
5502         int count = 0;
5503  
5504 +#ifdef CONFIG_VSERVER_COWBL
5505 +       int rflag = flag;
5506 +       int rmode = mode;
5507 +restart:
5508 +#endif
5509         acc_mode = ACC_MODE(flag);
5510  
5511         /* O_TRUNC implies we need access checks for write permissions */
5512 @@ -1810,6 +1884,22 @@ do_last:
5513                 goto exit;
5514  ok:
5515         error = may_open(nd, acc_mode, flag);
5516 +#ifdef CONFIG_VSERVER_COWBL
5517 +       if (error == -EMLINK) {
5518 +               struct dentry *dentry;
5519 +               dentry = cow_break_link(pathname);
5520 +               if (IS_ERR(dentry)) {
5521 +                       error = PTR_ERR(dentry);
5522 +                       goto exit;
5523 +               }
5524 +               dput(dentry);
5525 +               release_open_intent(nd);
5526 +               path_put(&nd->path);
5527 +               flag = rflag;
5528 +               mode = rmode;
5529 +               goto restart;
5530 +       }
5531 +#endif
5532         if (error)
5533                 goto exit;
5534         return 0;
5535 @@ -1921,16 +2011,25 @@ fail:
5536  }
5537  EXPORT_SYMBOL_GPL(lookup_create);
5538  
5539 -int vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
5540 +int vfs_mknod(struct inode *dir, struct dentry *dentry,
5541 +       int mode, dev_t dev, struct nameidata *nd)
5542  {
5543 -       int error = may_create(dir, dentry, NULL);
5544 +       int error = may_create(dir, dentry, nd);
5545  
5546         if (error)
5547                 return error;
5548  
5549 -       if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
5550 +       if (!(S_ISCHR(mode) || S_ISBLK(mode)))
5551 +               goto okay;
5552 +
5553 +       if (!capable(CAP_MKNOD))
5554                 return -EPERM;
5555  
5556 +       if (S_ISCHR(mode) && !vs_chrdev_perm(dev, DATTR_CREATE))
5557 +               return -EPERM;
5558 +       if (S_ISBLK(mode) && !vs_blkdev_perm(dev, DATTR_CREATE))
5559 +               return -EPERM;
5560 +okay:
5561         if (!dir->i_op || !dir->i_op->mknod)
5562                 return -EPERM;
5563  
5564 @@ -1973,11 +2072,12 @@ asmlinkage long sys_mknodat(int dfd, con
5565                         error = vfs_create(nd.path.dentry->d_inode,dentry,mode,&nd);
5566                         break;
5567                 case S_IFCHR: case S_IFBLK:
5568 -                       error = vfs_mknod(nd.path.dentry->d_inode,dentry,mode,
5569 -                                       new_decode_dev(dev));
5570 +                       error = vfs_mknod(nd.path.dentry->d_inode, dentry, mode,
5571 +                                       new_decode_dev(dev), &nd);
5572                         break;
5573                 case S_IFIFO: case S_IFSOCK:
5574 -                       error = vfs_mknod(nd.path.dentry->d_inode,dentry,mode,0);
5575 +                       error = vfs_mknod(nd.path.dentry->d_inode, dentry, mode,
5576 +                                       0, &nd);
5577                         break;
5578                 case S_IFDIR:
5579                         error = -EPERM;
5580 @@ -2000,9 +2100,10 @@ asmlinkage long sys_mknod(const char __u
5581         return sys_mknodat(AT_FDCWD, filename, mode, dev);
5582  }
5583  
5584 -int vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
5585 +int vfs_mkdir(struct inode *dir, struct dentry *dentry,
5586 +       int mode, struct nameidata *nd)
5587  {
5588 -       int error = may_create(dir, dentry, NULL);
5589 +       int error = may_create(dir, dentry, nd);
5590  
5591         if (error)
5592                 return error;
5593 @@ -2044,7 +2145,7 @@ asmlinkage long sys_mkdirat(int dfd, con
5594  
5595         if (!IS_POSIXACL(nd.path.dentry->d_inode))
5596                 mode &= ~current->fs->umask;
5597 -       error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
5598 +       error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode, &nd);
5599         dput(dentry);
5600  out_unlock:
5601         mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
5602 @@ -2087,9 +2188,10 @@ void dentry_unhash(struct dentry *dentry
5603         spin_unlock(&dcache_lock);
5604  }
5605  
5606 -int vfs_rmdir(struct inode *dir, struct dentry *dentry)
5607 +int vfs_rmdir(struct inode *dir, struct dentry *dentry,
5608 +       struct nameidata *nd)
5609  {
5610 -       int error = may_delete(dir, dentry, 1);
5611 +       int error = may_delete(dir, dentry, 1, nd);
5612  
5613         if (error)
5614                 return error;
5615 @@ -2151,7 +2253,7 @@ static long do_rmdir(int dfd, const char
5616         error = PTR_ERR(dentry);
5617         if (IS_ERR(dentry))
5618                 goto exit2;
5619 -       error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
5620 +       error = vfs_rmdir(nd.path.dentry->d_inode, dentry, &nd);
5621         dput(dentry);
5622  exit2:
5623         mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
5624 @@ -2167,9 +2269,10 @@ asmlinkage long sys_rmdir(const char __u
5625         return do_rmdir(AT_FDCWD, pathname);
5626  }
5627  
5628 -int vfs_unlink(struct inode *dir, struct dentry *dentry)
5629 +int vfs_unlink(struct inode *dir, struct dentry *dentry,
5630 +       struct nameidata *nd)
5631  {
5632 -       int error = may_delete(dir, dentry, 0);
5633 +       int error = may_delete(dir, dentry, 0, nd);
5634  
5635         if (error)
5636                 return error;
5637 @@ -2232,7 +2335,7 @@ static long do_unlinkat(int dfd, const c
5638                 inode = dentry->d_inode;
5639                 if (inode)
5640                         atomic_inc(&inode->i_count);
5641 -               error = vfs_unlink(nd.path.dentry->d_inode, dentry);
5642 +               error = vfs_unlink(nd.path.dentry->d_inode, dentry, &nd);
5643         exit2:
5644                 dput(dentry);
5645         }
5646 @@ -2267,9 +2370,10 @@ asmlinkage long sys_unlink(const char __
5647         return do_unlinkat(AT_FDCWD, pathname);
5648  }
5649  
5650 -int vfs_symlink(struct inode *dir, struct dentry *dentry, const char *oldname, int mode)
5651 +int vfs_symlink(struct inode *dir, struct dentry *dentry,
5652 +       const char *oldname, int mode, struct nameidata *nd)
5653  {
5654 -       int error = may_create(dir, dentry, NULL);
5655 +       int error = may_create(dir, dentry, nd);
5656  
5657         if (error)
5658                 return error;
5659 @@ -2313,7 +2417,8 @@ asmlinkage long sys_symlinkat(const char
5660         if (IS_ERR(dentry))
5661                 goto out_unlock;
5662  
5663 -       error = vfs_symlink(nd.path.dentry->d_inode, dentry, from, S_IALLUGO);
5664 +       error = vfs_symlink(nd.path.dentry->d_inode, dentry, from,
5665 +               S_IALLUGO, &nd);
5666         dput(dentry);
5667  out_unlock:
5668         mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
5669 @@ -2330,7 +2435,8 @@ asmlinkage long sys_symlink(const char _
5670         return sys_symlinkat(oldname, AT_FDCWD, newname);
5671  }
5672  
5673 -int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry)
5674 +int vfs_link(struct dentry *old_dentry, struct inode *dir,
5675 +       struct dentry *new_dentry, struct nameidata *nd)
5676  {
5677         struct inode *inode = old_dentry->d_inode;
5678         int error;
5679 @@ -2338,7 +2444,7 @@ int vfs_link(struct dentry *old_dentry, 
5680         if (!inode)
5681                 return -ENOENT;
5682  
5683 -       error = may_create(dir, new_dentry, NULL);
5684 +       error = may_create(dir, new_dentry, nd);
5685         if (error)
5686                 return error;
5687  
5688 @@ -2348,7 +2454,7 @@ int vfs_link(struct dentry *old_dentry, 
5689         /*
5690          * A link to an append-only or immutable file cannot be created.
5691          */
5692 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
5693 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
5694                 return -EPERM;
5695         if (!dir->i_op || !dir->i_op->link)
5696                 return -EPERM;
5697 @@ -2408,7 +2514,8 @@ asmlinkage long sys_linkat(int olddfd, c
5698         error = PTR_ERR(new_dentry);
5699         if (IS_ERR(new_dentry))
5700                 goto out_unlock;
5701 -       error = vfs_link(old_nd.path.dentry, nd.path.dentry->d_inode, new_dentry);
5702 +       error = vfs_link(old_nd.path.dentry, nd.path.dentry->d_inode,
5703 +               new_dentry, &nd);
5704         dput(new_dentry);
5705  out_unlock:
5706         mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
5707 @@ -2540,14 +2647,14 @@ int vfs_rename(struct inode *old_dir, st
5708         if (old_dentry->d_inode == new_dentry->d_inode)
5709                 return 0;
5710   
5711 -       error = may_delete(old_dir, old_dentry, is_dir);
5712 +       error = may_delete(old_dir, old_dentry, is_dir, NULL);
5713         if (error)
5714                 return error;
5715  
5716         if (!new_dentry->d_inode)
5717                 error = may_create(new_dir, new_dentry, NULL);
5718         else
5719 -               error = may_delete(new_dir, new_dentry, is_dir);
5720 +               error = may_delete(new_dir, new_dentry, is_dir, NULL);
5721         if (error)
5722                 return error;
5723  
5724 @@ -2625,6 +2732,9 @@ static int do_rename(int olddfd, const c
5725         error = -EINVAL;
5726         if (old_dentry == trap)
5727                 goto exit4;
5728 +       error = -EROFS;
5729 +       if (MNT_IS_RDONLY(newnd.path.mnt))
5730 +               goto exit4;
5731         new_dentry = lookup_hash(&newnd);
5732         error = PTR_ERR(new_dentry);
5733         if (IS_ERR(new_dentry))
5734 @@ -2718,6 +2828,214 @@ int vfs_follow_link(struct nameidata *nd
5735         return __vfs_follow_link(nd, link);
5736  }
5737  
5738 +
5739 +#ifdef CONFIG_VSERVER_COWBL
5740 +
5741 +#include <linux/file.h>
5742 +
5743 +static inline
5744 +long do_cow_splice(struct file *in, struct file *out, size_t len)
5745 +{
5746 +       loff_t ppos = 0;
5747 +
5748 +       return do_splice_direct(in, &ppos, out, len, 0);
5749 +}
5750 +
5751 +struct dentry *cow_break_link(const char *pathname)
5752 +{
5753 +       int ret, mode, pathlen, redo = 0;
5754 +       struct nameidata old_nd, dir_nd;
5755 +       struct path old_path, new_path;
5756 +       struct dentry *dir, *res = NULL;
5757 +       struct file *old_file;
5758 +       struct file *new_file;
5759 +       char *to, *path, pad='\251';
5760 +       loff_t size;
5761 +
5762 +       vxdprintk(VXD_CBIT(misc, 1), "cow_break_link(»%s«)", pathname);
5763 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
5764 +       ret = -ENOMEM;
5765 +       if (!path)
5766 +               goto out;
5767 +
5768 +       /* old_nd will have refs to dentry and mnt */
5769 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5770 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
5771 +       if (ret < 0)
5772 +               goto out_free_path;
5773 +
5774 +       old_path = old_nd.path;
5775 +       mode = old_path.dentry->d_inode->i_mode;
5776 +
5777 +       to = d_path(&old_path, path, PATH_MAX-2);
5778 +       pathlen = strlen(to);
5779 +       vxdprintk(VXD_CBIT(misc, 2), "old path Â»%s« [»%.*s«:%d]", to,
5780 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5781 +               old_path.dentry->d_name.len);
5782 +
5783 +       to[pathlen + 1] = 0;
5784 +retry:
5785 +       to[pathlen] = pad--;
5786 +       ret = -EMLINK;
5787 +       if (pad <= '\240')
5788 +               goto out_rel_old;
5789 +
5790 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy Â»%s«", to);
5791 +       /* dir_nd will have refs to dentry and mnt */
5792 +       ret = path_lookup(to,
5793 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
5794 +       vxdprintk(VXD_CBIT(misc, 2),
5795 +               "path_lookup(new): %d", ret);
5796 +       if (ret < 0)
5797 +               goto retry;
5798 +
5799 +       /* this puppy downs the inode mutex */
5800 +       new_path.dentry = lookup_create(&dir_nd, 0);
5801 +       vxdprintk(VXD_CBIT(misc, 2),
5802 +               "lookup_create(new): %p [»%.*s«:%d]", new_path.dentry,
5803 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5804 +               new_path.dentry->d_name.len);
5805 +       if (!new_path.dentry || IS_ERR(new_path.dentry)) {
5806 +               path_put(&dir_nd.path);
5807 +               goto retry;
5808 +       }
5809 +       dir = dir_nd.path.dentry;
5810 +
5811 +       ret = vfs_create(dir_nd.path.dentry->d_inode, new_path.dentry, mode, &dir_nd);
5812 +       vxdprintk(VXD_CBIT(misc, 2),
5813 +               "vfs_create(new): %d", ret);
5814 +       if (ret == -EEXIST) {
5815 +               mutex_unlock(&dir->d_inode->i_mutex);
5816 +               dput(new_path.dentry);
5817 +               path_put(&dir_nd.path);
5818 +               goto retry;
5819 +       }
5820 +       else if (ret < 0)
5821 +               goto out_unlock_new;
5822 +
5823 +       /* drop out early, ret passes ENOENT */
5824 +       ret = -ENOENT;
5825 +       if ((redo = d_unhashed(old_path.dentry)))
5826 +               goto out_unlock_new;
5827 +
5828 +       new_path.mnt = dir_nd.path.mnt;
5829 +       dget(old_path.dentry);
5830 +       mntget(old_path.mnt);
5831 +       /* this one cleans up the dentry/mnt in case of failure */
5832 +       old_file = dentry_open(old_path.dentry, old_path.mnt, O_RDONLY);
5833 +       vxdprintk(VXD_CBIT(misc, 2),
5834 +               "dentry_open(old): %p", old_file);
5835 +       if (!old_file || IS_ERR(old_file)) {
5836 +               res = IS_ERR(old_file) ? (void *) old_file : res;
5837 +               goto out_unlock_new;
5838 +       }
5839 +
5840 +       dget(new_path.dentry);
5841 +       mntget(new_path.mnt);
5842 +       /* this one cleans up the dentry/mnt in case of failure */
5843 +       new_file = dentry_open(new_path.dentry, new_path.mnt, O_WRONLY);
5844 +       vxdprintk(VXD_CBIT(misc, 2),
5845 +               "dentry_open(new): %p", new_file);
5846 +
5847 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
5848 +       if (!new_file || IS_ERR(new_file))
5849 +               goto out_fput_old;
5850 +
5851 +       size = i_size_read(old_file->f_dentry->d_inode);
5852 +       ret = do_cow_splice(old_file, new_file, size);
5853 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
5854 +       if (ret < 0) {
5855 +               goto out_fput_both;
5856 +       } else if (ret < size) {
5857 +               ret = -ENOSPC;
5858 +               goto out_fput_both;
5859 +       } else {
5860 +               struct inode *old_inode = old_path.dentry->d_inode;
5861 +               struct inode *new_inode = new_path.dentry->d_inode;
5862 +               struct iattr attr = {
5863 +                       .ia_uid = old_inode->i_uid,
5864 +                       .ia_gid = old_inode->i_gid,
5865 +                       .ia_valid = ATTR_UID | ATTR_GID
5866 +                       };
5867 +
5868 +               ret = inode_setattr(new_inode, &attr);
5869 +               if (ret)
5870 +                       goto out_fput_both;
5871 +       }
5872 +
5873 +       mutex_lock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5874 +
5875 +       /* drop out late */
5876 +       ret = -ENOENT;
5877 +       if ((redo = d_unhashed(old_path.dentry)))
5878 +               goto out_unlock;
5879 +
5880 +       vxdprintk(VXD_CBIT(misc, 2),
5881 +               "vfs_rename: [»%*s«:%d] -> [»%*s«:%d]",
5882 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5883 +               new_path.dentry->d_name.len,
5884 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5885 +               old_path.dentry->d_name.len);
5886 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
5887 +               old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
5888 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
5889 +       res = new_path.dentry;
5890 +
5891 +out_unlock:
5892 +       mutex_unlock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5893 +
5894 +out_fput_both:
5895 +       vxdprintk(VXD_CBIT(misc, 3),
5896 +               "fput(new_file=%p[#%d])", new_file,
5897 +               atomic_read(&new_file->f_count));
5898 +       fput(new_file);
5899 +
5900 +out_fput_old:
5901 +       vxdprintk(VXD_CBIT(misc, 3),
5902 +               "fput(old_file=%p[#%d])", old_file,
5903 +               atomic_read(&old_file->f_count));
5904 +       fput(old_file);
5905 +
5906 +out_unlock_new:
5907 +       mutex_unlock(&dir->d_inode->i_mutex);
5908 +       if (!ret)
5909 +               goto out_redo;
5910 +
5911 +       /* error path cleanup */
5912 +       vfs_unlink(dir->d_inode, new_path.dentry, &dir_nd);
5913 +       dput(new_path.dentry);
5914 +
5915 +out_redo:
5916 +       if (!redo)
5917 +               goto out_rel_both;
5918 +       /* lookup dentry once again */
5919 +       path_put(&old_nd.path);
5920 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5921 +       if (ret)
5922 +               goto out_rel_both;
5923 +
5924 +       new_path.dentry = old_nd.path.dentry;
5925 +       vxdprintk(VXD_CBIT(misc, 2),
5926 +               "path_lookup(redo): %p [»%.*s«:%d]", new_path.dentry,
5927 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5928 +               new_path.dentry->d_name.len);
5929 +       dget(new_path.dentry);
5930 +       res = new_path.dentry;
5931 +
5932 +out_rel_both:
5933 +       path_put(&dir_nd.path);
5934 +out_rel_old:
5935 +       path_put(&old_nd.path);
5936 +out_free_path:
5937 +       kfree(path);
5938 +out:
5939 +       if (ret)
5940 +               res = ERR_PTR(ret);
5941 +       return res;
5942 +}
5943 +
5944 +#endif
5945 +
5946  /* get the link contents into pagecache */
5947  static char *page_getlink(struct dentry * dentry, struct page **ppage)
5948  {
5949 diff -NurpP --minimal linux-2.6.25/fs/namespace.c linux-2.6.25-vs2.3.0.34.9/fs/namespace.c
5950 --- linux-2.6.25/fs/namespace.c 2008-04-17 12:05:40.000000000 -0400
5951 +++ linux-2.6.25-vs2.3.0.34.9/fs/namespace.c    2008-04-21 17:20:53.000000000 -0400
5952 @@ -26,6 +26,11 @@
5953  #include <linux/mount.h>
5954  #include <linux/ramfs.h>
5955  #include <linux/log2.h>
5956 +#include <linux/vs_base.h>
5957 +#include <linux/vs_context.h>
5958 +#include <linux/vs_tag.h>
5959 +#include <linux/vserver/space.h>
5960 +#include <linux/vserver/global.h>
5961  #include <asm/uaccess.h>
5962  #include <asm/unistd.h>
5963  #include "pnode.h"
5964 @@ -244,6 +249,7 @@ static struct vfsmount *clone_mnt(struct
5965                 mnt->mnt_root = dget(root);
5966                 mnt->mnt_mountpoint = mnt->mnt_root;
5967                 mnt->mnt_parent = mnt;
5968 +               mnt->mnt_tag = old->mnt_tag;
5969  
5970                 if (flag & CL_SLAVE) {
5971                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
5972 @@ -323,6 +329,31 @@ static inline void mangle(struct seq_fil
5973         seq_escape(m, s, " \t\n\\");
5974  }
5975  
5976 +static int mnt_is_reachable(struct vfsmount *mnt)
5977 +{
5978 +       struct path root;
5979 +       struct dentry *point;
5980 +       int ret;
5981 +
5982 +       if (mnt == mnt->mnt_ns->root)
5983 +               return 1;
5984 +
5985 +       spin_lock(&vfsmount_lock);
5986 +       root = current->fs->root;
5987 +       point = root.dentry;
5988 +
5989 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
5990 +               point = mnt->mnt_mountpoint;
5991 +               mnt = mnt->mnt_parent;
5992 +       }
5993 +
5994 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
5995 +
5996 +       spin_unlock(&vfsmount_lock);
5997 +
5998 +       return ret;
5999 +}
6000 +
6001  /*
6002   * Simple .show_options callback for filesystems which don't want to
6003   * implement more complex mount option showing.
6004 @@ -388,44 +419,61 @@ static int show_vfsmnt(struct seq_file *
6005         struct vfsmount *mnt = list_entry(v, struct vfsmount, mnt_list);
6006         int err = 0;
6007         static struct proc_fs_info {
6008 -               int flag;
6009 -               char *str;
6010 +               int s_flag;
6011 +               int mnt_flag;
6012 +               char *set_str;
6013 +               char *unset_str;
6014         } fs_info[] = {
6015 -               { MS_SYNCHRONOUS, ",sync" },
6016 -               { MS_DIRSYNC, ",dirsync" },
6017 -               { MS_MANDLOCK, ",mand" },
6018 -               { 0, NULL }
6019 -       };
6020 -       static struct proc_fs_info mnt_info[] = {
6021 -               { MNT_NOSUID, ",nosuid" },
6022 -               { MNT_NODEV, ",nodev" },
6023 -               { MNT_NOEXEC, ",noexec" },
6024 -               { MNT_NOATIME, ",noatime" },
6025 -               { MNT_NODIRATIME, ",nodiratime" },
6026 -               { MNT_RELATIME, ",relatime" },
6027 -               { 0, NULL }
6028 +               { MS_RDONLY, MNT_RDONLY, "ro", "rw" },
6029 +               { MS_SYNCHRONOUS, 0, ",sync", NULL },
6030 +               { MS_DIRSYNC, 0, ",dirsync", NULL },
6031 +               { MS_MANDLOCK, 0, ",mand", NULL },
6032 +               { MS_TAGGED, 0, ",tag", NULL },
6033 +               { MS_NOATIME, MNT_NOATIME, ",noatime", NULL },
6034 +               { MS_NODIRATIME, MNT_NODIRATIME, ",nodiratime", NULL },
6035 +               { MS_RELATIME, MNT_RELATIME, ",relatime", NULL },
6036 +               { 0, MNT_NOSUID, ",nosuid", NULL },
6037 +               { 0, MNT_NODEV, ",nodev", NULL },
6038 +               { 0, MNT_NOEXEC, ",noexec", NULL },
6039 +               { 0, 0, NULL, NULL }
6040         };
6041 -       struct proc_fs_info *fs_infop;
6042 -       struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6043 +       struct proc_fs_info *p;
6044 +       unsigned long s_flags = mnt->mnt_sb->s_flags;
6045 +       int mnt_flags = mnt->mnt_flags;
6046  
6047 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
6048 -       seq_putc(m, ' ');
6049 -       seq_path(m, &mnt_path, " \t\n\\");
6050 -       seq_putc(m, ' ');
6051 -       mangle(m, mnt->mnt_sb->s_type->name);
6052 -       if (mnt->mnt_sb->s_subtype && mnt->mnt_sb->s_subtype[0]) {
6053 -               seq_putc(m, '.');
6054 -               mangle(m, mnt->mnt_sb->s_subtype);
6055 -       }
6056 -       seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? " ro" : " rw");
6057 -       for (fs_infop = fs_info; fs_infop->flag; fs_infop++) {
6058 -               if (mnt->mnt_sb->s_flags & fs_infop->flag)
6059 -                       seq_puts(m, fs_infop->str);
6060 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6061 +               return 0;
6062 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6063 +               return 0;
6064 +
6065 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6066 +               mnt == current->fs->root.mnt) {
6067 +               seq_puts(m, "/dev/root / ");
6068 +       } else {
6069 +               struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6070 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
6071 +               seq_putc(m, ' ');
6072 +               seq_path(m, &mnt_path, " \t\n\\");
6073 +               seq_putc(m, ' ');
6074 +
6075 +               if (mnt->mnt_sb->s_subtype && mnt->mnt_sb->s_subtype[0]) {
6076 +                       seq_putc(m, '.');
6077 +                       mangle(m, mnt->mnt_sb->s_subtype);
6078 +               }
6079         }
6080 -       for (fs_infop = mnt_info; fs_infop->flag; fs_infop++) {
6081 -               if (mnt->mnt_flags & fs_infop->flag)
6082 -                       seq_puts(m, fs_infop->str);
6083 +       mangle(m, mnt->mnt_sb->s_type->name);
6084 +       seq_putc(m, ' ');
6085 +       for (p = fs_info; (p->s_flag | p->mnt_flag) ; p++) {
6086 +               if ((s_flags & p->s_flag) || (mnt_flags & p->mnt_flag)) {
6087 +                       if (p->set_str)
6088 +                               seq_puts(m, p->set_str);
6089 +               } else {
6090 +                       if (p->unset_str)
6091 +                               seq_puts(m, p->unset_str);
6092 +               }
6093         }
6094 +       if (mnt->mnt_flags & MNT_TAGID)
6095 +               seq_printf(m, ",tag=%d", mnt->mnt_tag);
6096         if (mnt->mnt_sb->s_op->show_options)
6097                 err = mnt->mnt_sb->s_op->show_options(m, mnt);
6098         seq_puts(m, " 0 0\n");
6099 @@ -445,17 +493,27 @@ static int show_vfsstat(struct seq_file 
6100         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6101         int err = 0;
6102  
6103 -       /* device */
6104 -       if (mnt->mnt_devname) {
6105 -               seq_puts(m, "device ");
6106 -               mangle(m, mnt->mnt_devname);
6107 -       } else
6108 -               seq_puts(m, "no device");
6109 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6110 +               return 0;
6111 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6112 +               return 0;
6113  
6114 -       /* mount point */
6115 -       seq_puts(m, " mounted on ");
6116 -       seq_path(m, &mnt_path, " \t\n\\");
6117 -       seq_putc(m, ' ');
6118 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6119 +               mnt == current->fs->root.mnt) {
6120 +               seq_puts(m, "device /dev/root mounted on / ");
6121 +       } else {
6122 +               /* device */
6123 +               if (mnt->mnt_devname) {
6124 +                       seq_puts(m, "device ");
6125 +                       mangle(m, mnt->mnt_devname);
6126 +               } else
6127 +                       seq_puts(m, "no device");
6128 +
6129 +               /* mount point */
6130 +               seq_puts(m, " mounted on ");
6131 +               seq_path(m, &mnt_path, " \t\n\\");
6132 +               seq_putc(m, ' ');
6133 +       }
6134  
6135         /* file system type */
6136         seq_puts(m, "with fstype ");
6137 @@ -693,7 +751,7 @@ asmlinkage long sys_umount(char __user *
6138                 goto dput_and_out;
6139  
6140         retval = -EPERM;
6141 -       if (!capable(CAP_SYS_ADMIN))
6142 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6143                 goto dput_and_out;
6144  
6145         retval = do_umount(nd.path.mnt, flags);
6146 @@ -719,7 +777,7 @@ asmlinkage long sys_oldumount(char __use
6147  
6148  static int mount_is_safe(struct nameidata *nd)
6149  {
6150 -       if (capable(CAP_SYS_ADMIN))
6151 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6152                 return 0;
6153         return -EPERM;
6154  #ifdef notyet
6155 @@ -974,11 +1032,13 @@ static noinline int do_change_type(struc
6156   * noinline this do_mount helper to save do_mount stack space.
6157   */
6158  static noinline int do_loopback(struct nameidata *nd, char *old_name,
6159 -                               int recurse)
6160 +       tag_t tag, unsigned long flags, int mnt_flags)
6161  {
6162         struct nameidata old_nd;
6163         struct vfsmount *mnt = NULL;
6164         int err = mount_is_safe(nd);
6165 +       int recurse = flags & MS_REC;
6166 +
6167         if (err)
6168                 return err;
6169         if (!old_name || !*old_name)
6170 @@ -1004,6 +1064,12 @@ static noinline int do_loopback(struct n
6171         if (!mnt)
6172                 goto out;
6173  
6174 +       mnt->mnt_flags = mnt_flags;
6175 +       if (flags & MS_TAGID) {
6176 +               mnt->mnt_tag = tag;
6177 +               mnt->mnt_flags |= MNT_TAGID;
6178 +       }
6179 +
6180         err = graft_tree(mnt, nd);
6181         if (err) {
6182                 LIST_HEAD(umount_list);
6183 @@ -1012,6 +1078,7 @@ static noinline int do_loopback(struct n
6184                 spin_unlock(&vfsmount_lock);
6185                 release_mounts(&umount_list);
6186         }
6187 +       mnt->mnt_flags = mnt_flags;
6188  
6189  out:
6190         up_write(&namespace_sem);
6191 @@ -1026,12 +1093,12 @@ out:
6192   * noinline this do_mount helper to save do_mount stack space.
6193   */
6194  static noinline int do_remount(struct nameidata *nd, int flags, int mnt_flags,
6195 -                     void *data)
6196 +       void *data, xid_t xid)
6197  {
6198         int err;
6199         struct super_block *sb = nd->path.mnt->mnt_sb;
6200  
6201 -       if (!capable(CAP_SYS_ADMIN))
6202 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
6203                 return -EPERM;
6204  
6205         if (!check_mnt(nd->path.mnt))
6206 @@ -1069,7 +1136,7 @@ static noinline int do_move_mount(struct
6207         struct path parent_path;
6208         struct vfsmount *p;
6209         int err = 0;
6210 -       if (!capable(CAP_SYS_ADMIN))
6211 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6212                 return -EPERM;
6213         if (!old_name || !*old_name)
6214                 return -EINVAL;
6215 @@ -1152,7 +1219,7 @@ static noinline int do_new_mount(struct 
6216                 return -EINVAL;
6217  
6218         /* we need capabilities... */
6219 -       if (!capable(CAP_SYS_ADMIN))
6220 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6221                 return -EPERM;
6222  
6223         mnt = do_kern_mount(type, flags, name, data);
6224 @@ -1397,6 +1464,7 @@ long do_mount(char *dev_name, char *dir_
6225         struct nameidata nd;
6226         int retval = 0;
6227         int mnt_flags = 0;
6228 +       tag_t tag = 0;
6229  
6230         /* Discard magic */
6231         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
6232 @@ -1412,7 +1480,17 @@ long do_mount(char *dev_name, char *dir_
6233         if (data_page)
6234                 ((char *)data_page)[PAGE_SIZE - 1] = 0;
6235  
6236 +       retval = dx_parse_tag(data_page, &tag, 1);
6237 +       if (retval) {
6238 +               mnt_flags |= retval;
6239 +               /* FIXME: bind and re-mounts get the tag flag? */
6240 +               if (flags & (MS_BIND|MS_REMOUNT))
6241 +                       flags |= MS_TAGID;
6242 +       }
6243 +
6244         /* Separate the per-mountpoint flags */
6245 +       if (flags & MS_RDONLY)
6246 +               mnt_flags |= MNT_RDONLY;
6247         if (flags & MS_NOSUID)
6248                 mnt_flags |= MNT_NOSUID;
6249         if (flags & MS_NODEV)
6250 @@ -1426,6 +1504,8 @@ long do_mount(char *dev_name, char *dir_
6251         if (flags & MS_RELATIME)
6252                 mnt_flags |= MNT_RELATIME;
6253  
6254 +       if (!capable(CAP_SYS_ADMIN))
6255 +               mnt_flags |= MNT_NODEV;
6256         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
6257                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT);
6258  
6259 @@ -1440,9 +1520,9 @@ long do_mount(char *dev_name, char *dir_
6260  
6261         if (flags & MS_REMOUNT)
6262                 retval = do_remount(&nd, flags & ~MS_REMOUNT, mnt_flags,
6263 -                                   data_page);
6264 +                                   data_page, tag);
6265         else if (flags & MS_BIND)
6266 -               retval = do_loopback(&nd, dev_name, flags & MS_REC);
6267 +               retval = do_loopback(&nd, dev_name, tag, flags, mnt_flags);
6268         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
6269                 retval = do_change_type(&nd, flags);
6270         else if (flags & MS_MOVE)
6271 @@ -1515,6 +1595,7 @@ static struct mnt_namespace *dup_mnt_ns(
6272                 q = next_mnt(q, new_ns->root);
6273         }
6274         up_write(&namespace_sem);
6275 +       atomic_inc(&vs_global_mnt_ns);
6276  
6277         if (rootmnt)
6278                 mntput(rootmnt);
6279 @@ -1850,5 +1931,6 @@ void __put_mnt_ns(struct mnt_namespace *
6280         spin_unlock(&vfsmount_lock);
6281         up_write(&namespace_sem);
6282         release_mounts(&umount_list);
6283 +       atomic_dec(&vs_global_mnt_ns);
6284         kfree(ns);
6285  }
6286 diff -NurpP --minimal linux-2.6.25/fs/nfs/client.c linux-2.6.25-vs2.3.0.34.9/fs/nfs/client.c
6287 --- linux-2.6.25/fs/nfs/client.c        2008-04-17 12:05:40.000000000 -0400
6288 +++ linux-2.6.25-vs2.3.0.34.9/fs/nfs/client.c   2008-04-19 15:14:52.000000000 -0400
6289 @@ -589,6 +589,9 @@ static int nfs_init_server_rpcclient(str
6290         if (server->flags & NFS_MOUNT_SOFT)
6291                 server->client->cl_softrtry = 1;
6292  
6293 +       server->client->cl_tag = 0;
6294 +       if (server->flags & NFS_MOUNT_TAGGED)
6295 +               server->client->cl_tag = 1;
6296         return 0;
6297  }
6298  
6299 @@ -742,6 +745,10 @@ static void nfs_server_set_fsinfo(struct
6300                 server->acdirmin = server->acdirmax = 0;
6301         }
6302  
6303 +       /* FIXME: needs fsinfo
6304 +       if (server->flags & NFS_MOUNT_TAGGED)
6305 +               sb->s_flags |= MS_TAGGED;       */
6306 +
6307         server->maxfilesize = fsinfo->maxfilesize;
6308  
6309         /* We're airborne Set socket buffersize */
6310 diff -NurpP --minimal linux-2.6.25/fs/nfs/dir.c linux-2.6.25-vs2.3.0.34.9/fs/nfs/dir.c
6311 --- linux-2.6.25/fs/nfs/dir.c   2008-04-17 12:05:40.000000000 -0400
6312 +++ linux-2.6.25-vs2.3.0.34.9/fs/nfs/dir.c      2008-04-21 16:52:03.000000000 -0400
6313 @@ -34,6 +34,7 @@
6314  #include <linux/namei.h>
6315  #include <linux/mount.h>
6316  #include <linux/sched.h>
6317 +#include <linux/vs_tag.h>
6318  
6319  #include "nfs4_fs.h"
6320  #include "delegation.h"
6321 @@ -930,6 +931,7 @@ static struct dentry *nfs_lookup(struct 
6322         if (IS_ERR(res))
6323                 goto out_unblock_sillyrename;
6324  
6325 +       dx_propagate_tag(nd, inode);
6326  no_entry:
6327         res = d_materialise_unique(dentry, inode);
6328         if (res != NULL) {
6329 @@ -967,7 +969,8 @@ static int is_atomic_open(struct inode *
6330         if (nd->flags & LOOKUP_DIRECTORY)
6331                 return 0;
6332         /* Are we trying to write to a read only partition? */
6333 -       if (IS_RDONLY(dir) && (nd->intent.open.flags & (O_CREAT|O_TRUNC|FMODE_WRITE)))
6334 +       if ((IS_RDONLY(dir) || MNT_IS_RDONLY(nd->path.mnt)) &&
6335 +               (nd->intent.open.flags & (O_CREAT|O_TRUNC|FMODE_WRITE)))
6336                 return 0;
6337         return 1;
6338  }
6339 diff -NurpP --minimal linux-2.6.25/fs/nfs/inode.c linux-2.6.25-vs2.3.0.34.9/fs/nfs/inode.c
6340 --- linux-2.6.25/fs/nfs/inode.c 2008-04-17 12:05:40.000000000 -0400
6341 +++ linux-2.6.25-vs2.3.0.34.9/fs/nfs/inode.c    2008-04-19 15:14:52.000000000 -0400
6342 @@ -37,6 +37,7 @@
6343  #include <linux/vfs.h>
6344  #include <linux/inet.h>
6345  #include <linux/nfs_xdr.h>
6346 +#include <linux/vs_tag.h>
6347  
6348  #include <asm/system.h>
6349  #include <asm/uaccess.h>
6350 @@ -316,8 +317,10 @@ nfs_fhget(struct super_block *sb, struct
6351                         nfsi->change_attr = fattr->change_attr;
6352                 inode->i_size = nfs_size_to_loff_t(fattr->size);
6353                 inode->i_nlink = fattr->nlink;
6354 -               inode->i_uid = fattr->uid;
6355 -               inode->i_gid = fattr->gid;
6356 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
6357 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
6358 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
6359 +                                        /* maybe fattr->xid someday */
6360                 if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
6361                         /*
6362                          * report the blocks in 512byte units
6363 @@ -410,6 +413,8 @@ void nfs_setattr_update_inode(struct ino
6364                         inode->i_uid = attr->ia_uid;
6365                 if ((attr->ia_valid & ATTR_GID) != 0)
6366                         inode->i_gid = attr->ia_gid;
6367 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
6368 +                       inode->i_tag = attr->ia_tag;
6369                 spin_lock(&inode->i_lock);
6370                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
6371                 spin_unlock(&inode->i_lock);
6372 @@ -841,6 +846,9 @@ static int nfs_check_inode_attributes(st
6373         struct nfs_inode *nfsi = NFS_I(inode);
6374         loff_t cur_size, new_isize;
6375         unsigned long invalid = 0;
6376 +       uid_t uid;
6377 +       gid_t gid;
6378 +       tag_t tag;
6379  
6380  
6381         /* Has the inode gone and changed behind our back? */
6382 @@ -865,10 +873,15 @@ static int nfs_check_inode_attributes(st
6383         if (cur_size != new_isize && nfsi->npages == 0)
6384                 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
6385  
6386 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
6387 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
6388 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
6389 +
6390         /* Have any file permissions changed? */
6391         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)
6392 -                       || inode->i_uid != fattr->uid
6393 -                       || inode->i_gid != fattr->gid)
6394 +                       || inode->i_uid != uid
6395 +                       || inode->i_gid != gid
6396 +                       || inode->i_tag != tag)
6397                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
6398  
6399         /* Has the link count changed? */
6400 @@ -989,6 +1002,9 @@ static int nfs_update_inode(struct inode
6401         loff_t cur_isize, new_isize;
6402         unsigned long invalid = 0;
6403         unsigned long now = jiffies;
6404 +       uid_t uid;
6405 +       gid_t gid;
6406 +       tag_t tag;
6407  
6408         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
6409                         __FUNCTION__, inode->i_sb->s_id, inode->i_ino,
6410 @@ -1062,15 +1078,21 @@ static int nfs_update_inode(struct inode
6411         memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
6412         nfsi->change_attr = fattr->change_attr;
6413  
6414 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
6415 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
6416 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
6417 +
6418         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO) ||
6419 -           inode->i_uid != fattr->uid ||
6420 -           inode->i_gid != fattr->gid)
6421 +           inode->i_uid != uid ||
6422 +           inode->i_gid != gid ||
6423 +           inode->i_tag != tag)
6424                 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
6425  
6426         inode->i_mode = fattr->mode;
6427         inode->i_nlink = fattr->nlink;
6428 -       inode->i_uid = fattr->uid;
6429 -       inode->i_gid = fattr->gid;
6430 +       inode->i_uid = uid;
6431 +       inode->i_gid = gid;
6432 +       inode->i_tag = tag;
6433  
6434         if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
6435                 /*
6436 diff -NurpP --minimal linux-2.6.25/fs/nfs/nfs3xdr.c linux-2.6.25-vs2.3.0.34.9/fs/nfs/nfs3xdr.c
6437 --- linux-2.6.25/fs/nfs/nfs3xdr.c       2008-04-17 12:05:40.000000000 -0400
6438 +++ linux-2.6.25-vs2.3.0.34.9/fs/nfs/nfs3xdr.c  2008-04-19 15:14:52.000000000 -0400
6439 @@ -22,6 +22,7 @@
6440  #include <linux/nfs3.h>
6441  #include <linux/nfs_fs.h>
6442  #include <linux/nfsacl.h>
6443 +#include <linux/vs_tag.h>
6444  #include "internal.h"
6445  
6446  #define NFSDBG_FACILITY                NFSDBG_XDR
6447 @@ -180,7 +181,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
6448  }
6449  
6450  static inline __be32 *
6451 -xdr_encode_sattr(__be32 *p, struct iattr *attr)
6452 +xdr_encode_sattr(__be32 *p, struct iattr *attr, int tag)
6453  {
6454         if (attr->ia_valid & ATTR_MODE) {
6455                 *p++ = xdr_one;
6456 @@ -188,15 +189,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
6457         } else {
6458                 *p++ = xdr_zero;
6459         }
6460 -       if (attr->ia_valid & ATTR_UID) {
6461 +       if (attr->ia_valid & ATTR_UID ||
6462 +               (tag && (attr->ia_valid & ATTR_TAG))) {
6463                 *p++ = xdr_one;
6464 -               *p++ = htonl(attr->ia_uid);
6465 +               *p++ = htonl(TAGINO_UID(tag, attr->ia_uid, attr->ia_tag));
6466         } else {
6467                 *p++ = xdr_zero;
6468         }
6469 -       if (attr->ia_valid & ATTR_GID) {
6470 +       if (attr->ia_valid & ATTR_GID ||
6471 +               (tag && (attr->ia_valid & ATTR_TAG))) {
6472                 *p++ = xdr_one;
6473 -               *p++ = htonl(attr->ia_gid);
6474 +               *p++ = htonl(TAGINO_GID(tag, attr->ia_gid, attr->ia_tag));
6475         } else {
6476                 *p++ = xdr_zero;
6477         }
6478 @@ -281,7 +284,8 @@ static int
6479  nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args)
6480  {
6481         p = xdr_encode_fhandle(p, args->fh);
6482 -       p = xdr_encode_sattr(p, args->sattr);
6483 +       p = xdr_encode_sattr(p, args->sattr,
6484 +               req->rq_task->tk_client->cl_tag);
6485         *p++ = htonl(args->guard);
6486         if (args->guard)
6487                 p = xdr_encode_time3(p, &args->guardtime);
6488 @@ -386,7 +390,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
6489                 *p++ = args->verifier[0];
6490                 *p++ = args->verifier[1];
6491         } else
6492 -               p = xdr_encode_sattr(p, args->sattr);
6493 +               p = xdr_encode_sattr(p, args->sattr,
6494 +                       req->rq_task->tk_client->cl_tag);
6495  
6496         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
6497         return 0;
6498 @@ -400,7 +405,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
6499  {
6500         p = xdr_encode_fhandle(p, args->fh);
6501         p = xdr_encode_array(p, args->name, args->len);
6502 -       p = xdr_encode_sattr(p, args->sattr);
6503 +       p = xdr_encode_sattr(p, args->sattr,
6504 +               req->rq_task->tk_client->cl_tag);
6505         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
6506         return 0;
6507  }
6508 @@ -413,7 +419,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
6509  {
6510         p = xdr_encode_fhandle(p, args->fromfh);
6511         p = xdr_encode_array(p, args->fromname, args->fromlen);
6512 -       p = xdr_encode_sattr(p, args->sattr);
6513 +       p = xdr_encode_sattr(p, args->sattr,
6514 +               req->rq_task->tk_client->cl_tag);
6515         *p++ = htonl(args->pathlen);
6516         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
6517  
6518 @@ -431,7 +438,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
6519         p = xdr_encode_fhandle(p, args->fh);
6520         p = xdr_encode_array(p, args->name, args->len);
6521         *p++ = htonl(args->type);
6522 -       p = xdr_encode_sattr(p, args->sattr);
6523 +       p = xdr_encode_sattr(p, args->sattr,
6524 +               req->rq_task->tk_client->cl_tag);
6525         if (args->type == NF3CHR || args->type == NF3BLK) {
6526                 *p++ = htonl(MAJOR(args->rdev));
6527                 *p++ = htonl(MINOR(args->rdev));
6528 diff -NurpP --minimal linux-2.6.25/fs/nfs/nfsroot.c linux-2.6.25-vs2.3.0.34.9/fs/nfs/nfsroot.c
6529 --- linux-2.6.25/fs/nfs/nfsroot.c       2008-04-17 12:05:40.000000000 -0400
6530 +++ linux-2.6.25-vs2.3.0.34.9/fs/nfs/nfsroot.c  2008-04-19 15:14:52.000000000 -0400
6531 @@ -119,12 +119,12 @@ static int mount_port __initdata = 0;             /
6532  enum {
6533         /* Options that take integer arguments */
6534         Opt_port, Opt_rsize, Opt_wsize, Opt_timeo, Opt_retrans, Opt_acregmin,
6535 -       Opt_acregmax, Opt_acdirmin, Opt_acdirmax,
6536 +       Opt_acregmax, Opt_acdirmin, Opt_acdirmax, Opt_tagid,
6537         /* Options that take no arguments */
6538         Opt_soft, Opt_hard, Opt_intr,
6539         Opt_nointr, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac, 
6540         Opt_noac, Opt_lock, Opt_nolock, Opt_v2, Opt_v3, Opt_udp, Opt_tcp,
6541 -       Opt_acl, Opt_noacl,
6542 +       Opt_acl, Opt_noacl, Opt_tag, Opt_notag,
6543         /* Error token */
6544         Opt_err
6545  };
6546 @@ -161,6 +161,9 @@ static match_table_t __initdata tokens =
6547         {Opt_tcp, "tcp"},
6548         {Opt_acl, "acl"},
6549         {Opt_noacl, "noacl"},
6550 +       {Opt_tag, "tag"},
6551 +       {Opt_notag, "notag"},
6552 +       {Opt_tagid, "tagid=%u"},
6553         {Opt_err, NULL}
6554         
6555  };
6556 @@ -272,6 +275,20 @@ static int __init root_nfs_parse(char *n
6557                         case Opt_noacl:
6558                                 nfs_data.flags |= NFS_MOUNT_NOACL;
6559                                 break;
6560 +#ifndef CONFIG_TAGGING_NONE
6561 +                       case Opt_tag:
6562 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
6563 +                               break;
6564 +                       case Opt_notag:
6565 +                               nfs_data.flags &= ~NFS_MOUNT_TAGGED;
6566 +                               break;
6567 +#endif
6568 +#ifdef CONFIG_PROPAGATE
6569 +                       case Opt_tagid:
6570 +                               /* use args[0] */
6571 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
6572 +                               break;
6573 +#endif
6574                         default:
6575                                 printk(KERN_WARNING "Root-NFS: unknown "
6576                                         "option: %s\n", p);
6577 diff -NurpP --minimal linux-2.6.25/fs/nfs/super.c linux-2.6.25-vs2.3.0.34.9/fs/nfs/super.c
6578 --- linux-2.6.25/fs/nfs/super.c 2008-04-17 12:05:40.000000000 -0400
6579 +++ linux-2.6.25-vs2.3.0.34.9/fs/nfs/super.c    2008-04-19 15:14:52.000000000 -0400
6580 @@ -50,6 +50,7 @@
6581  #include <linux/nfs_xdr.h>
6582  #include <linux/magic.h>
6583  #include <linux/parser.h>
6584 +#include <linux/vs_tag.h>
6585  
6586  #include <asm/system.h>
6587  #include <asm/uaccess.h>
6588 @@ -458,6 +459,7 @@ static void nfs_show_mount_options(struc
6589                 { NFS_MOUNT_NOACL, ",noacl", "" },
6590                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
6591                 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
6592 +               { NFS_MOUNT_TAGGED, ",tag", "" },
6593                 { 0, NULL, NULL }
6594         };
6595         const struct proc_nfs_info *nfs_infop;
6596 diff -NurpP --minimal linux-2.6.25/fs/nfsd/auth.c linux-2.6.25-vs2.3.0.34.9/fs/nfsd/auth.c
6597 --- linux-2.6.25/fs/nfsd/auth.c 2008-04-17 12:05:40.000000000 -0400
6598 +++ linux-2.6.25-vs2.3.0.34.9/fs/nfsd/auth.c    2008-04-19 17:07:41.000000000 -0400
6599 @@ -10,6 +10,7 @@
6600  #include <linux/sunrpc/svcauth.h>
6601  #include <linux/nfsd/nfsd.h>
6602  #include <linux/nfsd/export.h>
6603 +#include <linux/vs_tag.h>
6604  
6605  int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
6606  {
6607 @@ -54,19 +55,23 @@ int nfsd_setuser(struct svc_rqst *rqstp,
6608                 get_group_info(cred.cr_group_info);
6609  
6610         if (cred.cr_uid != (uid_t) -1)
6611 -               current->fsuid = cred.cr_uid;
6612 +               current->fsuid = INOTAG_UID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid);
6613         else
6614                 current->fsuid = exp->ex_anon_uid;
6615         if (cred.cr_gid != (gid_t) -1)
6616 -               current->fsgid = cred.cr_gid;
6617 +               current->fsgid = INOTAG_GID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid);
6618         else
6619                 current->fsgid = exp->ex_anon_gid;
6620  
6621 +       /* this desperately needs a tag :) */
6622 +       current->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
6623 +
6624         if (!cred.cr_group_info)
6625                 return -ENOMEM;
6626         ret = set_current_groups(cred.cr_group_info);
6627         put_group_info(cred.cr_group_info);
6628 -       if ((cred.cr_uid)) {
6629 +
6630 +       if (INOTAG_UID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid)) {
6631                 current->cap_effective =
6632                         cap_drop_nfsd_set(current->cap_effective);
6633         } else {
6634 diff -NurpP --minimal linux-2.6.25/fs/nfsd/nfs3xdr.c linux-2.6.25-vs2.3.0.34.9/fs/nfsd/nfs3xdr.c
6635 --- linux-2.6.25/fs/nfsd/nfs3xdr.c      2008-04-17 12:05:40.000000000 -0400
6636 +++ linux-2.6.25-vs2.3.0.34.9/fs/nfsd/nfs3xdr.c 2008-04-19 17:08:09.000000000 -0400
6637 @@ -21,6 +21,7 @@
6638  #include <linux/sunrpc/svc.h>
6639  #include <linux/nfsd/nfsd.h>
6640  #include <linux/nfsd/xdr3.h>
6641 +#include <linux/vs_tag.h>
6642  #include "auth.h"
6643  
6644  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6645 @@ -108,6 +109,8 @@ static __be32 *
6646  decode_sattr3(__be32 *p, struct iattr *iap)
6647  {
6648         u32     tmp;
6649 +       uid_t   uid = 0;
6650 +       gid_t   gid = 0;
6651  
6652         iap->ia_valid = 0;
6653  
6654 @@ -117,12 +120,15 @@ decode_sattr3(__be32 *p, struct iattr *i
6655         }
6656         if (*p++) {
6657                 iap->ia_valid |= ATTR_UID;
6658 -               iap->ia_uid = ntohl(*p++);
6659 +               uid = ntohl(*p++);
6660         }
6661         if (*p++) {
6662                 iap->ia_valid |= ATTR_GID;
6663 -               iap->ia_gid = ntohl(*p++);
6664 +               gid = ntohl(*p++);
6665         }
6666 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6667 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6668 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6669         if (*p++) {
6670                 u64     newsize;
6671  
6672 @@ -178,8 +184,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
6673         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
6674         *p++ = htonl((u32) stat->mode);
6675         *p++ = htonl((u32) stat->nlink);
6676 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6677 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6678 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6679 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6680 +               stat->uid, stat->tag)));
6681 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6682 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6683 +               stat->gid, stat->tag)));
6684         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
6685                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
6686         } else {
6687 diff -NurpP --minimal linux-2.6.25/fs/nfsd/nfs4recover.c linux-2.6.25-vs2.3.0.34.9/fs/nfsd/nfs4recover.c
6688 --- linux-2.6.25/fs/nfsd/nfs4recover.c  2008-04-17 12:05:40.000000000 -0400
6689 +++ linux-2.6.25-vs2.3.0.34.9/fs/nfsd/nfs4recover.c     2008-04-20 13:24:11.000000000 -0400
6690 @@ -154,7 +154,7 @@ nfsd4_create_clid_dir(struct nfs4_client
6691                 dprintk("NFSD: nfsd4_create_clid_dir: DIRECTORY EXISTS\n");
6692                 goto out_put;
6693         }
6694 -       status = vfs_mkdir(rec_dir.path.dentry->d_inode, dentry, S_IRWXU);
6695 +       status = vfs_mkdir(rec_dir.path.dentry->d_inode, dentry, S_IRWXU, NULL);
6696  out_put:
6697         dput(dentry);
6698  out_unlock:
6699 @@ -258,7 +258,7 @@ nfsd4_remove_clid_file(struct dentry *di
6700                 return -EINVAL;
6701         }
6702         mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
6703 -       status = vfs_unlink(dir->d_inode, dentry);
6704 +       status = vfs_unlink(dir->d_inode, dentry, NULL);
6705         mutex_unlock(&dir->d_inode->i_mutex);
6706         return status;
6707  }
6708 @@ -273,7 +273,7 @@ nfsd4_clear_clid_dir(struct dentry *dir,
6709          * a kernel from the future.... */
6710         nfsd4_list_rec_dir(dentry, nfsd4_remove_clid_file);
6711         mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
6712 -       status = vfs_rmdir(dir->d_inode, dentry);
6713 +       status = vfs_rmdir(dir->d_inode, dentry, NULL);
6714         mutex_unlock(&dir->d_inode->i_mutex);
6715         return status;
6716  }
6717 diff -NurpP --minimal linux-2.6.25/fs/nfsd/nfs4xdr.c linux-2.6.25-vs2.3.0.34.9/fs/nfsd/nfs4xdr.c
6718 --- linux-2.6.25/fs/nfsd/nfs4xdr.c      2008-04-17 12:05:40.000000000 -0400
6719 +++ linux-2.6.25-vs2.3.0.34.9/fs/nfsd/nfs4xdr.c 2008-04-19 15:14:52.000000000 -0400
6720 @@ -58,6 +58,7 @@
6721  #include <linux/nfs4_acl.h>
6722  #include <linux/sunrpc/gss_api.h>
6723  #include <linux/sunrpc/svcauth_gss.h>
6724 +#include <linux/vs_tag.h>
6725  
6726  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6727  
6728 @@ -1759,14 +1760,18 @@ out_acl:
6729                 WRITE32(stat.nlink);
6730         }
6731         if (bmval1 & FATTR4_WORD1_OWNER) {
6732 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
6733 +               status = nfsd4_encode_user(rqstp,
6734 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
6735 +                       stat.uid, stat.tag), &p, &buflen);
6736                 if (status == nfserr_resource)
6737                         goto out_resource;
6738                 if (status)
6739                         goto out;
6740         }
6741         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
6742 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
6743 +               status = nfsd4_encode_group(rqstp,
6744 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
6745 +                       stat.gid, stat.tag), &p, &buflen);
6746                 if (status == nfserr_resource)
6747                         goto out_resource;
6748                 if (status)
6749 diff -NurpP --minimal linux-2.6.25/fs/nfsd/nfsxdr.c linux-2.6.25-vs2.3.0.34.9/fs/nfsd/nfsxdr.c
6750 --- linux-2.6.25/fs/nfsd/nfsxdr.c       2008-04-17 12:05:40.000000000 -0400
6751 +++ linux-2.6.25-vs2.3.0.34.9/fs/nfsd/nfsxdr.c  2008-04-20 13:23:36.000000000 -0400
6752 @@ -15,6 +15,7 @@
6753  #include <linux/nfsd/nfsd.h>
6754  #include <linux/nfsd/xdr.h>
6755  #include <linux/mm.h>
6756 +#include <linux/vs_tag.h>
6757  #include "auth.h"
6758  
6759  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6760 @@ -98,6 +99,8 @@ static __be32 *
6761  decode_sattr(__be32 *p, struct iattr *iap)
6762  {
6763         u32     tmp, tmp1;
6764 +       uid_t   uid = 0;
6765 +       gid_t   gid = 0;
6766  
6767         iap->ia_valid = 0;
6768  
6769 @@ -111,12 +114,15 @@ decode_sattr(__be32 *p, struct iattr *ia
6770         }
6771         if ((tmp = ntohl(*p++)) != (u32)-1) {
6772                 iap->ia_valid |= ATTR_UID;
6773 -               iap->ia_uid = tmp;
6774 +               uid = tmp;
6775         }
6776         if ((tmp = ntohl(*p++)) != (u32)-1) {
6777                 iap->ia_valid |= ATTR_GID;
6778 -               iap->ia_gid = tmp;
6779 +               gid = tmp;
6780         }
6781 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6782 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6783 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6784         if ((tmp = ntohl(*p++)) != (u32)-1) {
6785                 iap->ia_valid |= ATTR_SIZE;
6786                 iap->ia_size = tmp;
6787 @@ -161,8 +167,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
6788         *p++ = htonl(nfs_ftypes[type >> 12]);
6789         *p++ = htonl((u32) stat->mode);
6790         *p++ = htonl((u32) stat->nlink);
6791 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6792 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6793 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6794 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
6795 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6796 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
6797  
6798         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
6799                 *p++ = htonl(NFS_MAXPATHLEN);
6800 diff -NurpP --minimal linux-2.6.25/fs/nfsd/vfs.c linux-2.6.25-vs2.3.0.34.9/fs/nfsd/vfs.c
6801 --- linux-2.6.25/fs/nfsd/vfs.c  2008-04-17 12:05:40.000000000 -0400
6802 +++ linux-2.6.25-vs2.3.0.34.9/fs/nfsd/vfs.c     2008-04-21 17:24:34.000000000 -0400
6803 @@ -1258,13 +1258,13 @@ nfsd_create(struct svc_rqst *rqstp, stru
6804                 host_err = vfs_create(dirp, dchild, iap->ia_mode, NULL);
6805                 break;
6806         case S_IFDIR:
6807 -               host_err = vfs_mkdir(dirp, dchild, iap->ia_mode);
6808 +               host_err = vfs_mkdir(dirp, dchild, iap->ia_mode, NULL);
6809                 break;
6810         case S_IFCHR:
6811         case S_IFBLK:
6812         case S_IFIFO:
6813         case S_IFSOCK:
6814 -               host_err = vfs_mknod(dirp, dchild, iap->ia_mode, rdev);
6815 +               host_err = vfs_mknod(dirp, dchild, iap->ia_mode, rdev, NULL);
6816                 break;
6817         default:
6818                 printk("nfsd: bad file type %o in nfsd_create\n", type);
6819 @@ -1529,11 +1529,13 @@ nfsd_symlink(struct svc_rqst *rqstp, str
6820                 else {
6821                         strncpy(path_alloced, path, plen);
6822                         path_alloced[plen] = 0;
6823 -                       host_err = vfs_symlink(dentry->d_inode, dnew, path_alloced, mode);
6824 +                       host_err = vfs_symlink(dentry->d_inode, dnew,
6825 +                               path_alloced, mode, NULL);
6826                         kfree(path_alloced);
6827                 }
6828         } else
6829 -               host_err = vfs_symlink(dentry->d_inode, dnew, path, mode);
6830 +               host_err = vfs_symlink(dentry->d_inode, dnew,
6831 +                       path, mode, NULL);
6832  
6833         if (!host_err) {
6834                 if (EX_ISSYNC(fhp->fh_export))
6835 @@ -1592,7 +1594,7 @@ nfsd_link(struct svc_rqst *rqstp, struct
6836         dold = tfhp->fh_dentry;
6837         dest = dold->d_inode;
6838  
6839 -       host_err = vfs_link(dold, dirp, dnew);
6840 +       host_err = vfs_link(dold, dirp, dnew, NULL);
6841         if (!host_err) {
6842                 if (EX_ISSYNC(ffhp->fh_export)) {
6843                         err = nfserrno(nfsd_sync_dir(ddir));
6844 @@ -1757,9 +1759,9 @@ nfsd_unlink(struct svc_rqst *rqstp, stru
6845                         host_err = -EPERM;
6846                 } else
6847  #endif
6848 -               host_err = vfs_unlink(dirp, rdentry);
6849 +               host_err = vfs_unlink(dirp, rdentry, NULL);
6850         } else { /* It's RMDIR */
6851 -               host_err = vfs_rmdir(dirp, rdentry);
6852 +               host_err = vfs_rmdir(dirp, rdentry, NULL);
6853         }
6854  
6855         dput(rdentry);
6856 @@ -1876,7 +1878,8 @@ nfsd_permission(struct svc_rqst *rqstp, 
6857          */
6858         if (!(acc & MAY_LOCAL_ACCESS))
6859                 if (acc & (MAY_WRITE | MAY_SATTR | MAY_TRUNC)) {
6860 -                       if (exp_rdonly(rqstp, exp) || IS_RDONLY(inode))
6861 +                       if (exp_rdonly(rqstp, exp) || IS_RDONLY(inode)
6862 +                               || MNT_IS_RDONLY(exp->ex_path.mnt))
6863                                 return nfserr_rofs;
6864                         if (/* (acc & MAY_WRITE) && */ IS_IMMUTABLE(inode))
6865                                 return nfserr_perm;
6866 diff -NurpP --minimal linux-2.6.25/fs/ocfs2/dlm/dlmfs.c linux-2.6.25-vs2.3.0.34.9/fs/ocfs2/dlm/dlmfs.c
6867 --- linux-2.6.25/fs/ocfs2/dlm/dlmfs.c   2008-04-17 12:05:40.000000000 -0400
6868 +++ linux-2.6.25-vs2.3.0.34.9/fs/ocfs2/dlm/dlmfs.c      2008-04-19 15:14:52.000000000 -0400
6869 @@ -43,6 +43,7 @@
6870  #include <linux/init.h>
6871  #include <linux/string.h>
6872  #include <linux/backing-dev.h>
6873 +#include <linux/vs_tag.h>
6874  
6875  #include <asm/uaccess.h>
6876  
6877 @@ -342,6 +343,7 @@ static struct inode *dlmfs_get_root_inod
6878                 inode->i_mode = mode;
6879                 inode->i_uid = current->fsuid;
6880                 inode->i_gid = current->fsgid;
6881 +               inode->i_tag = dx_current_fstag(sb);
6882                 inode->i_blocks = 0;
6883                 inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6884                 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6885 @@ -368,6 +370,7 @@ static struct inode *dlmfs_get_inode(str
6886         inode->i_mode = mode;
6887         inode->i_uid = current->fsuid;
6888         inode->i_gid = current->fsgid;
6889 +       inode->i_tag = dx_current_fstag(sb);
6890         inode->i_blocks = 0;
6891         inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6892         inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6893 diff -NurpP --minimal linux-2.6.25/fs/ocfs2/dlmglue.c linux-2.6.25-vs2.3.0.34.9/fs/ocfs2/dlmglue.c
6894 --- linux-2.6.25/fs/ocfs2/dlmglue.c     2008-04-17 12:05:40.000000000 -0400
6895 +++ linux-2.6.25-vs2.3.0.34.9/fs/ocfs2/dlmglue.c        2008-04-19 15:14:52.000000000 -0400
6896 @@ -1665,6 +1665,7 @@ static void __ocfs2_stuff_meta_lvb(struc
6897         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
6898         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
6899         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
6900 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
6901         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
6902         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
6903         lvb->lvb_iatime_packed  =
6904 @@ -1719,6 +1720,7 @@ static void ocfs2_refresh_inode_from_lvb
6905  
6906         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
6907         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
6908 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
6909         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
6910         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
6911         ocfs2_unpack_timespec(&inode->i_atime,
6912 diff -NurpP --minimal linux-2.6.25/fs/ocfs2/dlmglue.h linux-2.6.25-vs2.3.0.34.9/fs/ocfs2/dlmglue.h
6913 --- linux-2.6.25/fs/ocfs2/dlmglue.h     2008-04-17 12:05:40.000000000 -0400
6914 +++ linux-2.6.25-vs2.3.0.34.9/fs/ocfs2/dlmglue.h        2008-04-19 15:14:52.000000000 -0400
6915 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
6916         __be16       lvb_inlink;
6917         __be32       lvb_iattr;
6918         __be32       lvb_igeneration;
6919 -       __be32       lvb_reserved2;
6920 +       __be16       lvb_itag;
6921 +       __be16       lvb_reserved2;
6922  };
6923  
6924  /* ocfs2_inode_lock_full() 'arg_flags' flags */
6925 diff -NurpP --minimal linux-2.6.25/fs/ocfs2/file.c linux-2.6.25-vs2.3.0.34.9/fs/ocfs2/file.c
6926 --- linux-2.6.25/fs/ocfs2/file.c        2008-04-17 12:05:40.000000000 -0400
6927 +++ linux-2.6.25-vs2.3.0.34.9/fs/ocfs2/file.c   2008-04-19 15:14:52.000000000 -0400
6928 @@ -1054,13 +1054,15 @@ int ocfs2_setattr(struct dentry *dentry,
6929                 mlog(0, "uid change: %d\n", attr->ia_uid);
6930         if (attr->ia_valid & ATTR_GID)
6931                 mlog(0, "gid change: %d\n", attr->ia_gid);
6932 +       if (attr->ia_valid & ATTR_TAG)
6933 +               mlog(0, "tag change: %d\n", attr->ia_tag);
6934         if (attr->ia_valid & ATTR_SIZE)
6935                 mlog(0, "size change...\n");
6936         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
6937                 mlog(0, "time change...\n");
6938  
6939  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
6940 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
6941 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
6942         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
6943                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
6944                 return 0;
6945 @@ -2229,6 +2231,7 @@ const struct inode_operations ocfs2_file
6946  const struct inode_operations ocfs2_special_file_iops = {
6947         .setattr        = ocfs2_setattr,
6948         .getattr        = ocfs2_getattr,
6949 +       .sync_flags     = ocfs2_sync_flags,
6950         .permission     = ocfs2_permission,
6951  };
6952  
6953 diff -NurpP --minimal linux-2.6.25/fs/ocfs2/inode.c linux-2.6.25-vs2.3.0.34.9/fs/ocfs2/inode.c
6954 --- linux-2.6.25/fs/ocfs2/inode.c       2008-04-17 12:05:40.000000000 -0400
6955 +++ linux-2.6.25-vs2.3.0.34.9/fs/ocfs2/inode.c  2008-04-21 10:16:08.000000000 -0400
6956 @@ -28,6 +28,7 @@
6957  #include <linux/slab.h>
6958  #include <linux/highmem.h>
6959  #include <linux/pagemap.h>
6960 +#include <linux/vs_tag.h>
6961  
6962  #include <asm/byteorder.h>
6963  
6964 @@ -42,6 +43,7 @@
6965  #include "file.h"
6966  #include "heartbeat.h"
6967  #include "inode.h"
6968 +#include "ioctl.h"
6969  #include "journal.h"
6970  #include "namei.h"
6971  #include "suballoc.h"
6972 @@ -79,6 +81,10 @@ void ocfs2_set_inode_flags(struct inode 
6973  
6974         if (flags & OCFS2_IMMUTABLE_FL)
6975                 inode->i_flags |= S_IMMUTABLE;
6976 +       if (flags & OCFS2_IUNLINK_FL)
6977 +               inode->i_flags |= S_IUNLINK;
6978 +       if (flags & OCFS2_BARRIER_FL)
6979 +               inode->i_flags |= S_BARRIER;
6980  
6981         if (flags & OCFS2_SYNC_FL)
6982                 inode->i_flags |= S_SYNC;
6983 @@ -109,6 +115,27 @@ void ocfs2_get_inode_flags(struct ocfs2_
6984                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
6985  }
6986  
6987 +int ocfs2_sync_flags(struct inode *inode)
6988 +{
6989 +       unsigned int oldflags, newflags;
6990 +
6991 +       oldflags = OCFS2_I(inode)->ip_flags;
6992 +       newflags = oldflags & ~(OCFS2_IMMUTABLE_FL |
6993 +               OCFS2_IUNLINK_FL | OCFS2_BARRIER_FL);
6994 +
6995 +       if (IS_IMMUTABLE(inode))
6996 +               newflags |= OCFS2_IMMUTABLE_FL;
6997 +       if (IS_IUNLINK(inode))
6998 +               newflags |= OCFS2_IUNLINK_FL;
6999 +       if (IS_BARRIER(inode))
7000 +               newflags |= OCFS2_BARRIER_FL;
7001 +
7002 +       if (oldflags ^ newflags)
7003 +               return ocfs2_set_inode_attr(inode,
7004 +                       newflags, OCFS2_FL_MASK);
7005 +       return 0;
7006 +}
7007 +
7008  struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 blkno, unsigned flags,
7009                          int sysfile_type)
7010  {
7011 @@ -219,6 +246,8 @@ int ocfs2_populate_inode(struct inode *i
7012         struct super_block *sb;
7013         struct ocfs2_super *osb;
7014         int status = -EINVAL;
7015 +       uid_t uid;
7016 +       gid_t gid;
7017  
7018         mlog_entry("(0x%p, size:%llu)\n", inode,
7019                    (unsigned long long)le64_to_cpu(fe->i_size));
7020 @@ -254,8 +283,12 @@ int ocfs2_populate_inode(struct inode *i
7021         inode->i_generation = le32_to_cpu(fe->i_generation);
7022         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
7023         inode->i_mode = le16_to_cpu(fe->i_mode);
7024 -       inode->i_uid = le32_to_cpu(fe->i_uid);
7025 -       inode->i_gid = le32_to_cpu(fe->i_gid);
7026 +       uid = le32_to_cpu(fe->i_uid);
7027 +       gid = le32_to_cpu(fe->i_gid);
7028 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7029 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7030 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
7031 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
7032  
7033         /* Fast symlinks will have i_size but no allocated clusters. */
7034         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
7035 @@ -1230,8 +1263,11 @@ int ocfs2_mark_inode_dirty(handle_t *han
7036  
7037         fe->i_size = cpu_to_le64(i_size_read(inode));
7038         fe->i_links_count = cpu_to_le16(inode->i_nlink);
7039 -       fe->i_uid = cpu_to_le32(inode->i_uid);
7040 -       fe->i_gid = cpu_to_le32(inode->i_gid);
7041 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode),
7042 +               inode->i_uid, inode->i_tag));
7043 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode),
7044 +               inode->i_gid, inode->i_tag));
7045 +       /* i_tag = = cpu_to_le16(inode->i_tag); */
7046         fe->i_mode = cpu_to_le16(inode->i_mode);
7047         fe->i_atime = cpu_to_le64(inode->i_atime.tv_sec);
7048         fe->i_atime_nsec = cpu_to_le32(inode->i_atime.tv_nsec);
7049 @@ -1259,16 +1295,25 @@ leave:
7050  void ocfs2_refresh_inode(struct inode *inode,
7051                          struct ocfs2_dinode *fe)
7052  {
7053 +       uid_t uid;
7054 +       gid_t gid;
7055 +
7056         spin_lock(&OCFS2_I(inode)->ip_lock);
7057  
7058         OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters);
7059         OCFS2_I(inode)->ip_attr = le32_to_cpu(fe->i_attr);
7060 +       /* OCFS2_I(inode)->ip_flags &= ~OCFS2_FL_MASK;
7061 +          OCFS2_I(inode)->ip_flags |= le32_to_cpu(fe->i_flags) & OCFS2_FL_MASK; */
7062         OCFS2_I(inode)->ip_dyn_features = le16_to_cpu(fe->i_dyn_features);
7063         ocfs2_set_inode_flags(inode);
7064         i_size_write(inode, le64_to_cpu(fe->i_size));
7065         inode->i_nlink = le16_to_cpu(fe->i_links_count);
7066 -       inode->i_uid = le32_to_cpu(fe->i_uid);
7067 -       inode->i_gid = le32_to_cpu(fe->i_gid);
7068 +       uid = le32_to_cpu(fe->i_uid);
7069 +       gid = le32_to_cpu(fe->i_gid);
7070 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7071 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7072 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
7073 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
7074         inode->i_mode = le16_to_cpu(fe->i_mode);
7075         if (S_ISLNK(inode->i_mode) && le32_to_cpu(fe->i_clusters) == 0)
7076                 inode->i_blocks = 0;
7077 diff -NurpP --minimal linux-2.6.25/fs/ocfs2/inode.h linux-2.6.25-vs2.3.0.34.9/fs/ocfs2/inode.h
7078 --- linux-2.6.25/fs/ocfs2/inode.h       2008-04-17 12:05:40.000000000 -0400
7079 +++ linux-2.6.25-vs2.3.0.34.9/fs/ocfs2/inode.h  2008-04-19 15:14:52.000000000 -0400
7080 @@ -143,6 +143,7 @@ int ocfs2_aio_write(struct file *file, s
7081  
7082  void ocfs2_set_inode_flags(struct inode *inode);
7083  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
7084 +int ocfs2_sync_flags(struct inode *inode);
7085  
7086  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
7087  {
7088 diff -NurpP --minimal linux-2.6.25/fs/ocfs2/ioctl.c linux-2.6.25-vs2.3.0.34.9/fs/ocfs2/ioctl.c
7089 --- linux-2.6.25/fs/ocfs2/ioctl.c       2008-04-17 12:05:40.000000000 -0400
7090 +++ linux-2.6.25-vs2.3.0.34.9/fs/ocfs2/ioctl.c  2008-04-19 15:14:52.000000000 -0400
7091 @@ -41,7 +41,7 @@ static int ocfs2_get_inode_attr(struct i
7092         return status;
7093  }
7094  
7095 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
7096 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
7097                                 unsigned mask)
7098  {
7099         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
7100 diff -NurpP --minimal linux-2.6.25/fs/ocfs2/ioctl.h linux-2.6.25-vs2.3.0.34.9/fs/ocfs2/ioctl.h
7101 --- linux-2.6.25/fs/ocfs2/ioctl.h       2008-04-17 10:33:02.000000000 -0400
7102 +++ linux-2.6.25-vs2.3.0.34.9/fs/ocfs2/ioctl.h  2008-04-19 15:14:52.000000000 -0400
7103 @@ -10,6 +10,9 @@
7104  #ifndef OCFS2_IOCTL_H
7105  #define OCFS2_IOCTL_H
7106  
7107 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
7108 +                               unsigned mask);
7109 +
7110  int ocfs2_ioctl(struct inode * inode, struct file * filp,
7111         unsigned int cmd, unsigned long arg);
7112  long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg);
7113 diff -NurpP --minimal linux-2.6.25/fs/ocfs2/namei.c linux-2.6.25-vs2.3.0.34.9/fs/ocfs2/namei.c
7114 --- linux-2.6.25/fs/ocfs2/namei.c       2008-04-17 12:05:40.000000000 -0400
7115 +++ linux-2.6.25-vs2.3.0.34.9/fs/ocfs2/namei.c  2008-04-19 15:14:52.000000000 -0400
7116 @@ -40,6 +40,7 @@
7117  #include <linux/types.h>
7118  #include <linux/slab.h>
7119  #include <linux/highmem.h>
7120 +#include <linux/vs_tag.h>
7121  
7122  #define MLOG_MASK_PREFIX ML_NAMEI
7123  #include <cluster/masklog.h>
7124 @@ -366,6 +367,9 @@ static int ocfs2_mknod_locked(struct ocf
7125         u64 fe_blkno = 0;
7126         u16 suballoc_bit;
7127         struct inode *inode = NULL;
7128 +       uid_t uid;
7129 +       gid_t gid;
7130 +       tag_t tag;
7131  
7132         mlog_entry("(0x%p, 0x%p, %d, %lu, '%.*s')\n", dir, dentry, mode,
7133                    (unsigned long)dev, dentry->d_name.len,
7134 @@ -425,13 +429,19 @@ static int ocfs2_mknod_locked(struct ocf
7135         fe->i_blkno = cpu_to_le64(fe_blkno);
7136         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
7137         fe->i_suballoc_slot = cpu_to_le16(osb->slot_num);
7138 -       fe->i_uid = cpu_to_le32(current->fsuid);
7139 +
7140 +       tag = dx_current_fstag(osb->sb);
7141 +       uid = current->fsuid;
7142         if (dir->i_mode & S_ISGID) {
7143 -               fe->i_gid = cpu_to_le32(dir->i_gid);
7144 +               gid = dir->i_gid;
7145                 if (S_ISDIR(mode))
7146                         mode |= S_ISGID;
7147         } else
7148 -               fe->i_gid = cpu_to_le32(current->fsgid);
7149 +               gid = current->fsgid;
7150 +
7151 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), uid, tag));
7152 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), gid, tag));
7153 +       inode->i_tag = tag;
7154         fe->i_mode = cpu_to_le16(mode);
7155         if (S_ISCHR(mode) || S_ISBLK(mode))
7156                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
7157 @@ -1917,5 +1927,6 @@ const struct inode_operations ocfs2_dir_
7158         .rename         = ocfs2_rename,
7159         .setattr        = ocfs2_setattr,
7160         .getattr        = ocfs2_getattr,
7161 +       .sync_flags     = ocfs2_sync_flags,
7162         .permission     = ocfs2_permission,
7163  };
7164 diff -NurpP --minimal linux-2.6.25/fs/ocfs2/ocfs2_fs.h linux-2.6.25-vs2.3.0.34.9/fs/ocfs2/ocfs2_fs.h
7165 --- linux-2.6.25/fs/ocfs2/ocfs2_fs.h    2008-04-17 12:05:40.000000000 -0400
7166 +++ linux-2.6.25-vs2.3.0.34.9/fs/ocfs2/ocfs2_fs.h       2008-04-19 15:14:52.000000000 -0400
7167 @@ -188,8 +188,12 @@
7168  #define OCFS2_NOATIME_FL       (0x00000080)    /* do not update atime */
7169  #define OCFS2_DIRSYNC_FL       (0x00010000)    /* dirsync behaviour (directories only) */
7170  
7171 +#define OCFS2_BARRIER_FL       (0x04000000)    /* Barrier for chroot() */
7172 +#define OCFS2_IUNLINK_FL       (0x08000000)    /* Immutable unlink */
7173 +
7174  #define OCFS2_FL_VISIBLE       (0x000100FF)    /* User visible flags */
7175  #define OCFS2_FL_MODIFIABLE    (0x000100FF)    /* User modifiable flags */
7176 +#define OCFS2_FL_MASK          (0x0F0100FF)
7177  
7178  /*
7179   * Extent record flags (e_node.leaf.flags)
7180 diff -NurpP --minimal linux-2.6.25/fs/ocfs2/ocfs2.h linux-2.6.25-vs2.3.0.34.9/fs/ocfs2/ocfs2.h
7181 --- linux-2.6.25/fs/ocfs2/ocfs2.h       2008-04-17 12:05:40.000000000 -0400
7182 +++ linux-2.6.25-vs2.3.0.34.9/fs/ocfs2/ocfs2.h  2008-04-21 10:15:31.000000000 -0400
7183 @@ -171,6 +171,7 @@ enum ocfs2_mount_options
7184         OCFS2_MOUNT_ERRORS_PANIC = 1 << 3, /* Panic on errors */
7185         OCFS2_MOUNT_DATA_WRITEBACK = 1 << 4, /* No data ordering */
7186         OCFS2_MOUNT_LOCALFLOCKS = 1 << 5, /* No cluster aware user file locks */
7187 +       OCFS2_MOUNT_TAGGED = 1 << 8, /* use tagging */
7188  };
7189  
7190  #define OCFS2_OSB_SOFT_RO      0x0001
7191 diff -NurpP --minimal linux-2.6.25/fs/ocfs2/super.c linux-2.6.25-vs2.3.0.34.9/fs/ocfs2/super.c
7192 --- linux-2.6.25/fs/ocfs2/super.c       2008-04-17 12:05:40.000000000 -0400
7193 +++ linux-2.6.25-vs2.3.0.34.9/fs/ocfs2/super.c  2008-04-23 08:31:10.000000000 -0400
7194 @@ -154,6 +154,7 @@ enum {
7195         Opt_commit,
7196         Opt_localalloc,
7197         Opt_localflocks,
7198 +       Opt_tag, Opt_notag, Opt_tagid,
7199         Opt_err,
7200  };
7201  
7202 @@ -172,6 +173,9 @@ static match_table_t tokens = {
7203         {Opt_commit, "commit=%u"},
7204         {Opt_localalloc, "localalloc=%d"},
7205         {Opt_localflocks, "localflocks"},
7206 +       {Opt_tag, "tag"},
7207 +       {Opt_notag, "notag"},
7208 +       {Opt_tagid, "tagid=%u"},
7209         {Opt_err, NULL}
7210  };
7211  
7212 @@ -391,6 +395,13 @@ static int ocfs2_remount(struct super_bl
7213                 goto out;
7214         }
7215  
7216 +       if ((parsed_options.mount_opt & OCFS2_MOUNT_TAGGED) &&
7217 +               !(sb->s_flags & MS_TAGGED)) {
7218 +               ret = -EINVAL;
7219 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
7220 +               goto out;
7221 +       }
7222 +
7223         if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
7224             (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
7225                 ret = -EINVAL;
7226 @@ -691,6 +702,9 @@ static int ocfs2_fill_super(struct super
7227  
7228         ocfs2_complete_mount_recovery(osb);
7229  
7230 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
7231 +               sb->s_flags |= MS_TAGGED;
7232 +
7233         if (ocfs2_mount_local(osb))
7234                 snprintf(nodestr, sizeof(nodestr), "local");
7235         else
7236 @@ -864,6 +878,20 @@ static int ocfs2_parse_options(struct su
7237                         if (!is_remount)
7238                                 mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS;
7239                         break;
7240 +#ifndef CONFIG_TAGGING_NONE
7241 +               case Opt_tag:
7242 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
7243 +                       break;
7244 +               case Opt_notag:
7245 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
7246 +                       break;
7247 +#endif
7248 +#ifdef CONFIG_PROPAGATE
7249 +               case Opt_tagid:
7250 +                       /* use args[0] */
7251 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
7252 +                       break;
7253 +#endif
7254                 default:
7255                         mlog(ML_ERROR,
7256                              "Unrecognized mount option \"%s\" "
7257 diff -NurpP --minimal linux-2.6.25/fs/open.c linux-2.6.25-vs2.3.0.34.9/fs/open.c
7258 --- linux-2.6.25/fs/open.c      2008-04-17 12:05:41.000000000 -0400
7259 +++ linux-2.6.25-vs2.3.0.34.9/fs/open.c 2008-04-21 13:51:52.000000000 -0400
7260 @@ -27,22 +27,31 @@
7261  #include <linux/rcupdate.h>
7262  #include <linux/audit.h>
7263  #include <linux/falloc.h>
7264 +#include <linux/vs_base.h>
7265 +#include <linux/vs_limit.h>
7266 +#include <linux/vs_dlimit.h>
7267 +#include <linux/vs_tag.h>
7268 +#include <linux/vs_cowbl.h>
7269  
7270  int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
7271  {
7272         int retval = -ENODEV;
7273  
7274         if (dentry) {
7275 +               struct super_block *sb = dentry->d_sb;
7276 +
7277                 retval = -ENOSYS;
7278 -               if (dentry->d_sb->s_op->statfs) {
7279 +               if (sb->s_op->statfs) {
7280                         memset(buf, 0, sizeof(*buf));
7281                         retval = security_sb_statfs(dentry);
7282                         if (retval)
7283                                 return retval;
7284 -                       retval = dentry->d_sb->s_op->statfs(dentry, buf);
7285 +                       retval = sb->s_op->statfs(dentry, buf);
7286                         if (retval == 0 && buf->f_frsize == 0)
7287                                 buf->f_frsize = buf->f_bsize;
7288                 }
7289 +               if (!vx_check(0, VS_ADMIN|VS_WATCH))
7290 +                       vx_vsi_statfs(sb, buf);
7291         }
7292         return retval;
7293  }
7294 @@ -249,7 +258,7 @@ static long do_sys_truncate(const char _
7295                 goto dput_and_out;
7296  
7297         error = -EROFS;
7298 -       if (IS_RDONLY(inode))
7299 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(nd.path.mnt))
7300                 goto dput_and_out;
7301  
7302         error = -EPERM;
7303 @@ -458,7 +467,7 @@ asmlinkage long sys_faccessat(int dfd, c
7304            special_file(nd.path.dentry->d_inode->i_mode))
7305                 goto out_path_release;
7306  
7307 -       if(IS_RDONLY(nd.path.dentry->d_inode))
7308 +       if(IS_RDONLY(nd.path.dentry->d_inode) || MNT_IS_RDONLY(nd.path.mnt))
7309                 res = -EROFS;
7310  
7311  out_path_release:
7312 @@ -568,7 +577,7 @@ asmlinkage long sys_fchmod(unsigned int 
7313         audit_inode(NULL, dentry);
7314  
7315         err = -EROFS;
7316 -       if (IS_RDONLY(inode))
7317 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(file->f_vfsmnt))
7318                 goto out_putf;
7319         err = -EPERM;
7320         if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
7321 @@ -598,11 +607,11 @@ asmlinkage long sys_fchmodat(int dfd, co
7322         error = __user_walk_fd(dfd, filename, LOOKUP_FOLLOW, &nd);
7323         if (error)
7324                 goto out;
7325 -       inode = nd.path.dentry->d_inode;
7326 -
7327 -       error = -EROFS;
7328 -       if (IS_RDONLY(inode))
7329 +
7330 +       error = cow_check_and_break(&nd);
7331 +       if (error)
7332                 goto dput_and_out;
7333 +       inode = nd.path.dentry->d_inode;
7334  
7335         error = -EPERM;
7336         if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
7337 @@ -627,7 +636,8 @@ asmlinkage long sys_chmod(const char __u
7338         return sys_fchmodat(AT_FDCWD, filename, mode);
7339  }
7340  
7341 -static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
7342 +static int chown_common(struct dentry *dentry, struct vfsmount *mnt,
7343 +       uid_t user, gid_t group)
7344  {
7345         struct inode * inode;
7346         int error;
7347 @@ -639,7 +649,7 @@ static int chown_common(struct dentry * 
7348                 goto out;
7349         }
7350         error = -EROFS;
7351 -       if (IS_RDONLY(inode))
7352 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(mnt))
7353                 goto out;
7354         error = -EPERM;
7355         if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
7356 @@ -647,11 +657,11 @@ static int chown_common(struct dentry * 
7357         newattrs.ia_valid =  ATTR_CTIME;
7358         if (user != (uid_t) -1) {
7359                 newattrs.ia_valid |= ATTR_UID;
7360 -               newattrs.ia_uid = user;
7361 +               newattrs.ia_uid = dx_map_uid(user);
7362         }
7363         if (group != (gid_t) -1) {
7364                 newattrs.ia_valid |= ATTR_GID;
7365 -               newattrs.ia_gid = group;
7366 +               newattrs.ia_gid = dx_map_gid(group);
7367         }
7368         if (!S_ISDIR(inode->i_mode))
7369                 newattrs.ia_valid |=
7370 @@ -671,7 +681,11 @@ asmlinkage long sys_chown(const char __u
7371         error = user_path_walk(filename, &nd);
7372         if (error)
7373                 goto out;
7374 -       error = chown_common(nd.path.dentry, user, group);
7375 +#ifdef CONFIG_VSERVER_COWBL
7376 +       error = cow_check_and_break(&nd);
7377 +       if (!error)
7378 +#endif
7379 +               error = chown_common(nd.path.dentry, nd.path.mnt, user, group);
7380         path_put(&nd.path);
7381  out:
7382         return error;
7383 @@ -691,7 +705,11 @@ asmlinkage long sys_fchownat(int dfd, co
7384         error = __user_walk_fd(dfd, filename, follow, &nd);
7385         if (error)
7386                 goto out;
7387 -       error = chown_common(nd.path.dentry, user, group);
7388 +#ifdef CONFIG_VSERVER_COWBL
7389 +       error = cow_check_and_break(&nd);
7390 +       if (!error)
7391 +#endif
7392 +               error = chown_common(nd.path.dentry, nd.path.mnt, user, group);
7393         path_put(&nd.path);
7394  out:
7395         return error;
7396 @@ -705,7 +723,11 @@ asmlinkage long sys_lchown(const char __
7397         error = user_path_walk_link(filename, &nd);
7398         if (error)
7399                 goto out;
7400 -       error = chown_common(nd.path.dentry, user, group);
7401 +#ifdef CONFIG_VSERVER_COWBL
7402 +       error = cow_check_and_break(&nd);
7403 +       if (!error)
7404 +#endif
7405 +               error = chown_common(nd.path.dentry, nd.path.mnt, user, group);
7406         path_put(&nd.path);
7407  out:
7408         return error;
7409 @@ -724,7 +746,7 @@ asmlinkage long sys_fchown(unsigned int 
7410  
7411         dentry = file->f_path.dentry;
7412         audit_inode(NULL, dentry);
7413 -       error = chown_common(dentry, user, group);
7414 +       error = chown_common(dentry, file->f_vfsmnt, user, group);
7415         fput(file);
7416  out:
7417         return error;
7418 @@ -971,6 +993,7 @@ repeat:
7419         else
7420                 FD_CLR(fd, fdt->close_on_exec);
7421         files->next_fd = fd + 1;
7422 +       vx_openfd_inc(fd);
7423  #if 1
7424         /* Sanity check */
7425         if (fdt->fd[fd] != NULL) {
7426 @@ -998,6 +1021,7 @@ static void __put_unused_fd(struct files
7427         __FD_CLR(fd, fdt->open_fds);
7428         if (fd < files->next_fd)
7429                 files->next_fd = fd;
7430 +       vx_openfd_dec(fd);
7431  }
7432  
7433  void put_unused_fd(unsigned int fd)
7434 diff -NurpP --minimal linux-2.6.25/fs/proc/array.c linux-2.6.25-vs2.3.0.34.9/fs/proc/array.c
7435 --- linux-2.6.25/fs/proc/array.c        2008-04-17 12:05:41.000000000 -0400
7436 +++ linux-2.6.25-vs2.3.0.34.9/fs/proc/array.c   2008-04-22 18:22:56.000000000 -0400
7437 @@ -79,6 +79,8 @@
7438  #include <linux/delayacct.h>
7439  #include <linux/seq_file.h>
7440  #include <linux/pid_namespace.h>
7441 +#include <linux/vs_context.h>
7442 +#include <linux/vs_network.h>
7443  
7444  #include <asm/pgtable.h>
7445  #include <asm/processor.h>
7446 @@ -140,8 +142,9 @@ static const char *task_state_array[] = 
7447         "D (disk sleep)",       /*  2 */
7448         "T (stopped)",          /*  4 */
7449         "T (tracing stop)",     /*  8 */
7450 -       "Z (zombie)",           /* 16 */
7451 -       "X (dead)"              /* 32 */
7452 +       "H (on hold)",          /* 16 */
7453 +       "Z (zombie)",           /* 32 */
7454 +       "X (dead)",             /* 64 */
7455  };
7456  
7457  static inline const char *get_task_state(struct task_struct *tsk)
7458 @@ -162,6 +165,7 @@ static inline void task_state(struct seq
7459         struct group_info *group_info;
7460         int g;
7461         struct fdtable *fdt = NULL;
7462 +/* +   pid_t pid, ptgid, tppid, tgid; */
7463         pid_t ppid, tpid;
7464  
7465         rcu_read_lock();
7466 @@ -169,6 +173,12 @@ static inline void task_state(struct seq
7467                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
7468         tpid = pid_alive(p) && p->ptrace ?
7469                 task_pid_nr_ns(rcu_dereference(p->parent), ns) : 0;
7470 +/*     tgid = vx_map_tgid(p->tgid);
7471 +       pid = vx_map_pid(p->pid);
7472 +       ptgid = vx_map_pid(pid_alive(p) ?
7473 +               rcu_dereference(p->real_parent)->tgid : 0);
7474 +       tppid = vx_map_pid(pid_alive(p) && p->ptrace ?
7475 +               rcu_dereference(p->parent)->pid : 0); */
7476         seq_printf(m,
7477                 "State:\t%s\n"
7478                 "Tgid:\t%d\n"
7479 @@ -280,23 +290,23 @@ static inline void task_sig(struct seq_f
7480  }
7481  
7482  static void render_cap_t(struct seq_file *m, const char *header,
7483 -                       kernel_cap_t *a)
7484 +                       struct vx_info *vxi, kernel_cap_t *a)
7485  {
7486         unsigned __capi;
7487  
7488         seq_printf(m, "%s", header);
7489         CAP_FOR_EACH_U32(__capi) {
7490                 seq_printf(m, "%08x",
7491 -                          a->cap[(_LINUX_CAPABILITY_U32S-1) - __capi]);
7492 +                       a->cap[(_LINUX_CAPABILITY_U32S-1) - __capi]);
7493         }
7494         seq_printf(m, "\n");
7495  }
7496  
7497  static inline void task_cap(struct seq_file *m, struct task_struct *p)
7498  {
7499 -       render_cap_t(m, "CapInh:\t", &p->cap_inheritable);
7500 -       render_cap_t(m, "CapPrm:\t", &p->cap_permitted);
7501 -       render_cap_t(m, "CapEff:\t", &p->cap_effective);
7502 +       render_cap_t(m, "CapInh:\t", p->vx_info, &p->cap_inheritable);
7503 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &p->cap_permitted);
7504 +       render_cap_t(m, "CapEff:\t", p->vx_info, &p->cap_effective);
7505  }
7506  
7507  static inline void task_context_switch_counts(struct seq_file *m,
7508 @@ -308,6 +318,45 @@ static inline void task_context_switch_c
7509                         p->nivcsw);
7510  }
7511  
7512 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
7513 +                       struct pid *pid, struct task_struct *task)
7514 +{
7515 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
7516 +                       "Count:\t%u\n"
7517 +                       "uts:\t%p(%c)\n"
7518 +                       "ipc:\t%p(%c)\n"
7519 +                       "mnt:\t%p(%c)\n"
7520 +                       "pid:\t%p(%c)\n"
7521 +                       "user:\t%p(%c)\n"
7522 +                       "net:\t%p(%c)\n",
7523 +                       task->nsproxy,
7524 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
7525 +                       atomic_read(&task->nsproxy->count),
7526 +                       task->nsproxy->uts_ns,
7527 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
7528 +                       task->nsproxy->ipc_ns,
7529 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
7530 +                       task->nsproxy->mnt_ns,
7531 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
7532 +                       task->nsproxy->pid_ns,
7533 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
7534 +                       task->nsproxy->user_ns,
7535 +                       (task->nsproxy->user_ns == init_task.nsproxy->user_ns ? 'I' : '-'),
7536 +                       task->nsproxy->net_ns,
7537 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
7538 +       return 0;
7539 +}
7540 +
7541 +void task_vs_id(struct seq_file *m, struct task_struct *task)
7542 +{
7543 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
7544 +               return;
7545 +
7546 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
7547 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
7548 +}
7549 +
7550 +
7551  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
7552                         struct pid *pid, struct task_struct *task)
7553  {
7554 @@ -323,6 +372,7 @@ int proc_pid_status(struct seq_file *m, 
7555         task_sig(m, task);
7556         task_cap(m, task);
7557         cpuset_task_status_allowed(m, task);
7558 +       task_vs_id(m, task);
7559  #if defined(CONFIG_S390)
7560         task_show_regs(m, task);
7561  #endif
7562 @@ -494,6 +544,17 @@ static int do_task_stat(struct seq_file 
7563         /* convert nsec -> ticks */
7564         start_time = nsec_to_clock_t(start_time);
7565  
7566 +       /* fixup start time for virt uptime */
7567 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
7568 +               unsigned long long bias =
7569 +                       current->vx_info->cvirt.bias_clock;
7570 +
7571 +               if (start_time > bias)
7572 +                       start_time -= bias;
7573 +               else
7574 +                       start_time = 0;
7575 +       }
7576 +
7577         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
7578  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
7579  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
7580 diff -NurpP --minimal linux-2.6.25/fs/proc/base.c linux-2.6.25-vs2.3.0.34.9/fs/proc/base.c
7581 --- linux-2.6.25/fs/proc/base.c 2008-04-17 12:05:41.000000000 -0400
7582 +++ linux-2.6.25-vs2.3.0.34.9/fs/proc/base.c    2008-04-29 17:56:00.000000000 -0400
7583 @@ -76,6 +76,8 @@
7584  #include <linux/oom.h>
7585  #include <linux/elf.h>
7586  #include <linux/pid_namespace.h>
7587 +#include <linux/vs_context.h>
7588 +#include <linux/vs_network.h>
7589  #include "internal.h"
7590  
7591  /* NOTE:
7592 @@ -1290,6 +1292,8 @@ static struct inode *proc_pid_make_inode
7593                 inode->i_uid = task->euid;
7594                 inode->i_gid = task->egid;
7595         }
7596 +       /* procfs is xid tagged */
7597 +       inode->i_tag = (tag_t)vx_task_xid(task);
7598         security_task_to_inode(task, inode);
7599  
7600  out:
7601 @@ -1833,6 +1837,13 @@ static struct dentry *proc_pident_lookup
7602         if (!task)
7603                 goto out_no_task;
7604  
7605 +       /* TODO: maybe we can come up with a generic approach? */
7606 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
7607 +               (dentry->d_name.len == 5) &&
7608 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
7609 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
7610 +               goto out;
7611 +
7612         /*
7613          * Yes, it does not scale. And it should not. Don't add
7614          * new entries into /proc/<tgid>/ without very good reasons.
7615 @@ -2220,7 +2231,7 @@ out_iput:
7616  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
7617  {
7618         struct dentry *error;
7619 -       struct task_struct *task = get_proc_task(dir);
7620 +       struct task_struct *task = get_proc_task_real(dir);
7621         const struct pid_entry *p, *last;
7622  
7623         error = ERR_PTR(-ENOENT);
7624 @@ -2285,6 +2296,9 @@ static int proc_pid_io_accounting(struct
7625  static const struct file_operations proc_task_operations;
7626  static const struct inode_operations proc_task_inode_operations;
7627  
7628 +extern int proc_pid_vx_info(struct task_struct *, char *);
7629 +extern int proc_pid_nx_info(struct task_struct *, char *);
7630 +
7631  static const struct pid_entry tgid_base_stuff[] = {
7632         DIR("task",       S_IRUGO|S_IXUGO, task),
7633         DIR("fd",         S_IRUSR|S_IXUSR, fd),
7634 @@ -2335,6 +2349,8 @@ static const struct pid_entry tgid_base_
7635  #ifdef CONFIG_CGROUPS
7636         REG("cgroup",  S_IRUGO, cgroup),
7637  #endif
7638 +       INF("vinfo",      S_IRUGO, pid_vx_info),
7639 +       INF("ninfo",      S_IRUGO, pid_nx_info),
7640         INF("oom_score",  S_IRUGO, oom_score),
7641         REG("oom_adj",    S_IRUGO|S_IWUSR, oom_adjust),
7642  #ifdef CONFIG_AUDITSYSCALL
7643 @@ -2350,6 +2366,7 @@ static const struct pid_entry tgid_base_
7644  #ifdef CONFIG_TASK_IO_ACCOUNTING
7645         INF("io",       S_IRUGO, pid_io_accounting),
7646  #endif
7647 +       ONE("nsproxy",  S_IRUGO, pid_nsproxy),
7648  };
7649  
7650  static int proc_tgid_base_readdir(struct file * filp,
7651 @@ -2547,7 +2564,7 @@ retry:
7652         iter.task = NULL;
7653         pid = find_ge_pid(iter.tgid, ns);
7654         if (pid) {
7655 -               iter.tgid = pid_nr_ns(pid, ns);
7656 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
7657                 iter.task = pid_task(pid, PIDTYPE_PID);
7658                 /* What we to know is if the pid we have find is the
7659                  * pid of a thread_group_leader.  Testing for task
7660 @@ -2577,7 +2594,7 @@ static int proc_pid_fill_cache(struct fi
7661         struct tgid_iter iter)
7662  {
7663         char name[PROC_NUMBUF];
7664 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
7665 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
7666         return proc_fill_cache(filp, dirent, filldir, name, len,
7667                                 proc_pid_instantiate, iter.task, NULL);
7668  }
7669 @@ -2586,7 +2603,7 @@ static int proc_pid_fill_cache(struct fi
7670  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
7671  {
7672         unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
7673 -       struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
7674 +       struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
7675         struct tgid_iter iter;
7676         struct pid_namespace *ns;
7677  
7678 @@ -2606,6 +2623,8 @@ int proc_pid_readdir(struct file * filp,
7679              iter.task;
7680              iter.tgid += 1, iter = next_tgid(ns, iter)) {
7681                 filp->f_pos = iter.tgid + TGID_OFFSET;
7682 +               if (!vx_proc_task_visible(iter.task))
7683 +                       continue;
7684                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
7685                         put_task_struct(iter.task);
7686                         goto out;
7687 @@ -2742,6 +2761,8 @@ static struct dentry *proc_task_lookup(s
7688         tid = name_to_int(dentry);
7689         if (tid == ~0U)
7690                 goto out;
7691 +       if (vx_current_initpid(tid))
7692 +               goto out;
7693  
7694         ns = dentry->d_sb->s_fs_info;
7695         rcu_read_lock();
7696 diff -NurpP --minimal linux-2.6.25/fs/proc/generic.c linux-2.6.25-vs2.3.0.34.9/fs/proc/generic.c
7697 --- linux-2.6.25/fs/proc/generic.c      2008-04-17 12:05:41.000000000 -0400
7698 +++ linux-2.6.25-vs2.3.0.34.9/fs/proc/generic.c 2008-04-20 14:23:26.000000000 -0400
7699 @@ -21,6 +21,7 @@
7700  #include <linux/bitops.h>
7701  #include <linux/spinlock.h>
7702  #include <linux/completion.h>
7703 +#include <linux/vserver/inode.h>
7704  #include <asm/uaccess.h>
7705  
7706  #include "internal.h"
7707 @@ -389,6 +390,8 @@ struct dentry *proc_lookup_de(struct pro
7708                 for (de = de->subdir; de ; de = de->next) {
7709                         if (de->namelen != dentry->d_name.len)
7710                                 continue;
7711 +                       if (!vx_hide_check(0, de->vx_flags))
7712 +                               continue;
7713                         if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
7714                                 unsigned int ino;
7715  
7716 @@ -397,6 +400,8 @@ struct dentry *proc_lookup_de(struct pro
7717                                 spin_unlock(&proc_subdir_lock);
7718                                 error = -EINVAL;
7719                                 inode = proc_get_inode(dir->i_sb, ino, de);
7720 +                               /* generic proc entries belong to the host */
7721 +                               inode->i_tag = 0;
7722                                 goto out_unlock;
7723                         }
7724                 }
7725 @@ -481,6 +486,8 @@ int proc_readdir_de(struct proc_dir_entr
7726  
7727                                 /* filldir passes info to user space */
7728                                 de_get(de);
7729 +                               if (!vx_hide_check(0, de->vx_flags))
7730 +                                       goto skip;
7731                                 spin_unlock(&proc_subdir_lock);
7732                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
7733                                             de->low_ino, de->mode >> 12) < 0) {
7734 @@ -488,6 +495,7 @@ int proc_readdir_de(struct proc_dir_entr
7735                                         goto out;
7736                                 }
7737                                 spin_lock(&proc_subdir_lock);
7738 +                       skip:
7739                                 filp->f_pos++;
7740                                 next = de->next;
7741                                 de_put(de);
7742 @@ -602,6 +610,7 @@ static struct proc_dir_entry *__proc_cre
7743         ent->nlink = nlink;
7744         atomic_set(&ent->count, 1);
7745         ent->pde_users = 0;
7746 +       ent->vx_flags = IATTR_PROC_DEFAULT;
7747         spin_lock_init(&ent->pde_unload_lock);
7748         ent->pde_unload_completion = NULL;
7749   out:
7750 @@ -624,7 +633,8 @@ struct proc_dir_entry *proc_symlink(cons
7751                                 kfree(ent->data);
7752                                 kfree(ent);
7753                                 ent = NULL;
7754 -                       }
7755 +                       } else
7756 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
7757                 } else {
7758                         kfree(ent);
7759                         ent = NULL;
7760 diff -NurpP --minimal linux-2.6.25/fs/proc/inode.c linux-2.6.25-vs2.3.0.34.9/fs/proc/inode.c
7761 --- linux-2.6.25/fs/proc/inode.c        2008-04-17 12:05:41.000000000 -0400
7762 +++ linux-2.6.25-vs2.3.0.34.9/fs/proc/inode.c   2008-04-19 15:14:52.000000000 -0400
7763 @@ -408,6 +408,8 @@ struct inode *proc_get_inode(struct supe
7764                                 inode->i_uid = de->uid;
7765                                 inode->i_gid = de->gid;
7766                         }
7767 +               if (de->vx_flags)
7768 +                       PROC_I(inode)->vx_flags = de->vx_flags;
7769                         if (de->size)
7770                                 inode->i_size = de->size;
7771                         if (de->nlink)
7772 diff -NurpP --minimal linux-2.6.25/fs/proc/internal.h linux-2.6.25-vs2.3.0.34.9/fs/proc/internal.h
7773 --- linux-2.6.25/fs/proc/internal.h     2008-04-17 12:05:41.000000000 -0400
7774 +++ linux-2.6.25-vs2.3.0.34.9/fs/proc/internal.h        2008-04-20 14:21:17.000000000 -0400
7775 @@ -10,6 +10,7 @@
7776   */
7777  
7778  #include <linux/proc_fs.h>
7779 +#include <linux/vs_pid.h>
7780  
7781  #ifdef CONFIG_PROC_SYSCTL
7782  extern int proc_sys_init(void);
7783 @@ -57,6 +58,9 @@ extern int proc_pid_status(struct seq_fi
7784                                 struct pid *pid, struct task_struct *task);
7785  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
7786                                 struct pid *pid, struct task_struct *task);
7787 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
7788 +                               struct pid *pid, struct task_struct *task);
7789 +
7790  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
7791  
7792  extern const struct file_operations proc_maps_operations;
7793 @@ -76,11 +80,16 @@ static inline struct pid *proc_pid(struc
7794         return PROC_I(inode)->pid;
7795  }
7796  
7797 -static inline struct task_struct *get_proc_task(struct inode *inode)
7798 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
7799  {
7800         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
7801  }
7802  
7803 +static inline struct task_struct *get_proc_task(struct inode *inode)
7804 +{
7805 +       return vx_get_proc_task(inode, proc_pid(inode));
7806 +}
7807 +
7808  static inline int proc_fd(struct inode *inode)
7809  {
7810         return PROC_I(inode)->fd;
7811 diff -NurpP --minimal linux-2.6.25/fs/proc/proc_misc.c linux-2.6.25-vs2.3.0.34.9/fs/proc/proc_misc.c
7812 --- linux-2.6.25/fs/proc/proc_misc.c    2008-04-17 12:05:41.000000000 -0400
7813 +++ linux-2.6.25-vs2.3.0.34.9/fs/proc/proc_misc.c       2008-04-23 11:56:24.000000000 -0400
7814 @@ -56,6 +56,8 @@
7815  #include <asm/div64.h>
7816  #include "internal.h"
7817  
7818 +#include <linux/vs_cvirt.h>
7819 +
7820  #define LOAD_INT(x) ((x) >> FSHIFT)
7821  #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
7822  /*
7823 @@ -83,22 +85,38 @@ static int proc_calc_metrics(char *page,
7824  static int loadavg_read_proc(char *page, char **start, off_t off,
7825                                  int count, int *eof, void *data)
7826  {
7827 +       unsigned long running;
7828 +       unsigned int threads;
7829         int a, b, c;
7830         int len;
7831         unsigned long seq;
7832  
7833         do {
7834                 seq = read_seqbegin(&xtime_lock);
7835 -               a = avenrun[0] + (FIXED_1/200);
7836 -               b = avenrun[1] + (FIXED_1/200);
7837 -               c = avenrun[2] + (FIXED_1/200);
7838 +               if (vx_flags(VXF_VIRT_LOAD, 0)) {
7839 +                       struct vx_info *vxi = current->vx_info;
7840 +
7841 +                       a = vxi->cvirt.load[0] + (FIXED_1/200);
7842 +                       b = vxi->cvirt.load[1] + (FIXED_1/200);
7843 +                       c = vxi->cvirt.load[2] + (FIXED_1/200);
7844 +
7845 +                       running = atomic_read(&vxi->cvirt.nr_running);
7846 +                       threads = atomic_read(&vxi->cvirt.nr_threads);
7847 +               } else {
7848 +                       a = avenrun[0] + (FIXED_1/200);
7849 +                       b = avenrun[1] + (FIXED_1/200);
7850 +                       c = avenrun[2] + (FIXED_1/200);
7851 +
7852 +                       running = nr_running();
7853 +                       threads = nr_threads;
7854 +               }
7855         } while (read_seqretry(&xtime_lock, seq));
7856  
7857         len = sprintf(page,"%d.%02d %d.%02d %d.%02d %ld/%d %d\n",
7858                 LOAD_INT(a), LOAD_FRAC(a),
7859                 LOAD_INT(b), LOAD_FRAC(b),
7860                 LOAD_INT(c), LOAD_FRAC(c),
7861 -               nr_running(), nr_threads,
7862 +               running, threads,
7863                 task_active_pid_ns(current)->last_pid);
7864         return proc_calc_metrics(page, start, off, count, eof, len);
7865  }
7866 @@ -114,6 +132,9 @@ static int uptime_read_proc(char *page, 
7867         do_posix_clock_monotonic_gettime(&uptime);
7868         monotonic_to_bootbased(&uptime);
7869         cputime_to_timespec(idletime, &idle);
7870 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
7871 +               vx_vsi_uptime(&uptime, &idle);
7872 +
7873         len = sprintf(page,"%lu.%02lu %lu.%02lu\n",
7874                         (unsigned long) uptime.tv_sec,
7875                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
7876 @@ -145,7 +166,7 @@ static int meminfo_read_proc(char *page,
7877  
7878         cached = global_page_state(NR_FILE_PAGES) -
7879                         total_swapcache_pages - i.bufferram;
7880 -       if (cached < 0)
7881 +       if (cached < 0 || vx_flags(VXF_VIRT_MEM, 0))
7882                 cached = 0;
7883  
7884         get_vmalloc_info(&vmi);
7885 diff -NurpP --minimal linux-2.6.25/fs/proc/root.c linux-2.6.25-vs2.3.0.34.9/fs/proc/root.c
7886 --- linux-2.6.25/fs/proc/root.c 2008-04-17 12:05:41.000000000 -0400
7887 +++ linux-2.6.25-vs2.3.0.34.9/fs/proc/root.c    2008-04-19 15:14:52.000000000 -0400
7888 @@ -23,6 +23,9 @@
7889  #include "internal.h"
7890  
7891  struct proc_dir_entry *proc_bus, *proc_root_fs, *proc_root_driver;
7892 +struct proc_dir_entry *proc_virtual;
7893 +
7894 +extern void proc_vx_init(void);
7895  
7896  static int proc_test_super(struct super_block *sb, void *data)
7897  {
7898 @@ -138,6 +141,7 @@ void __init proc_root_init(void)
7899         proc_device_tree_init();
7900  #endif
7901         proc_bus = proc_mkdir("bus", NULL);
7902 +       proc_vx_init();
7903         proc_sys_init();
7904  }
7905  
7906 diff -NurpP --minimal linux-2.6.25/fs/quota.c linux-2.6.25-vs2.3.0.34.9/fs/quota.c
7907 --- linux-2.6.25/fs/quota.c     2008-04-17 12:05:41.000000000 -0400
7908 +++ linux-2.6.25-vs2.3.0.34.9/fs/quota.c        2008-04-21 09:21:04.000000000 -0400
7909 @@ -18,6 +18,7 @@
7910  #include <linux/capability.h>
7911  #include <linux/quotaops.h>
7912  #include <linux/types.h>
7913 +#include <linux/vs_context.h>
7914  
7915  /* Check validity of generic quotactl commands */
7916  static int generic_quotactl_valid(struct super_block *sb, int type, int cmd, qid_t id)
7917 @@ -82,11 +83,11 @@ static int generic_quotactl_valid(struct
7918         if (cmd == Q_GETQUOTA) {
7919                 if (((type == USRQUOTA && current->euid != id) ||
7920                      (type == GRPQUOTA && !in_egroup_p(id))) &&
7921 -                   !capable(CAP_SYS_ADMIN))
7922 +                   !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7923                         return -EPERM;
7924         }
7925         else if (cmd != Q_GETFMT && cmd != Q_SYNC && cmd != Q_GETINFO)
7926 -               if (!capable(CAP_SYS_ADMIN))
7927 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7928                         return -EPERM;
7929  
7930         return 0;
7931 @@ -133,10 +134,10 @@ static int xqm_quotactl_valid(struct sup
7932         if (cmd == Q_XGETQUOTA) {
7933                 if (((type == XQM_USRQUOTA && current->euid != id) ||
7934                      (type == XQM_GRPQUOTA && !in_egroup_p(id))) &&
7935 -                    !capable(CAP_SYS_ADMIN))
7936 +                    !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7937                         return -EPERM;
7938         } else if (cmd != Q_XGETQSTAT && cmd != Q_XQUOTASYNC) {
7939 -               if (!capable(CAP_SYS_ADMIN))
7940 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7941                         return -EPERM;
7942         }
7943  
7944 @@ -329,6 +330,46 @@ static int do_quotactl(struct super_bloc
7945         return 0;
7946  }
7947  
7948 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7949 +
7950 +#include <linux/vroot.h>
7951 +#include <linux/major.h>
7952 +#include <linux/module.h>
7953 +#include <linux/kallsyms.h>
7954 +#include <linux/vserver/debug.h>
7955 +
7956 +static vroot_grb_func *vroot_get_real_bdev = NULL;
7957 +
7958 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
7959 +
7960 +int register_vroot_grb(vroot_grb_func *func) {
7961 +       int ret = -EBUSY;
7962 +
7963 +       spin_lock(&vroot_grb_lock);
7964 +       if (!vroot_get_real_bdev) {
7965 +               vroot_get_real_bdev = func;
7966 +               ret = 0;
7967 +       }
7968 +       spin_unlock(&vroot_grb_lock);
7969 +       return ret;
7970 +}
7971 +EXPORT_SYMBOL(register_vroot_grb);
7972 +
7973 +int unregister_vroot_grb(vroot_grb_func *func) {
7974 +       int ret = -EINVAL;
7975 +
7976 +       spin_lock(&vroot_grb_lock);
7977 +       if (vroot_get_real_bdev) {
7978 +               vroot_get_real_bdev = NULL;
7979 +               ret = 0;
7980 +       }
7981 +       spin_unlock(&vroot_grb_lock);
7982 +       return ret;
7983 +}
7984 +EXPORT_SYMBOL(unregister_vroot_grb);
7985 +
7986 +#endif
7987 +
7988  /*
7989   * look up a superblock on which quota ops will be performed
7990   * - use the name of a block device to find the superblock thereon
7991 @@ -346,6 +387,22 @@ static inline struct super_block *quotac
7992         putname(tmp);
7993         if (IS_ERR(bdev))
7994                 return ERR_CAST(bdev);
7995 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7996 +       if (bdev && bdev->bd_inode &&
7997 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
7998 +               struct block_device *bdnew = (void *)-EINVAL;
7999 +
8000 +               if (vroot_get_real_bdev)
8001 +                       bdnew = vroot_get_real_bdev(bdev);
8002 +               else
8003 +                       vxdprintk(VXD_CBIT(misc, 0),
8004 +                                       "vroot_get_real_bdev not set");
8005 +               bdput(bdev);
8006 +               if (IS_ERR(bdnew))
8007 +                       return ERR_PTR(PTR_ERR(bdnew));
8008 +               bdev = bdnew;
8009 +       }
8010 +#endif
8011         sb = get_super(bdev);
8012         bdput(bdev);
8013         if (!sb)
8014 diff -NurpP --minimal linux-2.6.25/fs/reiserfs/bitmap.c linux-2.6.25-vs2.3.0.34.9/fs/reiserfs/bitmap.c
8015 --- linux-2.6.25/fs/reiserfs/bitmap.c   2008-04-17 12:05:41.000000000 -0400
8016 +++ linux-2.6.25-vs2.3.0.34.9/fs/reiserfs/bitmap.c      2008-04-19 15:14:52.000000000 -0400
8017 @@ -13,6 +13,7 @@
8018  #include <linux/reiserfs_fs_sb.h>
8019  #include <linux/reiserfs_fs_i.h>
8020  #include <linux/quotaops.h>
8021 +#include <linux/vs_dlimit.h>
8022  
8023  #define PREALLOCATION_SIZE 9
8024  
8025 @@ -429,8 +430,10 @@ static void _reiserfs_free_block(struct 
8026         set_sb_free_blocks(rs, sb_free_blocks(rs) + 1);
8027  
8028         journal_mark_dirty(th, s, sbh);
8029 -       if (for_unformatted)
8030 +       if (for_unformatted) {
8031 +               DLIMIT_FREE_BLOCK(inode, 1);
8032                 DQUOT_FREE_BLOCK_NODIRTY(inode, 1);
8033 +       }
8034  }
8035  
8036  void reiserfs_free_block(struct reiserfs_transaction_handle *th,
8037 @@ -1045,6 +1048,7 @@ static inline int blocknrs_and_prealloc_
8038         b_blocknr_t finish = SB_BLOCK_COUNT(s) - 1;
8039         int passno = 0;
8040         int nr_allocated = 0;
8041 +       int blocks;
8042  
8043         determine_prealloc_size(hint);
8044         if (!hint->formatted_node) {
8045 @@ -1054,19 +1058,30 @@ static inline int blocknrs_and_prealloc_
8046                                "reiserquota: allocating %d blocks id=%u",
8047                                amount_needed, hint->inode->i_uid);
8048  #endif
8049 -               quota_ret =
8050 -                   DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode, amount_needed);
8051 -               if (quota_ret)  /* Quota exceeded? */
8052 +               quota_ret = DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode,
8053 +                       amount_needed);
8054 +               if (quota_ret)
8055                         return QUOTA_EXCEEDED;
8056 +               if (DLIMIT_ALLOC_BLOCK(hint->inode, amount_needed)) {
8057 +                       DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
8058 +                               amount_needed);
8059 +                       return NO_DISK_SPACE;
8060 +               }
8061 +
8062                 if (hint->preallocate && hint->prealloc_size) {
8063  #ifdef REISERQUOTA_DEBUG
8064                         reiserfs_debug(s, REISERFS_DEBUG_CODE,
8065                                        "reiserquota: allocating (prealloc) %d blocks id=%u",
8066                                        hint->prealloc_size, hint->inode->i_uid);
8067  #endif
8068 -                       quota_ret =
8069 -                           DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
8070 -                                                        hint->prealloc_size);
8071 +                       quota_ret = DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
8072 +                               hint->prealloc_size);
8073 +                       if (!quota_ret &&
8074 +                               DLIMIT_ALLOC_BLOCK(hint->inode, hint->prealloc_size)) {
8075 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
8076 +                                       hint->prealloc_size);
8077 +                               quota_ret = 1;
8078 +                       }
8079                         if (quota_ret)
8080                                 hint->preallocate = hint->prealloc_size = 0;
8081                 }
8082 @@ -1098,7 +1113,10 @@ static inline int blocknrs_and_prealloc_
8083                                                nr_allocated,
8084                                                hint->inode->i_uid);
8085  #endif
8086 -                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed + hint->prealloc_size - nr_allocated);      /* Free not allocated blocks */
8087 +                               /* Free not allocated blocks */
8088 +                               blocks = amount_needed + hint->prealloc_size - nr_allocated;
8089 +                               DLIMIT_FREE_BLOCK(hint->inode, blocks);
8090 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
8091                         }
8092                         while (nr_allocated--)
8093                                 reiserfs_free_block(hint->th, hint->inode,
8094 @@ -1129,10 +1147,10 @@ static inline int blocknrs_and_prealloc_
8095                                REISERFS_I(hint->inode)->i_prealloc_count,
8096                                hint->inode->i_uid);
8097  #endif
8098 -               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed +
8099 -                                        hint->prealloc_size - nr_allocated -
8100 -                                        REISERFS_I(hint->inode)->
8101 -                                        i_prealloc_count);
8102 +               blocks = amount_needed + hint->prealloc_size - nr_allocated -
8103 +                       REISERFS_I(hint->inode)->i_prealloc_count;
8104 +               DLIMIT_FREE_BLOCK(hint->inode, blocks);
8105 +               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
8106         }
8107  
8108         return CARRY_ON;
8109 diff -NurpP --minimal linux-2.6.25/fs/reiserfs/file.c linux-2.6.25-vs2.3.0.34.9/fs/reiserfs/file.c
8110 --- linux-2.6.25/fs/reiserfs/file.c     2008-04-17 11:31:38.000000000 -0400
8111 +++ linux-2.6.25-vs2.3.0.34.9/fs/reiserfs/file.c        2008-04-19 15:14:52.000000000 -0400
8112 @@ -306,4 +306,5 @@ const struct inode_operations reiserfs_f
8113         .listxattr = reiserfs_listxattr,
8114         .removexattr = reiserfs_removexattr,
8115         .permission = reiserfs_permission,
8116 +       .sync_flags = reiserfs_sync_flags,
8117  };
8118 diff -NurpP --minimal linux-2.6.25/fs/reiserfs/inode.c linux-2.6.25-vs2.3.0.34.9/fs/reiserfs/inode.c
8119 --- linux-2.6.25/fs/reiserfs/inode.c    2008-04-17 12:05:41.000000000 -0400
8120 +++ linux-2.6.25-vs2.3.0.34.9/fs/reiserfs/inode.c       2008-04-19 15:14:52.000000000 -0400
8121 @@ -18,6 +18,8 @@
8122  #include <linux/writeback.h>
8123  #include <linux/quotaops.h>
8124  #include <linux/swap.h>
8125 +#include <linux/vs_dlimit.h>
8126 +#include <linux/vs_tag.h>
8127  
8128  int reiserfs_commit_write(struct file *f, struct page *page,
8129                           unsigned from, unsigned to);
8130 @@ -52,6 +54,7 @@ void reiserfs_delete_inode(struct inode 
8131                  * stat data deletion */
8132                 if (!err) 
8133                         DQUOT_FREE_INODE(inode);
8134 +               DLIMIT_FREE_INODE(inode);
8135  
8136                 if (journal_end(&th, inode->i_sb, jbegin_count))
8137                         goto out;
8138 @@ -1114,6 +1117,8 @@ static void init_inode(struct inode *ino
8139         struct buffer_head *bh;
8140         struct item_head *ih;
8141         __u32 rdev;
8142 +       uid_t uid;
8143 +       gid_t gid;
8144         //int version = ITEM_VERSION_1;
8145  
8146         bh = PATH_PLAST_BUFFER(path);
8147 @@ -1137,12 +1142,13 @@ static void init_inode(struct inode *ino
8148                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
8149                 unsigned long blocks;
8150  
8151 +               uid = sd_v1_uid(sd);
8152 +               gid = sd_v1_gid(sd);
8153 +
8154                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
8155                 set_inode_sd_version(inode, STAT_DATA_V1);
8156                 inode->i_mode = sd_v1_mode(sd);
8157                 inode->i_nlink = sd_v1_nlink(sd);
8158 -               inode->i_uid = sd_v1_uid(sd);
8159 -               inode->i_gid = sd_v1_gid(sd);
8160                 inode->i_size = sd_v1_size(sd);
8161                 inode->i_atime.tv_sec = sd_v1_atime(sd);
8162                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
8163 @@ -1184,11 +1190,12 @@ static void init_inode(struct inode *ino
8164                 // (directories and symlinks)
8165                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
8166  
8167 +               uid    = sd_v2_uid(sd);
8168 +               gid    = sd_v2_gid(sd);
8169 +
8170                 inode->i_mode = sd_v2_mode(sd);
8171                 inode->i_nlink = sd_v2_nlink(sd);
8172 -               inode->i_uid = sd_v2_uid(sd);
8173                 inode->i_size = sd_v2_size(sd);
8174 -               inode->i_gid = sd_v2_gid(sd);
8175                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
8176                 inode->i_atime.tv_sec = sd_v2_atime(sd);
8177                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
8178 @@ -1218,6 +1225,10 @@ static void init_inode(struct inode *ino
8179                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
8180         }
8181  
8182 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
8183 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
8184 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
8185 +
8186         pathrelse(path);
8187         if (S_ISREG(inode->i_mode)) {
8188                 inode->i_op = &reiserfs_file_inode_operations;
8189 @@ -1240,13 +1251,15 @@ static void init_inode(struct inode *ino
8190  static void inode2sd(void *sd, struct inode *inode, loff_t size)
8191  {
8192         struct stat_data *sd_v2 = (struct stat_data *)sd;
8193 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
8194 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
8195         __u16 flags;
8196  
8197 +       set_sd_v2_uid(sd_v2, uid);
8198 +       set_sd_v2_gid(sd_v2, gid);
8199         set_sd_v2_mode(sd_v2, inode->i_mode);
8200         set_sd_v2_nlink(sd_v2, inode->i_nlink);
8201 -       set_sd_v2_uid(sd_v2, inode->i_uid);
8202         set_sd_v2_size(sd_v2, size);
8203 -       set_sd_v2_gid(sd_v2, inode->i_gid);
8204         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
8205         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
8206         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
8207 @@ -1769,6 +1782,10 @@ int reiserfs_new_inode(struct reiserfs_t
8208  
8209         BUG_ON(!th->t_trans_id);
8210  
8211 +       if (DLIMIT_ALLOC_INODE(inode)) {
8212 +               err = -ENOSPC;
8213 +               goto out_bad_dlimit;
8214 +       }
8215         if (DQUOT_ALLOC_INODE(inode)) {
8216                 err = -EDQUOT;
8217                 goto out_end_trans;
8218 @@ -1954,6 +1971,9 @@ int reiserfs_new_inode(struct reiserfs_t
8219         DQUOT_FREE_INODE(inode);
8220  
8221        out_end_trans:
8222 +       DLIMIT_FREE_INODE(inode);
8223 +
8224 +      out_bad_dlimit:
8225         journal_end(th, th->t_super, th->t_blocks_allocated);
8226         /* Drop can be outside and it needs more credits so it's better to have it outside */
8227         DQUOT_DROP(inode);
8228 @@ -2848,6 +2868,14 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
8229                         inode->i_flags |= S_IMMUTABLE;
8230                 else
8231                         inode->i_flags &= ~S_IMMUTABLE;
8232 +               if (sd_attrs & REISERFS_IUNLINK_FL)
8233 +                       inode->i_flags |= S_IUNLINK;
8234 +               else
8235 +                       inode->i_flags &= ~S_IUNLINK;
8236 +               if (sd_attrs & REISERFS_BARRIER_FL)
8237 +                       inode->i_flags |= S_BARRIER;
8238 +               else
8239 +                       inode->i_flags &= ~S_BARRIER;
8240                 if (sd_attrs & REISERFS_APPEND_FL)
8241                         inode->i_flags |= S_APPEND;
8242                 else
8243 @@ -2870,6 +2898,14 @@ void i_attrs_to_sd_attrs(struct inode *i
8244                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
8245                 else
8246                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
8247 +               if (inode->i_flags & S_IUNLINK)
8248 +                       *sd_attrs |= REISERFS_IUNLINK_FL;
8249 +               else
8250 +                       *sd_attrs &= ~REISERFS_IUNLINK_FL;
8251 +               if (inode->i_flags & S_BARRIER)
8252 +                       *sd_attrs |= REISERFS_BARRIER_FL;
8253 +               else
8254 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
8255                 if (inode->i_flags & S_SYNC)
8256                         *sd_attrs |= REISERFS_SYNC_FL;
8257                 else
8258 @@ -3049,6 +3085,22 @@ static ssize_t reiserfs_direct_IO(int rw
8259                                   reiserfs_get_blocks_direct_io, NULL);
8260  }
8261  
8262 +int reiserfs_sync_flags(struct inode *inode)
8263 +{
8264 +       u16 oldflags, newflags;
8265 +
8266 +       oldflags = REISERFS_I(inode)->i_attrs;
8267 +       newflags = oldflags;
8268 +       i_attrs_to_sd_attrs(inode, &newflags);
8269 +
8270 +       if (oldflags ^ newflags) {
8271 +               REISERFS_I(inode)->i_attrs = newflags;
8272 +               inode->i_ctime = CURRENT_TIME_SEC;
8273 +               mark_inode_dirty(inode);
8274 +       }
8275 +       return 0;
8276 +}
8277 +
8278  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
8279  {
8280         struct inode *inode = dentry->d_inode;
8281 @@ -3102,9 +3154,11 @@ int reiserfs_setattr(struct dentry *dent
8282         }
8283  
8284         error = inode_change_ok(inode, attr);
8285 +
8286         if (!error) {
8287                 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
8288 -                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
8289 +                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
8290 +                   (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
8291                         error = reiserfs_chown_xattrs(inode, attr);
8292  
8293                         if (!error) {
8294 @@ -3134,6 +3188,9 @@ int reiserfs_setattr(struct dentry *dent
8295                                         inode->i_uid = attr->ia_uid;
8296                                 if (attr->ia_valid & ATTR_GID)
8297                                         inode->i_gid = attr->ia_gid;
8298 +                               if ((attr->ia_valid & ATTR_TAG) &&
8299 +                                       IS_TAGGED(inode))
8300 +                                       inode->i_tag = attr->ia_tag;
8301                                 mark_inode_dirty(inode);
8302                                 error =
8303                                     journal_end(&th, inode->i_sb, jbegin_count);
8304 diff -NurpP --minimal linux-2.6.25/fs/reiserfs/ioctl.c linux-2.6.25-vs2.3.0.34.9/fs/reiserfs/ioctl.c
8305 --- linux-2.6.25/fs/reiserfs/ioctl.c    2008-04-17 11:31:38.000000000 -0400
8306 +++ linux-2.6.25-vs2.3.0.34.9/fs/reiserfs/ioctl.c       2008-04-19 15:14:52.000000000 -0400
8307 @@ -6,6 +6,7 @@
8308  #include <linux/fs.h>
8309  #include <linux/reiserfs_fs.h>
8310  #include <linux/time.h>
8311 +#include <linux/mount.h>
8312  #include <asm/uaccess.h>
8313  #include <linux/pagemap.h>
8314  #include <linux/smp_lock.h>
8315 @@ -24,7 +25,7 @@ static int reiserfs_unpack(struct inode 
8316  int reiserfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
8317                    unsigned long arg)
8318  {
8319 -       unsigned int flags;
8320 +       unsigned int flags, oldflags;
8321  
8322         switch (cmd) {
8323         case REISERFS_IOC_UNPACK:
8324 @@ -43,12 +44,14 @@ int reiserfs_ioctl(struct inode *inode, 
8325  
8326                 flags = REISERFS_I(inode)->i_attrs;
8327                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
8328 +               flags &= REISERFS_FL_USER_VISIBLE;
8329                 return put_user(flags, (int __user *)arg);
8330         case REISERFS_IOC_SETFLAGS:{
8331                         if (!reiserfs_attrs(inode->i_sb))
8332                                 return -ENOTTY;
8333  
8334 -                       if (IS_RDONLY(inode))
8335 +                       if (IS_RDONLY(inode) ||
8336 +                               (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
8337                                 return -EROFS;
8338  
8339                         if (!is_owner_or_cap(inode))
8340 @@ -74,6 +77,10 @@ int reiserfs_ioctl(struct inode *inode, 
8341                                 if (result)
8342                                         return result;
8343                         }
8344 +
8345 +                       oldflags = REISERFS_I(inode)->i_attrs;
8346 +                       flags = flags & REISERFS_FL_USER_MODIFIABLE;
8347 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
8348                         sd_attrs_to_i_attrs(flags, inode);
8349                         REISERFS_I(inode)->i_attrs = flags;
8350                         inode->i_ctime = CURRENT_TIME_SEC;
8351 @@ -85,7 +92,8 @@ int reiserfs_ioctl(struct inode *inode, 
8352         case REISERFS_IOC_SETVERSION:
8353                 if (!is_owner_or_cap(inode))
8354                         return -EPERM;
8355 -               if (IS_RDONLY(inode))
8356 +               if (IS_RDONLY(inode) ||
8357 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
8358                         return -EROFS;
8359                 if (get_user(inode->i_generation, (int __user *)arg))
8360                         return -EFAULT;
8361 diff -NurpP --minimal linux-2.6.25/fs/reiserfs/namei.c linux-2.6.25-vs2.3.0.34.9/fs/reiserfs/namei.c
8362 --- linux-2.6.25/fs/reiserfs/namei.c    2008-04-17 12:05:41.000000000 -0400
8363 +++ linux-2.6.25-vs2.3.0.34.9/fs/reiserfs/namei.c       2008-04-19 15:14:52.000000000 -0400
8364 @@ -17,6 +17,7 @@
8365  #include <linux/reiserfs_acl.h>
8366  #include <linux/reiserfs_xattr.h>
8367  #include <linux/quotaops.h>
8368 +#include <linux/vs_tag.h>
8369  
8370  #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; }
8371  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
8372 @@ -360,6 +361,7 @@ static struct dentry *reiserfs_lookup(st
8373                         reiserfs_write_unlock(dir->i_sb);
8374                         return ERR_PTR(-EACCES);
8375                 }
8376 +               dx_propagate_tag(nd, inode);
8377  
8378                 /* Propogate the priv_object flag so we know we're in the priv tree */
8379                 if (is_reiserfs_priv_object(dir))
8380 @@ -595,6 +597,7 @@ static int new_inode_init(struct inode *
8381         } else {
8382                 inode->i_gid = current->fsgid;
8383         }
8384 +       inode->i_tag = dx_current_fstag(inode->i_sb);
8385         DQUOT_INIT(inode);
8386         return 0;
8387  }
8388 @@ -1541,6 +1544,7 @@ const struct inode_operations reiserfs_d
8389         .listxattr = reiserfs_listxattr,
8390         .removexattr = reiserfs_removexattr,
8391         .permission = reiserfs_permission,
8392 +       .sync_flags = reiserfs_sync_flags,
8393  };
8394  
8395  /*
8396 @@ -1557,6 +1561,7 @@ const struct inode_operations reiserfs_s
8397         .listxattr = reiserfs_listxattr,
8398         .removexattr = reiserfs_removexattr,
8399         .permission = reiserfs_permission,
8400 +       .sync_flags = reiserfs_sync_flags,
8401  
8402  };
8403  
8404 @@ -1570,5 +1575,6 @@ const struct inode_operations reiserfs_s
8405         .listxattr = reiserfs_listxattr,
8406         .removexattr = reiserfs_removexattr,
8407         .permission = reiserfs_permission,
8408 +       .sync_flags = reiserfs_sync_flags,
8409  
8410  };
8411 diff -NurpP --minimal linux-2.6.25/fs/reiserfs/stree.c linux-2.6.25-vs2.3.0.34.9/fs/reiserfs/stree.c
8412 --- linux-2.6.25/fs/reiserfs/stree.c    2008-04-17 11:31:38.000000000 -0400
8413 +++ linux-2.6.25-vs2.3.0.34.9/fs/reiserfs/stree.c       2008-04-19 15:14:52.000000000 -0400
8414 @@ -55,6 +55,7 @@
8415  #include <linux/reiserfs_fs.h>
8416  #include <linux/buffer_head.h>
8417  #include <linux/quotaops.h>
8418 +#include <linux/vs_dlimit.h>
8419  
8420  /* Does the buffer contain a disk block which is in the tree. */
8421  inline int B_IS_IN_TREE(const struct buffer_head *p_s_bh)
8422 @@ -1297,6 +1298,7 @@ int reiserfs_delete_item(struct reiserfs
8423                        "reiserquota delete_item(): freeing %u, id=%u type=%c",
8424                        quota_cut_bytes, p_s_inode->i_uid, head2type(&s_ih));
8425  #endif
8426 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
8427         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
8428  
8429         /* Return deleted body length */
8430 @@ -1385,6 +1387,7 @@ void reiserfs_delete_solid_item(struct r
8431  #endif
8432                                 DQUOT_FREE_SPACE_NODIRTY(inode,
8433                                                          quota_cut_bytes);
8434 +                               DLIMIT_FREE_SPACE(inode, quota_cut_bytes);
8435                         }
8436                         break;
8437                 }
8438 @@ -1735,6 +1738,7 @@ int reiserfs_cut_from_item(struct reiser
8439                        "reiserquota cut_from_item(): freeing %u id=%u type=%c",
8440                        quota_cut_bytes, p_s_inode->i_uid, '?');
8441  #endif
8442 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
8443         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
8444         return n_ret_value;
8445  }
8446 @@ -1976,6 +1980,11 @@ int reiserfs_paste_into_item(struct reis
8447                 pathrelse(p_s_search_path);
8448                 return -EDQUOT;
8449         }
8450 +       if (DLIMIT_ALLOC_SPACE(inode, n_pasted_size)) {
8451 +               DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
8452 +               pathrelse(p_s_search_path);
8453 +               return -ENOSPC;
8454 +       }
8455         init_tb_struct(th, &s_paste_balance, th->t_super, p_s_search_path,
8456                        n_pasted_size);
8457  #ifdef DISPLACE_NEW_PACKING_LOCALITIES
8458 @@ -2028,6 +2037,7 @@ int reiserfs_paste_into_item(struct reis
8459                        n_pasted_size, inode->i_uid,
8460                        key2type(&(p_s_key->on_disk_key)));
8461  #endif
8462 +       DLIMIT_FREE_SPACE(inode, n_pasted_size);
8463         DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
8464         return retval;
8465  }
8466 @@ -2065,6 +2075,11 @@ int reiserfs_insert_item(struct reiserfs
8467                         pathrelse(p_s_path);
8468                         return -EDQUOT;
8469                 }
8470 +               if (DLIMIT_ALLOC_SPACE(inode, quota_bytes)) {
8471 +                       DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
8472 +                       pathrelse(p_s_path);
8473 +                       return -ENOSPC;
8474 +               }
8475         }
8476         init_tb_struct(th, &s_ins_balance, th->t_super, p_s_path,
8477                        IH_SIZE + ih_item_len(p_s_ih));
8478 @@ -2112,7 +2127,9 @@ int reiserfs_insert_item(struct reiserfs
8479                        "reiserquota insert_item(): freeing %u id=%u type=%c",
8480                        quota_bytes, inode->i_uid, head2type(p_s_ih));
8481  #endif
8482 -       if (inode)
8483 +       if (inode) {
8484 +               DLIMIT_FREE_SPACE(inode, quota_bytes);
8485                 DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
8486 +       }
8487         return retval;
8488  }
8489 diff -NurpP --minimal linux-2.6.25/fs/reiserfs/super.c linux-2.6.25-vs2.3.0.34.9/fs/reiserfs/super.c
8490 --- linux-2.6.25/fs/reiserfs/super.c    2008-04-17 12:05:41.000000000 -0400
8491 +++ linux-2.6.25-vs2.3.0.34.9/fs/reiserfs/super.c       2008-04-19 15:14:52.000000000 -0400
8492 @@ -896,6 +896,14 @@ static int reiserfs_parse_options(struct
8493                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
8494                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
8495  #endif
8496 +#ifndef CONFIG_TAGGING_NONE
8497 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
8498 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
8499 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
8500 +#endif
8501 +#ifdef CONFIG_PROPAGATE
8502 +               {"tag",.arg_required = 'T',.values = NULL},
8503 +#endif
8504  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
8505                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
8506                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
8507 @@ -1159,6 +1167,12 @@ static int reiserfs_remount(struct super
8508                 goto out_err;
8509         }
8510  
8511 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
8512 +               !(s->s_flags & MS_TAGGED)) {
8513 +               reiserfs_warning(s, "reiserfs: tagging not permitted on remount.");
8514 +               return -EINVAL;
8515 +       }
8516 +
8517         handle_attrs(s);
8518  
8519         /* Add options that are safe here */
8520 @@ -1618,6 +1632,10 @@ static int reiserfs_fill_super(struct su
8521                 goto error;
8522         }
8523  
8524 +       /* map mount option tagxid */
8525 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
8526 +               s->s_flags |= MS_TAGGED;
8527 +
8528         rs = SB_DISK_SUPER_BLOCK(s);
8529         /* Let's do basic sanity check to verify that underlying device is not
8530            smaller than the filesystem. If the check fails then abort and scream,
8531 diff -NurpP --minimal linux-2.6.25/fs/reiserfs/xattr.c linux-2.6.25-vs2.3.0.34.9/fs/reiserfs/xattr.c
8532 --- linux-2.6.25/fs/reiserfs/xattr.c    2008-04-17 12:05:41.000000000 -0400
8533 +++ linux-2.6.25-vs2.3.0.34.9/fs/reiserfs/xattr.c       2008-04-19 15:14:52.000000000 -0400
8534 @@ -35,6 +35,7 @@
8535  #include <linux/namei.h>
8536  #include <linux/errno.h>
8537  #include <linux/fs.h>
8538 +#include <linux/mount.h>
8539  #include <linux/file.h>
8540  #include <linux/pagemap.h>
8541  #include <linux/xattr.h>
8542 @@ -747,7 +748,7 @@ int reiserfs_delete_xattrs(struct inode 
8543         if (dir->d_inode->i_nlink <= 2) {
8544                 root = get_xa_root(inode->i_sb, XATTR_REPLACE);
8545                 reiserfs_write_lock_xattrs(inode->i_sb);
8546 -               err = vfs_rmdir(root->d_inode, dir);
8547 +               err = vfs_rmdir(root->d_inode, dir, NULL);
8548                 reiserfs_write_unlock_xattrs(inode->i_sb);
8549                 dput(root);
8550         } else {
8551 diff -NurpP --minimal linux-2.6.25/fs/stat.c linux-2.6.25-vs2.3.0.34.9/fs/stat.c
8552 --- linux-2.6.25/fs/stat.c      2008-04-17 12:05:41.000000000 -0400
8553 +++ linux-2.6.25-vs2.3.0.34.9/fs/stat.c 2008-04-19 15:14:52.000000000 -0400
8554 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
8555         stat->nlink = inode->i_nlink;
8556         stat->uid = inode->i_uid;
8557         stat->gid = inode->i_gid;
8558 +       stat->tag = inode->i_tag;
8559         stat->rdev = inode->i_rdev;
8560         stat->atime = inode->i_atime;
8561         stat->mtime = inode->i_mtime;
8562 diff -NurpP --minimal linux-2.6.25/fs/super.c linux-2.6.25-vs2.3.0.34.9/fs/super.c
8563 --- linux-2.6.25/fs/super.c     2008-04-17 12:05:41.000000000 -0400
8564 +++ linux-2.6.25-vs2.3.0.34.9/fs/super.c        2008-04-19 15:14:52.000000000 -0400
8565 @@ -37,6 +37,9 @@
8566  #include <linux/idr.h>
8567  #include <linux/kobject.h>
8568  #include <linux/mutex.h>
8569 +#include <linux/devpts_fs.h>
8570 +#include <linux/proc_fs.h>
8571 +#include <linux/vs_context.h>
8572  #include <asm/uaccess.h>
8573  
8574  
8575 @@ -859,12 +862,18 @@ struct vfsmount *
8576  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
8577  {
8578         struct vfsmount *mnt;
8579 +       struct super_block *sb;
8580         char *secdata = NULL;
8581         int error;
8582  
8583         if (!type)
8584                 return ERR_PTR(-ENODEV);
8585  
8586 +       error = -EPERM;
8587 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
8588 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
8589 +               goto out;
8590 +
8591         error = -ENOMEM;
8592         mnt = alloc_vfsmnt(name);
8593         if (!mnt)
8594 @@ -885,7 +894,14 @@ vfs_kern_mount(struct file_system_type *
8595                 goto out_free_secdata;
8596         BUG_ON(!mnt->mnt_sb);
8597  
8598 -       error = security_sb_kern_mount(mnt->mnt_sb, secdata);
8599 +       sb = mnt->mnt_sb;
8600 +       error = -EPERM;
8601 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
8602 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
8603 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
8604 +               goto out_sb;
8605 +
8606 +       error = security_sb_kern_mount(sb, secdata);
8607         if (error)
8608                 goto out_sb;
8609  
8610 diff -NurpP --minimal linux-2.6.25/fs/sysfs/mount.c linux-2.6.25-vs2.3.0.34.9/fs/sysfs/mount.c
8611 --- linux-2.6.25/fs/sysfs/mount.c       2008-04-17 11:31:38.000000000 -0400
8612 +++ linux-2.6.25-vs2.3.0.34.9/fs/sysfs/mount.c  2008-04-19 15:14:52.000000000 -0400
8613 @@ -19,8 +19,6 @@
8614  
8615  #include "sysfs.h"
8616  
8617 -/* Random magic number */
8618 -#define SYSFS_MAGIC 0x62656572
8619  
8620  static struct vfsmount *sysfs_mount;
8621  struct super_block * sysfs_sb = NULL;
8622 @@ -46,7 +44,7 @@ static int sysfs_fill_super(struct super
8623  
8624         sb->s_blocksize = PAGE_CACHE_SIZE;
8625         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
8626 -       sb->s_magic = SYSFS_MAGIC;
8627 +       sb->s_magic = SYSFS_SUPER_MAGIC;
8628         sb->s_op = &sysfs_ops;
8629         sb->s_time_gran = 1;
8630         sysfs_sb = sb;
8631 diff -NurpP --minimal linux-2.6.25/fs/utimes.c linux-2.6.25-vs2.3.0.34.9/fs/utimes.c
8632 --- linux-2.6.25/fs/utimes.c    2008-04-17 12:05:41.000000000 -0400
8633 +++ linux-2.6.25-vs2.3.0.34.9/fs/utimes.c       2008-04-20 13:40:14.000000000 -0400
8634 @@ -7,6 +7,8 @@
8635  #include <linux/stat.h>
8636  #include <linux/utime.h>
8637  #include <linux/syscalls.h>
8638 +#include <linux/mount.h>
8639 +#include <linux/vs_cowbl.h>
8640  #include <asm/uaccess.h>
8641  #include <asm/unistd.h>
8642  
8643 @@ -84,6 +86,9 @@ long do_utimes(int dfd, char __user *fil
8644                 if (error)
8645                         goto out;
8646  
8647 +               error = cow_check_and_break(&nd);
8648 +               if (error)
8649 +                       goto dput_and_out;
8650                 dentry = nd.path.dentry;
8651         }
8652  
8653 diff -NurpP --minimal linux-2.6.25/fs/xattr.c linux-2.6.25-vs2.3.0.34.9/fs/xattr.c
8654 --- linux-2.6.25/fs/xattr.c     2008-04-17 12:05:41.000000000 -0400
8655 +++ linux-2.6.25-vs2.3.0.34.9/fs/xattr.c        2008-04-21 13:52:50.000000000 -0400
8656 @@ -17,6 +17,7 @@
8657  #include <linux/module.h>
8658  #include <linux/fsnotify.h>
8659  #include <linux/audit.h>
8660 +#include <linux/mount.h>
8661  #include <asm/uaccess.h>
8662  
8663  
8664 @@ -220,7 +221,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
8665   */
8666  static long
8667  setxattr(struct dentry *d, char __user *name, void __user *value,
8668 -        size_t size, int flags)
8669 +        size_t size, int flags, struct vfsmount *mnt)
8670  {
8671         int error;
8672         void *kvalue = NULL;
8673 @@ -247,6 +248,9 @@ setxattr(struct dentry *d, char __user *
8674                 }
8675         }
8676  
8677 +       if (MNT_IS_RDONLY(mnt))
8678 +               return -EROFS;
8679 +
8680         error = vfs_setxattr(d, kname, kvalue, size, flags);
8681         kfree(kvalue);
8682         return error;
8683 @@ -262,7 +266,7 @@ sys_setxattr(char __user *path, char __u
8684         error = user_path_walk(path, &nd);
8685         if (error)
8686                 return error;
8687 -       error = setxattr(nd.path.dentry, name, value, size, flags);
8688 +       error = setxattr(nd.path.dentry, name, value, size, flags, nd.path.mnt);
8689         path_put(&nd.path);
8690         return error;
8691  }
8692 @@ -277,7 +281,7 @@ sys_lsetxattr(char __user *path, char __
8693         error = user_path_walk_link(path, &nd);
8694         if (error)
8695                 return error;
8696 -       error = setxattr(nd.path.dentry, name, value, size, flags);
8697 +       error = setxattr(nd.path.dentry, name, value, size, flags, nd.path.mnt);
8698         path_put(&nd.path);
8699         return error;
8700  }
8701 @@ -295,7 +299,7 @@ sys_fsetxattr(int fd, char __user *name,
8702                 return error;
8703         dentry = f->f_path.dentry;
8704         audit_inode(NULL, dentry);
8705 -       error = setxattr(dentry, name, value, size, flags);
8706 +       error = setxattr(dentry, name, value, size, flags, f->f_vfsmnt);
8707         fput(f);
8708         return error;
8709  }
8710 @@ -459,7 +463,7 @@ sys_flistxattr(int fd, char __user *list
8711   * Extended attribute REMOVE operations
8712   */
8713  static long
8714 -removexattr(struct dentry *d, char __user *name)
8715 +removexattr(struct dentry *d, char __user *name, struct vfsmount *mnt)
8716  {
8717         int error;
8718         char kname[XATTR_NAME_MAX + 1];
8719 @@ -470,6 +474,9 @@ removexattr(struct dentry *d, char __use
8720         if (error < 0)
8721                 return error;
8722  
8723 +       if (MNT_IS_RDONLY(mnt))
8724 +               return -EROFS;
8725 +
8726         return vfs_removexattr(d, kname);
8727  }
8728  
8729 @@ -482,7 +489,7 @@ sys_removexattr(char __user *path, char 
8730         error = user_path_walk(path, &nd);
8731         if (error)
8732                 return error;
8733 -       error = removexattr(nd.path.dentry, name);
8734 +       error = removexattr(nd.path.dentry, name, nd.path.mnt);
8735         path_put(&nd.path);
8736         return error;
8737  }
8738 @@ -496,7 +503,7 @@ sys_lremovexattr(char __user *path, char
8739         error = user_path_walk_link(path, &nd);
8740         if (error)
8741                 return error;
8742 -       error = removexattr(nd.path.dentry, name);
8743 +       error = removexattr(nd.path.dentry, name, nd.path.mnt);
8744         path_put(&nd.path);
8745         return error;
8746  }
8747 @@ -513,7 +520,7 @@ sys_fremovexattr(int fd, char __user *na
8748                 return error;
8749         dentry = f->f_path.dentry;
8750         audit_inode(NULL, dentry);
8751 -       error = removexattr(dentry, name);
8752 +       error = removexattr(dentry, name, f->f_vfsmnt);
8753         fput(f);
8754         return error;
8755  }
8756 diff -NurpP --minimal linux-2.6.25/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.25-vs2.3.0.34.9/fs/xfs/linux-2.6/xfs_ioctl.c
8757 --- linux-2.6.25/fs/xfs/linux-2.6/xfs_ioctl.c   2008-04-17 12:05:41.000000000 -0400
8758 +++ linux-2.6.25-vs2.3.0.34.9/fs/xfs/linux-2.6/xfs_ioctl.c      2008-04-19 15:14:52.000000000 -0400
8759 @@ -1125,7 +1125,8 @@ xfs_merge_ioc_xflags(
8760  
8761  STATIC unsigned int
8762  xfs_di2lxflags(
8763 -       __uint16_t      di_flags)
8764 +       __uint16_t      di_flags,
8765 +       __uint16_t      di_vflags)
8766  {
8767         unsigned int    flags = 0;
8768  
8769 @@ -1139,6 +1140,11 @@ xfs_di2lxflags(
8770                 flags |= FS_NOATIME_FL;
8771         if (di_flags & XFS_DIFLAG_NODUMP)
8772                 flags |= FS_NODUMP_FL;
8773 +
8774 +       if (di_vflags & XFS_DIVFLAG_IUNLINK)
8775 +               flags |= FS_IUNLINK_FL;
8776 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
8777 +               flags |= FS_BARRIER_FL;
8778         return flags;
8779  }
8780  
8781 @@ -1219,7 +1225,7 @@ xfs_ioc_xattr(
8782         }
8783  
8784         case XFS_IOC_GETXFLAGS: {
8785 -               flags = xfs_di2lxflags(ip->i_d.di_flags);
8786 +               flags = xfs_di2lxflags(ip->i_d.di_flags, ip->i_d.di_vflags);
8787                 if (copy_to_user(arg, &flags, sizeof(flags)))
8788                         error = -EFAULT;
8789                 break;
8790 diff -NurpP --minimal linux-2.6.25/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.25-vs2.3.0.34.9/fs/xfs/linux-2.6/xfs_iops.c
8791 --- linux-2.6.25/fs/xfs/linux-2.6/xfs_iops.c    2008-04-17 12:05:41.000000000 -0400
8792 +++ linux-2.6.25-vs2.3.0.34.9/fs/xfs/linux-2.6/xfs_iops.c       2008-04-19 17:01:15.000000000 -0400
8793 @@ -53,6 +53,7 @@
8794  #include <linux/namei.h>
8795  #include <linux/security.h>
8796  #include <linux/falloc.h>
8797 +#include <linux/vs_tag.h>
8798  
8799  /*
8800   * Bring the atime in the XFS inode uptodate.
8801 @@ -391,6 +392,7 @@ xfs_vn_lookup(
8802                 d_add(dentry, NULL);
8803                 return NULL;
8804         }
8805 +       dx_propagate_tag(nd, vn_to_inode(cvp));
8806  
8807         return d_splice_alias(vn_to_inode(cvp), dentry);
8808  }
8809 @@ -655,6 +657,10 @@ xfs_vn_setattr(
8810         int             flags = 0;
8811         int             error;
8812  
8813 +       error = inode_change_ok(inode, attr);
8814 +       if (error)
8815 +               return error;
8816 +
8817         if (ia_valid & ATTR_UID) {
8818                 vattr.va_mask |= XFS_AT_UID;
8819                 vattr.va_uid = attr->ia_uid;
8820 @@ -663,6 +669,10 @@ xfs_vn_setattr(
8821                 vattr.va_mask |= XFS_AT_GID;
8822                 vattr.va_gid = attr->ia_gid;
8823         }
8824 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode)) {
8825 +               vattr.va_mask |= XFS_AT_TAG;
8826 +               vattr.va_tag = attr->ia_tag;
8827 +       }
8828         if (ia_valid & ATTR_SIZE) {
8829                 vattr.va_mask |= XFS_AT_SIZE;
8830                 vattr.va_size = attr->ia_size;
8831 @@ -708,6 +718,42 @@ xfs_vn_truncate(
8832  }
8833  
8834  STATIC int
8835 +xfs_vn_sync_flags(struct inode *inode)
8836 +{
8837 +       unsigned int oldflags, newflags;
8838 +       int             flags = 0;
8839 +       int             error;
8840 +       bhv_vattr_t     vattr;
8841 +       bhv_vnode_t     *vp = vn_from_inode(inode);
8842 +
8843 +       memset(&vattr, 0, sizeof vattr);
8844 +
8845 +       vattr.va_mask = XFS_AT_XFLAGS;
8846 +       error = xfs_getattr(XFS_I(inode), &vattr, 0);
8847 +
8848 +       if (error)
8849 +               return error;
8850 +       oldflags = vattr.va_xflags;
8851 +       newflags = oldflags & ~(XFS_XFLAG_IMMUTABLE |
8852 +               XFS_XFLAG_IUNLINK | XFS_XFLAG_BARRIER);
8853 +
8854 +       if (IS_IMMUTABLE(inode))
8855 +               newflags |= XFS_XFLAG_IMMUTABLE;
8856 +       if (IS_IUNLINK(inode))
8857 +               newflags |= XFS_XFLAG_IUNLINK;
8858 +       if (IS_BARRIER(inode))
8859 +               newflags |= XFS_XFLAG_BARRIER;
8860 +
8861 +       if (oldflags ^ newflags) {
8862 +               vattr.va_xflags = newflags;
8863 +               vattr.va_mask |= XFS_AT_XFLAGS;
8864 +               error = xfs_setattr(XFS_I(inode), &vattr, flags, NULL);
8865 +       }
8866 +       vn_revalidate(vp);
8867 +       return error;
8868 +}
8869 +
8870 +STATIC int
8871  xfs_vn_setxattr(
8872         struct dentry   *dentry,
8873         const char      *name,
8874 @@ -881,6 +927,8 @@ const struct inode_operations xfs_dir_in
8875         .getxattr               = xfs_vn_getxattr,
8876         .listxattr              = xfs_vn_listxattr,
8877         .removexattr            = xfs_vn_removexattr,
8878 +       .sync_flags             = xfs_vn_sync_flags,
8879 +       .sync_flags             = xfs_vn_sync_flags,
8880  };
8881  
8882  const struct inode_operations xfs_symlink_inode_operations = {
8883 @@ -894,4 +942,5 @@ const struct inode_operations xfs_symlin
8884         .getxattr               = xfs_vn_getxattr,
8885         .listxattr              = xfs_vn_listxattr,
8886         .removexattr            = xfs_vn_removexattr,
8887 +       .sync_flags             = xfs_vn_sync_flags,
8888  };
8889 diff -NurpP --minimal linux-2.6.25/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.25-vs2.3.0.34.9/fs/xfs/linux-2.6/xfs_linux.h
8890 --- linux-2.6.25/fs/xfs/linux-2.6/xfs_linux.h   2008-04-17 12:05:41.000000000 -0400
8891 +++ linux-2.6.25-vs2.3.0.34.9/fs/xfs/linux-2.6/xfs_linux.h      2008-04-19 15:14:52.000000000 -0400
8892 @@ -128,6 +128,7 @@
8893  #define current_pid()          (current->pid)
8894  #define current_fsuid(cred)    (current->fsuid)
8895  #define current_fsgid(cred)    (current->fsgid)
8896 +#define current_fstag(cred,vp) (dx_current_fstag(vn_to_inode(vp)->i_sb))
8897  #define current_test_flags(f)  (current->flags & (f))
8898  #define current_set_flags_nested(sp, f)                \
8899                 (*(sp) = current->flags, current->flags |= (f))
8900 diff -NurpP --minimal linux-2.6.25/fs/xfs/linux-2.6/xfs_super.c linux-2.6.25-vs2.3.0.34.9/fs/xfs/linux-2.6/xfs_super.c
8901 --- linux-2.6.25/fs/xfs/linux-2.6/xfs_super.c   2008-04-17 12:05:41.000000000 -0400
8902 +++ linux-2.6.25-vs2.3.0.34.9/fs/xfs/linux-2.6/xfs_super.c      2008-04-26 09:51:47.000000000 -0400
8903 @@ -137,6 +137,9 @@ xfs_args_allocate(
8904  #define MNTOPT_DMAPI   "dmapi"         /* DMI enabled (DMAPI / XDSM) */
8905  #define MNTOPT_XDSM    "xdsm"          /* DMI enabled (DMAPI / XDSM) */
8906  #define MNTOPT_DMI     "dmi"           /* DMI enabled (DMAPI / XDSM) */
8907 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
8908 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
8909 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
8910  
8911  STATIC unsigned long
8912  suffix_strtoul(char *s, char **endp, unsigned int base)
8913 @@ -355,6 +358,19 @@ xfs_parseargs(
8914                 } else if (!strcmp(this_char, "irixsgid")) {
8915                         cmn_err(CE_WARN,
8916         "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
8917 +#ifndef CONFIG_TAGGING_NONE
8918 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
8919 +                       args->flags2 |= XFSMNT2_TAGGED;
8920 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
8921 +                       args->flags2 &= ~XFSMNT2_TAGGED;
8922 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
8923 +                       args->flags2 |= XFSMNT2_TAGGED;
8924 +#endif
8925 +#ifdef CONFIG_PROPAGATE
8926 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
8927 +                       /* use value */
8928 +                       args->flags2 |= XFSMNT2_TAGGED;
8929 +#endif
8930                 } else {
8931                         cmn_err(CE_WARN,
8932                                 "XFS: unknown mount option [%s].", this_char);
8933 @@ -591,6 +607,7 @@ xfs_revalidate_inode(
8934         inode->i_nlink  = ip->i_d.di_nlink;
8935         inode->i_uid    = ip->i_d.di_uid;
8936         inode->i_gid    = ip->i_d.di_gid;
8937 +       inode->i_tag    = ip->i_d.di_tag;
8938  
8939         switch (inode->i_mode & S_IFMT) {
8940         case S_IFBLK:
8941 @@ -612,6 +629,7 @@ xfs_revalidate_inode(
8942         inode->i_mtime.tv_nsec  = ip->i_d.di_mtime.t_nsec;
8943         inode->i_ctime.tv_sec   = ip->i_d.di_ctime.t_sec;
8944         inode->i_ctime.tv_nsec  = ip->i_d.di_ctime.t_nsec;
8945 +
8946         if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE)
8947                 inode->i_flags |= S_IMMUTABLE;
8948         else
8949 @@ -628,6 +646,15 @@ xfs_revalidate_inode(
8950                 inode->i_flags |= S_NOATIME;
8951         else
8952                 inode->i_flags &= ~S_NOATIME;
8953 +
8954 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_IUNLINK)
8955 +               inode->i_flags |= S_IUNLINK;
8956 +       else
8957 +               inode->i_flags &= ~S_IUNLINK;
8958 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
8959 +               inode->i_flags |= S_BARRIER;
8960 +       else
8961 +               inode->i_flags &= ~S_BARRIER;
8962         xfs_iflags_clear(ip, XFS_IMODIFIED);
8963  }
8964  
8965 @@ -1220,6 +1247,12 @@ xfs_fs_remount(
8966         int                     error;
8967  
8968         error = xfs_parseargs(mp, options, args, 1);
8969 +       if ((args->flags2 & XFSMNT2_TAGGED) &&
8970 +               !(sb->s_flags & MS_TAGGED)) {
8971 +               printk("XFS: %s: tagging not permitted on remount.\n",
8972 +                       sb->s_id);
8973 +               error = EINVAL;
8974 +       }
8975         if (!error)
8976                 error = xfs_mntupdate(mp, flags, args);
8977         kmem_free(args, sizeof(*args));
8978 @@ -1336,6 +1369,9 @@ xfs_fs_fill_super(
8979         if (error)
8980                 goto fail_vfsop;
8981  
8982 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
8983 +               sb->s_flags |= MS_TAGGED;
8984 +
8985         sb->s_dirt = 1;
8986         sb->s_magic = XFS_SB_MAGIC;
8987         sb->s_blocksize = mp->m_sb.sb_blocksize;
8988 diff -NurpP --minimal linux-2.6.25/fs/xfs/linux-2.6/xfs_vnode.c linux-2.6.25-vs2.3.0.34.9/fs/xfs/linux-2.6/xfs_vnode.c
8989 --- linux-2.6.25/fs/xfs/linux-2.6/xfs_vnode.c   2008-04-17 12:05:41.000000000 -0400
8990 +++ linux-2.6.25-vs2.3.0.34.9/fs/xfs/linux-2.6/xfs_vnode.c      2008-04-19 17:04:58.000000000 -0400
8991 @@ -105,6 +105,7 @@ vn_revalidate(
8992         inode->i_mode       = ip->i_d.di_mode;
8993         inode->i_uid        = ip->i_d.di_uid;
8994         inode->i_gid        = ip->i_d.di_gid;
8995 +       inode->i_tag        = ip->i_d.di_tag;
8996         inode->i_mtime.tv_sec = ip->i_d.di_mtime.t_sec;
8997         inode->i_mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
8998         inode->i_ctime.tv_sec = ip->i_d.di_ctime.t_sec;
8999 @@ -115,6 +116,14 @@ vn_revalidate(
9000                 inode->i_flags |= S_IMMUTABLE;
9001         else
9002                 inode->i_flags &= ~S_IMMUTABLE;
9003 +       if (xflags & XFS_XFLAG_IUNLINK)
9004 +               inode->i_flags |= S_IUNLINK;
9005 +       else
9006 +               inode->i_flags &= ~S_IUNLINK;
9007 +       if (xflags & XFS_XFLAG_BARRIER)
9008 +               inode->i_flags |= S_BARRIER;
9009 +       else
9010 +               inode->i_flags &= ~S_BARRIER;
9011         if (xflags & XFS_XFLAG_APPEND)
9012                 inode->i_flags |= S_APPEND;
9013         else
9014 diff -NurpP --minimal linux-2.6.25/fs/xfs/linux-2.6/xfs_vnode.h linux-2.6.25-vs2.3.0.34.9/fs/xfs/linux-2.6/xfs_vnode.h
9015 --- linux-2.6.25/fs/xfs/linux-2.6/xfs_vnode.h   2008-04-17 12:05:41.000000000 -0400
9016 +++ linux-2.6.25-vs2.3.0.34.9/fs/xfs/linux-2.6/xfs_vnode.h      2008-04-19 15:14:52.000000000 -0400
9017 @@ -99,6 +99,7 @@ typedef struct bhv_vattr {
9018         xfs_nlink_t     va_nlink;       /* number of references to file */
9019         uid_t           va_uid;         /* owner user id */
9020         gid_t           va_gid;         /* owner group id */
9021 +       tag_t           va_tag;         /* owner group id */
9022         xfs_ino_t       va_nodeid;      /* file id */
9023         xfs_off_t       va_size;        /* file size in bytes */
9024         u_long          va_blocksize;   /* blocksize preferred for i/o */
9025 @@ -147,13 +148,15 @@ typedef struct bhv_vattr {
9026  #define XFS_AT_PROJID          0x04000000
9027  #define XFS_AT_SIZE_NOPERM     0x08000000
9028  #define XFS_AT_GENCOUNT                0x10000000
9029 +#define XFS_AT_TAG             0x20000000
9030  
9031  #define XFS_AT_ALL     (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
9032                 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
9033                 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
9034                 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|XFS_AT_MAC|\
9035                 XFS_AT_ACL|XFS_AT_CAP|XFS_AT_INF|XFS_AT_XFLAGS|XFS_AT_EXTSIZE|\
9036 -               XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_PROJID|XFS_AT_GENCOUNT)
9037 +               XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_PROJID|XFS_AT_GENCOUNT\
9038 +               XFS_AT_TAG)
9039  
9040  #define XFS_AT_STAT    (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
9041                 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
9042 diff -NurpP --minimal linux-2.6.25/fs/xfs/quota/xfs_qm_syscalls.c linux-2.6.25-vs2.3.0.34.9/fs/xfs/quota/xfs_qm_syscalls.c
9043 --- linux-2.6.25/fs/xfs/quota/xfs_qm_syscalls.c 2008-04-17 12:05:42.000000000 -0400
9044 +++ linux-2.6.25-vs2.3.0.34.9/fs/xfs/quota/xfs_qm_syscalls.c    2008-04-19 15:14:52.000000000 -0400
9045 @@ -17,6 +17,7 @@
9046   */
9047  
9048  #include <linux/capability.h>
9049 +#include <linux/vs_context.h>
9050  
9051  #include "xfs.h"
9052  #include "xfs_fs.h"
9053 @@ -205,7 +206,7 @@ xfs_qm_scall_quotaoff(
9054         xfs_qoff_logitem_t      *qoffstart;
9055         int                     nculprits;
9056  
9057 -       if (!force && !capable(CAP_SYS_ADMIN))
9058 +       if (!force && !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9059                 return XFS_ERROR(EPERM);
9060         /*
9061          * No file system can have quotas enabled on disk but not in core.
9062 @@ -374,7 +375,7 @@ xfs_qm_scall_trunc_qfiles(
9063         int             error;
9064         xfs_inode_t     *qip;
9065  
9066 -       if (!capable(CAP_SYS_ADMIN))
9067 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9068                 return XFS_ERROR(EPERM);
9069         error = 0;
9070         if (!xfs_sb_version_hasquota(&mp->m_sb) || flags == 0) {
9071 @@ -418,7 +419,7 @@ xfs_qm_scall_quotaon(
9072         uint            accflags;
9073         __int64_t       sbflags;
9074  
9075 -       if (!capable(CAP_SYS_ADMIN))
9076 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9077                 return XFS_ERROR(EPERM);
9078  
9079         flags &= (XFS_ALL_QUOTA_ACCT | XFS_ALL_QUOTA_ENFD);
9080 @@ -587,7 +588,7 @@ xfs_qm_scall_setqlim(
9081         int                     error;
9082         xfs_qcnt_t              hard, soft;
9083  
9084 -       if (!capable(CAP_SYS_ADMIN))
9085 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9086                 return XFS_ERROR(EPERM);
9087  
9088         if ((newlim->d_fieldmask &
9089 diff -NurpP --minimal linux-2.6.25/fs/xfs/xfs_clnt.h linux-2.6.25-vs2.3.0.34.9/fs/xfs/xfs_clnt.h
9090 --- linux-2.6.25/fs/xfs/xfs_clnt.h      2008-04-17 12:05:42.000000000 -0400
9091 +++ linux-2.6.25-vs2.3.0.34.9/fs/xfs/xfs_clnt.h 2008-04-19 15:14:52.000000000 -0400
9092 @@ -100,5 +100,6 @@ struct xfs_mount_args {
9093                                                  * I/O size in stat(2) */
9094  #define XFSMNT2_FILESTREAMS    0x00000002      /* enable the filestreams
9095                                                  * allocator */
9096 +#define XFSMNT2_TAGGED         0x80000000      /* context tagging */
9097  
9098  #endif /* __XFS_CLNT_H__ */
9099 diff -NurpP --minimal linux-2.6.25/fs/xfs/xfs_dinode.h linux-2.6.25-vs2.3.0.34.9/fs/xfs/xfs_dinode.h
9100 --- linux-2.6.25/fs/xfs/xfs_dinode.h    2008-04-17 12:05:42.000000000 -0400
9101 +++ linux-2.6.25-vs2.3.0.34.9/fs/xfs/xfs_dinode.h       2008-04-27 10:33:37.000000000 -0400
9102 @@ -53,7 +53,9 @@ typedef struct xfs_dinode_core {
9103         __be32          di_gid;         /* owner's group id */
9104         __be32          di_nlink;       /* number of links to file */
9105         __be16          di_projid;      /* owner's project id */
9106 -       __u8            di_pad[8];      /* unused, zeroed space */
9107 +       __be16          di_tag;         /* context tagging */
9108 +       __be16          di_vflags;      /* vserver specific flags */
9109 +       __u8            di_pad[4];      /* unused, zeroed space */
9110         __be16          di_flushiter;   /* incremented on flush */
9111         xfs_timestamp_t di_atime;       /* time last accessed */
9112         xfs_timestamp_t di_mtime;       /* time last modified */
9113 @@ -136,7 +138,9 @@ typedef struct xfs_dinode
9114  #define        XFS_DI_NEXT_UNLINKED    0x1000000
9115  #define        XFS_DI_U                0x2000000
9116  #define        XFS_DI_A                0x4000000
9117 -#define        XFS_DI_NUM_BITS         27
9118 +#define        XFS_DI_VFLAGS           0x8000000
9119 +#define        XFS_DI_TAG              0x10000000
9120 +#define        XFS_DI_NUM_BITS         29
9121  #define        XFS_DI_ALL_BITS         ((1 << XFS_DI_NUM_BITS) - 1)
9122  #define        XFS_DI_CORE_BITS        (XFS_DI_ALL_BITS & ~(XFS_DI_U|XFS_DI_A))
9123  
9124 @@ -223,6 +227,7 @@ typedef enum xfs_dinode_fmt
9125  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
9126  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
9127  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
9128 +
9129  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
9130  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
9131  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
9132 @@ -252,4 +257,7 @@ typedef enum xfs_dinode_fmt
9133          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
9134          XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
9135  
9136 +#define        XFS_DIVFLAG_BARRIER     0x01
9137 +#define        XFS_DIVFLAG_IUNLINK     0x02
9138 +
9139  #endif /* __XFS_DINODE_H__ */
9140 diff -NurpP --minimal linux-2.6.25/fs/xfs/xfs_fs.h linux-2.6.25-vs2.3.0.34.9/fs/xfs/xfs_fs.h
9141 --- linux-2.6.25/fs/xfs/xfs_fs.h        2008-04-17 12:05:42.000000000 -0400
9142 +++ linux-2.6.25-vs2.3.0.34.9/fs/xfs/xfs_fs.h   2008-04-19 15:14:52.000000000 -0400
9143 @@ -67,6 +67,8 @@ struct fsxattr {
9144  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
9145  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
9146  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
9147 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
9148 +#define XFS_XFLAG_IUNLINK      0x20000000      /* immutable unlink */
9149  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
9150  
9151  /*
9152 @@ -296,7 +298,8 @@ typedef struct xfs_bstat {
9153         __s32           bs_extents;     /* number of extents            */
9154         __u32           bs_gen;         /* generation count             */
9155         __u16           bs_projid;      /* project id                   */
9156 -       unsigned char   bs_pad[14];     /* pad space, unused            */
9157 +       __u16           bs_tag;         /* context tagging              */
9158 +       unsigned char   bs_pad[12];     /* pad space, unused            */
9159         __u32           bs_dmevmask;    /* DMIG event mask              */
9160         __u16           bs_dmstate;     /* DMIG state info              */
9161         __u16           bs_aextents;    /* attribute number of extents  */
9162 diff -NurpP --minimal linux-2.6.25/fs/xfs/xfs_ialloc.c linux-2.6.25-vs2.3.0.34.9/fs/xfs/xfs_ialloc.c
9163 --- linux-2.6.25/fs/xfs/xfs_ialloc.c    2008-04-17 12:05:42.000000000 -0400
9164 +++ linux-2.6.25-vs2.3.0.34.9/fs/xfs/xfs_ialloc.c       2008-04-27 10:30:39.000000000 -0400
9165 @@ -66,6 +66,8 @@ xfs_ialloc_log_di(
9166                 offsetof(xfs_dinode_core_t, di_gid),
9167                 offsetof(xfs_dinode_core_t, di_nlink),
9168                 offsetof(xfs_dinode_core_t, di_projid),
9169 +               offsetof(xfs_dinode_core_t, di_tag),
9170 +               offsetof(xfs_dinode_core_t, di_vflags),
9171                 offsetof(xfs_dinode_core_t, di_pad),
9172                 offsetof(xfs_dinode_core_t, di_atime),
9173                 offsetof(xfs_dinode_core_t, di_mtime),
9174 diff -NurpP --minimal linux-2.6.25/fs/xfs/xfs_inode.c linux-2.6.25-vs2.3.0.34.9/fs/xfs/xfs_inode.c
9175 --- linux-2.6.25/fs/xfs/xfs_inode.c     2008-04-17 12:05:42.000000000 -0400
9176 +++ linux-2.6.25-vs2.3.0.34.9/fs/xfs/xfs_inode.c        2008-04-26 11:06:34.000000000 -0400
9177 @@ -219,6 +219,7 @@ xfs_inotobp(
9178         return 0;
9179  }
9180  
9181 +#include <linux/vs_tag.h>
9182  
9183  /*
9184   * This routine is called to map an inode to the buffer containing
9185 @@ -716,13 +717,21 @@ xfs_dinode_from_disk(
9186         xfs_icdinode_t          *to,
9187         xfs_dinode_core_t       *from)
9188  {
9189 +       uint32_t uid, gid;
9190 +
9191         to->di_magic = be16_to_cpu(from->di_magic);
9192         to->di_mode = be16_to_cpu(from->di_mode);
9193         to->di_version = from ->di_version;
9194         to->di_format = from->di_format;
9195         to->di_onlink = be16_to_cpu(from->di_onlink);
9196 -       to->di_uid = be32_to_cpu(from->di_uid);
9197 -       to->di_gid = be32_to_cpu(from->di_gid);
9198 +
9199 +       uid = be32_to_cpu(from->di_uid);
9200 +       gid = be32_to_cpu(from->di_gid);
9201 +
9202 +       to->di_uid = INOTAG_UID(1, uid, gid);
9203 +       to->di_gid = INOTAG_GID(1, uid, gid);
9204 +       to->di_tag = INOTAG_TAG(1, uid, gid, 0);
9205 +
9206         to->di_nlink = be32_to_cpu(from->di_nlink);
9207         to->di_projid = be16_to_cpu(from->di_projid);
9208         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
9209 @@ -756,8 +765,10 @@ xfs_dinode_to_disk(
9210         to->di_version = from ->di_version;
9211         to->di_format = from->di_format;
9212         to->di_onlink = cpu_to_be16(from->di_onlink);
9213 -       to->di_uid = cpu_to_be32(from->di_uid);
9214 -       to->di_gid = cpu_to_be32(from->di_gid);
9215 +
9216 +       to->di_uid = cpu_to_be32(TAGINO_UID(1, from->di_uid, from->di_tag));
9217 +       to->di_gid = cpu_to_be32(TAGINO_GID(1, from->di_gid, from->di_tag));
9218 +
9219         to->di_nlink = cpu_to_be32(from->di_nlink);
9220         to->di_projid = cpu_to_be16(from->di_projid);
9221         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
9222 @@ -783,7 +794,8 @@ xfs_dinode_to_disk(
9223  
9224  STATIC uint
9225  _xfs_dic2xflags(
9226 -       __uint16_t              di_flags)
9227 +       __uint16_t              di_flags,
9228 +       __uint16_t              di_vflags)
9229  {
9230         uint                    flags = 0;
9231  
9232 @@ -817,7 +829,10 @@ _xfs_dic2xflags(
9233                 if (di_flags & XFS_DIFLAG_FILESTREAM)
9234                         flags |= XFS_XFLAG_FILESTREAM;
9235         }
9236 -
9237 +       if (di_vflags & XFS_DIVFLAG_IUNLINK)
9238 +               flags |= XFS_XFLAG_IUNLINK;
9239 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
9240 +               flags |= XFS_XFLAG_BARRIER;
9241         return flags;
9242  }
9243  
9244 @@ -827,7 +842,7 @@ xfs_ip2xflags(
9245  {
9246         xfs_icdinode_t          *dic = &ip->i_d;
9247  
9248 -       return _xfs_dic2xflags(dic->di_flags) |
9249 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
9250                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
9251  }
9252  
9253 @@ -837,7 +852,7 @@ xfs_dic2xflags(
9254  {
9255         xfs_dinode_core_t       *dic = &dip->di_core;
9256  
9257 -       return _xfs_dic2xflags(be16_to_cpu(dic->di_flags)) |
9258 +       return _xfs_dic2xflags(be16_to_cpu(dic->di_flags), be16_to_cpu(dic->di_vflags)) |
9259                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
9260  }
9261  
9262 @@ -1138,6 +1153,7 @@ xfs_ialloc(
9263         ASSERT(ip->i_d.di_nlink == nlink);
9264         ip->i_d.di_uid = current_fsuid(cr);
9265         ip->i_d.di_gid = current_fsgid(cr);
9266 +       ip->i_d.di_tag = current_fstag(cr, vp);
9267         ip->i_d.di_projid = prid;
9268         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
9269  
9270 diff -NurpP --minimal linux-2.6.25/fs/xfs/xfs_inode.h linux-2.6.25-vs2.3.0.34.9/fs/xfs/xfs_inode.h
9271 --- linux-2.6.25/fs/xfs/xfs_inode.h     2008-04-17 12:05:42.000000000 -0400
9272 +++ linux-2.6.25-vs2.3.0.34.9/fs/xfs/xfs_inode.h        2008-04-19 15:14:52.000000000 -0400
9273 @@ -187,7 +187,9 @@ typedef struct xfs_icdinode {
9274         __uint32_t      di_gid;         /* owner's group id */
9275         __uint32_t      di_nlink;       /* number of links to file */
9276         __uint16_t      di_projid;      /* owner's project id */
9277 -       __uint8_t       di_pad[8];      /* unused, zeroed space */
9278 +       __uint16_t      di_tag;         /* context tagging */
9279 +       __uint16_t      di_vflags;      /* vserver specific flags */
9280 +       __uint8_t       di_pad[4];      /* unused, zeroed space */
9281         __uint16_t      di_flushiter;   /* incremented on flush */
9282         xfs_ictimestamp_t di_atime;     /* time last accessed */
9283         xfs_ictimestamp_t di_mtime;     /* time last modified */
9284 diff -NurpP --minimal linux-2.6.25/fs/xfs/xfs_itable.c linux-2.6.25-vs2.3.0.34.9/fs/xfs/xfs_itable.c
9285 --- linux-2.6.25/fs/xfs/xfs_itable.c    2008-04-17 12:05:42.000000000 -0400
9286 +++ linux-2.6.25-vs2.3.0.34.9/fs/xfs/xfs_itable.c       2008-04-19 15:14:52.000000000 -0400
9287 @@ -89,6 +89,7 @@ xfs_bulkstat_one_iget(
9288         buf->bs_mode = dic->di_mode;
9289         buf->bs_uid = dic->di_uid;
9290         buf->bs_gid = dic->di_gid;
9291 +       buf->bs_tag = dic->di_tag;
9292         buf->bs_size = dic->di_size;
9293         vn_atime_to_bstime(vp, &buf->bs_atime);
9294         buf->bs_mtime.tv_sec = dic->di_mtime.t_sec;
9295 diff -NurpP --minimal linux-2.6.25/fs/xfs/xfs_mount.h linux-2.6.25-vs2.3.0.34.9/fs/xfs/xfs_mount.h
9296 --- linux-2.6.25/fs/xfs/xfs_mount.h     2008-04-17 12:05:43.000000000 -0400
9297 +++ linux-2.6.25-vs2.3.0.34.9/fs/xfs/xfs_mount.h        2008-04-19 15:14:52.000000000 -0400
9298 @@ -378,6 +378,7 @@ typedef struct xfs_mount {
9299  #define XFS_MOUNT_FILESTREAMS  (1ULL << 24)    /* enable the filestreams
9300                                                    allocator */
9301  
9302 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
9303  
9304  /*
9305   * Default minimum read and write sizes.
9306 diff -NurpP --minimal linux-2.6.25/fs/xfs/xfs_vfsops.c linux-2.6.25-vs2.3.0.34.9/fs/xfs/xfs_vfsops.c
9307 --- linux-2.6.25/fs/xfs/xfs_vfsops.c    2008-04-17 12:05:43.000000000 -0400
9308 +++ linux-2.6.25-vs2.3.0.34.9/fs/xfs/xfs_vfsops.c       2008-04-26 09:52:49.000000000 -0400
9309 @@ -290,6 +290,8 @@ xfs_start_flags(
9310  
9311         if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
9312                 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
9313 +       if (ap->flags2 & XFSMNT2_TAGGED)
9314 +               mp->m_flags |= XFS_MOUNT_TAGGED;
9315  
9316         /*
9317          * no recovery flag requires a read-only mount
9318 @@ -402,7 +404,6 @@ xfs_finish_flags(
9319                 if (ap->flags & XFSMNT_PQUOTAENF)
9320                         mp->m_qflags |= XFS_OQUOTA_ENFD;
9321         }
9322 -
9323         return 0;
9324  }
9325  
9326 diff -NurpP --minimal linux-2.6.25/fs/xfs/xfs_vnodeops.c linux-2.6.25-vs2.3.0.34.9/fs/xfs/xfs_vnodeops.c
9327 --- linux-2.6.25/fs/xfs/xfs_vnodeops.c  2008-04-17 12:05:43.000000000 -0400
9328 +++ linux-2.6.25-vs2.3.0.34.9/fs/xfs/xfs_vnodeops.c     2008-04-19 15:14:52.000000000 -0400
9329 @@ -122,6 +122,7 @@ xfs_getattr(
9330         vap->va_mode = ip->i_d.di_mode;
9331         vap->va_uid = ip->i_d.di_uid;
9332         vap->va_gid = ip->i_d.di_gid;
9333 +       vap->va_tag = ip->i_d.di_tag;
9334         vap->va_projid = ip->i_d.di_projid;
9335  
9336         /*
9337 @@ -221,6 +222,7 @@ xfs_setattr(
9338         uint                    commit_flags=0;
9339         uid_t                   uid=0, iuid=0;
9340         gid_t                   gid=0, igid=0;
9341 +       tag_t                   tag=0, itag=0;
9342         int                     timeflags = 0;
9343         xfs_prid_t              projid=0, iprojid=0;
9344         int                     mandlock_before, mandlock_after;
9345 @@ -272,6 +274,7 @@ xfs_setattr(
9346             (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_PROJID))) {
9347                 uint    qflags = 0;
9348  
9349 +               /* TODO: handle tagging? */
9350                 if ((mask & XFS_AT_UID) && XFS_IS_UQUOTA_ON(mp)) {
9351                         uid = vap->va_uid;
9352                         qflags |= XFS_QMOPT_UQUOTA;
9353 @@ -351,6 +354,8 @@ xfs_setattr(
9354         if (mask &
9355             (XFS_AT_MODE|XFS_AT_XFLAGS|XFS_AT_EXTSIZE|XFS_AT_UID|
9356              XFS_AT_GID|XFS_AT_PROJID)) {
9357 +               /* TODO: handle tagging? */
9358 +
9359                 /*
9360                  * CAP_FOWNER overrides the following restrictions:
9361                  *
9362 @@ -399,7 +404,7 @@ xfs_setattr(
9363          * and can change the group id only to a group of which he
9364          * or she is a member.
9365          */
9366 -       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_PROJID)) {
9367 +       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_TAG|XFS_AT_PROJID)) {
9368                 /*
9369                  * These IDs could have changed since we last looked at them.
9370                  * But, we're assured that if the ownership did change
9371 @@ -407,10 +412,12 @@ xfs_setattr(
9372                  * would have changed also.
9373                  */
9374                 iuid = ip->i_d.di_uid;
9375 -               iprojid = ip->i_d.di_projid;
9376                 igid = ip->i_d.di_gid;
9377 -               gid = (mask & XFS_AT_GID) ? vap->va_gid : igid;
9378 +               itag = ip->i_d.di_tag;
9379 +               iprojid = ip->i_d.di_projid;
9380                 uid = (mask & XFS_AT_UID) ? vap->va_uid : iuid;
9381 +               gid = (mask & XFS_AT_GID) ? vap->va_gid : igid;
9382 +               tag = (mask & XFS_AT_TAG) ? vap->va_tag : itag;
9383                 projid = (mask & XFS_AT_PROJID) ? (xfs_prid_t)vap->va_projid :
9384                          iprojid;
9385  
9386 @@ -438,6 +445,7 @@ xfs_setattr(
9387                 if ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
9388                     (XFS_IS_PQUOTA_ON(mp) && iprojid != projid) ||
9389                     (XFS_IS_GQUOTA_ON(mp) && igid != gid)) {
9390 +                       /* TODO: handle tagging? */
9391                         ASSERT(tp);
9392                         code = XFS_QM_DQVOPCHOWNRESV(mp, tp, ip, udqp, gdqp,
9393                                                 capable(CAP_FOWNER) ?
9394 @@ -686,7 +694,7 @@ xfs_setattr(
9395          * and can change the group id only to a group of which he
9396          * or she is a member.
9397          */
9398 -       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_PROJID)) {
9399 +       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_TAG|XFS_AT_PROJID)) {
9400                 /*
9401                  * CAP_FSETID overrides the following restrictions:
9402                  *
9403 @@ -702,6 +710,9 @@ xfs_setattr(
9404                  * Change the ownerships and register quota modifications
9405                  * in the transaction.
9406                  */
9407 +               if (itag != tag) {
9408 +                       ip->i_d.di_tag = tag;
9409 +               }
9410                 if (iuid != uid) {
9411                         if (XFS_IS_UQUOTA_ON(mp)) {
9412                                 ASSERT(mask & XFS_AT_UID);
9413 @@ -777,6 +788,7 @@ xfs_setattr(
9414                 }
9415                 if (mask & XFS_AT_XFLAGS) {
9416                         uint    di_flags;
9417 +                       uint    di_vflags = 0;
9418  
9419                         /* can't set PREALLOC this way, just preserve it */
9420                         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
9421 @@ -810,6 +822,11 @@ xfs_setattr(
9422                                         di_flags |= XFS_DIFLAG_EXTSIZE;
9423                         }
9424                         ip->i_d.di_flags = di_flags;
9425 +                       if (vap->va_xflags & XFS_XFLAG_IUNLINK)
9426 +                               di_vflags |= XFS_DIVFLAG_IUNLINK;
9427 +                       if (vap->va_xflags & XFS_XFLAG_BARRIER)
9428 +                               di_vflags |= XFS_DIVFLAG_BARRIER;
9429 +                       ip->i_d.di_vflags = di_vflags;
9430                 }
9431                 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
9432                 timeflags |= XFS_ICHGTIME_CHG;
9433 diff -NurpP --minimal linux-2.6.25/include/asm-arm/tlb.h linux-2.6.25-vs2.3.0.34.9/include/asm-arm/tlb.h
9434 --- linux-2.6.25/include/asm-arm/tlb.h  2008-04-17 12:05:43.000000000 -0400
9435 +++ linux-2.6.25-vs2.3.0.34.9/include/asm-arm/tlb.h     2008-04-19 15:14:52.000000000 -0400
9436 @@ -28,6 +28,7 @@
9437  #else /* !CONFIG_MMU */
9438  
9439  #include <asm/pgalloc.h>
9440 +#include <linux/vs_memory.h>
9441  
9442  /*
9443   * TLB handling.  This allows us to remove pages from the page
9444 diff -NurpP --minimal linux-2.6.25/include/asm-blackfin/unistd.h linux-2.6.25-vs2.3.0.34.9/include/asm-blackfin/unistd.h
9445 --- linux-2.6.25/include/asm-blackfin/unistd.h  2008-04-17 12:05:43.000000000 -0400
9446 +++ linux-2.6.25-vs2.3.0.34.9/include/asm-blackfin/unistd.h     2008-04-19 15:14:52.000000000 -0400
9447 @@ -278,7 +278,7 @@
9448  #define __NR_tgkill            271
9449  #define __NR_utimes            272
9450  #define __NR_fadvise64_64      273
9451 -                               /* 274 __NR_vserver */
9452 +#define __NR_vserver           274
9453                                 /* 275 __NR_mbind */
9454                                 /* 276 __NR_get_mempolicy */
9455                                 /* 277 __NR_set_mempolicy */
9456 diff -NurpP --minimal linux-2.6.25/include/asm-generic/tlb.h linux-2.6.25-vs2.3.0.34.9/include/asm-generic/tlb.h
9457 --- linux-2.6.25/include/asm-generic/tlb.h      2008-04-17 12:05:43.000000000 -0400
9458 +++ linux-2.6.25-vs2.3.0.34.9/include/asm-generic/tlb.h 2008-04-19 15:50:15.000000000 -0400
9459 @@ -14,6 +14,7 @@
9460  #define _ASM_GENERIC__TLB_H
9461  
9462  #include <linux/swap.h>
9463 +#include <linux/vs_memory.h>
9464  #include <asm/pgalloc.h>
9465  #include <asm/tlbflush.h>
9466  
9467 diff -NurpP --minimal linux-2.6.25/include/asm-ia64/tlb.h linux-2.6.25-vs2.3.0.34.9/include/asm-ia64/tlb.h
9468 --- linux-2.6.25/include/asm-ia64/tlb.h 2007-02-04 13:44:54.000000000 -0500
9469 +++ linux-2.6.25-vs2.3.0.34.9/include/asm-ia64/tlb.h    2008-04-19 15:14:52.000000000 -0400
9470 @@ -40,6 +40,7 @@
9471  #include <linux/mm.h>
9472  #include <linux/pagemap.h>
9473  #include <linux/swap.h>
9474 +#include <linux/vs_memory.h>
9475  
9476  #include <asm/pgalloc.h>
9477  #include <asm/processor.h>
9478 diff -NurpP --minimal linux-2.6.25/include/asm-powerpc/systbl.h linux-2.6.25-vs2.3.0.34.9/include/asm-powerpc/systbl.h
9479 --- linux-2.6.25/include/asm-powerpc/systbl.h   2008-04-17 12:05:44.000000000 -0400
9480 +++ linux-2.6.25-vs2.3.0.34.9/include/asm-powerpc/systbl.h      2008-04-19 15:14:52.000000000 -0400
9481 @@ -260,7 +260,7 @@ COMPAT_SYS_SPU(fstatfs64)
9482  SYSX(sys_ni_syscall, ppc_fadvise64_64, ppc_fadvise64_64)
9483  PPC_SYS_SPU(rtas)
9484  OLDSYS(debug_setcontext)
9485 -SYSCALL(ni_syscall)
9486 +SYSX(sys_vserver, sys32_vserver, sys_vserver)
9487  COMPAT_SYS(migrate_pages)
9488  COMPAT_SYS(mbind)
9489  COMPAT_SYS(get_mempolicy)
9490 diff -NurpP --minimal linux-2.6.25/include/asm-powerpc/unistd.h linux-2.6.25-vs2.3.0.34.9/include/asm-powerpc/unistd.h
9491 --- linux-2.6.25/include/asm-powerpc/unistd.h   2008-04-17 12:05:44.000000000 -0400
9492 +++ linux-2.6.25-vs2.3.0.34.9/include/asm-powerpc/unistd.h      2008-04-19 15:14:52.000000000 -0400
9493 @@ -275,7 +275,7 @@
9494  #endif
9495  #define __NR_rtas              255
9496  #define __NR_sys_debug_setcontext 256
9497 -/* Number 257 is reserved for vserver */
9498 +#define __NR_vserver           257
9499  #define __NR_migrate_pages     258
9500  #define __NR_mbind             259
9501  #define __NR_get_mempolicy     260
9502 diff -NurpP --minimal linux-2.6.25/include/asm-s390/unistd.h linux-2.6.25-vs2.3.0.34.9/include/asm-s390/unistd.h
9503 --- linux-2.6.25/include/asm-s390/unistd.h      2008-04-17 12:05:44.000000000 -0400
9504 +++ linux-2.6.25-vs2.3.0.34.9/include/asm-s390/unistd.h 2008-04-19 15:14:52.000000000 -0400
9505 @@ -202,7 +202,7 @@
9506  #define __NR_clock_gettime     (__NR_timer_create+6)
9507  #define __NR_clock_getres      (__NR_timer_create+7)
9508  #define __NR_clock_nanosleep   (__NR_timer_create+8)
9509 -/* Number 263 is reserved for vserver */
9510 +#define __NR_vserver           263
9511  #define __NR_statfs64          265
9512  #define __NR_fstatfs64         266
9513  #define __NR_remap_file_pages  267
9514 diff -NurpP --minimal linux-2.6.25/include/asm-sparc/unistd.h linux-2.6.25-vs2.3.0.34.9/include/asm-sparc/unistd.h
9515 --- linux-2.6.25/include/asm-sparc/unistd.h     2008-04-17 12:05:44.000000000 -0400
9516 +++ linux-2.6.25-vs2.3.0.34.9/include/asm-sparc/unistd.h        2008-04-19 15:14:52.000000000 -0400
9517 @@ -282,7 +282,7 @@
9518  #define __NR_timer_getoverrun  264
9519  #define __NR_timer_delete      265
9520  #define __NR_timer_create      266
9521 -/* #define __NR_vserver                267 Reserved for VSERVER */
9522 +#define __NR_vserver           267
9523  #define __NR_io_setup          268
9524  #define __NR_io_destroy                269
9525  #define __NR_io_submit         270
9526 diff -NurpP --minimal linux-2.6.25/include/asm-sparc64/tlb.h linux-2.6.25-vs2.3.0.34.9/include/asm-sparc64/tlb.h
9527 --- linux-2.6.25/include/asm-sparc64/tlb.h      2008-04-17 12:05:44.000000000 -0400
9528 +++ linux-2.6.25-vs2.3.0.34.9/include/asm-sparc64/tlb.h 2008-04-19 15:14:52.000000000 -0400
9529 @@ -3,6 +3,7 @@
9530  
9531  #include <linux/swap.h>
9532  #include <linux/pagemap.h>
9533 +#include <linux/vs_memory.h>
9534  #include <asm/pgalloc.h>
9535  #include <asm/tlbflush.h>
9536  #include <asm/mmu_context.h>
9537 diff -NurpP --minimal linux-2.6.25/include/asm-sparc64/unistd.h linux-2.6.25-vs2.3.0.34.9/include/asm-sparc64/unistd.h
9538 --- linux-2.6.25/include/asm-sparc64/unistd.h   2008-04-17 12:05:44.000000000 -0400
9539 +++ linux-2.6.25-vs2.3.0.34.9/include/asm-sparc64/unistd.h      2008-04-19 15:14:52.000000000 -0400
9540 @@ -284,7 +284,7 @@
9541  #define __NR_timer_getoverrun  264
9542  #define __NR_timer_delete      265
9543  #define __NR_timer_create      266
9544 -/* #define __NR_vserver                267 Reserved for VSERVER */
9545 +#define __NR_vserver           267
9546  #define __NR_io_setup          268
9547  #define __NR_io_destroy                269
9548  #define __NR_io_submit         270
9549 diff -NurpP --minimal linux-2.6.25/include/asm-x86/unistd_64.h linux-2.6.25-vs2.3.0.34.9/include/asm-x86/unistd_64.h
9550 --- linux-2.6.25/include/asm-x86/unistd_64.h    2008-04-17 12:05:44.000000000 -0400
9551 +++ linux-2.6.25-vs2.3.0.34.9/include/asm-x86/unistd_64.h       2008-04-19 15:14:52.000000000 -0400
9552 @@ -535,7 +535,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
9553  #define __NR_utimes                            235
9554  __SYSCALL(__NR_utimes, sys_utimes)
9555  #define __NR_vserver                           236
9556 -__SYSCALL(__NR_vserver, sys_ni_syscall)
9557 +__SYSCALL(__NR_vserver, sys_vserver)
9558  #define __NR_mbind                             237
9559  __SYSCALL(__NR_mbind, sys_mbind)
9560  #define __NR_set_mempolicy                     238
9561 diff -NurpP --minimal linux-2.6.25/include/linux/capability.h linux-2.6.25-vs2.3.0.34.9/include/linux/capability.h
9562 --- linux-2.6.25/include/linux/capability.h     2008-04-17 12:05:44.000000000 -0400
9563 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/capability.h        2008-04-22 11:01:12.000000000 -0400
9564 @@ -260,6 +260,7 @@ typedef struct kernel_cap_struct {
9565     arbitrary SCSI commands */
9566  /* Allow setting encryption key on loopback filesystem */
9567  /* Allow setting zone reclaim policy */
9568 +/* Allow the selection of a security context */
9569  
9570  #define CAP_SYS_ADMIN        21
9571  
9572 @@ -332,7 +333,13 @@ typedef struct kernel_cap_struct {
9573  
9574  #define CAP_MAC_ADMIN        33
9575  
9576 -#define CAP_LAST_CAP         CAP_MAC_ADMIN
9577 +/* Allow context manipulations */
9578 +/* Allow changing context info on files */
9579 +
9580 +#define CAP_CONTEXT         34
9581 +
9582 +
9583 +#define CAP_LAST_CAP         CAP_CONTEXT
9584  
9585  #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
9586  
9587 diff -NurpP --minimal linux-2.6.25/include/linux/devpts_fs.h linux-2.6.25-vs2.3.0.34.9/include/linux/devpts_fs.h
9588 --- linux-2.6.25/include/linux/devpts_fs.h      2007-02-04 13:44:54.000000000 -0500
9589 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/devpts_fs.h 2008-04-19 15:14:52.000000000 -0400
9590 @@ -30,5 +30,4 @@ static inline void devpts_pty_kill(int n
9591  
9592  #endif
9593  
9594 -
9595  #endif /* _LINUX_DEVPTS_FS_H */
9596 diff -NurpP --minimal linux-2.6.25/include/linux/ext2_fs.h linux-2.6.25-vs2.3.0.34.9/include/linux/ext2_fs.h
9597 --- linux-2.6.25/include/linux/ext2_fs.h        2008-04-17 11:31:39.000000000 -0400
9598 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/ext2_fs.h   2008-04-19 15:14:52.000000000 -0400
9599 @@ -189,6 +189,8 @@ struct ext2_group_desc
9600  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
9601  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
9602  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
9603 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
9604 +#define EXT2_IUNLINK_FL                        FS_IUNLINK_FL   /* Immutable unlink */
9605  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
9606  
9607  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
9608 @@ -247,7 +249,7 @@ struct ext2_inode {
9609                 struct {
9610                         __u8    l_i_frag;       /* Fragment number */
9611                         __u8    l_i_fsize;      /* Fragment size */
9612 -                       __u16   i_pad1;
9613 +                       __u16   l_i_tag;        /* Context Tag */
9614                         __le16  l_i_uid_high;   /* these 2 fields    */
9615                         __le16  l_i_gid_high;   /* were reserved2[0] */
9616                         __u32   l_i_reserved2;
9617 @@ -279,6 +281,7 @@ struct ext2_inode {
9618  #define i_gid_low      i_gid
9619  #define i_uid_high     osd2.linux2.l_i_uid_high
9620  #define i_gid_high     osd2.linux2.l_i_gid_high
9621 +#define i_raw_tag      osd2.linux2.l_i_tag
9622  #define i_reserved2    osd2.linux2.l_i_reserved2
9623  #endif
9624  
9625 @@ -323,6 +326,7 @@ struct ext2_inode {
9626  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
9627  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
9628  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
9629 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
9630  
9631  
9632  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
9633 diff -NurpP --minimal linux-2.6.25/include/linux/ext3_fs.h linux-2.6.25-vs2.3.0.34.9/include/linux/ext3_fs.h
9634 --- linux-2.6.25/include/linux/ext3_fs.h        2008-04-17 12:05:44.000000000 -0400
9635 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/ext3_fs.h   2008-04-19 15:14:52.000000000 -0400
9636 @@ -173,6 +173,8 @@ struct ext3_group_desc
9637  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
9638  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
9639  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
9640 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
9641 +#define EXT3_IUNLINK_FL                        0x08000000 /* Immutable unlink */
9642  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
9643  
9644  #define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
9645 @@ -292,7 +294,7 @@ struct ext3_inode {
9646                 struct {
9647                         __u8    l_i_frag;       /* Fragment number */
9648                         __u8    l_i_fsize;      /* Fragment size */
9649 -                       __u16   i_pad1;
9650 +                       __u16   l_i_tag;        /* Context Tag */
9651                         __le16  l_i_uid_high;   /* these 2 fields    */
9652                         __le16  l_i_gid_high;   /* were reserved2[0] */
9653                         __u32   l_i_reserved2;
9654 @@ -326,6 +328,7 @@ struct ext3_inode {
9655  #define i_gid_low      i_gid
9656  #define i_uid_high     osd2.linux2.l_i_uid_high
9657  #define i_gid_high     osd2.linux2.l_i_gid_high
9658 +#define i_raw_tag      osd2.linux2.l_i_tag
9659  #define i_reserved2    osd2.linux2.l_i_reserved2
9660  
9661  #elif defined(__GNU__)
9662 @@ -380,6 +383,7 @@ struct ext3_inode {
9663  #define EXT3_MOUNT_QUOTA               0x80000 /* Some quota option set */
9664  #define EXT3_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
9665  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
9666 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
9667  
9668  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
9669  #ifndef _LINUX_EXT2_FS_H
9670 @@ -822,6 +826,7 @@ struct buffer_head * ext3_bread (handle_
9671  int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
9672         sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result,
9673         int create, int extend_disksize);
9674 +extern int ext3_sync_flags(struct inode *inode);
9675  
9676  extern struct inode *ext3_iget(struct super_block *, unsigned long);
9677  extern int  ext3_write_inode (struct inode *, int);
9678 diff -NurpP --minimal linux-2.6.25/include/linux/ext4_fs.h linux-2.6.25-vs2.3.0.34.9/include/linux/ext4_fs.h
9679 --- linux-2.6.25/include/linux/ext4_fs.h        2008-04-17 12:05:44.000000000 -0400
9680 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/ext4_fs.h   2008-04-19 15:43:04.000000000 -0400
9681 @@ -231,6 +231,8 @@ struct ext4_group_desc
9682  #define EXT4_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
9683  #define EXT4_HUGE_FILE_FL               0x00040000 /* Set to each huge file */
9684  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
9685 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
9686 +#define EXT4_IUNLINK_FL                        0x08000000 /* Immutable unlink */
9687  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
9688  
9689  #define EXT4_FL_USER_VISIBLE           0x000BDFFF /* User visible flags */
9690 @@ -359,7 +361,8 @@ struct ext4_inode {
9691                         __le16  l_i_file_acl_high;
9692                         __le16  l_i_uid_high;   /* these 2 fields */
9693                         __le16  l_i_gid_high;   /* were reserved2[0] */
9694 -                       __u32   l_i_reserved2;
9695 +                       __u16   l_i_tag;        /* Context Tag */
9696 +                       __u16   l_i_reserved2;
9697                 } linux2;
9698                 struct {
9699                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
9700 @@ -465,6 +468,7 @@ do {                                                                               \
9701  #define i_gid_low      i_gid
9702  #define i_uid_high     osd2.linux2.l_i_uid_high
9703  #define i_gid_high     osd2.linux2.l_i_gid_high
9704 +#define i_raw_tag      osd2.linux2.l_i_tag
9705  #define i_reserved2    osd2.linux2.l_i_reserved2
9706  
9707  #elif defined(__GNU__)
9708 @@ -528,6 +532,7 @@ do {                                                                               \
9709  #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT        0x1000000 /* Journal Async Commit */
9710  #define EXT4_MOUNT_I_VERSION            0x2000000 /* i_version support */
9711  #define EXT4_MOUNT_MBALLOC             0x4000000 /* Buddy allocation support */
9712 +#define EXT4_MOUNT_TAGGED              0x8000000 /* Enable Context Tags */
9713  /* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */
9714  #ifndef _LINUX_EXT2_FS_H
9715  #define clear_opt(o, opt)              o &= ~EXT4_MOUNT_##opt
9716 @@ -1030,6 +1035,7 @@ int ext4_get_blocks_handle(handle_t *han
9717                                 ext4_lblk_t iblock, unsigned long maxblocks,
9718                                 struct buffer_head *bh_result,
9719                                 int create, int extend_disksize);
9720 +extern int ext4_sync_flags(struct inode *inode);
9721  
9722  extern struct inode *ext4_iget(struct super_block *, unsigned long);
9723  extern int  ext4_write_inode (struct inode *, int);
9724 diff -NurpP --minimal linux-2.6.25/include/linux/fs.h linux-2.6.25-vs2.3.0.34.9/include/linux/fs.h
9725 --- linux-2.6.25/include/linux/fs.h     2008-04-17 12:05:44.000000000 -0400
9726 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/fs.h        2008-04-19 15:37:28.000000000 -0400
9727 @@ -125,6 +125,8 @@ extern int dir_notify_enable;
9728  #define MS_RELATIME    (1<<21) /* Update atime relative to mtime/ctime. */
9729  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
9730  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
9731 +#define MS_TAGGED      (1<<24) /* use generic inode tagging */
9732 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
9733  #define MS_ACTIVE      (1<<30)
9734  #define MS_NOUSER      (1<<31)
9735  
9736 @@ -151,6 +153,8 @@ extern int dir_notify_enable;
9737  #define S_NOCMTIME     128     /* Do not update file c/mtime */
9738  #define S_SWAPFILE     256     /* Do not truncate: swapon got its bmaps */
9739  #define S_PRIVATE      512     /* Inode is fs-internal */
9740 +#define S_BARRIER      1024    /* Barrier for chroot() */
9741 +#define S_IUNLINK      2048    /* Immutable unlink */
9742  
9743  /*
9744   * Note that nosuid etc flags are inode-specific: setting some file-system
9745 @@ -167,25 +171,37 @@ extern int dir_notify_enable;
9746   */
9747  #define __IS_FLG(inode,flg) ((inode)->i_sb->s_flags & (flg))
9748  
9749 -#define IS_RDONLY(inode) ((inode)->i_sb->s_flags & MS_RDONLY)
9750 +#define IS_RDONLY(inode)       __IS_FLG(inode, MS_RDONLY)
9751  #define IS_SYNC(inode)         (__IS_FLG(inode, MS_SYNCHRONOUS) || \
9752                                         ((inode)->i_flags & S_SYNC))
9753  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
9754                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
9755  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
9756 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
9757 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
9758 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
9759 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
9760 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
9761  
9762  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
9763  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
9764  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
9765 +#define IS_IUNLINK(inode)      ((inode)->i_flags & S_IUNLINK)
9766 +#define IS_IXORUNLINK(inode)   ((IS_IUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
9767  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
9768  
9769 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_flags & S_BARRIER))
9770  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
9771  #define IS_NOCMTIME(inode)     ((inode)->i_flags & S_NOCMTIME)
9772  #define IS_SWAPFILE(inode)     ((inode)->i_flags & S_SWAPFILE)
9773  #define IS_PRIVATE(inode)      ((inode)->i_flags & S_PRIVATE)
9774  
9775 +#ifdef CONFIG_VSERVER_COWBL
9776 +#  define IS_COW(inode)                (IS_IUNLINK(inode) && IS_IMMUTABLE(inode))
9777 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
9778 +#else
9779 +#  define IS_COW(inode)                (0)
9780 +#  define IS_COW_LINK(inode)   (0)
9781 +#endif
9782 +
9783  /* the read-only stuff doesn't really belong here, but any other place is
9784     probably as bad and I don't want to create yet another include file. */
9785  
9786 @@ -259,12 +275,13 @@ extern int dir_notify_enable;
9787  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
9788  #define FS_EXTENT_FL                   0x00080000 /* Extents */
9789  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
9790 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
9791 +#define FS_IUNLINK_FL                  0x08000000 /* Immutable unlink */
9792  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
9793  
9794  #define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
9795  #define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
9796  
9797 -
9798  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
9799  #define SYNC_FILE_RANGE_WRITE          2
9800  #define SYNC_FILE_RANGE_WAIT_AFTER     4
9801 @@ -334,6 +351,7 @@ typedef void (dio_iodone_t)(struct kiocb
9802  #define ATTR_FILE      8192
9803  #define ATTR_KILL_PRIV 16384
9804  #define ATTR_OPEN      32768   /* Truncating from open(O_TRUNC) */
9805 +#define ATTR_TAG       65536
9806  
9807  /*
9808   * This is the Inode Attributes structure, used for notify_change().  It
9809 @@ -349,6 +367,7 @@ struct iattr {
9810         umode_t         ia_mode;
9811         uid_t           ia_uid;
9812         gid_t           ia_gid;
9813 +       tag_t           ia_tag;
9814         loff_t          ia_size;
9815         struct timespec ia_atime;
9816         struct timespec ia_mtime;
9817 @@ -362,6 +381,9 @@ struct iattr {
9818         struct file     *ia_file;
9819  };
9820  
9821 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
9822 +#define ATTR_FLAG_IUNLINK      1024    /* Immutable unlink */
9823 +
9824  /*
9825   * Includes for diskquotas.
9826   */
9827 @@ -600,7 +622,9 @@ struct inode {
9828         unsigned int            i_nlink;
9829         uid_t                   i_uid;
9830         gid_t                   i_gid;
9831 +       tag_t                   i_tag;
9832         dev_t                   i_rdev;
9833 +       dev_t                   i_mdev;
9834         u64                     i_version;
9835         loff_t                  i_size;
9836  #ifdef __NEED_I_SIZE_ORDERED
9837 @@ -735,12 +759,12 @@ static inline void i_size_write(struct i
9838  
9839  static inline unsigned iminor(const struct inode *inode)
9840  {
9841 -       return MINOR(inode->i_rdev);
9842 +       return MINOR(inode->i_mdev);
9843  }
9844  
9845  static inline unsigned imajor(const struct inode *inode)
9846  {
9847 -       return MAJOR(inode->i_rdev);
9848 +       return MAJOR(inode->i_mdev);
9849  }
9850  
9851  extern struct block_device *I_BDEV(struct inode *inode);
9852 @@ -795,6 +819,7 @@ struct file {
9853         loff_t                  f_pos;
9854         struct fown_struct      f_owner;
9855         unsigned int            f_uid, f_gid;
9856 +       xid_t                   f_xid;
9857         struct file_ra_state    f_ra;
9858  
9859         u64                     f_version;
9860 @@ -879,6 +904,7 @@ struct file_lock {
9861         unsigned char fl_type;
9862         loff_t fl_start;
9863         loff_t fl_end;
9864 +       xid_t fl_xid;
9865  
9866         struct fasync_struct *  fl_fasync; /* for lease break notifications */
9867         unsigned long fl_break_time;    /* for nonblocking lease breaks */
9868 @@ -1076,12 +1102,12 @@ extern void unlock_super(struct super_bl
9869   */
9870  extern int vfs_permission(struct nameidata *, int);
9871  extern int vfs_create(struct inode *, struct dentry *, int, struct nameidata *);
9872 -extern int vfs_mkdir(struct inode *, struct dentry *, int);
9873 -extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t);
9874 -extern int vfs_symlink(struct inode *, struct dentry *, const char *, int);
9875 -extern int vfs_link(struct dentry *, struct inode *, struct dentry *);
9876 -extern int vfs_rmdir(struct inode *, struct dentry *);
9877 -extern int vfs_unlink(struct inode *, struct dentry *);
9878 +extern int vfs_mkdir(struct inode *, struct dentry *, int, struct nameidata *);
9879 +extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t, struct nameidata *);
9880 +extern int vfs_symlink(struct inode *, struct dentry *, const char *, int, struct nameidata *);
9881 +extern int vfs_link(struct dentry *, struct inode *, struct dentry *, struct nameidata *);
9882 +extern int vfs_rmdir(struct inode *, struct dentry *, struct nameidata *);
9883 +extern int vfs_unlink(struct inode *, struct dentry *, struct nameidata *);
9884  extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
9885  
9886  /*
9887 @@ -1223,6 +1249,7 @@ struct inode_operations {
9888         void (*truncate_range)(struct inode *, loff_t, loff_t);
9889         long (*fallocate)(struct inode *inode, int mode, loff_t offset,
9890                           loff_t len);
9891 +       int (*sync_flags) (struct inode *);
9892  };
9893  
9894  struct seq_file;
9895 @@ -1238,6 +1265,7 @@ extern ssize_t vfs_readv(struct file *, 
9896                 unsigned long, loff_t *);
9897  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
9898                 unsigned long, loff_t *);
9899 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
9900  
9901  /*
9902   * NOTE: write_inode, delete_inode, clear_inode, put_inode can be called
9903 @@ -1934,6 +1962,7 @@ extern int dcache_dir_open(struct inode 
9904  extern int dcache_dir_close(struct inode *, struct file *);
9905  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
9906  extern int dcache_readdir(struct file *, void *, filldir_t);
9907 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
9908  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
9909  extern int simple_statfs(struct dentry *, struct kstatfs *);
9910  extern int simple_link(struct dentry *, struct inode *, struct dentry *);
9911 diff -NurpP --minimal linux-2.6.25/include/linux/if_tun.h linux-2.6.25-vs2.3.0.34.9/include/linux/if_tun.h
9912 --- linux-2.6.25/include/linux/if_tun.h 2008-04-17 12:05:44.000000000 -0400
9913 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/if_tun.h    2008-04-19 15:14:52.000000000 -0400
9914 @@ -42,6 +42,7 @@
9915  #define TUNSETOWNER   _IOW('T', 204, int)
9916  #define TUNSETLINK    _IOW('T', 205, int)
9917  #define TUNSETGROUP   _IOW('T', 206, int)
9918 +#define TUNSETNID     _IOW('T', 215, int)
9919  
9920  /* TUNSETIFF ifr flags */
9921  #define IFF_TUN                0x0001
9922 diff -NurpP --minimal linux-2.6.25/include/linux/init_task.h linux-2.6.25-vs2.3.0.34.9/include/linux/init_task.h
9923 --- linux-2.6.25/include/linux/init_task.h      2008-04-17 12:05:44.000000000 -0400
9924 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/init_task.h 2008-04-19 15:14:52.000000000 -0400
9925 @@ -196,6 +196,10 @@ extern struct group_info init_groups;
9926         INIT_IDS                                                        \
9927         INIT_TRACE_IRQFLAGS                                             \
9928         INIT_LOCKDEP                                                    \
9929 +       .xid            = 0,                                            \
9930 +       .vx_info        = NULL,                                         \
9931 +       .nid            = 0,                                            \
9932 +       .nx_info        = NULL,                                         \
9933  }
9934  
9935  
9936 diff -NurpP --minimal linux-2.6.25/include/linux/interrupt.h linux-2.6.25-vs2.3.0.34.9/include/linux/interrupt.h
9937 --- linux-2.6.25/include/linux/interrupt.h      2008-04-17 12:05:44.000000000 -0400
9938 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/interrupt.h 2008-04-19 15:14:52.000000000 -0400
9939 @@ -8,8 +8,8 @@
9940  #include <linux/preempt.h>
9941  #include <linux/cpumask.h>
9942  #include <linux/irqreturn.h>
9943 -#include <linux/hardirq.h>
9944  #include <linux/sched.h>
9945 +#include <linux/hardirq.h>
9946  #include <linux/irqflags.h>
9947  #include <asm/atomic.h>
9948  #include <asm/ptrace.h>
9949 diff -NurpP --minimal linux-2.6.25/include/linux/ipc.h linux-2.6.25-vs2.3.0.34.9/include/linux/ipc.h
9950 --- linux-2.6.25/include/linux/ipc.h    2008-04-17 12:05:44.000000000 -0400
9951 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/ipc.h       2008-04-19 15:14:52.000000000 -0400
9952 @@ -93,6 +93,7 @@ struct kern_ipc_perm
9953         key_t           key;
9954         uid_t           uid;
9955         gid_t           gid;
9956 +       xid_t           xid;
9957         uid_t           cuid;
9958         gid_t           cgid;
9959         mode_t          mode; 
9960 diff -NurpP --minimal linux-2.6.25/include/linux/Kbuild linux-2.6.25-vs2.3.0.34.9/include/linux/Kbuild
9961 --- linux-2.6.25/include/linux/Kbuild   2008-04-17 12:05:44.000000000 -0400
9962 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/Kbuild      2008-04-19 15:14:52.000000000 -0400
9963 @@ -354,3 +354,6 @@ unifdef-y += xattr.h
9964  unifdef-y += xfrm.h
9965  
9966  objhdr-y += version.h
9967 +
9968 +header-y += vserver/
9969 +
9970 diff -NurpP --minimal linux-2.6.25/include/linux/loop.h linux-2.6.25-vs2.3.0.34.9/include/linux/loop.h
9971 --- linux-2.6.25/include/linux/loop.h   2008-04-17 12:05:44.000000000 -0400
9972 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/loop.h      2008-04-19 15:14:52.000000000 -0400
9973 @@ -45,6 +45,7 @@ struct loop_device {
9974         struct loop_func_table *lo_encryption;
9975         __u32           lo_init[2];
9976         uid_t           lo_key_owner;   /* Who set the key */
9977 +       xid_t           lo_xid;
9978         int             (*ioctl)(struct loop_device *, int cmd, 
9979                                  unsigned long arg); 
9980  
9981 diff -NurpP --minimal linux-2.6.25/include/linux/magic.h linux-2.6.25-vs2.3.0.34.9/include/linux/magic.h
9982 --- linux-2.6.25/include/linux/magic.h  2008-04-17 11:31:39.000000000 -0400
9983 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/magic.h     2008-04-19 15:14:52.000000000 -0400
9984 @@ -3,7 +3,7 @@
9985  
9986  #define ADFS_SUPER_MAGIC       0xadf5
9987  #define AFFS_SUPER_MAGIC       0xadff
9988 -#define AFS_SUPER_MAGIC                0x5346414F
9989 +#define AFS_SUPER_MAGIC                0x5346414F
9990  #define AUTOFS_SUPER_MAGIC     0x0187
9991  #define CODA_SUPER_MAGIC       0x73757245
9992  #define EFS_SUPER_MAGIC                0x414A53
9993 @@ -26,6 +26,7 @@
9994  #define NFS_SUPER_MAGIC                0x6969
9995  #define OPENPROM_SUPER_MAGIC   0x9fa1
9996  #define PROC_SUPER_MAGIC       0x9fa0
9997 +#define DEVPTS_SUPER_MAGIC     0x1cd1
9998  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
9999  
10000  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
10001 diff -NurpP --minimal linux-2.6.25/include/linux/major.h linux-2.6.25-vs2.3.0.34.9/include/linux/major.h
10002 --- linux-2.6.25/include/linux/major.h  2008-04-17 10:37:24.000000000 -0400
10003 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/major.h     2008-04-19 15:14:52.000000000 -0400
10004 @@ -15,6 +15,7 @@
10005  #define HD_MAJOR               IDE0_MAJOR
10006  #define PTY_SLAVE_MAJOR                3
10007  #define TTY_MAJOR              4
10008 +#define VROOT_MAJOR            4
10009  #define TTYAUX_MAJOR           5
10010  #define LP_MAJOR               6
10011  #define VCS_MAJOR              7
10012 diff -NurpP --minimal linux-2.6.25/include/linux/mm_types.h linux-2.6.25-vs2.3.0.34.9/include/linux/mm_types.h
10013 --- linux-2.6.25/include/linux/mm_types.h       2008-04-17 12:05:44.000000000 -0400
10014 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/mm_types.h  2008-04-19 15:14:52.000000000 -0400
10015 @@ -201,6 +201,7 @@ struct mm_struct {
10016  
10017         /* Architecture-specific MM context */
10018         mm_context_t context;
10019 +       struct vx_info *mm_vx_info;
10020  
10021         /* Swap token stuff */
10022         /*
10023 diff -NurpP --minimal linux-2.6.25/include/linux/mount.h linux-2.6.25-vs2.3.0.34.9/include/linux/mount.h
10024 --- linux-2.6.25/include/linux/mount.h  2008-04-17 12:05:44.000000000 -0400
10025 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/mount.h     2008-04-19 15:45:19.000000000 -0400
10026 @@ -28,6 +28,9 @@ struct mnt_namespace;
10027  #define MNT_NOATIME    0x08
10028  #define MNT_NODIRATIME 0x10
10029  #define MNT_RELATIME   0x20
10030 +#define MNT_RDONLY     0x40
10031 +
10032 +#define MNT_IS_RDONLY(m)       ((m) && ((m)->mnt_flags & MNT_RDONLY))
10033  
10034  #define MNT_SHRINKABLE 0x100
10035  
10036 @@ -35,6 +38,10 @@ struct mnt_namespace;
10037  #define MNT_UNBINDABLE 0x2000  /* if the vfsmount is a unbindable mount */
10038  #define MNT_PNODE_MASK 0x3000  /* propagation flag mask */
10039  
10040 +#define MNT_TAGID      0x10000
10041 +#define MNT_NOTAG      0x20000
10042 +#define MNT_NOTAGCHECK 0x40000
10043 +
10044  struct vfsmount {
10045         struct list_head mnt_hash;
10046         struct vfsmount *mnt_parent;    /* fs we are mounted on */
10047 @@ -62,6 +69,7 @@ struct vfsmount {
10048         int mnt_expiry_mark;            /* true if marked for expiry */
10049         int mnt_pinned;
10050         int mnt_ghosts;
10051 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
10052  };
10053  
10054  static inline struct vfsmount *mntget(struct vfsmount *mnt)
10055 diff -NurpP --minimal linux-2.6.25/include/linux/net.h linux-2.6.25-vs2.3.0.34.9/include/linux/net.h
10056 --- linux-2.6.25/include/linux/net.h    2008-04-17 12:05:44.000000000 -0400
10057 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/net.h       2008-04-19 15:14:52.000000000 -0400
10058 @@ -65,6 +65,7 @@ typedef enum {
10059  #define SOCK_NOSPACE           2
10060  #define SOCK_PASSCRED          3
10061  #define SOCK_PASSSEC           4
10062 +#define SOCK_USER_SOCKET       5
10063  
10064  #ifndef ARCH_HAS_SOCKET_TYPES
10065  /**
10066 diff -NurpP --minimal linux-2.6.25/include/linux/nfs_mount.h linux-2.6.25-vs2.3.0.34.9/include/linux/nfs_mount.h
10067 --- linux-2.6.25/include/linux/nfs_mount.h      2008-04-17 12:05:44.000000000 -0400
10068 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/nfs_mount.h 2008-04-19 15:14:52.000000000 -0400
10069 @@ -63,6 +63,7 @@ struct nfs_mount_data {
10070  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
10071  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
10072  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
10073 -#define NFS_MOUNT_FLAGMASK     0xFFFF
10074 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
10075 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
10076  
10077  #endif
10078 diff -NurpP --minimal linux-2.6.25/include/linux/nsproxy.h linux-2.6.25-vs2.3.0.34.9/include/linux/nsproxy.h
10079 --- linux-2.6.25/include/linux/nsproxy.h        2008-04-17 11:31:39.000000000 -0400
10080 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/nsproxy.h   2008-04-19 15:14:52.000000000 -0400
10081 @@ -3,6 +3,7 @@
10082  
10083  #include <linux/spinlock.h>
10084  #include <linux/sched.h>
10085 +#include <linux/vserver/debug.h>
10086  
10087  struct mnt_namespace;
10088  struct uts_namespace;
10089 @@ -63,22 +64,33 @@ static inline struct nsproxy *task_nspro
10090  }
10091  
10092  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
10093 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
10094  void exit_task_namespaces(struct task_struct *tsk);
10095  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
10096  void free_nsproxy(struct nsproxy *ns);
10097  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
10098         struct fs_struct *);
10099  
10100 -static inline void put_nsproxy(struct nsproxy *ns)
10101 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
10102 +
10103 +static inline void __get_nsproxy(struct nsproxy *ns,
10104 +       const char *_file, int _line)
10105  {
10106 -       if (atomic_dec_and_test(&ns->count)) {
10107 -               free_nsproxy(ns);
10108 -       }
10109 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
10110 +               ns, atomic_read(&ns->count), _file, _line);
10111 +       atomic_inc(&ns->count);
10112  }
10113  
10114 -static inline void get_nsproxy(struct nsproxy *ns)
10115 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
10116 +
10117 +static inline void __put_nsproxy(struct nsproxy *ns,
10118 +       const char *_file, int _line)
10119  {
10120 -       atomic_inc(&ns->count);
10121 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
10122 +               ns, atomic_read(&ns->count), _file, _line);
10123 +       if (atomic_dec_and_test(&ns->count)) {
10124 +               free_nsproxy(ns);
10125 +       }
10126  }
10127  
10128  #ifdef CONFIG_CGROUP_NS
10129 diff -NurpP --minimal linux-2.6.25/include/linux/pid.h linux-2.6.25-vs2.3.0.34.9/include/linux/pid.h
10130 --- linux-2.6.25/include/linux/pid.h    2008-04-17 12:05:44.000000000 -0400
10131 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/pid.h       2008-04-29 17:56:00.000000000 -0400
10132 @@ -8,7 +8,8 @@ enum pid_type
10133         PIDTYPE_PID,
10134         PIDTYPE_PGID,
10135         PIDTYPE_SID,
10136 -       PIDTYPE_MAX
10137 +       PIDTYPE_MAX,
10138 +       PIDTYPE_REALPID
10139  };
10140  
10141  /*
10142 @@ -142,6 +143,7 @@ static inline pid_t pid_nr(struct pid *p
10143  }
10144  
10145  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
10146 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
10147  pid_t pid_vnr(struct pid *pid);
10148  
10149  #define do_each_pid_task(pid, type, task)                              \
10150 diff -NurpP --minimal linux-2.6.25/include/linux/proc_fs.h linux-2.6.25-vs2.3.0.34.9/include/linux/proc_fs.h
10151 --- linux-2.6.25/include/linux/proc_fs.h        2008-04-17 12:05:44.000000000 -0400
10152 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/proc_fs.h   2008-04-19 15:44:54.000000000 -0400
10153 @@ -59,6 +59,7 @@ struct proc_dir_entry {
10154         nlink_t nlink;
10155         uid_t uid;
10156         gid_t gid;
10157 +       int vx_flags;
10158         loff_t size;
10159         const struct inode_operations *proc_iops;
10160         /*
10161 @@ -265,16 +266,23 @@ static inline void kclist_add(struct kco
10162  extern void kclist_add(struct kcore_list *, void *, size_t);
10163  #endif
10164  
10165 +struct vx_info;
10166 +struct nx_info;
10167 +
10168  union proc_op {
10169         int (*proc_get_link)(struct inode *, struct path *);
10170         int (*proc_read)(struct task_struct *task, char *page);
10171         int (*proc_show)(struct seq_file *m,
10172                 struct pid_namespace *ns, struct pid *pid,
10173                 struct task_struct *task);
10174 +       int (*proc_vs_read)(char *page);
10175 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
10176 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
10177  };
10178  
10179  struct proc_inode {
10180         struct pid *pid;
10181 +       int vx_flags;
10182         int fd;
10183         union proc_op op;
10184         struct proc_dir_entry *pde;
10185 diff -NurpP --minimal linux-2.6.25/include/linux/reiserfs_fs.h linux-2.6.25-vs2.3.0.34.9/include/linux/reiserfs_fs.h
10186 --- linux-2.6.25/include/linux/reiserfs_fs.h    2008-04-17 12:05:44.000000000 -0400
10187 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/reiserfs_fs.h       2008-04-19 15:14:52.000000000 -0400
10188 @@ -837,6 +837,10 @@ struct stat_data_v1 {
10189  #define REISERFS_COMPR_FL     FS_COMPR_FL
10190  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
10191  
10192 +/* unfortunately reiserfs sdattr is only 16 bit */
10193 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
10194 +#define REISERFS_IUNLINK_FL   (FS_IUNLINK_FL >> 16)
10195 +
10196  /* persistent flags that file inherits from the parent directory */
10197  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
10198                                 REISERFS_SYNC_FL |      \
10199 @@ -846,6 +850,9 @@ struct stat_data_v1 {
10200                                 REISERFS_COMPR_FL |     \
10201                                 REISERFS_NOTAIL_FL )
10202  
10203 +#define REISERFS_FL_USER_VISIBLE       0x80FF
10204 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
10205 +
10206  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
10207     address blocks) */
10208  struct stat_data {
10209 @@ -1911,6 +1918,7 @@ static inline void reiserfs_update_sd(st
10210  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
10211  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
10212  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
10213 +int reiserfs_sync_flags(struct inode *inode);
10214  
10215  /* namei.c */
10216  void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
10217 diff -NurpP --minimal linux-2.6.25/include/linux/reiserfs_fs_sb.h linux-2.6.25-vs2.3.0.34.9/include/linux/reiserfs_fs_sb.h
10218 --- linux-2.6.25/include/linux/reiserfs_fs_sb.h 2008-04-17 12:05:44.000000000 -0400
10219 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/reiserfs_fs_sb.h    2008-04-19 15:14:52.000000000 -0400
10220 @@ -456,6 +456,7 @@ enum reiserfs_mount_options {
10221         REISERFS_POSIXACL,
10222         REISERFS_BARRIER_NONE,
10223         REISERFS_BARRIER_FLUSH,
10224 +       REISERFS_TAGGED,
10225  
10226         /* Actions on error */
10227         REISERFS_ERROR_PANIC,
10228 diff -NurpP --minimal linux-2.6.25/include/linux/sched.h linux-2.6.25-vs2.3.0.34.9/include/linux/sched.h
10229 --- linux-2.6.25/include/linux/sched.h  2008-04-17 12:05:44.000000000 -0400
10230 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/sched.h     2008-04-21 11:09:01.000000000 -0400
10231 @@ -73,7 +73,6 @@ struct sched_param {
10232  #include <linux/fs_struct.h>
10233  #include <linux/compiler.h>
10234  #include <linux/completion.h>
10235 -#include <linux/pid.h>
10236  #include <linux/percpu.h>
10237  #include <linux/topology.h>
10238  #include <linux/proportions.h>
10239 @@ -89,6 +88,7 @@ struct sched_param {
10240  #include <linux/task_io_accounting.h>
10241  #include <linux/kobject.h>
10242  #include <linux/latencytop.h>
10243 +#include <linux/pid.h>
10244  
10245  #include <asm/processor.h>
10246  
10247 @@ -355,25 +355,27 @@ extern void arch_unmap_area_topdown(stru
10248   * The mm counters are not protected by its page_table_lock,
10249   * so must be incremented atomically.
10250   */
10251 -#define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
10252 -#define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
10253 -#define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
10254 -#define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
10255 -#define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
10256 -
10257 +#define __set_mm_counter(mm, member, value) \
10258 +       atomic_long_set(&(mm)->_##member, value)
10259 +#define get_mm_counter(mm, member) \
10260 +       ((unsigned long)atomic_long_read(&(mm)->_##member))
10261  #else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
10262  /*
10263   * The mm counters are protected by its page_table_lock,
10264   * so can be incremented directly.
10265   */
10266 -#define set_mm_counter(mm, member, value) (mm)->_##member = (value)
10267 +#define __set_mm_counter(mm, member, value) (mm)->_##member = (value)
10268  #define get_mm_counter(mm, member) ((mm)->_##member)
10269 -#define add_mm_counter(mm, member, value) (mm)->_##member += (value)
10270 -#define inc_mm_counter(mm, member) (mm)->_##member++
10271 -#define dec_mm_counter(mm, member) (mm)->_##member--
10272  
10273  #endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
10274  
10275 +#define set_mm_counter(mm, member, value) \
10276 +       vx_ ## member ## pages_sub((mm), (get_mm_counter(mm, member) - value))
10277 +#define add_mm_counter(mm, member, value) \
10278 +       vx_ ## member ## pages_add((mm), (value))
10279 +#define inc_mm_counter(mm, member) vx_ ## member ## pages_inc((mm))
10280 +#define dec_mm_counter(mm, member) vx_ ## member ## pages_dec((mm))
10281 +
10282  #define get_mm_rss(mm)                                 \
10283         (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
10284  #define update_hiwater_rss(mm) do {                    \
10285 @@ -1162,6 +1164,14 @@ struct task_struct {
10286  #endif
10287         seccomp_t seccomp;
10288  
10289 +/* vserver context data */
10290 +       struct vx_info *vx_info;
10291 +       struct nx_info *nx_info;
10292 +
10293 +       xid_t xid;
10294 +       nid_t nid;
10295 +       tag_t tag;
10296 +
10297  /* Thread group tracking */
10298         u32 parent_exec_id;
10299         u32 self_exec_id;
10300 @@ -1350,6 +1360,11 @@ struct pid_namespace;
10301   * see also pid_nr() etc in include/linux/pid.h
10302   */
10303  
10304 +#include <linux/vserver/base.h>
10305 +#include <linux/vserver/context.h>
10306 +#include <linux/vserver/debug.h>
10307 +#include <linux/vserver/pid.h>
10308 +
10309  static inline pid_t task_pid_nr(struct task_struct *tsk)
10310  {
10311         return tsk->pid;
10312 @@ -1359,7 +1374,7 @@ pid_t task_pid_nr_ns(struct task_struct 
10313  
10314  static inline pid_t task_pid_vnr(struct task_struct *tsk)
10315  {
10316 -       return pid_vnr(task_pid(tsk));
10317 +       return vx_map_pid(pid_vnr(task_pid(tsk)));
10318  }
10319  
10320  
10321 @@ -1372,7 +1387,7 @@ pid_t task_tgid_nr_ns(struct task_struct
10322  
10323  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
10324  {
10325 -       return pid_vnr(task_tgid(tsk));
10326 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
10327  }
10328  
10329  
10330 diff -NurpP --minimal linux-2.6.25/include/linux/shmem_fs.h linux-2.6.25-vs2.3.0.34.9/include/linux/shmem_fs.h
10331 --- linux-2.6.25/include/linux/shmem_fs.h       2008-04-17 12:05:44.000000000 -0400
10332 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/shmem_fs.h  2008-04-19 15:14:52.000000000 -0400
10333 @@ -8,6 +8,9 @@
10334  
10335  #define SHMEM_NR_DIRECT 16
10336  
10337 +#define TMPFS_SUPER_MAGIC      0x01021994
10338 +
10339 +
10340  struct shmem_inode_info {
10341         spinlock_t              lock;
10342         unsigned long           flags;
10343 diff -NurpP --minimal linux-2.6.25/include/linux/stat.h linux-2.6.25-vs2.3.0.34.9/include/linux/stat.h
10344 --- linux-2.6.25/include/linux/stat.h   2008-04-17 10:33:07.000000000 -0400
10345 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/stat.h      2008-04-19 15:14:52.000000000 -0400
10346 @@ -66,6 +66,7 @@ struct kstat {
10347         unsigned int    nlink;
10348         uid_t           uid;
10349         gid_t           gid;
10350 +       tag_t           tag;
10351         dev_t           rdev;
10352         loff_t          size;
10353         struct timespec  atime;
10354 diff -NurpP --minimal linux-2.6.25/include/linux/sunrpc/auth.h linux-2.6.25-vs2.3.0.34.9/include/linux/sunrpc/auth.h
10355 --- linux-2.6.25/include/linux/sunrpc/auth.h    2008-04-17 10:37:24.000000000 -0400
10356 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/sunrpc/auth.h       2008-04-19 15:14:52.000000000 -0400
10357 @@ -25,6 +25,7 @@
10358  struct auth_cred {
10359         uid_t   uid;
10360         gid_t   gid;
10361 +       tag_t   tag;
10362         struct group_info *group_info;
10363  };
10364  
10365 diff -NurpP --minimal linux-2.6.25/include/linux/sunrpc/clnt.h linux-2.6.25-vs2.3.0.34.9/include/linux/sunrpc/clnt.h
10366 --- linux-2.6.25/include/linux/sunrpc/clnt.h    2008-04-17 12:05:44.000000000 -0400
10367 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/sunrpc/clnt.h       2008-04-19 15:14:52.000000000 -0400
10368 @@ -42,7 +42,8 @@ struct rpc_clnt {
10369  
10370         unsigned int            cl_softrtry : 1,/* soft timeouts */
10371                                 cl_discrtry : 1,/* disconnect before retry */
10372 -                               cl_autobind : 1;/* use getport() */
10373 +                               cl_autobind : 1,/* use getport() */
10374 +                               cl_tag      : 1;/* context tagging */
10375  
10376         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
10377         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
10378 diff -NurpP --minimal linux-2.6.25/include/linux/syscalls.h linux-2.6.25-vs2.3.0.34.9/include/linux/syscalls.h
10379 --- linux-2.6.25/include/linux/syscalls.h       2008-04-17 12:05:44.000000000 -0400
10380 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/syscalls.h  2008-04-19 15:14:52.000000000 -0400
10381 @@ -294,6 +294,8 @@ asmlinkage long sys_symlink(const char _
10382  asmlinkage long sys_unlink(const char __user *pathname);
10383  asmlinkage long sys_rename(const char __user *oldname,
10384                                 const char __user *newname);
10385 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
10386 +                               umode_t mode);
10387  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
10388  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
10389  
10390 diff -NurpP --minimal linux-2.6.25/include/linux/sysctl.h linux-2.6.25-vs2.3.0.34.9/include/linux/sysctl.h
10391 --- linux-2.6.25/include/linux/sysctl.h 2008-04-17 12:05:44.000000000 -0400
10392 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/sysctl.h    2008-04-19 15:14:52.000000000 -0400
10393 @@ -70,6 +70,7 @@ enum
10394         CTL_ABI=9,              /* Binary emulation */
10395         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
10396         CTL_ARLAN=254,          /* arlan wireless driver */
10397 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
10398         CTL_S390DBF=5677,       /* s390 debug */
10399         CTL_SUNRPC=7249,        /* sunrpc debug */
10400         CTL_PM=9899,            /* frv power management */
10401 @@ -104,6 +105,7 @@ enum
10402  
10403         KERN_PANIC=15,          /* int: panic timeout */
10404         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
10405 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
10406  
10407         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
10408         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
10409 diff -NurpP --minimal linux-2.6.25/include/linux/sysfs.h linux-2.6.25-vs2.3.0.34.9/include/linux/sysfs.h
10410 --- linux-2.6.25/include/linux/sysfs.h  2008-04-17 12:05:44.000000000 -0400
10411 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/sysfs.h     2008-04-19 15:14:52.000000000 -0400
10412 @@ -17,6 +17,8 @@
10413  #include <linux/list.h>
10414  #include <asm/atomic.h>
10415  
10416 +#define SYSFS_SUPER_MAGIC      0x62656572
10417 +
10418  struct kobject;
10419  struct module;
10420  
10421 diff -NurpP --minimal linux-2.6.25/include/linux/time.h linux-2.6.25-vs2.3.0.34.9/include/linux/time.h
10422 --- linux-2.6.25/include/linux/time.h   2008-04-17 12:05:44.000000000 -0400
10423 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/time.h      2008-04-19 15:14:52.000000000 -0400
10424 @@ -183,6 +183,9 @@ static inline void timespec_add_ns(struc
10425         }
10426         a->tv_nsec = ns;
10427  }
10428 +
10429 +#include <linux/vs_time.h>
10430 +
10431  #endif /* __KERNEL__ */
10432  
10433  #define NFDBITS                        __NFDBITS
10434 diff -NurpP --minimal linux-2.6.25/include/linux/types.h linux-2.6.25-vs2.3.0.34.9/include/linux/types.h
10435 --- linux-2.6.25/include/linux/types.h  2008-04-17 12:05:44.000000000 -0400
10436 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/types.h     2008-04-19 15:14:52.000000000 -0400
10437 @@ -36,6 +36,9 @@ typedef __kernel_uid32_t      uid_t;
10438  typedef __kernel_gid32_t       gid_t;
10439  typedef __kernel_uid16_t        uid16_t;
10440  typedef __kernel_gid16_t        gid16_t;
10441 +typedef unsigned int           xid_t;
10442 +typedef unsigned int           nid_t;
10443 +typedef unsigned int           tag_t;
10444  
10445  typedef unsigned long          uintptr_t;
10446  
10447 diff -NurpP --minimal linux-2.6.25/include/linux/vroot.h linux-2.6.25-vs2.3.0.34.9/include/linux/vroot.h
10448 --- linux-2.6.25/include/linux/vroot.h  1969-12-31 19:00:00.000000000 -0500
10449 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vroot.h     2008-04-19 15:14:52.000000000 -0400
10450 @@ -0,0 +1,51 @@
10451 +
10452 +/*
10453 + * include/linux/vroot.h
10454 + *
10455 + * written by Herbert Pötzl, 9/11/2002
10456 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
10457 + *
10458 + * Copyright (C) 2002-2007 by Herbert Pötzl.
10459 + * Redistribution of this file is permitted under the
10460 + * GNU General Public License.
10461 + */
10462 +
10463 +#ifndef _LINUX_VROOT_H
10464 +#define _LINUX_VROOT_H
10465 +
10466 +
10467 +#ifdef __KERNEL__
10468 +
10469 +/* Possible states of device */
10470 +enum {
10471 +       Vr_unbound,
10472 +       Vr_bound,
10473 +};
10474 +
10475 +struct vroot_device {
10476 +       int             vr_number;
10477 +       int             vr_refcnt;
10478 +
10479 +       struct semaphore        vr_ctl_mutex;
10480 +       struct block_device    *vr_device;
10481 +       int                     vr_state;
10482 +};
10483 +
10484 +
10485 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
10486 +
10487 +extern int register_vroot_grb(vroot_grb_func *);
10488 +extern int unregister_vroot_grb(vroot_grb_func *);
10489 +
10490 +#endif /* __KERNEL__ */
10491 +
10492 +#define MAX_VROOT_DEFAULT      8
10493 +
10494 +/*
10495 + * IOCTL commands --- we will commandeer 0x56 ('V')
10496 + */
10497 +
10498 +#define VROOT_SET_DEV          0x5600
10499 +#define VROOT_CLR_DEV          0x5601
10500 +
10501 +#endif /* _LINUX_VROOT_H */
10502 diff -NurpP --minimal linux-2.6.25/include/linux/vs_base.h linux-2.6.25-vs2.3.0.34.9/include/linux/vs_base.h
10503 --- linux-2.6.25/include/linux/vs_base.h        1969-12-31 19:00:00.000000000 -0500
10504 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vs_base.h   2008-04-19 15:14:52.000000000 -0400
10505 @@ -0,0 +1,10 @@
10506 +#ifndef _VS_BASE_H
10507 +#define _VS_BASE_H
10508 +
10509 +#include "vserver/base.h"
10510 +#include "vserver/check.h"
10511 +#include "vserver/debug.h"
10512 +
10513 +#else
10514 +#warning duplicate inclusion
10515 +#endif
10516 diff -NurpP --minimal linux-2.6.25/include/linux/vs_context.h linux-2.6.25-vs2.3.0.34.9/include/linux/vs_context.h
10517 --- linux-2.6.25/include/linux/vs_context.h     1969-12-31 19:00:00.000000000 -0500
10518 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vs_context.h        2008-04-29 18:42:09.000000000 -0400
10519 @@ -0,0 +1,227 @@
10520 +#ifndef _VS_CONTEXT_H
10521 +#define _VS_CONTEXT_H
10522 +
10523 +#include "vserver/base.h"
10524 +#include "vserver/check.h"
10525 +#include "vserver/context.h"
10526 +#include "vserver/history.h"
10527 +#include "vserver/debug.h"
10528 +
10529 +#include <linux/sched.h>
10530 +
10531 +
10532 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
10533 +
10534 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
10535 +       const char *_file, int _line, void *_here)
10536 +{
10537 +       if (!vxi)
10538 +               return NULL;
10539 +
10540 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
10541 +               vxi, vxi ? vxi->vx_id : 0,
10542 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
10543 +               _file, _line);
10544 +       __vxh_get_vx_info(vxi, _here);
10545 +
10546 +       atomic_inc(&vxi->vx_usecnt);
10547 +       return vxi;
10548 +}
10549 +
10550 +
10551 +extern void free_vx_info(struct vx_info *);
10552 +
10553 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
10554 +
10555 +static inline void __put_vx_info(struct vx_info *vxi,
10556 +       const char *_file, int _line, void *_here)
10557 +{
10558 +       if (!vxi)
10559 +               return;
10560 +
10561 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
10562 +               vxi, vxi ? vxi->vx_id : 0,
10563 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
10564 +               _file, _line);
10565 +       __vxh_put_vx_info(vxi, _here);
10566 +
10567 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
10568 +               free_vx_info(vxi);
10569 +}
10570 +
10571 +
10572 +#define init_vx_info(p, i) \
10573 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
10574 +
10575 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
10576 +       const char *_file, int _line, void *_here)
10577 +{
10578 +       if (vxi) {
10579 +               vxlprintk(VXD_CBIT(xid, 3),
10580 +                       "init_vx_info(%p[#%d.%d])",
10581 +                       vxi, vxi ? vxi->vx_id : 0,
10582 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
10583 +                       _file, _line);
10584 +               __vxh_init_vx_info(vxi, vxp, _here);
10585 +
10586 +               atomic_inc(&vxi->vx_usecnt);
10587 +       }
10588 +       *vxp = vxi;
10589 +}
10590 +
10591 +
10592 +#define set_vx_info(p, i) \
10593 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
10594 +
10595 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
10596 +       const char *_file, int _line, void *_here)
10597 +{
10598 +       struct vx_info *vxo;
10599 +
10600 +       if (!vxi)
10601 +               return;
10602 +
10603 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
10604 +               vxi, vxi ? vxi->vx_id : 0,
10605 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
10606 +               _file, _line);
10607 +       __vxh_set_vx_info(vxi, vxp, _here);
10608 +
10609 +       atomic_inc(&vxi->vx_usecnt);
10610 +       vxo = xchg(vxp, vxi);
10611 +       BUG_ON(vxo);
10612 +}
10613 +
10614 +
10615 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
10616 +
10617 +static inline void __clr_vx_info(struct vx_info **vxp,
10618 +       const char *_file, int _line, void *_here)
10619 +{
10620 +       struct vx_info *vxo;
10621 +
10622 +       vxo = xchg(vxp, NULL);
10623 +       if (!vxo)
10624 +               return;
10625 +
10626 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
10627 +               vxo, vxo ? vxo->vx_id : 0,
10628 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
10629 +               _file, _line);
10630 +       __vxh_clr_vx_info(vxo, vxp, _here);
10631 +
10632 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
10633 +               free_vx_info(vxo);
10634 +}
10635 +
10636 +
10637 +#define claim_vx_info(v, p) \
10638 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
10639 +
10640 +static inline void __claim_vx_info(struct vx_info *vxi,
10641 +       struct task_struct *task,
10642 +       const char *_file, int _line, void *_here)
10643 +{
10644 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
10645 +               vxi, vxi ? vxi->vx_id : 0,
10646 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
10647 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
10648 +               task, _file, _line);
10649 +       __vxh_claim_vx_info(vxi, task, _here);
10650 +
10651 +       atomic_inc(&vxi->vx_tasks);
10652 +}
10653 +
10654 +
10655 +extern void unhash_vx_info(struct vx_info *);
10656 +
10657 +#define release_vx_info(v, p) \
10658 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
10659 +
10660 +static inline void __release_vx_info(struct vx_info *vxi,
10661 +       struct task_struct *task,
10662 +       const char *_file, int _line, void *_here)
10663 +{
10664 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
10665 +               vxi, vxi ? vxi->vx_id : 0,
10666 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
10667 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
10668 +               task, _file, _line);
10669 +       __vxh_release_vx_info(vxi, task, _here);
10670 +
10671 +       might_sleep();
10672 +
10673 +       if (atomic_dec_and_test(&vxi->vx_tasks))
10674 +               unhash_vx_info(vxi);
10675 +}
10676 +
10677 +
10678 +#define task_get_vx_info(p) \
10679 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
10680 +
10681 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
10682 +       const char *_file, int _line, void *_here)
10683 +{
10684 +       struct vx_info *vxi;
10685 +
10686 +       task_lock(p);
10687 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
10688 +               p, _file, _line);
10689 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
10690 +       task_unlock(p);
10691 +       return vxi;
10692 +}
10693 +
10694 +
10695 +static inline void __wakeup_vx_info(struct vx_info *vxi)
10696 +{
10697 +       if (waitqueue_active(&vxi->vx_wait))
10698 +               wake_up_interruptible(&vxi->vx_wait);
10699 +}
10700 +
10701 +
10702 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
10703 +
10704 +static inline void __enter_vx_info(struct vx_info *vxi,
10705 +       struct vx_info_save *vxis, const char *_file, int _line)
10706 +{
10707 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
10708 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
10709 +               current->xid, current->vx_info, _file, _line);
10710 +       vxis->vxi = xchg(&current->vx_info, vxi);
10711 +       vxis->xid = current->xid;
10712 +       current->xid = vxi ? vxi->vx_id : 0;
10713 +}
10714 +
10715 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
10716 +
10717 +static inline void __leave_vx_info(struct vx_info_save *vxis,
10718 +       const char *_file, int _line)
10719 +{
10720 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
10721 +               vxis, vxis->xid, vxis->vxi, current,
10722 +               current->xid, current->vx_info, _file, _line);
10723 +       (void)xchg(&current->vx_info, vxis->vxi);
10724 +       current->xid = vxis->xid;
10725 +}
10726 +
10727 +
10728 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
10729 +{
10730 +       vxis->vxi = xchg(&current->vx_info, NULL);
10731 +       vxis->xid = xchg(&current->xid, (xid_t)0);
10732 +}
10733 +
10734 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
10735 +{
10736 +       (void)xchg(&current->xid, vxis->xid);
10737 +       (void)xchg(&current->vx_info, vxis->vxi);
10738 +}
10739 +
10740 +extern void exit_vx_info(struct task_struct *, int);
10741 +extern void exit_vx_info_early(struct task_struct *, int);
10742 +
10743 +
10744 +#else
10745 +#warning duplicate inclusion
10746 +#endif
10747 diff -NurpP --minimal linux-2.6.25/include/linux/vs_cowbl.h linux-2.6.25-vs2.3.0.34.9/include/linux/vs_cowbl.h
10748 --- linux-2.6.25/include/linux/vs_cowbl.h       1969-12-31 19:00:00.000000000 -0500
10749 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vs_cowbl.h  2008-04-21 13:49:51.000000000 -0400
10750 @@ -0,0 +1,44 @@
10751 +#ifndef _VS_COWBL_H
10752 +#define _VS_COWBL_H
10753 +
10754 +#include <linux/fs.h>
10755 +#include <linux/dcache.h>
10756 +#include <linux/namei.h>
10757 +
10758 +extern struct dentry *cow_break_link(const char *pathname);
10759 +
10760 +static inline int cow_check_and_break(struct nameidata *nd)
10761 +{
10762 +       struct inode *inode = nd->path.dentry->d_inode;
10763 +       int error = 0;
10764 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(nd->path.mnt))
10765 +               return -EROFS;
10766 +       if (IS_COW(inode)) {
10767 +               if (IS_COW_LINK(inode)) {
10768 +                       struct dentry *new_dentry, *old_dentry = nd->path.dentry;
10769 +                       char *path, *buf;
10770 +
10771 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
10772 +                       if (!buf) {
10773 +                               return -ENOMEM;
10774 +                       }
10775 +                       path = d_path(&nd->path, buf, PATH_MAX);
10776 +                       new_dentry = cow_break_link(path);
10777 +                       kfree(buf);
10778 +                       if (!IS_ERR(new_dentry)) {
10779 +                               nd->path.dentry = new_dentry;
10780 +                               dput(old_dentry);
10781 +                       } else
10782 +                               error = PTR_ERR(new_dentry);
10783 +               } else {
10784 +                       inode->i_flags &= ~(S_IUNLINK | S_IMMUTABLE);
10785 +                       inode->i_ctime = CURRENT_TIME;
10786 +                       mark_inode_dirty(inode);
10787 +               }
10788 +       }
10789 +       return error;
10790 +}
10791 +
10792 +#else
10793 +#warning duplicate inclusion
10794 +#endif
10795 diff -NurpP --minimal linux-2.6.25/include/linux/vs_cvirt.h linux-2.6.25-vs2.3.0.34.9/include/linux/vs_cvirt.h
10796 --- linux-2.6.25/include/linux/vs_cvirt.h       1969-12-31 19:00:00.000000000 -0500
10797 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vs_cvirt.h  2008-04-19 15:14:52.000000000 -0400
10798 @@ -0,0 +1,50 @@
10799 +#ifndef _VS_CVIRT_H
10800 +#define _VS_CVIRT_H
10801 +
10802 +#include "vserver/cvirt.h"
10803 +#include "vserver/context.h"
10804 +#include "vserver/base.h"
10805 +#include "vserver/check.h"
10806 +#include "vserver/debug.h"
10807 +
10808 +
10809 +static inline void vx_activate_task(struct task_struct *p)
10810 +{
10811 +       struct vx_info *vxi;
10812 +
10813 +       if ((vxi = p->vx_info)) {
10814 +               vx_update_load(vxi);
10815 +               atomic_inc(&vxi->cvirt.nr_running);
10816 +       }
10817 +}
10818 +
10819 +static inline void vx_deactivate_task(struct task_struct *p)
10820 +{
10821 +       struct vx_info *vxi;
10822 +
10823 +       if ((vxi = p->vx_info)) {
10824 +               vx_update_load(vxi);
10825 +               atomic_dec(&vxi->cvirt.nr_running);
10826 +       }
10827 +}
10828 +
10829 +static inline void vx_uninterruptible_inc(struct task_struct *p)
10830 +{
10831 +       struct vx_info *vxi;
10832 +
10833 +       if ((vxi = p->vx_info))
10834 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
10835 +}
10836 +
10837 +static inline void vx_uninterruptible_dec(struct task_struct *p)
10838 +{
10839 +       struct vx_info *vxi;
10840 +
10841 +       if ((vxi = p->vx_info))
10842 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
10843 +}
10844 +
10845 +
10846 +#else
10847 +#warning duplicate inclusion
10848 +#endif
10849 diff -NurpP --minimal linux-2.6.25/include/linux/vs_device.h linux-2.6.25-vs2.3.0.34.9/include/linux/vs_device.h
10850 --- linux-2.6.25/include/linux/vs_device.h      1969-12-31 19:00:00.000000000 -0500
10851 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vs_device.h 2008-04-19 15:14:52.000000000 -0400
10852 @@ -0,0 +1,45 @@
10853 +#ifndef _VS_DEVICE_H
10854 +#define _VS_DEVICE_H
10855 +
10856 +#include "vserver/base.h"
10857 +#include "vserver/device.h"
10858 +#include "vserver/debug.h"
10859 +
10860 +
10861 +#ifdef CONFIG_VSERVER_DEVICE
10862 +
10863 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
10864 +
10865 +#define vs_device_perm(v, d, m, p) \
10866 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
10867 +
10868 +#else
10869 +
10870 +static inline
10871 +int vs_map_device(struct vx_info *vxi,
10872 +       dev_t device, dev_t *target, umode_t mode)
10873 +{
10874 +       if (target)
10875 +               *target = device;
10876 +       return ~0;
10877 +}
10878 +
10879 +#define vs_device_perm(v, d, m, p) ((p) == (p))
10880 +
10881 +#endif
10882 +
10883 +
10884 +#define vs_map_chrdev(d, t, p) \
10885 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
10886 +#define vs_map_blkdev(d, t, p) \
10887 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
10888 +
10889 +#define vs_chrdev_perm(d, p) \
10890 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
10891 +#define vs_blkdev_perm(d, p) \
10892 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
10893 +
10894 +
10895 +#else
10896 +#warning duplicate inclusion
10897 +#endif
10898 diff -NurpP --minimal linux-2.6.25/include/linux/vs_dlimit.h linux-2.6.25-vs2.3.0.34.9/include/linux/vs_dlimit.h
10899 --- linux-2.6.25/include/linux/vs_dlimit.h      1969-12-31 19:00:00.000000000 -0500
10900 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vs_dlimit.h 2008-04-19 15:14:52.000000000 -0400
10901 @@ -0,0 +1,211 @@
10902 +#ifndef _VS_DLIMIT_H
10903 +#define _VS_DLIMIT_H
10904 +
10905 +#include <linux/fs.h>
10906 +
10907 +#include "vserver/dlimit.h"
10908 +#include "vserver/base.h"
10909 +#include "vserver/debug.h"
10910 +
10911 +
10912 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
10913 +
10914 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
10915 +       const char *_file, int _line)
10916 +{
10917 +       if (!dli)
10918 +               return NULL;
10919 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
10920 +               dli, dli ? dli->dl_tag : 0,
10921 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
10922 +               _file, _line);
10923 +       atomic_inc(&dli->dl_usecnt);
10924 +       return dli;
10925 +}
10926 +
10927 +
10928 +#define free_dl_info(i) \
10929 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
10930 +
10931 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
10932 +
10933 +static inline void __put_dl_info(struct dl_info *dli,
10934 +       const char *_file, int _line)
10935 +{
10936 +       if (!dli)
10937 +               return;
10938 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
10939 +               dli, dli ? dli->dl_tag : 0,
10940 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
10941 +               _file, _line);
10942 +       if (atomic_dec_and_test(&dli->dl_usecnt))
10943 +               free_dl_info(dli);
10944 +}
10945 +
10946 +
10947 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
10948 +
10949 +static inline int __dl_alloc_space(struct super_block *sb,
10950 +       tag_t tag, dlsize_t nr, const char *file, int line)
10951 +{
10952 +       struct dl_info *dli = NULL;
10953 +       int ret = 0;
10954 +
10955 +       if (nr == 0)
10956 +               goto out;
10957 +       dli = locate_dl_info(sb, tag);
10958 +       if (!dli)
10959 +               goto out;
10960 +
10961 +       spin_lock(&dli->dl_lock);
10962 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
10963 +       if (!ret)
10964 +               dli->dl_space_used += nr;
10965 +       spin_unlock(&dli->dl_lock);
10966 +       put_dl_info(dli);
10967 +out:
10968 +       vxlprintk(VXD_CBIT(dlim, 1),
10969 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
10970 +               sb, tag, __dlimit_char(dli), (long long)nr,
10971 +               ret, file, line);
10972 +       return ret;
10973 +}
10974 +
10975 +static inline void __dl_free_space(struct super_block *sb,
10976 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
10977 +{
10978 +       struct dl_info *dli = NULL;
10979 +
10980 +       if (nr == 0)
10981 +               goto out;
10982 +       dli = locate_dl_info(sb, tag);
10983 +       if (!dli)
10984 +               goto out;
10985 +
10986 +       spin_lock(&dli->dl_lock);
10987 +       if (dli->dl_space_used > nr)
10988 +               dli->dl_space_used -= nr;
10989 +       else
10990 +               dli->dl_space_used = 0;
10991 +       spin_unlock(&dli->dl_lock);
10992 +       put_dl_info(dli);
10993 +out:
10994 +       vxlprintk(VXD_CBIT(dlim, 1),
10995 +               "FREE  (%p,#%d)%c %lld bytes",
10996 +               sb, tag, __dlimit_char(dli), (long long)nr,
10997 +               _file, _line);
10998 +}
10999 +
11000 +static inline int __dl_alloc_inode(struct super_block *sb,
11001 +       tag_t tag, const char *_file, int _line)
11002 +{
11003 +       struct dl_info *dli;
11004 +       int ret = 0;
11005 +
11006 +       dli = locate_dl_info(sb, tag);
11007 +       if (!dli)
11008 +               goto out;
11009 +
11010 +       spin_lock(&dli->dl_lock);
11011 +       ret = (dli->dl_inodes_used >= dli->dl_inodes_total);
11012 +       if (!ret)
11013 +               dli->dl_inodes_used++;
11014 +       spin_unlock(&dli->dl_lock);
11015 +       put_dl_info(dli);
11016 +out:
11017 +       vxlprintk(VXD_CBIT(dlim, 0),
11018 +               "ALLOC (%p,#%d)%c inode (%d)",
11019 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
11020 +       return ret;
11021 +}
11022 +
11023 +static inline void __dl_free_inode(struct super_block *sb,
11024 +       tag_t tag, const char *_file, int _line)
11025 +{
11026 +       struct dl_info *dli;
11027 +
11028 +       dli = locate_dl_info(sb, tag);
11029 +       if (!dli)
11030 +               goto out;
11031 +
11032 +       spin_lock(&dli->dl_lock);
11033 +       if (dli->dl_inodes_used > 1)
11034 +               dli->dl_inodes_used--;
11035 +       else
11036 +               dli->dl_inodes_used = 0;
11037 +       spin_unlock(&dli->dl_lock);
11038 +       put_dl_info(dli);
11039 +out:
11040 +       vxlprintk(VXD_CBIT(dlim, 0),
11041 +               "FREE  (%p,#%d)%c inode",
11042 +               sb, tag, __dlimit_char(dli), _file, _line);
11043 +}
11044 +
11045 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
11046 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
11047 +       const char *_file, int _line)
11048 +{
11049 +       struct dl_info *dli;
11050 +       uint64_t broot, bfree;
11051 +
11052 +       dli = locate_dl_info(sb, tag);
11053 +       if (!dli)
11054 +               return;
11055 +
11056 +       spin_lock(&dli->dl_lock);
11057 +       broot = (dli->dl_space_total -
11058 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
11059 +               >> sb->s_blocksize_bits;
11060 +       bfree = (dli->dl_space_total - dli->dl_space_used)
11061 +                       >> sb->s_blocksize_bits;
11062 +       spin_unlock(&dli->dl_lock);
11063 +
11064 +       vxlprintk(VXD_CBIT(dlim, 2),
11065 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
11066 +               (long long)bfree, (long long)broot,
11067 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
11068 +               _file, _line);
11069 +       if (free_blocks) {
11070 +               if (*free_blocks > bfree)
11071 +                       *free_blocks = bfree;
11072 +       }
11073 +       if (root_blocks) {
11074 +               if (*root_blocks > broot)
11075 +                       *root_blocks = broot;
11076 +       }
11077 +       put_dl_info(dli);
11078 +}
11079 +
11080 +#define DLIMIT_ALLOC_SPACE(in, bytes) \
11081 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
11082 +               __FILE__, __LINE__ )
11083 +
11084 +#define DLIMIT_FREE_SPACE(in, bytes) \
11085 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
11086 +               __FILE__, __LINE__ )
11087 +
11088 +#define DLIMIT_ALLOC_BLOCK(in, nr) \
11089 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, \
11090 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
11091 +               __FILE__, __LINE__ )
11092 +
11093 +#define DLIMIT_FREE_BLOCK(in, nr) \
11094 +       __dl_free_space((in)->i_sb, (in)->i_tag, \
11095 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
11096 +               __FILE__, __LINE__ )
11097 +
11098 +
11099 +#define DLIMIT_ALLOC_INODE(in) \
11100 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
11101 +
11102 +#define DLIMIT_FREE_INODE(in) \
11103 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
11104 +
11105 +
11106 +#define DLIMIT_ADJUST_BLOCK(sb, tag, fb, rb) \
11107 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
11108 +
11109 +
11110 +#else
11111 +#warning duplicate inclusion
11112 +#endif
11113 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/base.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/base.h
11114 --- linux-2.6.25/include/linux/vserver/base.h   1969-12-31 19:00:00.000000000 -0500
11115 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/base.h      2008-04-23 20:52:31.000000000 -0400
11116 @@ -0,0 +1,157 @@
11117 +#ifndef _VX_BASE_H
11118 +#define _VX_BASE_H
11119 +
11120 +
11121 +/* context state changes */
11122 +
11123 +enum {
11124 +       VSC_STARTUP = 1,
11125 +       VSC_SHUTDOWN,
11126 +
11127 +       VSC_NETUP,
11128 +       VSC_NETDOWN,
11129 +};
11130 +
11131 +
11132 +
11133 +#define vx_task_xid(t) ((t)->xid)
11134 +
11135 +#define vx_current_xid() vx_task_xid(current)
11136 +
11137 +#define current_vx_info() (current->vx_info)
11138 +
11139 +
11140 +#define nx_task_nid(t) ((t)->nid)
11141 +
11142 +#define nx_current_nid() nx_task_nid(current)
11143 +
11144 +#define current_nx_info() (current->nx_info)
11145 +
11146 +
11147 +/* generic flag merging */
11148 +
11149 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
11150 +
11151 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
11152 +
11153 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
11154 +
11155 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
11156 +
11157 +
11158 +/* context flags */
11159 +
11160 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
11161 +
11162 +#define vx_current_flags()     __vx_flags(current->vx_info)
11163 +
11164 +#define vx_info_flags(v, m, f) \
11165 +       vs_check_flags(__vx_flags(v), m, f)
11166 +
11167 +#define task_vx_flags(t, m, f) \
11168 +       ((t) && vx_info_flags((t)->vx_info, m, f))
11169 +
11170 +#define vx_flags(m, f) vx_info_flags(current->vx_info, m, f)
11171 +
11172 +
11173 +/* context caps */
11174 +
11175 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
11176 +
11177 +#define vx_current_ccaps()     __vx_ccaps(current->vx_info)
11178 +
11179 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
11180 +
11181 +#define vx_ccaps(c)    vx_info_ccaps(current->vx_info, (c))
11182 +
11183 +
11184 +
11185 +/* network flags */
11186 +
11187 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
11188 +
11189 +#define nx_current_flags()     __nx_flags(current->nx_info)
11190 +
11191 +#define nx_info_flags(n, m, f) \
11192 +       vs_check_flags(__nx_flags(n), m, f)
11193 +
11194 +#define task_nx_flags(t, m, f) \
11195 +       ((t) && nx_info_flags((t)->nx_info, m, f))
11196 +
11197 +#define nx_flags(m, f) nx_info_flags(current->nx_info, m, f)
11198 +
11199 +
11200 +/* network caps */
11201 +
11202 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
11203 +
11204 +#define nx_current_ncaps()     __nx_ncaps(current->nx_info)
11205 +
11206 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
11207 +
11208 +#define nx_ncaps(c)    nx_info_ncaps(current->nx_info, c)
11209 +
11210 +
11211 +/* context mask capabilities */
11212 +
11213 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
11214 +
11215 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
11216 +
11217 +#define vx_mcaps(c)    vx_info_mcaps(current->vx_info, c)
11218 +
11219 +
11220 +/* context bcap mask */
11221 +
11222 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
11223 +
11224 +#define vx_current_bcaps()     __vx_bcaps(current->vx_info)
11225 +
11226 +
11227 +/* mask given bcaps */
11228 +
11229 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
11230 +
11231 +#define vx_mbcaps(c)           vx_info_mbcaps(current->vx_info, c)
11232 +
11233 +
11234 +/* masked cap_bset */
11235 +
11236 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
11237 +
11238 +#define vx_current_cap_bset()  vx_info_cap_bset(current->vx_info)
11239 +
11240 +#if 0
11241 +#define vx_info_mbcap(v, b) \
11242 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
11243 +       vx_info_bcaps(v, b) : (b))
11244 +
11245 +#define task_vx_mbcap(t, b) \
11246 +       vx_info_mbcap((t)->vx_info, (t)->b)
11247 +
11248 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
11249 +#endif
11250 +
11251 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
11252 +
11253 +#define vx_capable(b, c) (capable(b) || \
11254 +       (cap_raised(current->cap_effective, b) && vx_ccaps(c)))
11255 +
11256 +#define nx_capable(b, c) (capable(b) || \
11257 +       (cap_raised(current->cap_effective, b) && nx_ncaps(c)))
11258 +
11259 +#define vx_current_initpid(n) \
11260 +       (current->vx_info && \
11261 +       (current->vx_info->vx_initpid == (n)))
11262 +
11263 +
11264 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
11265 +
11266 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
11267 +
11268 +
11269 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
11270 +
11271 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
11272 +
11273 +#endif
11274 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/cacct_cmd.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/cacct_cmd.h
11275 --- linux-2.6.25/include/linux/vserver/cacct_cmd.h      1969-12-31 19:00:00.000000000 -0500
11276 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/cacct_cmd.h 2008-04-19 15:14:52.000000000 -0400
11277 @@ -0,0 +1,23 @@
11278 +#ifndef _VX_CACCT_CMD_H
11279 +#define _VX_CACCT_CMD_H
11280 +
11281 +
11282 +/* virtual host info name commands */
11283 +
11284 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
11285 +
11286 +struct vcmd_sock_stat_v0 {
11287 +       uint32_t field;
11288 +       uint32_t count[3];
11289 +       uint64_t total[3];
11290 +};
11291 +
11292 +
11293 +#ifdef __KERNEL__
11294 +
11295 +#include <linux/compiler.h>
11296 +
11297 +extern int vc_sock_stat(struct vx_info *, void __user *);
11298 +
11299 +#endif /* __KERNEL__ */
11300 +#endif /* _VX_CACCT_CMD_H */
11301 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/cacct_def.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/cacct_def.h
11302 --- linux-2.6.25/include/linux/vserver/cacct_def.h      1969-12-31 19:00:00.000000000 -0500
11303 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/cacct_def.h 2008-04-19 15:14:52.000000000 -0400
11304 @@ -0,0 +1,43 @@
11305 +#ifndef _VX_CACCT_DEF_H
11306 +#define _VX_CACCT_DEF_H
11307 +
11308 +#include <asm/atomic.h>
11309 +#include <linux/vserver/cacct.h>
11310 +
11311 +
11312 +struct _vx_sock_acc {
11313 +       atomic_long_t count;
11314 +       atomic_long_t total;
11315 +};
11316 +
11317 +/* context sub struct */
11318 +
11319 +struct _vx_cacct {
11320 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
11321 +       atomic_t slab[8];
11322 +       atomic_t page[6][8];
11323 +};
11324 +
11325 +#ifdef CONFIG_VSERVER_DEBUG
11326 +
11327 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
11328 +{
11329 +       int i, j;
11330 +
11331 +       printk("\t_vx_cacct:");
11332 +       for (i = 0; i < 6; i++) {
11333 +               struct _vx_sock_acc *ptr = cacct->sock[i];
11334 +
11335 +               printk("\t [%d] =", i);
11336 +               for (j = 0; j < 3; j++) {
11337 +                       printk(" [%d] = %8lu, %8lu", j,
11338 +                               atomic_long_read(&ptr[j].count),
11339 +                               atomic_long_read(&ptr[j].total));
11340 +               }
11341 +               printk("\n");
11342 +       }
11343 +}
11344 +
11345 +#endif
11346 +
11347 +#endif /* _VX_CACCT_DEF_H */
11348 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/cacct.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/cacct.h
11349 --- linux-2.6.25/include/linux/vserver/cacct.h  1969-12-31 19:00:00.000000000 -0500
11350 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/cacct.h     2008-04-19 15:14:52.000000000 -0400
11351 @@ -0,0 +1,15 @@
11352 +#ifndef _VX_CACCT_H
11353 +#define _VX_CACCT_H
11354 +
11355 +
11356 +enum sock_acc_field {
11357 +       VXA_SOCK_UNSPEC = 0,
11358 +       VXA_SOCK_UNIX,
11359 +       VXA_SOCK_INET,
11360 +       VXA_SOCK_INET6,
11361 +       VXA_SOCK_PACKET,
11362 +       VXA_SOCK_OTHER,
11363 +       VXA_SOCK_SIZE   /* array size */
11364 +};
11365 +
11366 +#endif /* _VX_CACCT_H */
11367 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/cacct_int.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/cacct_int.h
11368 --- linux-2.6.25/include/linux/vserver/cacct_int.h      1969-12-31 19:00:00.000000000 -0500
11369 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/cacct_int.h 2008-04-19 15:14:52.000000000 -0400
11370 @@ -0,0 +1,21 @@
11371 +#ifndef _VX_CACCT_INT_H
11372 +#define _VX_CACCT_INT_H
11373 +
11374 +
11375 +#ifdef __KERNEL__
11376 +
11377 +static inline
11378 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
11379 +{
11380 +       return atomic_long_read(&cacct->sock[type][pos].count);
11381 +}
11382 +
11383 +
11384 +static inline
11385 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
11386 +{
11387 +       return atomic_long_read(&cacct->sock[type][pos].total);
11388 +}
11389 +
11390 +#endif /* __KERNEL__ */
11391 +#endif /* _VX_CACCT_INT_H */
11392 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/check.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/check.h
11393 --- linux-2.6.25/include/linux/vserver/check.h  1969-12-31 19:00:00.000000000 -0500
11394 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/check.h     2008-04-19 15:14:52.000000000 -0400
11395 @@ -0,0 +1,89 @@
11396 +#ifndef _VS_CHECK_H
11397 +#define _VS_CHECK_H
11398 +
11399 +
11400 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
11401 +
11402 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
11403 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
11404 +#else
11405 +#define MIN_D_CONTEXT  65536
11406 +#endif
11407 +
11408 +/* check conditions */
11409 +
11410 +#define VS_ADMIN       0x0001
11411 +#define VS_WATCH       0x0002
11412 +#define VS_HIDE                0x0004
11413 +#define VS_HOSTID      0x0008
11414 +
11415 +#define VS_IDENT       0x0010
11416 +#define VS_EQUIV       0x0020
11417 +#define VS_PARENT      0x0040
11418 +#define VS_CHILD       0x0080
11419 +
11420 +#define VS_ARG_MASK    0x00F0
11421 +
11422 +#define VS_DYNAMIC     0x0100
11423 +#define VS_STATIC      0x0200
11424 +
11425 +#define VS_ATR_MASK    0x0F00
11426 +
11427 +#ifdef CONFIG_VSERVER_PRIVACY
11428 +#define VS_ADMIN_P     (0)
11429 +#define VS_WATCH_P     (0)
11430 +#else
11431 +#define VS_ADMIN_P     VS_ADMIN
11432 +#define VS_WATCH_P     VS_WATCH
11433 +#endif
11434 +
11435 +#define VS_HARDIRQ     0x1000
11436 +#define VS_SOFTIRQ     0x2000
11437 +#define VS_IRQ         0x4000
11438 +
11439 +#define VS_IRQ_MASK    0xF000
11440 +
11441 +#include <linux/hardirq.h>
11442 +
11443 +/*
11444 + * check current context for ADMIN/WATCH and
11445 + * optionally against supplied argument
11446 + */
11447 +static inline int __vs_check(int cid, int id, unsigned int mode)
11448 +{
11449 +       if (mode & VS_ARG_MASK) {
11450 +               if ((mode & VS_IDENT) && (id == cid))
11451 +                       return 1;
11452 +       }
11453 +       if (mode & VS_ATR_MASK) {
11454 +               if ((mode & VS_DYNAMIC) &&
11455 +                       (id >= MIN_D_CONTEXT) &&
11456 +                       (id <= MAX_S_CONTEXT))
11457 +                       return 1;
11458 +               if ((mode & VS_STATIC) &&
11459 +                       (id > 1) && (id < MIN_D_CONTEXT))
11460 +                       return 1;
11461 +       }
11462 +       if (mode & VS_IRQ_MASK) {
11463 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
11464 +                       return 1;
11465 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
11466 +                       return 1;
11467 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
11468 +                       return 1;
11469 +       }
11470 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
11471 +               ((mode & VS_WATCH) && (cid == 1)) ||
11472 +               ((mode & VS_HOSTID) && (id == 0)));
11473 +}
11474 +
11475 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
11476 +
11477 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
11478 +
11479 +
11480 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
11481 +
11482 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
11483 +
11484 +#endif
11485 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/context_cmd.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/context_cmd.h
11486 --- linux-2.6.25/include/linux/vserver/context_cmd.h    1969-12-31 19:00:00.000000000 -0500
11487 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/context_cmd.h       2008-04-19 15:14:52.000000000 -0400
11488 @@ -0,0 +1,128 @@
11489 +#ifndef _VX_CONTEXT_CMD_H
11490 +#define _VX_CONTEXT_CMD_H
11491 +
11492 +
11493 +/* vinfo commands */
11494 +
11495 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
11496 +
11497 +#ifdef __KERNEL__
11498 +extern int vc_task_xid(uint32_t);
11499 +
11500 +#endif /* __KERNEL__ */
11501 +
11502 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
11503 +
11504 +struct vcmd_vx_info_v0 {
11505 +       uint32_t xid;
11506 +       uint32_t initpid;
11507 +       /* more to come */
11508 +};
11509 +
11510 +#ifdef __KERNEL__
11511 +extern int vc_vx_info(struct vx_info *, void __user *);
11512 +
11513 +#endif /* __KERNEL__ */
11514 +
11515 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
11516 +
11517 +struct vcmd_ctx_stat_v0 {
11518 +       uint32_t usecnt;
11519 +       uint32_t tasks;
11520 +       /* more to come */
11521 +};
11522 +
11523 +#ifdef __KERNEL__
11524 +extern int vc_ctx_stat(struct vx_info *, void __user *);
11525 +
11526 +#endif /* __KERNEL__ */
11527 +
11528 +/* context commands */
11529 +
11530 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
11531 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
11532 +
11533 +struct vcmd_ctx_create {
11534 +       uint64_t flagword;
11535 +};
11536 +
11537 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
11538 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
11539 +
11540 +struct vcmd_ctx_migrate {
11541 +       uint64_t flagword;
11542 +};
11543 +
11544 +#ifdef __KERNEL__
11545 +extern int vc_ctx_create(uint32_t, void __user *);
11546 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
11547 +
11548 +#endif /* __KERNEL__ */
11549 +
11550 +
11551 +/* flag commands */
11552 +
11553 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
11554 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
11555 +
11556 +struct vcmd_ctx_flags_v0 {
11557 +       uint64_t flagword;
11558 +       uint64_t mask;
11559 +};
11560 +
11561 +#ifdef __KERNEL__
11562 +extern int vc_get_cflags(struct vx_info *, void __user *);
11563 +extern int vc_set_cflags(struct vx_info *, void __user *);
11564 +
11565 +#endif /* __KERNEL__ */
11566 +
11567 +
11568 +/* context caps commands */
11569 +
11570 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
11571 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
11572 +
11573 +struct vcmd_ctx_caps_v1 {
11574 +       uint64_t ccaps;
11575 +       uint64_t cmask;
11576 +};
11577 +
11578 +#ifdef __KERNEL__
11579 +extern int vc_get_ccaps(struct vx_info *, void __user *);
11580 +extern int vc_set_ccaps(struct vx_info *, void __user *);
11581 +
11582 +#endif /* __KERNEL__ */
11583 +
11584 +
11585 +/* bcaps commands */
11586 +
11587 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
11588 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
11589 +
11590 +struct vcmd_bcaps {
11591 +       uint64_t bcaps;
11592 +       uint64_t bmask;
11593 +};
11594 +
11595 +#ifdef __KERNEL__
11596 +extern int vc_get_bcaps(struct vx_info *, void __user *);
11597 +extern int vc_set_bcaps(struct vx_info *, void __user *);
11598 +
11599 +#endif /* __KERNEL__ */
11600 +
11601 +
11602 +/* OOM badness */
11603 +
11604 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
11605 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
11606 +
11607 +struct vcmd_badness_v0 {
11608 +       int64_t bias;
11609 +};
11610 +
11611 +#ifdef __KERNEL__
11612 +extern int vc_get_badness(struct vx_info *, void __user *);
11613 +extern int vc_set_badness(struct vx_info *, void __user *);
11614 +
11615 +#endif /* __KERNEL__ */
11616 +#endif /* _VX_CONTEXT_CMD_H */
11617 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/context.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/context.h
11618 --- linux-2.6.25/include/linux/vserver/context.h        1969-12-31 19:00:00.000000000 -0500
11619 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/context.h   2008-04-22 15:14:28.000000000 -0400
11620 @@ -0,0 +1,176 @@
11621 +#ifndef _VX_CONTEXT_H
11622 +#define _VX_CONTEXT_H
11623 +
11624 +#include <linux/types.h>
11625 +#include <linux/capability.h>
11626 +
11627 +
11628 +/* context flags */
11629 +
11630 +#define VXF_INFO_SCHED         0x00000002
11631 +#define VXF_INFO_NPROC         0x00000004
11632 +#define VXF_INFO_PRIVATE       0x00000008
11633 +
11634 +#define VXF_INFO_INIT          0x00000010
11635 +#define VXF_INFO_HIDE          0x00000020
11636 +#define VXF_INFO_ULIMIT                0x00000040
11637 +#define VXF_INFO_NSPACE                0x00000080
11638 +
11639 +#define VXF_SCHED_HARD         0x00000100
11640 +#define VXF_SCHED_PRIO         0x00000200
11641 +#define VXF_SCHED_PAUSE                0x00000400
11642 +
11643 +#define VXF_VIRT_MEM           0x00010000
11644 +#define VXF_VIRT_UPTIME                0x00020000
11645 +#define VXF_VIRT_CPU           0x00040000
11646 +#define VXF_VIRT_LOAD          0x00080000
11647 +#define VXF_VIRT_TIME          0x00100000
11648 +
11649 +#define VXF_HIDE_MOUNT         0x01000000
11650 +/* was VXF_HIDE_NETIF          0x02000000 */
11651 +#define VXF_HIDE_VINFO         0x04000000
11652 +
11653 +#define VXF_STATE_SETUP                (1ULL << 32)
11654 +#define VXF_STATE_INIT         (1ULL << 33)
11655 +#define VXF_STATE_ADMIN                (1ULL << 34)
11656 +
11657 +#define VXF_SC_HELPER          (1ULL << 36)
11658 +#define VXF_REBOOT_KILL                (1ULL << 37)
11659 +#define VXF_PERSISTENT         (1ULL << 38)
11660 +
11661 +#define VXF_FORK_RSS           (1ULL << 48)
11662 +#define VXF_PROLIFIC           (1ULL << 49)
11663 +
11664 +#define VXF_IGNEG_NICE         (1ULL << 52)
11665 +
11666 +#define VXF_ONE_TIME           (0x0007ULL << 32)
11667 +
11668 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
11669 +
11670 +
11671 +/* context migration */
11672 +
11673 +#define VXM_SET_INIT           0x00000001
11674 +#define VXM_SET_REAPER         0x00000002
11675 +
11676 +/* context caps */
11677 +
11678 +#define VXC_CAP_MASK           0x00000000
11679 +
11680 +#define VXC_SET_UTSNAME                0x00000001
11681 +#define VXC_SET_RLIMIT         0x00000002
11682 +
11683 +/* was VXC_RAW_ICMP            0x00000100 */
11684 +#define VXC_SYSLOG             0x00001000
11685 +
11686 +#define VXC_SECURE_MOUNT       0x00010000
11687 +#define VXC_SECURE_REMOUNT     0x00020000
11688 +#define VXC_BINARY_MOUNT       0x00040000
11689 +
11690 +#define VXC_QUOTA_CTL          0x00100000
11691 +#define VXC_ADMIN_MAPPER       0x00200000
11692 +#define VXC_ADMIN_CLOOP                0x00400000
11693 +
11694 +#define VXC_KTHREAD            0x01000000
11695 +
11696 +
11697 +#ifdef __KERNEL__
11698 +
11699 +#include <linux/list.h>
11700 +#include <linux/spinlock.h>
11701 +#include <linux/rcupdate.h>
11702 +
11703 +#include "limit_def.h"
11704 +#include "sched_def.h"
11705 +#include "cvirt_def.h"
11706 +#include "cacct_def.h"
11707 +#include "device_def.h"
11708 +
11709 +struct _vx_info_pc {
11710 +       struct _vx_sched_pc sched_pc;
11711 +       struct _vx_cvirt_pc cvirt_pc;
11712 +};
11713 +
11714 +struct vx_info {
11715 +       struct hlist_node vx_hlist;             /* linked list of contexts */
11716 +       xid_t vx_id;                            /* context id */
11717 +       atomic_t vx_usecnt;                     /* usage count */
11718 +       atomic_t vx_tasks;                      /* tasks count */
11719 +       struct vx_info *vx_parent;              /* parent context */
11720 +       int vx_state;                           /* context state */
11721 +
11722 +       unsigned long vx_nsmask;                /* assignment mask */
11723 +       struct nsproxy *vx_nsproxy;             /* private namespace */
11724 +       struct fs_struct *vx_fs;                /* private namespace fs */
11725 +
11726 +       uint64_t vx_flags;                      /* context flags */
11727 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
11728 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
11729 +       // kernel_cap_t vx_cap_bset;            /* the guest's bset */
11730 +
11731 +       struct task_struct *vx_reaper;          /* guest reaper process */
11732 +       pid_t vx_initpid;                       /* PID of guest init */
11733 +       int64_t vx_badness_bias;                /* OOM points bias */
11734 +
11735 +       struct _vx_limit limit;                 /* vserver limits */
11736 +       struct _vx_sched sched;                 /* vserver scheduler */
11737 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
11738 +       struct _vx_cacct cacct;                 /* context accounting */
11739 +
11740 +       struct _vx_device dmap;                 /* default device map targets */
11741 +
11742 +#ifndef CONFIG_SMP
11743 +       struct _vx_info_pc info_pc;             /* per cpu data */
11744 +#else
11745 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
11746 +#endif
11747 +
11748 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
11749 +       int reboot_cmd;                         /* last sys_reboot() cmd */
11750 +       int exit_code;                          /* last process exit code */
11751 +
11752 +       char vx_name[65];                       /* vserver name */
11753 +};
11754 +
11755 +#ifndef CONFIG_SMP
11756 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
11757 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
11758 +#else
11759 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
11760 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
11761 +#endif
11762 +
11763 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
11764 +
11765 +
11766 +struct vx_info_save {
11767 +       struct vx_info *vxi;
11768 +       xid_t xid;
11769 +};
11770 +
11771 +
11772 +/* status flags */
11773 +
11774 +#define VXS_HASHED     0x0001
11775 +#define VXS_PAUSED     0x0010
11776 +#define VXS_SHUTDOWN   0x0100
11777 +#define VXS_HELPER     0x1000
11778 +#define VXS_RELEASED   0x8000
11779 +
11780 +
11781 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
11782 +extern void release_vx_info(struct vx_info *, struct task_struct *);
11783 +
11784 +extern struct vx_info *lookup_vx_info(int);
11785 +extern struct vx_info *lookup_or_create_vx_info(int);
11786 +
11787 +extern int get_xid_list(int, unsigned int *, int);
11788 +extern int xid_is_hashed(xid_t);
11789 +
11790 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
11791 +
11792 +extern long vs_state_change(struct vx_info *, unsigned int);
11793 +
11794 +
11795 +#endif /* __KERNEL__ */
11796 +#endif /* _VX_CONTEXT_H */
11797 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/cvirt_cmd.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/cvirt_cmd.h
11798 --- linux-2.6.25/include/linux/vserver/cvirt_cmd.h      1969-12-31 19:00:00.000000000 -0500
11799 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/cvirt_cmd.h 2008-04-19 15:14:52.000000000 -0400
11800 @@ -0,0 +1,53 @@
11801 +#ifndef _VX_CVIRT_CMD_H
11802 +#define _VX_CVIRT_CMD_H
11803 +
11804 +
11805 +/* virtual host info name commands */
11806 +
11807 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
11808 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
11809 +
11810 +struct vcmd_vhi_name_v0 {
11811 +       uint32_t field;
11812 +       char name[65];
11813 +};
11814 +
11815 +
11816 +enum vhi_name_field {
11817 +       VHIN_CONTEXT = 0,
11818 +       VHIN_SYSNAME,
11819 +       VHIN_NODENAME,
11820 +       VHIN_RELEASE,
11821 +       VHIN_VERSION,
11822 +       VHIN_MACHINE,
11823 +       VHIN_DOMAINNAME,
11824 +};
11825 +
11826 +
11827 +#ifdef __KERNEL__
11828 +
11829 +#include <linux/compiler.h>
11830 +
11831 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
11832 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
11833 +
11834 +#endif /* __KERNEL__ */
11835 +
11836 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
11837 +
11838 +struct vcmd_virt_stat_v0 {
11839 +       uint64_t offset;
11840 +       uint64_t uptime;
11841 +       uint32_t nr_threads;
11842 +       uint32_t nr_running;
11843 +       uint32_t nr_uninterruptible;
11844 +       uint32_t nr_onhold;
11845 +       uint32_t nr_forks;
11846 +       uint32_t load[3];
11847 +};
11848 +
11849 +#ifdef __KERNEL__
11850 +extern int vc_virt_stat(struct vx_info *, void __user *);
11851 +
11852 +#endif /* __KERNEL__ */
11853 +#endif /* _VX_CVIRT_CMD_H */
11854 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/cvirt_def.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/cvirt_def.h
11855 --- linux-2.6.25/include/linux/vserver/cvirt_def.h      1969-12-31 19:00:00.000000000 -0500
11856 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/cvirt_def.h 2008-04-19 15:14:52.000000000 -0400
11857 @@ -0,0 +1,80 @@
11858 +#ifndef _VX_CVIRT_DEF_H
11859 +#define _VX_CVIRT_DEF_H
11860 +
11861 +#include <linux/jiffies.h>
11862 +#include <linux/spinlock.h>
11863 +#include <linux/wait.h>
11864 +#include <linux/time.h>
11865 +#include <asm/atomic.h>
11866 +
11867 +
11868 +struct _vx_usage_stat {
11869 +       uint64_t user;
11870 +       uint64_t nice;
11871 +       uint64_t system;
11872 +       uint64_t softirq;
11873 +       uint64_t irq;
11874 +       uint64_t idle;
11875 +       uint64_t iowait;
11876 +};
11877 +
11878 +struct _vx_syslog {
11879 +       wait_queue_head_t log_wait;
11880 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
11881 +
11882 +       unsigned long log_start;        /* next char to be read by syslog() */
11883 +       unsigned long con_start;        /* next char to be sent to consoles */
11884 +       unsigned long log_end;  /* most-recently-written-char + 1 */
11885 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
11886 +
11887 +       char log_buf[1024];
11888 +};
11889 +
11890 +
11891 +/* context sub struct */
11892 +
11893 +struct _vx_cvirt {
11894 +       atomic_t nr_threads;            /* number of current threads */
11895 +       atomic_t nr_running;            /* number of running threads */
11896 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
11897 +
11898 +       atomic_t nr_onhold;             /* processes on hold */
11899 +       uint32_t onhold_last;           /* jiffies when put on hold */
11900 +
11901 +       struct timeval bias_tv;         /* time offset to the host */
11902 +       struct timespec bias_idle;
11903 +       struct timespec bias_uptime;    /* context creation point */
11904 +       uint64_t bias_clock;            /* offset in clock_t */
11905 +
11906 +       spinlock_t load_lock;           /* lock for the load averages */
11907 +       atomic_t load_updates;          /* nr of load updates done so far */
11908 +       uint32_t load_last;             /* last time load was calculated */
11909 +       uint32_t load[3];               /* load averages 1,5,15 */
11910 +
11911 +       atomic_t total_forks;           /* number of forks so far */
11912 +
11913 +       struct _vx_syslog syslog;
11914 +};
11915 +
11916 +struct _vx_cvirt_pc {
11917 +       struct _vx_usage_stat cpustat;
11918 +};
11919 +
11920 +
11921 +#ifdef CONFIG_VSERVER_DEBUG
11922 +
11923 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
11924 +{
11925 +       printk("\t_vx_cvirt:\n");
11926 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
11927 +               atomic_read(&cvirt->nr_threads),
11928 +               atomic_read(&cvirt->nr_running),
11929 +               atomic_read(&cvirt->nr_uninterruptible),
11930 +               atomic_read(&cvirt->nr_onhold));
11931 +       /* add rest here */
11932 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
11933 +}
11934 +
11935 +#endif
11936 +
11937 +#endif /* _VX_CVIRT_DEF_H */
11938 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/cvirt.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/cvirt.h
11939 --- linux-2.6.25/include/linux/vserver/cvirt.h  1969-12-31 19:00:00.000000000 -0500
11940 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/cvirt.h     2008-04-19 15:14:52.000000000 -0400
11941 @@ -0,0 +1,20 @@
11942 +#ifndef _VX_CVIRT_H
11943 +#define _VX_CVIRT_H
11944 +
11945 +
11946 +#ifdef __KERNEL__
11947 +
11948 +struct timespec;
11949 +
11950 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11951 +
11952 +
11953 +struct vx_info;
11954 +
11955 +void vx_update_load(struct vx_info *);
11956 +
11957 +
11958 +int vx_do_syslog(int, char __user *, int);
11959 +
11960 +#endif /* __KERNEL__ */
11961 +#endif /* _VX_CVIRT_H */
11962 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/debug_cmd.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/debug_cmd.h
11963 --- linux-2.6.25/include/linux/vserver/debug_cmd.h      1969-12-31 19:00:00.000000000 -0500
11964 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/debug_cmd.h 2008-04-19 15:14:52.000000000 -0400
11965 @@ -0,0 +1,58 @@
11966 +#ifndef _VX_DEBUG_CMD_H
11967 +#define _VX_DEBUG_CMD_H
11968 +
11969 +
11970 +/* debug commands */
11971 +
11972 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
11973 +
11974 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
11975 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
11976 +
11977 +struct  vcmd_read_history_v0 {
11978 +       uint32_t index;
11979 +       uint32_t count;
11980 +       char __user *data;
11981 +};
11982 +
11983 +struct  vcmd_read_monitor_v0 {
11984 +       uint32_t index;
11985 +       uint32_t count;
11986 +       char __user *data;
11987 +};
11988 +
11989 +
11990 +#ifdef __KERNEL__
11991 +
11992 +#ifdef CONFIG_COMPAT
11993 +
11994 +#include <asm/compat.h>
11995 +
11996 +struct vcmd_read_history_v0_x32 {
11997 +       uint32_t index;
11998 +       uint32_t count;
11999 +       compat_uptr_t data_ptr;
12000 +};
12001 +
12002 +struct vcmd_read_monitor_v0_x32 {
12003 +       uint32_t index;
12004 +       uint32_t count;
12005 +       compat_uptr_t data_ptr;
12006 +};
12007 +
12008 +#endif  /* CONFIG_COMPAT */
12009 +
12010 +extern int vc_dump_history(uint32_t);
12011 +
12012 +extern int vc_read_history(uint32_t, void __user *);
12013 +extern int vc_read_monitor(uint32_t, void __user *);
12014 +
12015 +#ifdef CONFIG_COMPAT
12016 +
12017 +extern int vc_read_history_x32(uint32_t, void __user *);
12018 +extern int vc_read_monitor_x32(uint32_t, void __user *);
12019 +
12020 +#endif  /* CONFIG_COMPAT */
12021 +
12022 +#endif /* __KERNEL__ */
12023 +#endif /* _VX_DEBUG_CMD_H */
12024 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/debug.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/debug.h
12025 --- linux-2.6.25/include/linux/vserver/debug.h  1969-12-31 19:00:00.000000000 -0500
12026 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/debug.h     2008-04-21 13:55:14.000000000 -0400
12027 @@ -0,0 +1,130 @@
12028 +#ifndef _VX_DEBUG_H
12029 +#define _VX_DEBUG_H
12030 +
12031 +
12032 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
12033 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
12034 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
12035 +
12036 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
12037 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
12038 +#define VXF_DEV                "%p[%lu,%d:%d]"
12039 +
12040 +
12041 +#define __FUNC__       __func__
12042 +
12043 +
12044 +#define vxd_path(p)                                            \
12045 +       ({ static char _buffer[PATH_MAX];                       \
12046 +          d_path(p, _buffer, sizeof(_buffer)); })
12047 +
12048 +#define vxd_cond_path(n)                                       \
12049 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
12050 +
12051 +
12052 +#ifdef CONFIG_VSERVER_DEBUG
12053 +
12054 +extern unsigned int vx_debug_switch;
12055 +extern unsigned int vx_debug_xid;
12056 +extern unsigned int vx_debug_nid;
12057 +extern unsigned int vx_debug_tag;
12058 +extern unsigned int vx_debug_net;
12059 +extern unsigned int vx_debug_limit;
12060 +extern unsigned int vx_debug_cres;
12061 +extern unsigned int vx_debug_dlim;
12062 +extern unsigned int vx_debug_quota;
12063 +extern unsigned int vx_debug_cvirt;
12064 +extern unsigned int vx_debug_space;
12065 +extern unsigned int vx_debug_misc;
12066 +
12067 +
12068 +#define VX_LOGLEVEL    "vxD: "
12069 +#define VX_PROC_FMT    "%p: "
12070 +#define VX_PROCESS     current
12071 +
12072 +#define vxdprintk(c, f, x...)                                  \
12073 +       do {                                                    \
12074 +               if (c)                                          \
12075 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
12076 +                               VX_PROCESS , ##x);              \
12077 +       } while (0)
12078 +
12079 +#define vxlprintk(c, f, x...)                                  \
12080 +       do {                                                    \
12081 +               if (c)                                          \
12082 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
12083 +       } while (0)
12084 +
12085 +#define vxfprintk(c, f, x...)                                  \
12086 +       do {                                                    \
12087 +               if (c)                                          \
12088 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
12089 +       } while (0)
12090 +
12091 +
12092 +struct vx_info;
12093 +
12094 +void dump_vx_info(struct vx_info *, int);
12095 +void dump_vx_info_inactive(int);
12096 +
12097 +#else  /* CONFIG_VSERVER_DEBUG */
12098 +
12099 +#define vx_debug_switch 0
12100 +#define vx_debug_xid   0
12101 +#define vx_debug_nid   0
12102 +#define vx_debug_tag   0
12103 +#define vx_debug_net   0
12104 +#define vx_debug_limit 0
12105 +#define vx_debug_cres  0
12106 +#define vx_debug_dlim  0
12107 +#define vx_debug_cvirt 0
12108 +
12109 +#define vxdprintk(x...) do { } while (0)
12110 +#define vxlprintk(x...) do { } while (0)
12111 +#define vxfprintk(x...) do { } while (0)
12112 +
12113 +#endif /* CONFIG_VSERVER_DEBUG */
12114 +
12115 +
12116 +#ifdef CONFIG_VSERVER_WARN
12117 +
12118 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
12119 +#define VX_WARN_TASK   "[»%s«,%u:#%u|%u|%u] "
12120 +#define VX_WARN_XID    "[xid #%u] "
12121 +#define VX_WARN_NID    "[nid #%u] "
12122 +#define VX_WARN_TAG    "[tag #%u] "
12123 +
12124 +#define vxwprintk(c, f, x...)                                  \
12125 +       do {                                                    \
12126 +               if (c)                                          \
12127 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
12128 +       } while (0)
12129 +
12130 +#else  /* CONFIG_VSERVER_WARN */
12131 +
12132 +#define vxwprintk(x...) do { } while (0)
12133 +
12134 +#endif /* CONFIG_VSERVER_WARN */
12135 +
12136 +#define vxwprintk_task(c, f, x...)                             \
12137 +       vxwprintk(c, VX_WARN_TASK f,                            \
12138 +               current->comm, current->pid,                    \
12139 +               current->xid, current->nid, current->tag, ##x)
12140 +#define vxwprintk_xid(c, f, x...)                              \
12141 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
12142 +#define vxwprintk_nid(c, f, x...)                              \
12143 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
12144 +#define vxwprintk_tag(c, f, x...)                              \
12145 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
12146 +
12147 +#ifdef CONFIG_VSERVER_DEBUG
12148 +#define vxd_assert_lock(l)     assert_spin_locked(l)
12149 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
12150 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
12151 +#else
12152 +#define vxd_assert_lock(l)     do { } while (0)
12153 +#define vxd_assert(c, f, x...) do { } while (0)
12154 +#endif
12155 +
12156 +
12157 +#endif /* _VX_DEBUG_H */
12158 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/device_cmd.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/device_cmd.h
12159 --- linux-2.6.25/include/linux/vserver/device_cmd.h     1969-12-31 19:00:00.000000000 -0500
12160 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/device_cmd.h        2008-04-19 15:14:52.000000000 -0400
12161 @@ -0,0 +1,44 @@
12162 +#ifndef _VX_DEVICE_CMD_H
12163 +#define _VX_DEVICE_CMD_H
12164 +
12165 +
12166 +/*  device vserver commands */
12167 +
12168 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
12169 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
12170 +
12171 +struct vcmd_set_mapping_v0 {
12172 +       const char __user *device;
12173 +       const char __user *target;
12174 +       uint32_t flags;
12175 +};
12176 +
12177 +
12178 +#ifdef __KERNEL__
12179 +
12180 +#ifdef CONFIG_COMPAT
12181 +
12182 +#include <asm/compat.h>
12183 +
12184 +struct vcmd_set_mapping_v0_x32 {
12185 +       compat_uptr_t device_ptr;
12186 +       compat_uptr_t target_ptr;
12187 +       uint32_t flags;
12188 +};
12189 +
12190 +#endif /* CONFIG_COMPAT */
12191 +
12192 +#include <linux/compiler.h>
12193 +
12194 +extern int vc_set_mapping(struct vx_info *, void __user *);
12195 +extern int vc_unset_mapping(struct vx_info *, void __user *);
12196 +
12197 +#ifdef CONFIG_COMPAT
12198 +
12199 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
12200 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
12201 +
12202 +#endif /* CONFIG_COMPAT */
12203 +
12204 +#endif /* __KERNEL__ */
12205 +#endif /* _VX_DEVICE_CMD_H */
12206 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/device_def.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/device_def.h
12207 --- linux-2.6.25/include/linux/vserver/device_def.h     1969-12-31 19:00:00.000000000 -0500
12208 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/device_def.h        2008-04-19 15:14:52.000000000 -0400
12209 @@ -0,0 +1,17 @@
12210 +#ifndef _VX_DEVICE_DEF_H
12211 +#define _VX_DEVICE_DEF_H
12212 +
12213 +#include <linux/types.h>
12214 +
12215 +struct vx_dmap_target {
12216 +       dev_t target;
12217 +       uint32_t flags;
12218 +};
12219 +
12220 +struct _vx_device {
12221 +#ifdef CONFIG_VSERVER_DEVICE
12222 +       struct vx_dmap_target targets[2];
12223 +#endif
12224 +};
12225 +
12226 +#endif /* _VX_DEVICE_DEF_H */
12227 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/device.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/device.h
12228 --- linux-2.6.25/include/linux/vserver/device.h 1969-12-31 19:00:00.000000000 -0500
12229 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/device.h    2008-04-19 15:14:52.000000000 -0400
12230 @@ -0,0 +1,15 @@
12231 +#ifndef _VX_DEVICE_H
12232 +#define _VX_DEVICE_H
12233 +
12234 +
12235 +#define DATTR_CREATE   0x00000001
12236 +#define DATTR_OPEN     0x00000002
12237 +
12238 +#define DATTR_REMAP    0x00000010
12239 +
12240 +#define DATTR_MASK     0x00000013
12241 +
12242 +
12243 +#else  /* _VX_DEVICE_H */
12244 +#warning duplicate inclusion
12245 +#endif /* _VX_DEVICE_H */
12246 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/dlimit_cmd.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/dlimit_cmd.h
12247 --- linux-2.6.25/include/linux/vserver/dlimit_cmd.h     1969-12-31 19:00:00.000000000 -0500
12248 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/dlimit_cmd.h        2008-04-19 15:14:52.000000000 -0400
12249 @@ -0,0 +1,74 @@
12250 +#ifndef _VX_DLIMIT_CMD_H
12251 +#define _VX_DLIMIT_CMD_H
12252 +
12253 +
12254 +/*  dlimit vserver commands */
12255 +
12256 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
12257 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
12258 +
12259 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
12260 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
12261 +
12262 +struct vcmd_ctx_dlimit_base_v0 {
12263 +       const char __user *name;
12264 +       uint32_t flags;
12265 +};
12266 +
12267 +struct vcmd_ctx_dlimit_v0 {
12268 +       const char __user *name;
12269 +       uint32_t space_used;                    /* used space in kbytes */
12270 +       uint32_t space_total;                   /* maximum space in kbytes */
12271 +       uint32_t inodes_used;                   /* used inodes */
12272 +       uint32_t inodes_total;                  /* maximum inodes */
12273 +       uint32_t reserved;                      /* reserved for root in % */
12274 +       uint32_t flags;
12275 +};
12276 +
12277 +#define CDLIM_UNSET            ((uint32_t)0UL)
12278 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
12279 +#define CDLIM_KEEP             ((uint32_t)~1UL)
12280 +
12281 +#ifdef __KERNEL__
12282 +
12283 +#ifdef CONFIG_COMPAT
12284 +
12285 +#include <asm/compat.h>
12286 +
12287 +struct vcmd_ctx_dlimit_base_v0_x32 {
12288 +       compat_uptr_t name_ptr;
12289 +       uint32_t flags;
12290 +};
12291 +
12292 +struct vcmd_ctx_dlimit_v0_x32 {
12293 +       compat_uptr_t name_ptr;
12294 +       uint32_t space_used;                    /* used space in kbytes */
12295 +       uint32_t space_total;                   /* maximum space in kbytes */
12296 +       uint32_t inodes_used;                   /* used inodes */
12297 +       uint32_t inodes_total;                  /* maximum inodes */
12298 +       uint32_t reserved;                      /* reserved for root in % */
12299 +       uint32_t flags;
12300 +};
12301 +
12302 +#endif /* CONFIG_COMPAT */
12303 +
12304 +#include <linux/compiler.h>
12305 +
12306 +extern int vc_add_dlimit(uint32_t, void __user *);
12307 +extern int vc_rem_dlimit(uint32_t, void __user *);
12308 +
12309 +extern int vc_set_dlimit(uint32_t, void __user *);
12310 +extern int vc_get_dlimit(uint32_t, void __user *);
12311 +
12312 +#ifdef CONFIG_COMPAT
12313 +
12314 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
12315 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
12316 +
12317 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
12318 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
12319 +
12320 +#endif /* CONFIG_COMPAT */
12321 +
12322 +#endif /* __KERNEL__ */
12323 +#endif /* _VX_DLIMIT_CMD_H */
12324 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/dlimit.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/dlimit.h
12325 --- linux-2.6.25/include/linux/vserver/dlimit.h 1969-12-31 19:00:00.000000000 -0500
12326 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/dlimit.h    2008-04-19 15:14:52.000000000 -0400
12327 @@ -0,0 +1,54 @@
12328 +#ifndef _VX_DLIMIT_H
12329 +#define _VX_DLIMIT_H
12330 +
12331 +#include "switch.h"
12332 +
12333 +
12334 +#ifdef __KERNEL__
12335 +
12336 +/*      keep in sync with CDLIM_INFINITY       */
12337 +
12338 +#define DLIM_INFINITY          (~0ULL)
12339 +
12340 +#include <linux/spinlock.h>
12341 +#include <linux/rcupdate.h>
12342 +
12343 +struct super_block;
12344 +
12345 +struct dl_info {
12346 +       struct hlist_node dl_hlist;             /* linked list of contexts */
12347 +       struct rcu_head dl_rcu;                 /* the rcu head */
12348 +       tag_t dl_tag;                           /* context tag */
12349 +       atomic_t dl_usecnt;                     /* usage count */
12350 +       atomic_t dl_refcnt;                     /* reference count */
12351 +
12352 +       struct super_block *dl_sb;              /* associated superblock */
12353 +
12354 +       spinlock_t dl_lock;                     /* protect the values */
12355 +
12356 +       unsigned long long dl_space_used;       /* used space in bytes */
12357 +       unsigned long long dl_space_total;      /* maximum space in bytes */
12358 +       unsigned long dl_inodes_used;           /* used inodes */
12359 +       unsigned long dl_inodes_total;          /* maximum inodes */
12360 +
12361 +       unsigned int dl_nrlmult;                /* non root limit mult */
12362 +};
12363 +
12364 +struct rcu_head;
12365 +
12366 +extern void rcu_free_dl_info(struct rcu_head *);
12367 +extern void unhash_dl_info(struct dl_info *);
12368 +
12369 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
12370 +
12371 +
12372 +struct kstatfs;
12373 +
12374 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
12375 +
12376 +typedef uint64_t dlsize_t;
12377 +
12378 +#endif /* __KERNEL__ */
12379 +#else  /* _VX_DLIMIT_H */
12380 +#warning duplicate inclusion
12381 +#endif /* _VX_DLIMIT_H */
12382 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/global.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/global.h
12383 --- linux-2.6.25/include/linux/vserver/global.h 1969-12-31 19:00:00.000000000 -0500
12384 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/global.h    2008-04-19 15:14:52.000000000 -0400
12385 @@ -0,0 +1,20 @@
12386 +#ifndef _VX_GLOBAL_H
12387 +#define _VX_GLOBAL_H
12388 +
12389 +
12390 +extern atomic_t vx_global_ctotal;
12391 +extern atomic_t vx_global_cactive;
12392 +
12393 +extern atomic_t nx_global_ctotal;
12394 +extern atomic_t nx_global_cactive;
12395 +
12396 +extern atomic_t vs_global_nsproxy;
12397 +extern atomic_t vs_global_fs;
12398 +extern atomic_t vs_global_mnt_ns;
12399 +extern atomic_t vs_global_uts_ns;
12400 +extern atomic_t vs_global_ipc_ns;
12401 +extern atomic_t vs_global_user_ns;
12402 +extern atomic_t vs_global_pid_ns;
12403 +
12404 +
12405 +#endif /* _VX_GLOBAL_H */
12406 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/history.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/history.h
12407 --- linux-2.6.25/include/linux/vserver/history.h        1969-12-31 19:00:00.000000000 -0500
12408 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/history.h   2008-04-19 15:14:52.000000000 -0400
12409 @@ -0,0 +1,197 @@
12410 +#ifndef _VX_HISTORY_H
12411 +#define _VX_HISTORY_H
12412 +
12413 +
12414 +enum {
12415 +       VXH_UNUSED = 0,
12416 +       VXH_THROW_OOPS = 1,
12417 +
12418 +       VXH_GET_VX_INFO,
12419 +       VXH_PUT_VX_INFO,
12420 +       VXH_INIT_VX_INFO,
12421 +       VXH_SET_VX_INFO,
12422 +       VXH_CLR_VX_INFO,
12423 +       VXH_CLAIM_VX_INFO,
12424 +       VXH_RELEASE_VX_INFO,
12425 +       VXH_ALLOC_VX_INFO,
12426 +       VXH_DEALLOC_VX_INFO,
12427 +       VXH_HASH_VX_INFO,
12428 +       VXH_UNHASH_VX_INFO,
12429 +       VXH_LOC_VX_INFO,
12430 +       VXH_LOOKUP_VX_INFO,
12431 +       VXH_CREATE_VX_INFO,
12432 +};
12433 +
12434 +struct _vxhe_vxi {
12435 +       struct vx_info *ptr;
12436 +       unsigned xid;
12437 +       unsigned usecnt;
12438 +       unsigned tasks;
12439 +};
12440 +
12441 +struct _vxhe_set_clr {
12442 +       void *data;
12443 +};
12444 +
12445 +struct _vxhe_loc_lookup {
12446 +       unsigned arg;
12447 +};
12448 +
12449 +struct _vx_hist_entry {
12450 +       void *loc;
12451 +       unsigned short seq;
12452 +       unsigned short type;
12453 +       struct _vxhe_vxi vxi;
12454 +       union {
12455 +               struct _vxhe_set_clr sc;
12456 +               struct _vxhe_loc_lookup ll;
12457 +       };
12458 +};
12459 +
12460 +#ifdef CONFIG_VSERVER_HISTORY
12461 +
12462 +extern unsigned volatile int vxh_active;
12463 +
12464 +struct _vx_hist_entry *vxh_advance(void *loc);
12465 +
12466 +
12467 +static inline
12468 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
12469 +{
12470 +       entry->vxi.ptr = vxi;
12471 +       if (vxi) {
12472 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
12473 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
12474 +               entry->vxi.xid = vxi->vx_id;
12475 +       }
12476 +}
12477 +
12478 +
12479 +#define        __HERE__ current_text_addr()
12480 +
12481 +#define __VXH_BODY(__type, __data, __here)     \
12482 +       struct _vx_hist_entry *entry;           \
12483 +                                               \
12484 +       preempt_disable();                      \
12485 +       entry = vxh_advance(__here);            \
12486 +       __data;                                 \
12487 +       entry->type = __type;                   \
12488 +       preempt_enable();
12489 +
12490 +
12491 +       /* pass vxi only */
12492 +
12493 +#define __VXH_SMPL                             \
12494 +       __vxh_copy_vxi(entry, vxi)
12495 +
12496 +static inline
12497 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
12498 +{
12499 +       __VXH_BODY(__type, __VXH_SMPL, __here)
12500 +}
12501 +
12502 +       /* pass vxi and data (void *) */
12503 +
12504 +#define __VXH_DATA                             \
12505 +       __vxh_copy_vxi(entry, vxi);             \
12506 +       entry->sc.data = data
12507 +
12508 +static inline
12509 +void   __vxh_data(struct vx_info *vxi, void *data,
12510 +                       int __type, void *__here)
12511 +{
12512 +       __VXH_BODY(__type, __VXH_DATA, __here)
12513 +}
12514 +
12515 +       /* pass vxi and arg (long) */
12516 +
12517 +#define __VXH_LONG                             \
12518 +       __vxh_copy_vxi(entry, vxi);             \
12519 +       entry->ll.arg = arg
12520 +
12521 +static inline
12522 +void   __vxh_long(struct vx_info *vxi, long arg,
12523 +                       int __type, void *__here)
12524 +{
12525 +       __VXH_BODY(__type, __VXH_LONG, __here)
12526 +}
12527 +
12528 +
12529 +static inline
12530 +void   __vxh_throw_oops(void *__here)
12531 +{
12532 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
12533 +       /* prevent further acquisition */
12534 +       vxh_active = 0;
12535 +}
12536 +
12537 +
12538 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
12539 +
12540 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
12541 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
12542 +
12543 +#define __vxh_init_vx_info(v, d, h) \
12544 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
12545 +#define __vxh_set_vx_info(v, d, h) \
12546 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
12547 +#define __vxh_clr_vx_info(v, d, h) \
12548 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
12549 +
12550 +#define __vxh_claim_vx_info(v, d, h) \
12551 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
12552 +#define __vxh_release_vx_info(v, d, h) \
12553 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
12554 +
12555 +#define vxh_alloc_vx_info(v) \
12556 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
12557 +#define vxh_dealloc_vx_info(v) \
12558 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
12559 +
12560 +#define vxh_hash_vx_info(v) \
12561 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
12562 +#define vxh_unhash_vx_info(v) \
12563 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
12564 +
12565 +#define vxh_loc_vx_info(v, l) \
12566 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
12567 +#define vxh_lookup_vx_info(v, l) \
12568 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
12569 +#define vxh_create_vx_info(v, l) \
12570 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
12571 +
12572 +extern void vxh_dump_history(void);
12573 +
12574 +
12575 +#else  /* CONFIG_VSERVER_HISTORY */
12576 +
12577 +#define        __HERE__        0
12578 +
12579 +#define vxh_throw_oops()               do { } while (0)
12580 +
12581 +#define __vxh_get_vx_info(v, h)                do { } while (0)
12582 +#define __vxh_put_vx_info(v, h)                do { } while (0)
12583 +
12584 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
12585 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
12586 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
12587 +
12588 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
12589 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
12590 +
12591 +#define vxh_alloc_vx_info(v)           do { } while (0)
12592 +#define vxh_dealloc_vx_info(v)         do { } while (0)
12593 +
12594 +#define vxh_hash_vx_info(v)            do { } while (0)
12595 +#define vxh_unhash_vx_info(v)          do { } while (0)
12596 +
12597 +#define vxh_loc_vx_info(v, l)          do { } while (0)
12598 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
12599 +#define vxh_create_vx_info(v, l)       do { } while (0)
12600 +
12601 +#define vxh_dump_history()             do { } while (0)
12602 +
12603 +
12604 +#endif /* CONFIG_VSERVER_HISTORY */
12605 +
12606 +#endif /* _VX_HISTORY_H */
12607 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/inode_cmd.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/inode_cmd.h
12608 --- linux-2.6.25/include/linux/vserver/inode_cmd.h      1969-12-31 19:00:00.000000000 -0500
12609 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/inode_cmd.h 2008-04-19 15:14:52.000000000 -0400
12610 @@ -0,0 +1,59 @@
12611 +#ifndef _VX_INODE_CMD_H
12612 +#define _VX_INODE_CMD_H
12613 +
12614 +
12615 +/*  inode vserver commands */
12616 +
12617 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
12618 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
12619 +
12620 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
12621 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
12622 +
12623 +struct vcmd_ctx_iattr_v1 {
12624 +       const char __user *name;
12625 +       uint32_t tag;
12626 +       uint32_t flags;
12627 +       uint32_t mask;
12628 +};
12629 +
12630 +struct vcmd_ctx_fiattr_v0 {
12631 +       uint32_t tag;
12632 +       uint32_t flags;
12633 +       uint32_t mask;
12634 +};
12635 +
12636 +
12637 +#ifdef __KERNEL__
12638 +
12639 +
12640 +#ifdef CONFIG_COMPAT
12641 +
12642 +#include <asm/compat.h>
12643 +
12644 +struct vcmd_ctx_iattr_v1_x32 {
12645 +       compat_uptr_t name_ptr;
12646 +       uint32_t tag;
12647 +       uint32_t flags;
12648 +       uint32_t mask;
12649 +};
12650 +
12651 +#endif /* CONFIG_COMPAT */
12652 +
12653 +#include <linux/compiler.h>
12654 +
12655 +extern int vc_get_iattr(void __user *);
12656 +extern int vc_set_iattr(void __user *);
12657 +
12658 +extern int vc_fget_iattr(uint32_t, void __user *);
12659 +extern int vc_fset_iattr(uint32_t, void __user *);
12660 +
12661 +#ifdef CONFIG_COMPAT
12662 +
12663 +extern int vc_get_iattr_x32(void __user *);
12664 +extern int vc_set_iattr_x32(void __user *);
12665 +
12666 +#endif /* CONFIG_COMPAT */
12667 +
12668 +#endif /* __KERNEL__ */
12669 +#endif /* _VX_INODE_CMD_H */
12670 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/inode.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/inode.h
12671 --- linux-2.6.25/include/linux/vserver/inode.h  1969-12-31 19:00:00.000000000 -0500
12672 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/inode.h     2008-04-19 15:14:52.000000000 -0400
12673 @@ -0,0 +1,38 @@
12674 +#ifndef _VX_INODE_H
12675 +#define _VX_INODE_H
12676 +
12677 +
12678 +#define IATTR_TAG      0x01000000
12679 +
12680 +#define IATTR_ADMIN    0x00000001
12681 +#define IATTR_WATCH    0x00000002
12682 +#define IATTR_HIDE     0x00000004
12683 +#define IATTR_FLAGS    0x00000007
12684 +
12685 +#define IATTR_BARRIER  0x00010000
12686 +#define IATTR_IUNLINK  0x00020000
12687 +#define IATTR_IMMUTABLE 0x00040000
12688 +
12689 +#ifdef __KERNEL__
12690 +
12691 +
12692 +#ifdef CONFIG_VSERVER_PROC_SECURE
12693 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
12694 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12695 +#else
12696 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
12697 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12698 +#endif
12699 +
12700 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
12701 +
12702 +#endif /* __KERNEL__ */
12703 +
12704 +/* inode ioctls */
12705 +
12706 +#define FIOC_GETXFLG   _IOR('x', 5, long)
12707 +#define FIOC_SETXFLG   _IOW('x', 6, long)
12708 +
12709 +#else  /* _VX_INODE_H */
12710 +#warning duplicate inclusion
12711 +#endif /* _VX_INODE_H */
12712 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/Kbuild linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/Kbuild
12713 --- linux-2.6.25/include/linux/vserver/Kbuild   1969-12-31 19:00:00.000000000 -0500
12714 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/Kbuild      2008-04-19 15:14:52.000000000 -0400
12715 @@ -0,0 +1,8 @@
12716 +
12717 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
12718 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
12719 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
12720 +       debug_cmd.h device_cmd.h
12721 +
12722 +unifdef-y += switch.h network.h monitor.h inode.h device.h
12723 +
12724 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/limit_cmd.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/limit_cmd.h
12725 --- linux-2.6.25/include/linux/vserver/limit_cmd.h      1969-12-31 19:00:00.000000000 -0500
12726 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/limit_cmd.h 2008-04-19 15:14:52.000000000 -0400
12727 @@ -0,0 +1,69 @@
12728 +#ifndef _VX_LIMIT_CMD_H
12729 +#define _VX_LIMIT_CMD_H
12730 +
12731 +
12732 +/*  rlimit vserver commands */
12733 +
12734 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
12735 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
12736 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
12737 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
12738 +
12739 +struct vcmd_ctx_rlimit_v0 {
12740 +       uint32_t id;
12741 +       uint64_t minimum;
12742 +       uint64_t softlimit;
12743 +       uint64_t maximum;
12744 +};
12745 +
12746 +struct vcmd_ctx_rlimit_mask_v0 {
12747 +       uint32_t minimum;
12748 +       uint32_t softlimit;
12749 +       uint32_t maximum;
12750 +};
12751 +
12752 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
12753 +
12754 +struct vcmd_rlimit_stat_v0 {
12755 +       uint32_t id;
12756 +       uint32_t hits;
12757 +       uint64_t value;
12758 +       uint64_t minimum;
12759 +       uint64_t maximum;
12760 +};
12761 +
12762 +#define CRLIM_UNSET            (0ULL)
12763 +#define CRLIM_INFINITY         (~0ULL)
12764 +#define CRLIM_KEEP             (~1ULL)
12765 +
12766 +#ifdef __KERNEL__
12767 +
12768 +#ifdef CONFIG_IA32_EMULATION
12769 +
12770 +struct vcmd_ctx_rlimit_v0_x32 {
12771 +       uint32_t id;
12772 +       uint64_t minimum;
12773 +       uint64_t softlimit;
12774 +       uint64_t maximum;
12775 +} __attribute__ ((aligned (4)));
12776 +
12777 +#endif /* CONFIG_IA32_EMULATION */
12778 +
12779 +#include <linux/compiler.h>
12780 +
12781 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
12782 +extern int vc_get_rlimit(struct vx_info *, void __user *);
12783 +extern int vc_set_rlimit(struct vx_info *, void __user *);
12784 +extern int vc_reset_minmax(struct vx_info *, void __user *);
12785 +
12786 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
12787 +
12788 +#ifdef CONFIG_IA32_EMULATION
12789 +
12790 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
12791 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
12792 +
12793 +#endif /* CONFIG_IA32_EMULATION */
12794 +
12795 +#endif /* __KERNEL__ */
12796 +#endif /* _VX_LIMIT_CMD_H */
12797 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/limit_def.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/limit_def.h
12798 --- linux-2.6.25/include/linux/vserver/limit_def.h      1969-12-31 19:00:00.000000000 -0500
12799 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/limit_def.h 2008-04-19 15:14:52.000000000 -0400
12800 @@ -0,0 +1,47 @@
12801 +#ifndef _VX_LIMIT_DEF_H
12802 +#define _VX_LIMIT_DEF_H
12803 +
12804 +#include <asm/atomic.h>
12805 +#include <asm/resource.h>
12806 +
12807 +#include "limit.h"
12808 +
12809 +
12810 +struct _vx_res_limit {
12811 +       rlim_t soft;            /* Context soft limit */
12812 +       rlim_t hard;            /* Context hard limit */
12813 +
12814 +       rlim_atomic_t rcur;     /* Current value */
12815 +       rlim_t rmin;            /* Context minimum */
12816 +       rlim_t rmax;            /* Context maximum */
12817 +
12818 +       atomic_t lhit;          /* Limit hits */
12819 +};
12820 +
12821 +/* context sub struct */
12822 +
12823 +struct _vx_limit {
12824 +       struct _vx_res_limit res[NUM_LIMITS];
12825 +};
12826 +
12827 +#ifdef CONFIG_VSERVER_DEBUG
12828 +
12829 +static inline void __dump_vx_limit(struct _vx_limit *limit)
12830 +{
12831 +       int i;
12832 +
12833 +       printk("\t_vx_limit:");
12834 +       for (i = 0; i < NUM_LIMITS; i++) {
12835 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
12836 +                       i, (unsigned long)__rlim_get(limit, i),
12837 +                       (unsigned long)__rlim_rmin(limit, i),
12838 +                       (unsigned long)__rlim_rmax(limit, i),
12839 +                       (long)__rlim_soft(limit, i),
12840 +                       (long)__rlim_hard(limit, i),
12841 +                       atomic_read(&__rlim_lhit(limit, i)));
12842 +       }
12843 +}
12844 +
12845 +#endif
12846 +
12847 +#endif /* _VX_LIMIT_DEF_H */
12848 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/limit.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/limit.h
12849 --- linux-2.6.25/include/linux/vserver/limit.h  1969-12-31 19:00:00.000000000 -0500
12850 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/limit.h     2008-04-19 15:14:52.000000000 -0400
12851 @@ -0,0 +1,70 @@
12852 +#ifndef _VX_LIMIT_H
12853 +#define _VX_LIMIT_H
12854 +
12855 +#define VLIMIT_NSOCK   16
12856 +#define VLIMIT_OPENFD  17
12857 +#define VLIMIT_ANON    18
12858 +#define VLIMIT_SHMEM   19
12859 +#define VLIMIT_SEMARY  20
12860 +#define VLIMIT_NSEMS   21
12861 +#define VLIMIT_DENTRY  22
12862 +#define VLIMIT_MAPPED  23
12863 +
12864 +
12865 +#ifdef __KERNEL__
12866 +
12867 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
12868 +
12869 +/*     keep in sync with CRLIM_INFINITY */
12870 +
12871 +#define        VLIM_INFINITY   (~0ULL)
12872 +
12873 +#include <asm/atomic.h>
12874 +#include <asm/resource.h>
12875 +
12876 +#ifndef RLIM_INFINITY
12877 +#warning RLIM_INFINITY is undefined
12878 +#endif
12879 +
12880 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
12881 +
12882 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
12883 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
12884 +
12885 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
12886 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
12887 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
12888 +
12889 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
12890 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
12891 +
12892 +typedef atomic_long_t rlim_atomic_t;
12893 +typedef unsigned long rlim_t;
12894 +
12895 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
12896 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
12897 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
12898 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
12899 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
12900 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
12901 +
12902 +
12903 +#if    (RLIM_INFINITY == VLIM_INFINITY)
12904 +#define        VX_VLIM(r) ((long long)(long)(r))
12905 +#define        VX_RLIM(v) ((rlim_t)(v))
12906 +#else
12907 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
12908 +               ? VLIM_INFINITY : (long long)(r))
12909 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
12910 +               ? RLIM_INFINITY : (rlim_t)(v))
12911 +#endif
12912 +
12913 +struct sysinfo;
12914 +
12915 +void vx_vsi_meminfo(struct sysinfo *);
12916 +void vx_vsi_swapinfo(struct sysinfo *);
12917 +
12918 +#define NUM_LIMITS     24
12919 +
12920 +#endif /* __KERNEL__ */
12921 +#endif /* _VX_LIMIT_H */
12922 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/limit_int.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/limit_int.h
12923 --- linux-2.6.25/include/linux/vserver/limit_int.h      1969-12-31 19:00:00.000000000 -0500
12924 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/limit_int.h 2008-04-19 15:14:52.000000000 -0400
12925 @@ -0,0 +1,198 @@
12926 +#ifndef _VX_LIMIT_INT_H
12927 +#define _VX_LIMIT_INT_H
12928 +
12929 +#include "context.h"
12930 +
12931 +#ifdef __KERNEL__
12932 +
12933 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
12934 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
12935 +
12936 +extern const char *vlimit_name[NUM_LIMITS];
12937 +
12938 +static inline void __vx_acc_cres(struct vx_info *vxi,
12939 +       int res, int dir, void *_data, char *_file, int _line)
12940 +{
12941 +       if (VXD_RCRES_COND(res))
12942 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12943 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12944 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12945 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
12946 +       if (!vxi)
12947 +               return;
12948 +
12949 +       if (dir > 0)
12950 +               __rlim_inc(&vxi->limit, res);
12951 +       else
12952 +               __rlim_dec(&vxi->limit, res);
12953 +}
12954 +
12955 +static inline void __vx_add_cres(struct vx_info *vxi,
12956 +       int res, int amount, void *_data, char *_file, int _line)
12957 +{
12958 +       if (VXD_RCRES_COND(res))
12959 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12960 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12961 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12962 +                       amount, _data, _file, _line);
12963 +       if (amount == 0)
12964 +               return;
12965 +       if (!vxi)
12966 +               return;
12967 +       __rlim_add(&vxi->limit, res, amount);
12968 +}
12969 +
12970 +static inline
12971 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12972 +{
12973 +       int cond = (value > __rlim_rmax(limit, res));
12974 +
12975 +       if (cond)
12976 +               __rlim_rmax(limit, res) = value;
12977 +       return cond;
12978 +}
12979 +
12980 +static inline
12981 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12982 +{
12983 +       int cond = (value < __rlim_rmin(limit, res));
12984 +
12985 +       if (cond)
12986 +               __rlim_rmin(limit, res) = value;
12987 +       return cond;
12988 +}
12989 +
12990 +static inline
12991 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12992 +{
12993 +       if (!__vx_cres_adjust_max(limit, res, value))
12994 +               __vx_cres_adjust_min(limit, res, value);
12995 +}
12996 +
12997 +
12998 +/*     return values:
12999 +        +1 ... no limit hit
13000 +        -1 ... over soft limit
13001 +         0 ... over hard limit         */
13002 +
13003 +static inline int __vx_cres_avail(struct vx_info *vxi,
13004 +       int res, int num, char *_file, int _line)
13005 +{
13006 +       struct _vx_limit *limit;
13007 +       rlim_t value;
13008 +
13009 +       if (VXD_RLIMIT_COND(res))
13010 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
13011 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
13012 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
13013 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
13014 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
13015 +                       num, _file, _line);
13016 +       if (!vxi)
13017 +               return 1;
13018 +
13019 +       limit = &vxi->limit;
13020 +       value = __rlim_get(limit, res);
13021 +
13022 +       if (!__vx_cres_adjust_max(limit, res, value))
13023 +               __vx_cres_adjust_min(limit, res, value);
13024 +
13025 +       if (num == 0)
13026 +               return 1;
13027 +
13028 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
13029 +               return -1;
13030 +       if (value + num <= __rlim_soft(limit, res))
13031 +               return -1;
13032 +
13033 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
13034 +               return 1;
13035 +       if (value + num <= __rlim_hard(limit, res))
13036 +               return 1;
13037 +
13038 +       __rlim_hit(limit, res);
13039 +       return 0;
13040 +}
13041 +
13042 +
13043 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
13044 +
13045 +static inline
13046 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
13047 +{
13048 +       rlim_t value, sum = 0;
13049 +       int res;
13050 +
13051 +       while ((res = *array++)) {
13052 +               value = __rlim_get(limit, res);
13053 +               __vx_cres_fixup(limit, res, value);
13054 +               sum += value;
13055 +       }
13056 +       return sum;
13057 +}
13058 +
13059 +static inline
13060 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
13061 +{
13062 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
13063 +       int res = *array;
13064 +
13065 +       if (value == __rlim_get(limit, res))
13066 +               return value;
13067 +
13068 +       __rlim_set(limit, res, value);
13069 +       /* now adjust min/max */
13070 +       if (!__vx_cres_adjust_max(limit, res, value))
13071 +               __vx_cres_adjust_min(limit, res, value);
13072 +
13073 +       return value;
13074 +}
13075 +
13076 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
13077 +       const int *array, int num, char *_file, int _line)
13078 +{
13079 +       struct _vx_limit *limit;
13080 +       rlim_t value = 0;
13081 +       int res;
13082 +
13083 +       if (num == 0)
13084 +               return 1;
13085 +       if (!vxi)
13086 +               return 1;
13087 +
13088 +       limit = &vxi->limit;
13089 +       res = *array;
13090 +       value = __vx_cres_array_sum(limit, array + 1);
13091 +
13092 +       __rlim_set(limit, res, value);
13093 +       __vx_cres_fixup(limit, res, value);
13094 +
13095 +       return __vx_cres_avail(vxi, res, num, _file, _line);
13096 +}
13097 +
13098 +
13099 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
13100 +{
13101 +       rlim_t value;
13102 +       int res;
13103 +
13104 +       /* complex resources first */
13105 +       if ((id < 0) || (id == RLIMIT_RSS))
13106 +               __vx_cres_array_fixup(limit, VLA_RSS);
13107 +
13108 +       for (res = 0; res < NUM_LIMITS; res++) {
13109 +               if ((id > 0) && (res != id))
13110 +                       continue;
13111 +
13112 +               value = __rlim_get(limit, res);
13113 +               __vx_cres_fixup(limit, res, value);
13114 +
13115 +               /* not supposed to happen, maybe warn? */
13116 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
13117 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
13118 +       }
13119 +}
13120 +
13121 +
13122 +#endif /* __KERNEL__ */
13123 +#endif /* _VX_LIMIT_INT_H */
13124 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/monitor.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/monitor.h
13125 --- linux-2.6.25/include/linux/vserver/monitor.h        1969-12-31 19:00:00.000000000 -0500
13126 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/monitor.h   2008-04-19 15:14:52.000000000 -0400
13127 @@ -0,0 +1,96 @@
13128 +#ifndef _VX_MONITOR_H
13129 +#define _VX_MONITOR_H
13130 +
13131 +#include <linux/types.h>
13132 +
13133 +enum {
13134 +       VXM_UNUSED = 0,
13135 +
13136 +       VXM_SYNC = 0x10,
13137 +
13138 +       VXM_UPDATE = 0x20,
13139 +       VXM_UPDATE_1,
13140 +       VXM_UPDATE_2,
13141 +
13142 +       VXM_RQINFO_1 = 0x24,
13143 +       VXM_RQINFO_2,
13144 +
13145 +       VXM_ACTIVATE = 0x40,
13146 +       VXM_DEACTIVATE,
13147 +       VXM_IDLE,
13148 +
13149 +       VXM_HOLD = 0x44,
13150 +       VXM_UNHOLD,
13151 +
13152 +       VXM_MIGRATE = 0x48,
13153 +       VXM_RESCHED,
13154 +
13155 +       /* all other bits are flags */
13156 +       VXM_SCHED = 0x80,
13157 +};
13158 +
13159 +struct _vxm_update_1 {
13160 +       uint32_t tokens_max;
13161 +       uint32_t fill_rate;
13162 +       uint32_t interval;
13163 +};
13164 +
13165 +struct _vxm_update_2 {
13166 +       uint32_t tokens_min;
13167 +       uint32_t fill_rate;
13168 +       uint32_t interval;
13169 +};
13170 +
13171 +struct _vxm_rqinfo_1 {
13172 +       uint16_t running;
13173 +       uint16_t onhold;
13174 +       uint16_t iowait;
13175 +       uint16_t uintr;
13176 +       uint32_t idle_tokens;
13177 +};
13178 +
13179 +struct _vxm_rqinfo_2 {
13180 +       uint32_t norm_time;
13181 +       uint32_t idle_time;
13182 +       uint32_t idle_skip;
13183 +};
13184 +
13185 +struct _vxm_sched {
13186 +       uint32_t tokens;
13187 +       uint32_t norm_time;
13188 +       uint32_t idle_time;
13189 +};
13190 +
13191 +struct _vxm_task {
13192 +       uint16_t pid;
13193 +       uint16_t state;
13194 +};
13195 +
13196 +struct _vxm_event {
13197 +       uint32_t jif;
13198 +       union {
13199 +               uint32_t seq;
13200 +               uint32_t sec;
13201 +       };
13202 +       union {
13203 +               uint32_t tokens;
13204 +               uint32_t nsec;
13205 +               struct _vxm_task tsk;
13206 +       };
13207 +};
13208 +
13209 +struct _vx_mon_entry {
13210 +       uint16_t type;
13211 +       uint16_t xid;
13212 +       union {
13213 +               struct _vxm_event ev;
13214 +               struct _vxm_sched sd;
13215 +               struct _vxm_update_1 u1;
13216 +               struct _vxm_update_2 u2;
13217 +               struct _vxm_rqinfo_1 q1;
13218 +               struct _vxm_rqinfo_2 q2;
13219 +       };
13220 +};
13221 +
13222 +
13223 +#endif /* _VX_MONITOR_H */
13224 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/network_cmd.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/network_cmd.h
13225 --- linux-2.6.25/include/linux/vserver/network_cmd.h    1969-12-31 19:00:00.000000000 -0500
13226 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/network_cmd.h       2008-04-19 15:14:52.000000000 -0400
13227 @@ -0,0 +1,150 @@
13228 +#ifndef _VX_NETWORK_CMD_H
13229 +#define _VX_NETWORK_CMD_H
13230 +
13231 +
13232 +/* vinfo commands */
13233 +
13234 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
13235 +
13236 +#ifdef __KERNEL__
13237 +extern int vc_task_nid(uint32_t);
13238 +
13239 +#endif /* __KERNEL__ */
13240 +
13241 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
13242 +
13243 +struct vcmd_nx_info_v0 {
13244 +       uint32_t nid;
13245 +       /* more to come */
13246 +};
13247 +
13248 +#ifdef __KERNEL__
13249 +extern int vc_nx_info(struct nx_info *, void __user *);
13250 +
13251 +#endif /* __KERNEL__ */
13252 +
13253 +#include <linux/in.h>
13254 +#include <linux/in6.h>
13255 +
13256 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
13257 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
13258 +
13259 +struct  vcmd_net_create {
13260 +       uint64_t flagword;
13261 +};
13262 +
13263 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
13264 +
13265 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
13266 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
13267 +
13268 +struct vcmd_net_addr_v0 {
13269 +       uint16_t type;
13270 +       uint16_t count;
13271 +       struct in_addr ip[4];
13272 +       struct in_addr mask[4];
13273 +};
13274 +
13275 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
13276 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
13277 +
13278 +struct vcmd_net_addr_ipv4_v1 {
13279 +       uint16_t type;
13280 +       uint16_t flags;
13281 +       struct in_addr ip;
13282 +       struct in_addr mask;
13283 +};
13284 +
13285 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
13286 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
13287 +
13288 +struct vcmd_net_addr_ipv6_v1 {
13289 +       uint16_t type;
13290 +       uint16_t flags;
13291 +       uint32_t prefix;
13292 +       struct in6_addr ip;
13293 +       struct in6_addr mask;
13294 +};
13295 +
13296 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
13297 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
13298 +
13299 +struct vcmd_match_ipv4_v0 {
13300 +       uint16_t type;
13301 +       uint16_t flags;
13302 +       uint16_t parent;
13303 +       uint16_t prefix;
13304 +       struct in_addr ip;
13305 +       struct in_addr ip2;
13306 +       struct in_addr mask;
13307 +};
13308 +
13309 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
13310 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
13311 +
13312 +struct vcmd_match_ipv6_v0 {
13313 +       uint16_t type;
13314 +       uint16_t flags;
13315 +       uint16_t parent;
13316 +       uint16_t prefix;
13317 +       struct in6_addr ip;
13318 +       struct in6_addr ip2;
13319 +       struct in6_addr mask;
13320 +};
13321 +
13322 +
13323 +#ifdef __KERNEL__
13324 +extern int vc_net_create(uint32_t, void __user *);
13325 +extern int vc_net_migrate(struct nx_info *, void __user *);
13326 +
13327 +extern int vc_net_add(struct nx_info *, void __user *);
13328 +extern int vc_net_remove(struct nx_info *, void __user *);
13329 +
13330 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
13331 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
13332 +
13333 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
13334 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
13335 +
13336 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
13337 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
13338 +
13339 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
13340 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
13341 +
13342 +#endif /* __KERNEL__ */
13343 +
13344 +
13345 +/* flag commands */
13346 +
13347 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
13348 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
13349 +
13350 +struct vcmd_net_flags_v0 {
13351 +       uint64_t flagword;
13352 +       uint64_t mask;
13353 +};
13354 +
13355 +#ifdef __KERNEL__
13356 +extern int vc_get_nflags(struct nx_info *, void __user *);
13357 +extern int vc_set_nflags(struct nx_info *, void __user *);
13358 +
13359 +#endif /* __KERNEL__ */
13360 +
13361 +
13362 +/* network caps commands */
13363 +
13364 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
13365 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
13366 +
13367 +struct vcmd_net_caps_v0 {
13368 +       uint64_t ncaps;
13369 +       uint64_t cmask;
13370 +};
13371 +
13372 +#ifdef __KERNEL__
13373 +extern int vc_get_ncaps(struct nx_info *, void __user *);
13374 +extern int vc_set_ncaps(struct nx_info *, void __user *);
13375 +
13376 +#endif /* __KERNEL__ */
13377 +#endif /* _VX_CONTEXT_CMD_H */
13378 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/network.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/network.h
13379 --- linux-2.6.25/include/linux/vserver/network.h        1969-12-31 19:00:00.000000000 -0500
13380 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/network.h   2008-04-19 15:14:52.000000000 -0400
13381 @@ -0,0 +1,146 @@
13382 +#ifndef _VX_NETWORK_H
13383 +#define _VX_NETWORK_H
13384 +
13385 +#include <linux/types.h>
13386 +
13387 +
13388 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
13389 +
13390 +
13391 +/* network flags */
13392 +
13393 +#define NXF_INFO_PRIVATE       0x00000008
13394 +
13395 +#define NXF_SINGLE_IP          0x00000100
13396 +#define NXF_LBACK_REMAP                0x00000200
13397 +#define NXF_LBACK_ALLOW                0x00000400
13398 +
13399 +#define NXF_HIDE_NETIF         0x02000000
13400 +#define NXF_HIDE_LBACK         0x04000000
13401 +
13402 +#define NXF_STATE_SETUP                (1ULL << 32)
13403 +#define NXF_STATE_ADMIN                (1ULL << 34)
13404 +
13405 +#define NXF_SC_HELPER          (1ULL << 36)
13406 +#define NXF_PERSISTENT         (1ULL << 38)
13407 +
13408 +#define NXF_ONE_TIME           (0x0005ULL << 32)
13409 +
13410 +
13411 +#define        NXF_INIT_SET            (__nxf_init_set())
13412 +
13413 +static inline uint64_t __nxf_init_set(void) {
13414 +       return    NXF_STATE_ADMIN
13415 +#ifdef CONFIG_VSERVER_AUTO_LBACK
13416 +               | NXF_LBACK_REMAP
13417 +               | NXF_HIDE_LBACK
13418 +#endif
13419 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
13420 +               | NXF_SINGLE_IP
13421 +#endif
13422 +               | NXF_HIDE_NETIF;
13423 +}
13424 +
13425 +
13426 +/* network caps */
13427 +
13428 +#define NXC_TUN_CREATE         0x00000001
13429 +
13430 +#define NXC_RAW_ICMP           0x00000100
13431 +
13432 +
13433 +/* address types */
13434 +
13435 +#define NXA_TYPE_IPV4          0x0001
13436 +#define NXA_TYPE_IPV6          0x0002
13437 +
13438 +#define NXA_TYPE_NONE          0x0000
13439 +#define NXA_TYPE_ANY           0x00FF
13440 +
13441 +#define NXA_TYPE_ADDR          0x0010
13442 +#define NXA_TYPE_MASK          0x0020
13443 +#define NXA_TYPE_RANGE         0x0040
13444 +
13445 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
13446 +
13447 +#define NXA_MOD_BCAST          0x0100
13448 +#define NXA_MOD_LBACK          0x0200
13449 +
13450 +#define NXA_LOOPBACK           0x1000
13451 +
13452 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
13453 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
13454 +
13455 +#ifdef __KERNEL__
13456 +
13457 +#include <linux/list.h>
13458 +#include <linux/spinlock.h>
13459 +#include <linux/rcupdate.h>
13460 +#include <linux/in.h>
13461 +#include <linux/in6.h>
13462 +#include <asm/atomic.h>
13463 +
13464 +struct nx_addr_v4 {
13465 +       struct nx_addr_v4 *next;
13466 +       struct in_addr ip[2];
13467 +       struct in_addr mask;
13468 +       uint16_t type;
13469 +       uint16_t flags;
13470 +};
13471 +
13472 +struct nx_addr_v6 {
13473 +       struct nx_addr_v6 *next;
13474 +       struct in6_addr ip;
13475 +       struct in6_addr mask;
13476 +       uint32_t prefix;
13477 +       uint16_t type;
13478 +       uint16_t flags;
13479 +};
13480 +
13481 +struct nx_info {
13482 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
13483 +       nid_t nx_id;                    /* vnet id */
13484 +       atomic_t nx_usecnt;             /* usage count */
13485 +       atomic_t nx_tasks;              /* tasks count */
13486 +       int nx_state;                   /* context state */
13487 +
13488 +       uint64_t nx_flags;              /* network flag word */
13489 +       uint64_t nx_ncaps;              /* network capabilities */
13490 +
13491 +       struct in_addr v4_lback;        /* Loopback address */
13492 +       struct in_addr v4_bcast;        /* Broadcast address */
13493 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
13494 +#ifdef CONFIG_IPV6
13495 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
13496 +#endif
13497 +       char nx_name[65];               /* network context name */
13498 +};
13499 +
13500 +
13501 +/* status flags */
13502 +
13503 +#define NXS_HASHED      0x0001
13504 +#define NXS_SHUTDOWN    0x0100
13505 +#define NXS_RELEASED    0x8000
13506 +
13507 +extern struct nx_info *lookup_nx_info(int);
13508 +
13509 +extern int get_nid_list(int, unsigned int *, int);
13510 +extern int nid_is_hashed(nid_t);
13511 +
13512 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
13513 +
13514 +extern long vs_net_change(struct nx_info *, unsigned int);
13515 +
13516 +struct sock;
13517 +
13518 +
13519 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
13520 +#ifdef  CONFIG_IPV6
13521 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
13522 +#else
13523 +#define NX_IPV6(n)     (0)
13524 +#endif
13525 +
13526 +#endif /* __KERNEL__ */
13527 +#endif /* _VX_NETWORK_H */
13528 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/percpu.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/percpu.h
13529 --- linux-2.6.25/include/linux/vserver/percpu.h 1969-12-31 19:00:00.000000000 -0500
13530 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/percpu.h    2008-04-19 15:14:52.000000000 -0400
13531 @@ -0,0 +1,14 @@
13532 +#ifndef _VX_PERCPU_H
13533 +#define _VX_PERCPU_H
13534 +
13535 +#include "cvirt_def.h"
13536 +#include "sched_def.h"
13537 +
13538 +struct _vx_percpu {
13539 +       struct _vx_cvirt_pc cvirt;
13540 +       struct _vx_sched_pc sched;
13541 +};
13542 +
13543 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
13544 +
13545 +#endif /* _VX_PERCPU_H */
13546 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/pid.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/pid.h
13547 --- linux-2.6.25/include/linux/vserver/pid.h    1969-12-31 19:00:00.000000000 -0500
13548 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/pid.h       2008-04-19 15:14:52.000000000 -0400
13549 @@ -0,0 +1,51 @@
13550 +#ifndef _VSERVER_PID_H
13551 +#define _VSERVER_PID_H
13552 +
13553 +/* pid faking stuff */
13554 +
13555 +#define vx_info_map_pid(v, p) \
13556 +       __vx_info_map_pid((v), (p), __FUNC__, __FILE__, __LINE__)
13557 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
13558 +#define vx_map_pid(p) vx_info_map_pid(current->vx_info, p)
13559 +#define vx_map_tgid(p) vx_map_pid(p)
13560 +
13561 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
13562 +       const char *func, const char *file, int line)
13563 +{
13564 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13565 +               vxfprintk(VXD_CBIT(cvirt, 2),
13566 +                       "vx_map_tgid: %p/%llx: %d -> %d",
13567 +                       vxi, (long long)vxi->vx_flags, pid,
13568 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
13569 +                       func, file, line);
13570 +               if (pid == 0)
13571 +                       return 0;
13572 +               if (pid == vxi->vx_initpid)
13573 +                       return 1;
13574 +       }
13575 +       return pid;
13576 +}
13577 +
13578 +#define vx_info_rmap_pid(v, p) \
13579 +       __vx_info_rmap_pid((v), (p), __FUNC__, __FILE__, __LINE__)
13580 +#define vx_rmap_pid(p) vx_info_rmap_pid(current->vx_info, p)
13581 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
13582 +
13583 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
13584 +       const char *func, const char *file, int line)
13585 +{
13586 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13587 +               vxfprintk(VXD_CBIT(cvirt, 2),
13588 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
13589 +                       vxi, (long long)vxi->vx_flags, pid,
13590 +                       (pid == 1) ? vxi->vx_initpid : pid,
13591 +                       func, file, line);
13592 +               if ((pid == 1) && vxi->vx_initpid)
13593 +                       return vxi->vx_initpid;
13594 +               if (pid == vxi->vx_initpid)
13595 +                       return ~0U;
13596 +       }
13597 +       return pid;
13598 +}
13599 +
13600 +#endif
13601 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/sched_cmd.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/sched_cmd.h
13602 --- linux-2.6.25/include/linux/vserver/sched_cmd.h      1969-12-31 19:00:00.000000000 -0500
13603 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/sched_cmd.h 2008-04-19 15:14:52.000000000 -0400
13604 @@ -0,0 +1,108 @@
13605 +#ifndef _VX_SCHED_CMD_H
13606 +#define _VX_SCHED_CMD_H
13607 +
13608 +
13609 +/*  sched vserver commands */
13610 +
13611 +#define VCMD_set_sched_v2      VC_CMD(SCHED, 1, 2)
13612 +#define VCMD_set_sched_v3      VC_CMD(SCHED, 1, 3)
13613 +#define VCMD_set_sched_v4      VC_CMD(SCHED, 1, 4)
13614 +
13615 +struct vcmd_set_sched_v2 {
13616 +       int32_t fill_rate;
13617 +       int32_t interval;
13618 +       int32_t tokens;
13619 +       int32_t tokens_min;
13620 +       int32_t tokens_max;
13621 +       uint64_t cpu_mask;
13622 +};
13623 +
13624 +struct vcmd_set_sched_v3 {
13625 +       uint32_t set_mask;
13626 +       int32_t fill_rate;
13627 +       int32_t interval;
13628 +       int32_t tokens;
13629 +       int32_t tokens_min;
13630 +       int32_t tokens_max;
13631 +       int32_t priority_bias;
13632 +};
13633 +
13634 +struct vcmd_set_sched_v4 {
13635 +       uint32_t set_mask;
13636 +       int32_t fill_rate;
13637 +       int32_t interval;
13638 +       int32_t tokens;
13639 +       int32_t tokens_min;
13640 +       int32_t tokens_max;
13641 +       int32_t prio_bias;
13642 +       int32_t cpu_id;
13643 +       int32_t bucket_id;
13644 +};
13645 +
13646 +#define VCMD_set_sched         VC_CMD(SCHED, 1, 5)
13647 +#define VCMD_get_sched         VC_CMD(SCHED, 2, 5)
13648 +
13649 +struct vcmd_sched_v5 {
13650 +       uint32_t mask;
13651 +       int32_t cpu_id;
13652 +       int32_t bucket_id;
13653 +       int32_t fill_rate[2];
13654 +       int32_t interval[2];
13655 +       int32_t tokens;
13656 +       int32_t tokens_min;
13657 +       int32_t tokens_max;
13658 +       int32_t prio_bias;
13659 +};
13660 +
13661 +#define VXSM_FILL_RATE         0x0001
13662 +#define VXSM_INTERVAL          0x0002
13663 +#define VXSM_FILL_RATE2                0x0004
13664 +#define VXSM_INTERVAL2         0x0008
13665 +#define VXSM_TOKENS            0x0010
13666 +#define VXSM_TOKENS_MIN                0x0020
13667 +#define VXSM_TOKENS_MAX                0x0040
13668 +#define VXSM_PRIO_BIAS         0x0100
13669 +
13670 +#define VXSM_IDLE_TIME         0x0200
13671 +#define VXSM_FORCE             0x0400
13672 +
13673 +#define        VXSM_V3_MASK            0x0173
13674 +#define        VXSM_SET_MASK           0x01FF
13675 +
13676 +#define VXSM_CPU_ID            0x1000
13677 +#define VXSM_BUCKET_ID         0x2000
13678 +
13679 +#define VXSM_MSEC              0x4000
13680 +
13681 +#define SCHED_KEEP             (-2)    /* only for v2 */
13682 +
13683 +#ifdef __KERNEL__
13684 +
13685 +#include <linux/compiler.h>
13686 +
13687 +extern int vc_set_sched_v2(struct vx_info *, void __user *);
13688 +extern int vc_set_sched_v3(struct vx_info *, void __user *);
13689 +extern int vc_set_sched_v4(struct vx_info *, void __user *);
13690 +extern int vc_set_sched(struct vx_info *, void __user *);
13691 +extern int vc_get_sched(struct vx_info *, void __user *);
13692 +
13693 +#endif /* __KERNEL__ */
13694 +
13695 +#define VCMD_sched_info                VC_CMD(SCHED, 3, 0)
13696 +
13697 +struct vcmd_sched_info {
13698 +       int32_t cpu_id;
13699 +       int32_t bucket_id;
13700 +       uint64_t user_msec;
13701 +       uint64_t sys_msec;
13702 +       uint64_t hold_msec;
13703 +       uint32_t token_usec;
13704 +       int32_t vavavoom;
13705 +};
13706 +
13707 +#ifdef __KERNEL__
13708 +
13709 +extern int vc_sched_info(struct vx_info *, void __user *);
13710 +
13711 +#endif /* __KERNEL__ */
13712 +#endif /* _VX_SCHED_CMD_H */
13713 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/sched_def.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/sched_def.h
13714 --- linux-2.6.25/include/linux/vserver/sched_def.h      1969-12-31 19:00:00.000000000 -0500
13715 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/sched_def.h 2008-04-19 15:14:52.000000000 -0400
13716 @@ -0,0 +1,68 @@
13717 +#ifndef _VX_SCHED_DEF_H
13718 +#define _VX_SCHED_DEF_H
13719 +
13720 +#include <linux/spinlock.h>
13721 +#include <linux/jiffies.h>
13722 +#include <linux/cpumask.h>
13723 +#include <asm/atomic.h>
13724 +#include <asm/param.h>
13725 +
13726 +
13727 +/* context sub struct */
13728 +
13729 +struct _vx_sched {
13730 +       spinlock_t tokens_lock;         /* lock for token bucket */
13731 +
13732 +       int tokens;                     /* number of CPU tokens */
13733 +       int fill_rate[2];               /* Fill rate: add X tokens... */
13734 +       int interval[2];                /* Divisor:   per Y jiffies   */
13735 +       int tokens_min;                 /* Limit:     minimum for unhold */
13736 +       int tokens_max;                 /* Limit:     no more than N tokens */
13737 +
13738 +       int prio_bias;                  /* bias offset for priority */
13739 +
13740 +       unsigned update_mask;           /* which features should be updated */
13741 +       cpumask_t update;               /* CPUs which should update */
13742 +};
13743 +
13744 +struct _vx_sched_pc {
13745 +       int tokens;                     /* number of CPU tokens */
13746 +       int flags;                      /* bucket flags */
13747 +
13748 +       int fill_rate[2];               /* Fill rate: add X tokens... */
13749 +       int interval[2];                /* Divisor:   per Y jiffies   */
13750 +       int tokens_min;                 /* Limit:     minimum for unhold */
13751 +       int tokens_max;                 /* Limit:     no more than N tokens */
13752 +
13753 +       int prio_bias;                  /* bias offset for priority */
13754 +       int vavavoom;                   /* last calculated vavavoom */
13755 +
13756 +       unsigned long norm_time;        /* last time accounted */
13757 +       unsigned long idle_time;        /* non linear time for fair sched */
13758 +       unsigned long token_time;       /* token time for accounting */
13759 +       unsigned long onhold;           /* jiffies when put on hold */
13760 +
13761 +       uint64_t user_ticks;            /* token tick events */
13762 +       uint64_t sys_ticks;             /* token tick events */
13763 +       uint64_t hold_ticks;            /* token ticks paused */
13764 +};
13765 +
13766 +
13767 +#define VXSF_ONHOLD    0x0001
13768 +#define VXSF_IDLE_TIME 0x0100
13769 +
13770 +#ifdef CONFIG_VSERVER_DEBUG
13771 +
13772 +static inline void __dump_vx_sched(struct _vx_sched *sched)
13773 +{
13774 +       printk("\t_vx_sched:\n");
13775 +       printk("\t tokens: %4d/%4d, %4d/%4d, %4d, %4d\n",
13776 +               sched->fill_rate[0], sched->interval[0],
13777 +               sched->fill_rate[1], sched->interval[1],
13778 +               sched->tokens_min, sched->tokens_max);
13779 +       printk("\t priority = %4d\n", sched->prio_bias);
13780 +}
13781 +
13782 +#endif
13783 +
13784 +#endif /* _VX_SCHED_DEF_H */
13785 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/sched.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/sched.h
13786 --- linux-2.6.25/include/linux/vserver/sched.h  1969-12-31 19:00:00.000000000 -0500
13787 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/sched.h     2008-04-19 15:14:52.000000000 -0400
13788 @@ -0,0 +1,26 @@
13789 +#ifndef _VX_SCHED_H
13790 +#define _VX_SCHED_H
13791 +
13792 +
13793 +#ifdef __KERNEL__
13794 +
13795 +struct timespec;
13796 +
13797 +void vx_vsi_uptime(struct timespec *, struct timespec *);
13798 +
13799 +
13800 +struct vx_info;
13801 +
13802 +void vx_update_load(struct vx_info *);
13803 +
13804 +
13805 +int vx_tokens_recalc(struct _vx_sched_pc *,
13806 +       unsigned long *, unsigned long *, int [2]);
13807 +
13808 +void vx_update_sched_param(struct _vx_sched *sched,
13809 +       struct _vx_sched_pc *sched_pc);
13810 +
13811 +#endif /* __KERNEL__ */
13812 +#else  /* _VX_SCHED_H */
13813 +#warning duplicate inclusion
13814 +#endif /* _VX_SCHED_H */
13815 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/signal_cmd.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/signal_cmd.h
13816 --- linux-2.6.25/include/linux/vserver/signal_cmd.h     1969-12-31 19:00:00.000000000 -0500
13817 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/signal_cmd.h        2008-04-19 15:14:52.000000000 -0400
13818 @@ -0,0 +1,43 @@
13819 +#ifndef _VX_SIGNAL_CMD_H
13820 +#define _VX_SIGNAL_CMD_H
13821 +
13822 +
13823 +/*  signalling vserver commands */
13824 +
13825 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13826 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13827 +
13828 +struct vcmd_ctx_kill_v0 {
13829 +       int32_t pid;
13830 +       int32_t sig;
13831 +};
13832 +
13833 +struct vcmd_wait_exit_v0 {
13834 +       int32_t reboot_cmd;
13835 +       int32_t exit_code;
13836 +};
13837 +
13838 +#ifdef __KERNEL__
13839 +
13840 +extern int vc_ctx_kill(struct vx_info *, void __user *);
13841 +extern int vc_wait_exit(struct vx_info *, void __user *);
13842 +
13843 +#endif /* __KERNEL__ */
13844 +
13845 +/*  process alteration commands */
13846 +
13847 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13848 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13849 +
13850 +struct vcmd_pflags_v0 {
13851 +       uint32_t flagword;
13852 +       uint32_t mask;
13853 +};
13854 +
13855 +#ifdef __KERNEL__
13856 +
13857 +extern int vc_get_pflags(uint32_t pid, void __user *);
13858 +extern int vc_set_pflags(uint32_t pid, void __user *);
13859 +
13860 +#endif /* __KERNEL__ */
13861 +#endif /* _VX_SIGNAL_CMD_H */
13862 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/signal.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/signal.h
13863 --- linux-2.6.25/include/linux/vserver/signal.h 1969-12-31 19:00:00.000000000 -0500
13864 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/signal.h    2008-04-19 15:14:52.000000000 -0400
13865 @@ -0,0 +1,14 @@
13866 +#ifndef _VX_SIGNAL_H
13867 +#define _VX_SIGNAL_H
13868 +
13869 +
13870 +#ifdef __KERNEL__
13871 +
13872 +struct vx_info;
13873 +
13874 +int vx_info_kill(struct vx_info *, int, int);
13875 +
13876 +#endif /* __KERNEL__ */
13877 +#else  /* _VX_SIGNAL_H */
13878 +#warning duplicate inclusion
13879 +#endif /* _VX_SIGNAL_H */
13880 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/space_cmd.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/space_cmd.h
13881 --- linux-2.6.25/include/linux/vserver/space_cmd.h      1969-12-31 19:00:00.000000000 -0500
13882 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/space_cmd.h 2008-04-19 15:14:52.000000000 -0400
13883 @@ -0,0 +1,26 @@
13884 +#ifndef _VX_SPACE_CMD_H
13885 +#define _VX_SPACE_CMD_H
13886 +
13887 +
13888 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13889 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 1)
13890 +
13891 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13892 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 1)
13893 +
13894 +#define VCMD_get_space_mask    VC_CMD(PROCALT, 4, 0)
13895 +
13896 +
13897 +struct vcmd_space_mask {
13898 +       uint64_t mask;
13899 +};
13900 +
13901 +
13902 +#ifdef __KERNEL__
13903 +
13904 +extern int vc_enter_space(struct vx_info *, void __user *);
13905 +extern int vc_set_space(struct vx_info *, void __user *);
13906 +extern int vc_get_space_mask(struct vx_info *, void __user *);
13907 +
13908 +#endif /* __KERNEL__ */
13909 +#endif /* _VX_SPACE_CMD_H */
13910 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/space.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/space.h
13911 --- linux-2.6.25/include/linux/vserver/space.h  1969-12-31 19:00:00.000000000 -0500
13912 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/space.h     2008-04-19 15:14:52.000000000 -0400
13913 @@ -0,0 +1,13 @@
13914 +#ifndef _VX_SPACE_H
13915 +#define _VX_SPACE_H
13916 +
13917 +
13918 +#include <linux/types.h>
13919 +
13920 +struct vx_info;
13921 +
13922 +int vx_set_space(struct vx_info *vxi, unsigned long mask);
13923 +
13924 +#else  /* _VX_SPACE_H */
13925 +#warning duplicate inclusion
13926 +#endif /* _VX_SPACE_H */
13927 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/switch.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/switch.h
13928 --- linux-2.6.25/include/linux/vserver/switch.h 1969-12-31 19:00:00.000000000 -0500
13929 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/switch.h    2008-04-19 15:14:52.000000000 -0400
13930 @@ -0,0 +1,99 @@
13931 +#ifndef _VX_SWITCH_H
13932 +#define _VX_SWITCH_H
13933 +
13934 +#include <linux/types.h>
13935 +
13936 +
13937 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13938 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13939 +#define VC_VERSION(c)          ((c) & 0xFFF)
13940 +
13941 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13942 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13943 +
13944 +/*
13945 +
13946 +  Syscall Matrix V2.8
13947 +
13948 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13949 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13950 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13951 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13952 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13953 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13954 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13955 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13956 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13957 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13958 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13959 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13960 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13961 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13962 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13963 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13964 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13965 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13966 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13967 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13968 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13969 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13970 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |       |       |
13971 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13972 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13973 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13974 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13975 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13976 +
13977 +*/
13978 +
13979 +#define VC_CAT_VERSION         0
13980 +
13981 +#define VC_CAT_VSETUP          1
13982 +#define VC_CAT_VHOST           2
13983 +
13984 +#define VC_CAT_DEVICE          6
13985 +
13986 +#define VC_CAT_VPROC           9
13987 +#define VC_CAT_PROCALT         10
13988 +#define VC_CAT_PROCMIG         11
13989 +#define VC_CAT_PROCTRL         12
13990 +
13991 +#define VC_CAT_SCHED           14
13992 +#define VC_CAT_MEMCTRL         20
13993 +
13994 +#define VC_CAT_VNET            25
13995 +#define VC_CAT_NETALT          26
13996 +#define VC_CAT_NETMIG          27
13997 +#define VC_CAT_NETCTRL         28
13998 +
13999 +#define VC_CAT_TAGMIG          35
14000 +#define VC_CAT_DLIMIT          36
14001 +#define VC_CAT_INODE           38
14002 +
14003 +#define VC_CAT_VSTAT           40
14004 +#define VC_CAT_VINFO           46
14005 +#define VC_CAT_EVENT           48
14006 +
14007 +#define VC_CAT_FLAGS           52
14008 +#define VC_CAT_DEBUG           56
14009 +#define VC_CAT_RLIMIT          60
14010 +
14011 +#define VC_CAT_SYSTEST         61
14012 +#define VC_CAT_COMPAT          63
14013 +
14014 +/*  query version */
14015 +
14016 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
14017 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
14018 +
14019 +
14020 +#ifdef __KERNEL__
14021 +
14022 +#include <linux/errno.h>
14023 +
14024 +
14025 +#else  /* __KERNEL__ */
14026 +#define __user
14027 +#endif /* __KERNEL__ */
14028 +
14029 +#endif /* _VX_SWITCH_H */
14030 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/tag_cmd.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/tag_cmd.h
14031 --- linux-2.6.25/include/linux/vserver/tag_cmd.h        1969-12-31 19:00:00.000000000 -0500
14032 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/tag_cmd.h   2008-04-19 15:14:52.000000000 -0400
14033 @@ -0,0 +1,22 @@
14034 +#ifndef _VX_TAG_CMD_H
14035 +#define _VX_TAG_CMD_H
14036 +
14037 +
14038 +/* vinfo commands */
14039 +
14040 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
14041 +
14042 +#ifdef __KERNEL__
14043 +extern int vc_task_tag(uint32_t);
14044 +
14045 +#endif /* __KERNEL__ */
14046 +
14047 +/* context commands */
14048 +
14049 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
14050 +
14051 +#ifdef __KERNEL__
14052 +extern int vc_tag_migrate(uint32_t);
14053 +
14054 +#endif /* __KERNEL__ */
14055 +#endif /* _VX_TAG_CMD_H */
14056 diff -NurpP --minimal linux-2.6.25/include/linux/vserver/tag.h linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/tag.h
14057 --- linux-2.6.25/include/linux/vserver/tag.h    1969-12-31 19:00:00.000000000 -0500
14058 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vserver/tag.h       2008-04-21 13:53:47.000000000 -0400
14059 @@ -0,0 +1,143 @@
14060 +#ifndef _DX_TAG_H
14061 +#define _DX_TAG_H
14062 +
14063 +#include <linux/types.h>
14064 +
14065 +
14066 +#define DX_TAG(in)     (IS_TAGGED(in))
14067 +
14068 +
14069 +#ifdef CONFIG_DX_TAG_NFSD
14070 +#define DX_TAG_NFSD    1
14071 +#else
14072 +#define DX_TAG_NFSD    0
14073 +#endif
14074 +
14075 +
14076 +#ifdef CONFIG_TAGGING_NONE
14077 +
14078 +#define MAX_UID                0xFFFFFFFF
14079 +#define MAX_GID                0xFFFFFFFF
14080 +
14081 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
14082 +
14083 +#define TAGINO_UID(cond, uid, tag)     (uid)
14084 +#define TAGINO_GID(cond, gid, tag)     (gid)
14085 +
14086 +#endif
14087 +
14088 +
14089 +#ifdef CONFIG_TAGGING_GID16
14090 +
14091 +#define MAX_UID                0xFFFFFFFF
14092 +#define MAX_GID                0x0000FFFF
14093 +
14094 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14095 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
14096 +
14097 +#define TAGINO_UID(cond, uid, tag)     (uid)
14098 +#define TAGINO_GID(cond, gid, tag)     \
14099 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
14100 +
14101 +#endif
14102 +
14103 +
14104 +#ifdef CONFIG_TAGGING_ID24
14105 +
14106 +#define MAX_UID                0x00FFFFFF
14107 +#define MAX_GID                0x00FFFFFF
14108 +
14109 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14110 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
14111 +
14112 +#define TAGINO_UID(cond, uid, tag)     \
14113 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
14114 +#define TAGINO_GID(cond, gid, tag)     \
14115 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
14116 +
14117 +#endif
14118 +
14119 +
14120 +#ifdef CONFIG_TAGGING_UID16
14121 +
14122 +#define MAX_UID                0x0000FFFF
14123 +#define MAX_GID                0xFFFFFFFF
14124 +
14125 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14126 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
14127 +
14128 +#define TAGINO_UID(cond, uid, tag)     \
14129 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
14130 +#define TAGINO_GID(cond, gid, tag)     (gid)
14131 +
14132 +#endif
14133 +
14134 +
14135 +#ifdef CONFIG_TAGGING_INTERN
14136 +
14137 +#define MAX_UID                0xFFFFFFFF
14138 +#define MAX_GID                0xFFFFFFFF
14139 +
14140 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14141 +       ((cond) ? (tag) : 0)
14142 +
14143 +#define TAGINO_UID(cond, uid, tag)     (uid)
14144 +#define TAGINO_GID(cond, gid, tag)     (gid)
14145 +
14146 +#endif
14147 +
14148 +
14149 +#ifndef CONFIG_TAGGING_NONE
14150 +#define dx_current_fstag(sb)   \
14151 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
14152 +#else
14153 +#define dx_current_fstag(sb)   (0)
14154 +#endif
14155 +
14156 +#ifndef CONFIG_TAGGING_INTERN
14157 +#define TAGINO_TAG(cond, tag)  (0)
14158 +#else
14159 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
14160 +#endif
14161 +
14162 +#define INOTAG_UID(cond, uid, gid)     \
14163 +       ((cond) ? ((uid) & MAX_UID) : (uid))
14164 +#define INOTAG_GID(cond, uid, gid)     \
14165 +       ((cond) ? ((gid) & MAX_GID) : (gid))
14166 +
14167 +
14168 +static inline uid_t dx_map_uid(uid_t uid)
14169 +{
14170 +       if ((uid > MAX_UID) && (uid != -1))
14171 +               uid = -2;
14172 +       return (uid & MAX_UID);
14173 +}
14174 +
14175 +static inline gid_t dx_map_gid(gid_t gid)
14176 +{
14177 +       if ((gid > MAX_GID) && (gid != -1))
14178 +               gid = -2;
14179 +       return (gid & MAX_GID);
14180 +}
14181 +
14182 +struct peer_tag {
14183 +       int32_t xid;
14184 +       int32_t nid;
14185 +};
14186 +
14187 +#define dx_notagcheck(nd) ((nd) && (nd)->path.mnt && \
14188 +       ((nd)->path.mnt->mnt_flags & MNT_NOTAGCHECK))
14189 +
14190 +int dx_parse_tag(char *string, tag_t *tag, int remove);
14191 +
14192 +#ifdef CONFIG_PROPAGATE
14193 +
14194 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
14195 +
14196 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
14197 +
14198 +#else
14199 +#define dx_propagate_tag(n, i) do { } while (0)
14200 +#endif
14201 +
14202 +#endif /* _DX_TAG_H */
14203 diff -NurpP --minimal linux-2.6.25/include/linux/vs_inet6.h linux-2.6.25-vs2.3.0.34.9/include/linux/vs_inet6.h
14204 --- linux-2.6.25/include/linux/vs_inet6.h       1969-12-31 19:00:00.000000000 -0500
14205 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vs_inet6.h  2008-04-19 15:14:52.000000000 -0400
14206 @@ -0,0 +1,229 @@
14207 +#ifndef _VS_INET6_H
14208 +#define _VS_INET6_H
14209 +
14210 +#include "vserver/base.h"
14211 +#include "vserver/network.h"
14212 +#include "vserver/debug.h"
14213 +
14214 +#include <net/ipv6.h>
14215 +
14216 +#define NXAV6(a)       NIP6((a)->ip), NIP6((a)->mask), (a)->prefix, (a)->type
14217 +#define NXAV6_FMT      "[" NIP6_FMT "/" NIP6_FMT "/%d:%04x]"
14218 +
14219 +
14220 +#ifdef CONFIG_IPV6
14221 +
14222 +static inline
14223 +int v6_addr_match(struct nx_addr_v6 *nxa,
14224 +       const struct in6_addr *addr, uint16_t mask)
14225 +{
14226 +       switch (nxa->type & mask) {
14227 +       case NXA_TYPE_MASK:
14228 +               return ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
14229 +       case NXA_TYPE_ADDR:
14230 +               return ipv6_addr_equal(&nxa->ip, addr);
14231 +       case NXA_TYPE_ANY:
14232 +               return 1;
14233 +       default:
14234 +               return 0;
14235 +       }
14236 +}
14237 +
14238 +static inline
14239 +int v6_addr_in_nx_info(struct nx_info *nxi,
14240 +       const struct in6_addr *addr, uint16_t mask)
14241 +{
14242 +       struct nx_addr_v6 *nxa;
14243 +
14244 +       if (!nxi)
14245 +               return 1;
14246 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
14247 +               if (v6_addr_match(nxa, addr, mask))
14248 +                       return 1;
14249 +       return 0;
14250 +}
14251 +
14252 +static inline
14253 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
14254 +{
14255 +       /* FIXME: needs full range checks */
14256 +       return v6_addr_match(nxa, &addr->ip, mask);
14257 +}
14258 +
14259 +static inline
14260 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
14261 +{
14262 +       struct nx_addr_v6 *ptr;
14263 +
14264 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
14265 +               if (v6_nx_addr_match(ptr, nxa, mask))
14266 +                       return 1;
14267 +       return 0;
14268 +}
14269 +
14270 +
14271 +/*
14272 + *     Check if a given address matches for a socket
14273 + *
14274 + *     nxi:            the socket's nx_info if any
14275 + *     addr:           to be verified address
14276 + */
14277 +static inline
14278 +int v6_sock_addr_match (
14279 +       struct nx_info *nxi,
14280 +       struct inet_sock *inet,
14281 +       struct in6_addr *addr)
14282 +{
14283 +       struct sock *sk = &inet->sk;
14284 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
14285 +
14286 +       if (!ipv6_addr_any(addr) &&
14287 +               ipv6_addr_equal(saddr, addr))
14288 +               return 1;
14289 +       if (ipv6_addr_any(saddr))
14290 +               return v6_addr_in_nx_info(nxi, addr, -1);
14291 +       return 0;
14292 +}
14293 +
14294 +/*
14295 + *     check if address is covered by socket
14296 + *
14297 + *     sk:     the socket to check against
14298 + *     addr:   the address in question (must be != 0)
14299 + */
14300 +
14301 +static inline
14302 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
14303 +{
14304 +       struct nx_info *nxi = sk->sk_nx_info;
14305 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
14306 +
14307 +       vxdprintk(VXD_CBIT(net, 5),
14308 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:" NIP6_FMT " %p;%lx",
14309 +               sk, NXAV6(nxa), nxi, NIP6(*saddr), sk->sk_socket,
14310 +               (sk->sk_socket?sk->sk_socket->flags:0));
14311 +
14312 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
14313 +               return v6_addr_match(nxa, saddr, -1);
14314 +       } else if (nxi) {               /* match against nx_info */
14315 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
14316 +       } else {                        /* unrestricted any socket */
14317 +               return 1;
14318 +       }
14319 +}
14320 +
14321 +
14322 +/* inet related checks and helpers */
14323 +
14324 +
14325 +struct in_ifaddr;
14326 +struct net_device;
14327 +struct sock;
14328 +
14329 +
14330 +#include <linux/netdevice.h>
14331 +#include <linux/inetdevice.h>
14332 +#include <net/inet_timewait_sock.h>
14333 +
14334 +
14335 +int dev_in_nx_info(struct net_device *, struct nx_info *);
14336 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
14337 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
14338 +
14339 +
14340 +
14341 +static inline
14342 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
14343 +{
14344 +       if (!nxi)
14345 +               return 1;
14346 +       if (!ifa)
14347 +               return 0;
14348 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
14349 +}
14350 +
14351 +static inline
14352 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
14353 +{
14354 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
14355 +               return 1;
14356 +       if (v6_ifa_in_nx_info(ifa, nxi))
14357 +               return 1;
14358 +       return 0;
14359 +}
14360 +
14361 +
14362 +struct nx_v6_sock_addr {
14363 +       struct in6_addr saddr;  /* Address used for validation */
14364 +       struct in6_addr baddr;  /* Address used for socket bind */
14365 +};
14366 +
14367 +static inline
14368 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
14369 +       struct nx_v6_sock_addr *nsa)
14370 +{
14371 +       // struct sock *sk = &inet->sk;
14372 +       // struct nx_info *nxi = sk->sk_nx_info;
14373 +       struct in6_addr saddr = addr->sin6_addr;
14374 +       struct in6_addr baddr = saddr;
14375 +
14376 +       nsa->saddr = saddr;
14377 +       nsa->baddr = baddr;
14378 +       return 0;
14379 +}
14380 +
14381 +static inline
14382 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
14383 +{
14384 +       // struct sock *sk = &inet->sk;
14385 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
14386 +
14387 +       // *saddr = nsa->baddr;
14388 +       // inet->saddr = nsa->baddr;
14389 +}
14390 +
14391 +static inline
14392 +int nx_info_has_v6(struct nx_info *nxi)
14393 +{
14394 +       if (!nxi)
14395 +               return 1;
14396 +       if (NX_IPV6(nxi))
14397 +               return 1;
14398 +       return 0;
14399 +}
14400 +
14401 +#else /* CONFIG_IPV6 */
14402 +
14403 +static inline
14404 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
14405 +{
14406 +       return 1;
14407 +}
14408 +
14409 +
14410 +static inline
14411 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
14412 +{
14413 +       return 1;
14414 +}
14415 +
14416 +static inline
14417 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
14418 +{
14419 +       return 1;
14420 +}
14421 +
14422 +static inline
14423 +int nx_info_has_v6(struct nx_info *nxi)
14424 +{
14425 +       return 0;
14426 +}
14427 +
14428 +#endif /* CONFIG_IPV6 */
14429 +
14430 +#define current_nx_info_has_v6() \
14431 +       nx_info_has_v6(current_nx_info())
14432 +
14433 +#else
14434 +#warning duplicate inclusion
14435 +#endif
14436 diff -NurpP --minimal linux-2.6.25/include/linux/vs_inet.h linux-2.6.25-vs2.3.0.34.9/include/linux/vs_inet.h
14437 --- linux-2.6.25/include/linux/vs_inet.h        1969-12-31 19:00:00.000000000 -0500
14438 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vs_inet.h   2008-04-19 15:14:52.000000000 -0400
14439 @@ -0,0 +1,342 @@
14440 +#ifndef _VS_INET_H
14441 +#define _VS_INET_H
14442 +
14443 +#include "vserver/base.h"
14444 +#include "vserver/network.h"
14445 +#include "vserver/debug.h"
14446 +
14447 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
14448 +
14449 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
14450 +                       NIPQUAD((a)->mask), (a)->type
14451 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
14452 +
14453 +
14454 +static inline
14455 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
14456 +{
14457 +       __be32 ip = nxa->ip[0].s_addr;
14458 +       __be32 mask = nxa->mask.s_addr;
14459 +       __be32 bcast = ip | ~mask;
14460 +       int ret = 0;
14461 +
14462 +       switch (nxa->type & tmask) {
14463 +       case NXA_TYPE_MASK:
14464 +               ret = (ip == (addr & mask));
14465 +               break;
14466 +       case NXA_TYPE_ADDR:
14467 +               ret = 3;
14468 +               if (addr == ip)
14469 +                       break;
14470 +               /* fall through to broadcast */
14471 +       case NXA_MOD_BCAST:
14472 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
14473 +               break;
14474 +       case NXA_TYPE_RANGE:
14475 +               ret = ((nxa->ip[0].s_addr <= addr) &&
14476 +                       (nxa->ip[1].s_addr > addr));
14477 +               break;
14478 +       case NXA_TYPE_ANY:
14479 +               ret = 2;
14480 +               break;
14481 +       }
14482 +
14483 +       vxdprintk(VXD_CBIT(net, 0),
14484 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
14485 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
14486 +       return ret;
14487 +}
14488 +
14489 +static inline
14490 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
14491 +{
14492 +       struct nx_addr_v4 *nxa;
14493 +       int ret = 1;
14494 +
14495 +       if (!nxi)
14496 +               goto out;
14497 +
14498 +       ret = 2;
14499 +       /* allow 127.0.0.1 when remapping lback */
14500 +       if ((tmask & NXA_LOOPBACK) &&
14501 +               (addr == IPI_LOOPBACK) &&
14502 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
14503 +               goto out;
14504 +       ret = 3;
14505 +       /* check for lback address */
14506 +       if ((tmask & NXA_MOD_LBACK) &&
14507 +               (nxi->v4_lback.s_addr == addr))
14508 +               goto out;
14509 +       ret = 4;
14510 +       /* check for broadcast address */
14511 +       if ((tmask & NXA_MOD_BCAST) &&
14512 +               (nxi->v4_bcast.s_addr == addr))
14513 +               goto out;
14514 +       ret = 5;
14515 +       /* check for v4 addresses */
14516 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
14517 +               if (v4_addr_match(nxa, addr, tmask))
14518 +                       goto out;
14519 +       ret = 0;
14520 +out:
14521 +       vxdprintk(VXD_CBIT(net, 0),
14522 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
14523 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
14524 +       return ret;
14525 +}
14526 +
14527 +static inline
14528 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
14529 +{
14530 +       /* FIXME: needs full range checks */
14531 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
14532 +}
14533 +
14534 +static inline
14535 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
14536 +{
14537 +       struct nx_addr_v4 *ptr;
14538 +
14539 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
14540 +               if (v4_nx_addr_match(ptr, nxa, mask))
14541 +                       return 1;
14542 +       return 0;
14543 +}
14544 +
14545 +#include <net/inet_sock.h>
14546 +
14547 +/*
14548 + *     Check if a given address matches for a socket
14549 + *
14550 + *     nxi:            the socket's nx_info if any
14551 + *     addr:           to be verified address
14552 + */
14553 +static inline
14554 +int v4_sock_addr_match (
14555 +       struct nx_info *nxi,
14556 +       struct inet_sock *inet,
14557 +       __be32 addr)
14558 +{
14559 +       __be32 saddr = inet->rcv_saddr;
14560 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
14561 +
14562 +       if (addr && (saddr == addr || bcast == addr))
14563 +               return 1;
14564 +       if (!saddr)
14565 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
14566 +       return 0;
14567 +}
14568 +
14569 +
14570 +/* inet related checks and helpers */
14571 +
14572 +
14573 +struct in_ifaddr;
14574 +struct net_device;
14575 +struct sock;
14576 +
14577 +#ifdef CONFIG_INET
14578 +
14579 +#include <linux/netdevice.h>
14580 +#include <linux/inetdevice.h>
14581 +#include <net/inet_sock.h>
14582 +#include <net/inet_timewait_sock.h>
14583 +
14584 +
14585 +int dev_in_nx_info(struct net_device *, struct nx_info *);
14586 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
14587 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
14588 +
14589 +
14590 +/*
14591 + *     check if address is covered by socket
14592 + *
14593 + *     sk:     the socket to check against
14594 + *     addr:   the address in question (must be != 0)
14595 + */
14596 +
14597 +static inline
14598 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
14599 +{
14600 +       struct nx_info *nxi = sk->sk_nx_info;
14601 +       __be32 saddr = inet_rcv_saddr(sk);
14602 +
14603 +       vxdprintk(VXD_CBIT(net, 5),
14604 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
14605 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
14606 +               (sk->sk_socket?sk->sk_socket->flags:0));
14607 +
14608 +       if (saddr) {            /* direct address match */
14609 +               return v4_addr_match(nxa, saddr, -1);
14610 +       } else if (nxi) {       /* match against nx_info */
14611 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
14612 +       } else {                /* unrestricted any socket */
14613 +               return 1;
14614 +       }
14615 +}
14616 +
14617 +
14618 +
14619 +static inline
14620 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
14621 +{
14622 +       vxdprintk(VXD_CBIT(net, 1), "nx_dev_visible(%p[#%u],%p Â»%s«) %d",
14623 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
14624 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
14625 +
14626 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
14627 +               return 1;
14628 +       if (dev_in_nx_info(dev, nxi))
14629 +               return 1;
14630 +       return 0;
14631 +}
14632 +
14633 +
14634 +static inline
14635 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
14636 +{
14637 +       if (!nxi)
14638 +               return 1;
14639 +       if (!ifa)
14640 +               return 0;
14641 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
14642 +}
14643 +
14644 +static inline
14645 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
14646 +{
14647 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
14648 +               nxi, nxi ? nxi->nx_id : 0, ifa,
14649 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
14650 +
14651 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
14652 +               return 1;
14653 +       if (v4_ifa_in_nx_info(ifa, nxi))
14654 +               return 1;
14655 +       return 0;
14656 +}
14657 +
14658 +
14659 +struct nx_v4_sock_addr {
14660 +       __be32 saddr;   /* Address used for validation */
14661 +       __be32 baddr;   /* Address used for socket bind */
14662 +};
14663 +
14664 +static inline
14665 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
14666 +       struct nx_v4_sock_addr *nsa)
14667 +{
14668 +       struct sock *sk = &inet->sk;
14669 +       struct nx_info *nxi = sk->sk_nx_info;
14670 +       __be32 saddr = addr->sin_addr.s_addr;
14671 +       __be32 baddr = saddr;
14672 +
14673 +       vxdprintk(VXD_CBIT(net, 3),
14674 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
14675 +               sk, sk->sk_nx_info, sk->sk_socket,
14676 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
14677 +               NIPQUAD(saddr));
14678 +
14679 +       if (nxi) {
14680 +               if (saddr == INADDR_ANY) {
14681 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
14682 +                               baddr = nxi->v4.ip[0].s_addr;
14683 +               } else if (saddr == IPI_LOOPBACK) {
14684 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
14685 +                               baddr = nxi->v4_lback.s_addr;
14686 +               } else {        /* normal address bind */
14687 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
14688 +                               return -EADDRNOTAVAIL;
14689 +               }
14690 +       }
14691 +
14692 +       vxdprintk(VXD_CBIT(net, 3),
14693 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
14694 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
14695 +
14696 +       nsa->saddr = saddr;
14697 +       nsa->baddr = baddr;
14698 +       return 0;
14699 +}
14700 +
14701 +static inline
14702 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
14703 +{
14704 +       inet->saddr = nsa->baddr;
14705 +       inet->rcv_saddr = nsa->baddr;
14706 +}
14707 +
14708 +
14709 +/*
14710 + *      helper to simplify inet_lookup_listener
14711 + *
14712 + *      nxi:   the socket's nx_info if any
14713 + *      addr:  to be verified address
14714 + *      saddr: socket address
14715 + */
14716 +static inline int v4_inet_addr_match (
14717 +       struct nx_info *nxi,
14718 +       __be32 addr,
14719 +       __be32 saddr)
14720 +{
14721 +       if (addr && (saddr == addr))
14722 +               return 1;
14723 +       if (!saddr)
14724 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
14725 +       return 0;
14726 +}
14727 +
14728 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
14729 +{
14730 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
14731 +               (addr == nxi->v4_lback.s_addr))
14732 +               return IPI_LOOPBACK;
14733 +       return addr;
14734 +}
14735 +
14736 +static inline
14737 +int nx_info_has_v4(struct nx_info *nxi)
14738 +{
14739 +       if (!nxi)
14740 +               return 1;
14741 +       if (NX_IPV4(nxi))
14742 +               return 1;
14743 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
14744 +               return 1;
14745 +       return 0;
14746 +}
14747 +
14748 +#else /* CONFIG_INET */
14749 +
14750 +static inline
14751 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
14752 +{
14753 +       return 1;
14754 +}
14755 +
14756 +static inline
14757 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
14758 +{
14759 +       return 1;
14760 +}
14761 +
14762 +static inline
14763 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
14764 +{
14765 +       return 1;
14766 +}
14767 +
14768 +static inline
14769 +int nx_info_has_v4(struct nx_info *nxi)
14770 +{
14771 +       return 0;
14772 +}
14773 +
14774 +#endif /* CONFIG_INET */
14775 +
14776 +#define current_nx_info_has_v4() \
14777 +       nx_info_has_v4(current_nx_info())
14778 +
14779 +#else
14780 +// #warning duplicate inclusion
14781 +#endif
14782 diff -NurpP --minimal linux-2.6.25/include/linux/vs_limit.h linux-2.6.25-vs2.3.0.34.9/include/linux/vs_limit.h
14783 --- linux-2.6.25/include/linux/vs_limit.h       1969-12-31 19:00:00.000000000 -0500
14784 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vs_limit.h  2008-04-19 15:14:52.000000000 -0400
14785 @@ -0,0 +1,140 @@
14786 +#ifndef _VS_LIMIT_H
14787 +#define _VS_LIMIT_H
14788 +
14789 +#include "vserver/limit.h"
14790 +#include "vserver/base.h"
14791 +#include "vserver/context.h"
14792 +#include "vserver/debug.h"
14793 +#include "vserver/context.h"
14794 +#include "vserver/limit_int.h"
14795 +
14796 +
14797 +#define vx_acc_cres(v, d, p, r) \
14798 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
14799 +
14800 +#define vx_acc_cres_cond(x, d, p, r) \
14801 +       __vx_acc_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
14802 +       r, d, p, __FILE__, __LINE__)
14803 +
14804 +
14805 +#define vx_add_cres(v, a, p, r) \
14806 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
14807 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
14808 +
14809 +#define vx_add_cres_cond(x, a, p, r) \
14810 +       __vx_add_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
14811 +       r, a, p, __FILE__, __LINE__)
14812 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
14813 +
14814 +
14815 +/* process and file limits */
14816 +
14817 +#define vx_nproc_inc(p) \
14818 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
14819 +
14820 +#define vx_nproc_dec(p) \
14821 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
14822 +
14823 +#define vx_files_inc(f) \
14824 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
14825 +
14826 +#define vx_files_dec(f) \
14827 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
14828 +
14829 +#define vx_locks_inc(l) \
14830 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
14831 +
14832 +#define vx_locks_dec(l) \
14833 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
14834 +
14835 +#define vx_openfd_inc(f) \
14836 +       vx_acc_cres(current->vx_info, 1, (void *)(long)(f), VLIMIT_OPENFD)
14837 +
14838 +#define vx_openfd_dec(f) \
14839 +       vx_acc_cres(current->vx_info,-1, (void *)(long)(f), VLIMIT_OPENFD)
14840 +
14841 +
14842 +#define vx_cres_avail(v, n, r) \
14843 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
14844 +
14845 +
14846 +#define vx_nproc_avail(n) \
14847 +       vx_cres_avail(current->vx_info, n, RLIMIT_NPROC)
14848 +
14849 +#define vx_files_avail(n) \
14850 +       vx_cres_avail(current->vx_info, n, RLIMIT_NOFILE)
14851 +
14852 +#define vx_locks_avail(n) \
14853 +       vx_cres_avail(current->vx_info, n, RLIMIT_LOCKS)
14854 +
14855 +#define vx_openfd_avail(n) \
14856 +       vx_cres_avail(current->vx_info, n, VLIMIT_OPENFD)
14857 +
14858 +
14859 +/* dentry limits */
14860 +
14861 +#define vx_dentry_inc(d) do {                                          \
14862 +       if (atomic_read(&d->d_count) == 1)                              \
14863 +               vx_acc_cres(current->vx_info, 1, d, VLIMIT_DENTRY);     \
14864 +       } while (0)
14865 +
14866 +#define vx_dentry_dec(d) do {                                          \
14867 +       if (atomic_read(&d->d_count) == 0)                              \
14868 +               vx_acc_cres(current->vx_info,-1, d, VLIMIT_DENTRY);     \
14869 +       } while (0)
14870 +
14871 +#define vx_dentry_avail(n) \
14872 +       vx_cres_avail(current->vx_info, n, VLIMIT_DENTRY)
14873 +
14874 +
14875 +/* socket limits */
14876 +
14877 +#define vx_sock_inc(s) \
14878 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
14879 +
14880 +#define vx_sock_dec(s) \
14881 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
14882 +
14883 +#define vx_sock_avail(n) \
14884 +       vx_cres_avail(current->vx_info, n, VLIMIT_NSOCK)
14885 +
14886 +
14887 +/* ipc resource limits */
14888 +
14889 +#define vx_ipcmsg_add(v, u, a) \
14890 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
14891 +
14892 +#define vx_ipcmsg_sub(v, u, a) \
14893 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
14894 +
14895 +#define vx_ipcmsg_avail(v, a) \
14896 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
14897 +
14898 +
14899 +#define vx_ipcshm_add(v, k, a) \
14900 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
14901 +
14902 +#define vx_ipcshm_sub(v, k, a) \
14903 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
14904 +
14905 +#define vx_ipcshm_avail(v, a) \
14906 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
14907 +
14908 +
14909 +#define vx_semary_inc(a) \
14910 +       vx_acc_cres(current->vx_info, 1, a, VLIMIT_SEMARY)
14911 +
14912 +#define vx_semary_dec(a) \
14913 +       vx_acc_cres(current->vx_info, -1, a, VLIMIT_SEMARY)
14914 +
14915 +
14916 +#define vx_nsems_add(a,n) \
14917 +       vx_add_cres(current->vx_info, n, a, VLIMIT_NSEMS)
14918 +
14919 +#define vx_nsems_sub(a,n) \
14920 +       vx_sub_cres(current->vx_info, n, a, VLIMIT_NSEMS)
14921 +
14922 +
14923 +#else
14924 +#warning duplicate inclusion
14925 +#endif
14926 diff -NurpP --minimal linux-2.6.25/include/linux/vs_memory.h linux-2.6.25-vs2.3.0.34.9/include/linux/vs_memory.h
14927 --- linux-2.6.25/include/linux/vs_memory.h      1969-12-31 19:00:00.000000000 -0500
14928 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vs_memory.h 2008-04-19 15:14:52.000000000 -0400
14929 @@ -0,0 +1,159 @@
14930 +#ifndef _VS_MEMORY_H
14931 +#define _VS_MEMORY_H
14932 +
14933 +#include "vserver/limit.h"
14934 +#include "vserver/base.h"
14935 +#include "vserver/context.h"
14936 +#include "vserver/debug.h"
14937 +#include "vserver/context.h"
14938 +#include "vserver/limit_int.h"
14939 +
14940 +
14941 +#define __acc_add_long(a, v)   (*(v) += (a))
14942 +#define __acc_inc_long(v)      (++*(v))
14943 +#define __acc_dec_long(v)      (--*(v))
14944 +
14945 +#if    NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
14946 +#define __acc_add_atomic(a, v) atomic_long_add(a, v)
14947 +#define __acc_inc_atomic(v)    atomic_long_inc(v)
14948 +#define __acc_dec_atomic(v)    atomic_long_dec(v)
14949 +#else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14950 +#define __acc_add_atomic(a, v) __acc_add_long(a, v)
14951 +#define __acc_inc_atomic(v)    __acc_inc_long(v)
14952 +#define __acc_dec_atomic(v)    __acc_dec_long(v)
14953 +#endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14954 +
14955 +
14956 +#define vx_acc_page(m, d, v, r) do {                                   \
14957 +       if ((d) > 0)                                                    \
14958 +               __acc_inc_long(&(m)->v);                                \
14959 +       else                                                            \
14960 +               __acc_dec_long(&(m)->v);                                \
14961 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14962 +} while (0)
14963 +
14964 +#define vx_acc_page_atomic(m, d, v, r) do {                            \
14965 +       if ((d) > 0)                                                    \
14966 +               __acc_inc_atomic(&(m)->v);                              \
14967 +       else                                                            \
14968 +               __acc_dec_atomic(&(m)->v);                              \
14969 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14970 +} while (0)
14971 +
14972 +
14973 +#define vx_acc_pages(m, p, v, r) do {                                  \
14974 +       unsigned long __p = (p);                                        \
14975 +       __acc_add_long(__p, &(m)->v);                                   \
14976 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14977 +} while (0)
14978 +
14979 +#define vx_acc_pages_atomic(m, p, v, r) do {                           \
14980 +       unsigned long __p = (p);                                        \
14981 +       __acc_add_atomic(__p, &(m)->v);                                 \
14982 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14983 +} while (0)
14984 +
14985 +
14986 +
14987 +#define vx_acc_vmpage(m, d) \
14988 +       vx_acc_page(m, d, total_vm,  RLIMIT_AS)
14989 +#define vx_acc_vmlpage(m, d) \
14990 +       vx_acc_page(m, d, locked_vm, RLIMIT_MEMLOCK)
14991 +#define vx_acc_file_rsspage(m, d) \
14992 +       vx_acc_page_atomic(m, d, _file_rss, VLIMIT_MAPPED)
14993 +#define vx_acc_anon_rsspage(m, d) \
14994 +       vx_acc_page_atomic(m, d, _anon_rss, VLIMIT_ANON)
14995 +
14996 +#define vx_acc_vmpages(m, p) \
14997 +       vx_acc_pages(m, p, total_vm,  RLIMIT_AS)
14998 +#define vx_acc_vmlpages(m, p) \
14999 +       vx_acc_pages(m, p, locked_vm, RLIMIT_MEMLOCK)
15000 +#define vx_acc_file_rsspages(m, p) \
15001 +       vx_acc_pages_atomic(m, p, _file_rss, VLIMIT_MAPPED)
15002 +#define vx_acc_anon_rsspages(m, p) \
15003 +       vx_acc_pages_atomic(m, p, _anon_rss, VLIMIT_ANON)
15004 +
15005 +#define vx_pages_add(s, r, p)  __vx_add_cres(s, r, p, 0, __FILE__, __LINE__)
15006 +#define vx_pages_sub(s, r, p)  vx_pages_add(s, r, -(p))
15007 +
15008 +#define vx_vmpages_inc(m)              vx_acc_vmpage(m, 1)
15009 +#define vx_vmpages_dec(m)              vx_acc_vmpage(m, -1)
15010 +#define vx_vmpages_add(m, p)           vx_acc_vmpages(m, p)
15011 +#define vx_vmpages_sub(m, p)           vx_acc_vmpages(m, -(p))
15012 +
15013 +#define vx_vmlocked_inc(m)             vx_acc_vmlpage(m, 1)
15014 +#define vx_vmlocked_dec(m)             vx_acc_vmlpage(m, -1)
15015 +#define vx_vmlocked_add(m, p)          vx_acc_vmlpages(m, p)
15016 +#define vx_vmlocked_sub(m, p)          vx_acc_vmlpages(m, -(p))
15017 +
15018 +#define vx_file_rsspages_inc(m)                vx_acc_file_rsspage(m, 1)
15019 +#define vx_file_rsspages_dec(m)                vx_acc_file_rsspage(m, -1)
15020 +#define vx_file_rsspages_add(m, p)     vx_acc_file_rsspages(m, p)
15021 +#define vx_file_rsspages_sub(m, p)     vx_acc_file_rsspages(m, -(p))
15022 +
15023 +#define vx_anon_rsspages_inc(m)                vx_acc_anon_rsspage(m, 1)
15024 +#define vx_anon_rsspages_dec(m)                vx_acc_anon_rsspage(m, -1)
15025 +#define vx_anon_rsspages_add(m, p)     vx_acc_anon_rsspages(m, p)
15026 +#define vx_anon_rsspages_sub(m, p)     vx_acc_anon_rsspages(m, -(p))
15027 +
15028 +
15029 +#define vx_pages_avail(m, p, r) \
15030 +       __vx_cres_avail((m)->mm_vx_info, r, p, __FILE__, __LINE__)
15031 +
15032 +#define vx_vmpages_avail(m, p) vx_pages_avail(m, p, RLIMIT_AS)
15033 +#define vx_vmlocked_avail(m, p)        vx_pages_avail(m, p, RLIMIT_MEMLOCK)
15034 +#define vx_anon_avail(m, p)    vx_pages_avail(m, p, VLIMIT_ANON)
15035 +#define vx_mapped_avail(m, p)  vx_pages_avail(m, p, VLIMIT_MAPPED)
15036 +
15037 +#define vx_rss_avail(m, p) \
15038 +       __vx_cres_array_avail((m)->mm_vx_info, VLA_RSS, p, __FILE__, __LINE__)
15039 +
15040 +
15041 +enum {
15042 +       VXPT_UNKNOWN = 0,
15043 +       VXPT_ANON,
15044 +       VXPT_NONE,
15045 +       VXPT_FILE,
15046 +       VXPT_SWAP,
15047 +       VXPT_WRITE
15048 +};
15049 +
15050 +#if 0
15051 +#define        vx_page_fault(mm, vma, type, ret)
15052 +#else
15053 +
15054 +static inline
15055 +void __vx_page_fault(struct mm_struct *mm,
15056 +       struct vm_area_struct *vma, int type, int ret)
15057 +{
15058 +       struct vx_info *vxi = mm->mm_vx_info;
15059 +       int what;
15060 +/*
15061 +       static char *page_type[6] =
15062 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
15063 +       static char *page_what[4] =
15064 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
15065 +*/
15066 +
15067 +       if (!vxi)
15068 +               return;
15069 +
15070 +       what = (ret & 0x3);
15071 +
15072 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
15073 +               type, what, ret, page_type[type], page_what[what]);
15074 +*/
15075 +       if (ret & VM_FAULT_WRITE)
15076 +               what |= 0x4;
15077 +       atomic_inc(&vxi->cacct.page[type][what]);
15078 +}
15079 +
15080 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
15081 +#endif
15082 +
15083 +
15084 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
15085 +
15086 +#else
15087 +#warning duplicate inclusion
15088 +#endif
15089 diff -NurpP --minimal linux-2.6.25/include/linux/vs_network.h linux-2.6.25-vs2.3.0.34.9/include/linux/vs_network.h
15090 --- linux-2.6.25/include/linux/vs_network.h     1969-12-31 19:00:00.000000000 -0500
15091 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vs_network.h        2008-04-29 18:42:49.000000000 -0400
15092 @@ -0,0 +1,169 @@
15093 +#ifndef _NX_VS_NETWORK_H
15094 +#define _NX_VS_NETWORK_H
15095 +
15096 +#include "vserver/context.h"
15097 +#include "vserver/network.h"
15098 +#include "vserver/base.h"
15099 +#include "vserver/check.h"
15100 +#include "vserver/debug.h"
15101 +
15102 +#include <linux/sched.h>
15103 +
15104 +
15105 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
15106 +
15107 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
15108 +       const char *_file, int _line)
15109 +{
15110 +       if (!nxi)
15111 +               return NULL;
15112 +
15113 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
15114 +               nxi, nxi ? nxi->nx_id : 0,
15115 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
15116 +               _file, _line);
15117 +
15118 +       atomic_inc(&nxi->nx_usecnt);
15119 +       return nxi;
15120 +}
15121 +
15122 +
15123 +extern void free_nx_info(struct nx_info *);
15124 +
15125 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
15126 +
15127 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
15128 +{
15129 +       if (!nxi)
15130 +               return;
15131 +
15132 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
15133 +               nxi, nxi ? nxi->nx_id : 0,
15134 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
15135 +               _file, _line);
15136 +
15137 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
15138 +               free_nx_info(nxi);
15139 +}
15140 +
15141 +
15142 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
15143 +
15144 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
15145 +               const char *_file, int _line)
15146 +{
15147 +       if (nxi) {
15148 +               vxlprintk(VXD_CBIT(nid, 3),
15149 +                       "init_nx_info(%p[#%d.%d])",
15150 +                       nxi, nxi ? nxi->nx_id : 0,
15151 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
15152 +                       _file, _line);
15153 +
15154 +               atomic_inc(&nxi->nx_usecnt);
15155 +       }
15156 +       *nxp = nxi;
15157 +}
15158 +
15159 +
15160 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
15161 +
15162 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
15163 +       const char *_file, int _line)
15164 +{
15165 +       struct nx_info *nxo;
15166 +
15167 +       if (!nxi)
15168 +               return;
15169 +
15170 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
15171 +               nxi, nxi ? nxi->nx_id : 0,
15172 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
15173 +               _file, _line);
15174 +
15175 +       atomic_inc(&nxi->nx_usecnt);
15176 +       nxo = xchg(nxp, nxi);
15177 +       BUG_ON(nxo);
15178 +}
15179 +
15180 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
15181 +
15182 +static inline void __clr_nx_info(struct nx_info **nxp,
15183 +       const char *_file, int _line)
15184 +{
15185 +       struct nx_info *nxo;
15186 +
15187 +       nxo = xchg(nxp, NULL);
15188 +       if (!nxo)
15189 +               return;
15190 +
15191 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
15192 +               nxo, nxo ? nxo->nx_id : 0,
15193 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
15194 +               _file, _line);
15195 +
15196 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
15197 +               free_nx_info(nxo);
15198 +}
15199 +
15200 +
15201 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
15202 +
15203 +static inline void __claim_nx_info(struct nx_info *nxi,
15204 +       struct task_struct *task, const char *_file, int _line)
15205 +{
15206 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
15207 +               nxi, nxi ? nxi->nx_id : 0,
15208 +               nxi?atomic_read(&nxi->nx_usecnt):0,
15209 +               nxi?atomic_read(&nxi->nx_tasks):0,
15210 +               task, _file, _line);
15211 +
15212 +       atomic_inc(&nxi->nx_tasks);
15213 +}
15214 +
15215 +
15216 +extern void unhash_nx_info(struct nx_info *);
15217 +
15218 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
15219 +
15220 +static inline void __release_nx_info(struct nx_info *nxi,
15221 +       struct task_struct *task, const char *_file, int _line)
15222 +{
15223 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
15224 +               nxi, nxi ? nxi->nx_id : 0,
15225 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
15226 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
15227 +               task, _file, _line);
15228 +
15229 +       might_sleep();
15230 +
15231 +       if (atomic_dec_and_test(&nxi->nx_tasks))
15232 +               unhash_nx_info(nxi);
15233 +}
15234 +
15235 +
15236 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
15237 +
15238 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
15239 +       const char *_file, int _line)
15240 +{
15241 +       struct nx_info *nxi;
15242 +
15243 +       task_lock(p);
15244 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
15245 +               p, _file, _line);
15246 +       nxi = __get_nx_info(p->nx_info, _file, _line);
15247 +       task_unlock(p);
15248 +       return nxi;
15249 +}
15250 +
15251 +
15252 +static inline void exit_nx_info(struct task_struct *p)
15253 +{
15254 +       if (p->nx_info)
15255 +               release_nx_info(p->nx_info, p);
15256 +}
15257 +
15258 +
15259 +#else
15260 +#warning duplicate inclusion
15261 +#endif
15262 diff -NurpP --minimal linux-2.6.25/include/linux/vs_pid.h linux-2.6.25-vs2.3.0.34.9/include/linux/vs_pid.h
15263 --- linux-2.6.25/include/linux/vs_pid.h 1969-12-31 19:00:00.000000000 -0500
15264 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vs_pid.h    2008-04-19 15:14:52.000000000 -0400
15265 @@ -0,0 +1,95 @@
15266 +#ifndef _VS_PID_H
15267 +#define _VS_PID_H
15268 +
15269 +#include "vserver/base.h"
15270 +#include "vserver/check.h"
15271 +#include "vserver/context.h"
15272 +#include "vserver/debug.h"
15273 +#include "vserver/pid.h"
15274 +#include <linux/pid_namespace.h>
15275 +
15276 +
15277 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
15278 +
15279 +static inline
15280 +int vx_proc_task_visible(struct task_struct *task)
15281 +{
15282 +       if ((task->pid == 1) &&
15283 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
15284 +               /* show a blend through init */
15285 +               goto visible;
15286 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
15287 +               goto visible;
15288 +       return 0;
15289 +visible:
15290 +       return 1;
15291 +}
15292 +
15293 +#define find_task_by_real_pid find_task_by_pid
15294 +
15295 +#if 0
15296 +
15297 +static inline
15298 +struct task_struct *vx_find_proc_task_by_pid(int pid)
15299 +{
15300 +       struct task_struct *task = find_task_by_real_pid(pid);
15301 +
15302 +       if (task && !vx_proc_task_visible(task)) {
15303 +               vxdprintk(VXD_CBIT(misc, 6),
15304 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
15305 +                       task, task->xid, task->pid,
15306 +                       current, current->xid, current->pid);
15307 +               task = NULL;
15308 +       }
15309 +       return task;
15310 +}
15311 +
15312 +#endif
15313 +
15314 +static inline
15315 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
15316 +{
15317 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
15318 +
15319 +       if (task && !vx_proc_task_visible(task)) {
15320 +               vxdprintk(VXD_CBIT(misc, 6),
15321 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
15322 +                       task, task->xid, task->pid,
15323 +                       current, current->xid, current->pid);
15324 +               put_task_struct(task);
15325 +               task = NULL;
15326 +       }
15327 +       return task;
15328 +}
15329 +
15330 +#if 0
15331 +
15332 +static inline
15333 +struct task_struct *vx_child_reaper(struct task_struct *p)
15334 +{
15335 +       struct vx_info *vxi = p->vx_info;
15336 +       struct task_struct *reaper = child_reaper(p);
15337 +
15338 +       if (!vxi)
15339 +               goto out;
15340 +
15341 +       BUG_ON(!p->vx_info->vx_reaper);
15342 +
15343 +       /* child reaper for the guest reaper */
15344 +       if (vxi->vx_reaper == p)
15345 +               goto out;
15346 +
15347 +       reaper = vxi->vx_reaper;
15348 +out:
15349 +       vxdprintk(VXD_CBIT(xid, 7),
15350 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
15351 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
15352 +       return reaper;
15353 +}
15354 +
15355 +#endif
15356 +
15357 +
15358 +#else
15359 +#warning duplicate inclusion
15360 +#endif
15361 diff -NurpP --minimal linux-2.6.25/include/linux/vs_sched.h linux-2.6.25-vs2.3.0.34.9/include/linux/vs_sched.h
15362 --- linux-2.6.25/include/linux/vs_sched.h       1969-12-31 19:00:00.000000000 -0500
15363 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vs_sched.h  2008-04-19 15:14:52.000000000 -0400
15364 @@ -0,0 +1,110 @@
15365 +#ifndef _VS_SCHED_H
15366 +#define _VS_SCHED_H
15367 +
15368 +#include "vserver/base.h"
15369 +#include "vserver/context.h"
15370 +#include "vserver/sched.h"
15371 +
15372 +
15373 +#define VAVAVOOM_RATIO          50
15374 +
15375 +#define MAX_PRIO_BIAS           20
15376 +#define MIN_PRIO_BIAS          -20
15377 +
15378 +
15379 +#ifdef CONFIG_VSERVER_HARDCPU
15380 +
15381 +/*
15382 + * effective_prio - return the priority that is based on the static
15383 + * priority but is modified by bonuses/penalties.
15384 + *
15385 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
15386 + * into a -4 ... 0 ... +4 bonus/penalty range.
15387 + *
15388 + * Additionally, we scale another amount based on the number of
15389 + * CPU tokens currently held by the context, if the process is
15390 + * part of a context (and the appropriate SCHED flag is set).
15391 + * This ranges from -5 ... 0 ... +15, quadratically.
15392 + *
15393 + * So, the total bonus is -9 .. 0 .. +19
15394 + * We use ~50% of the full 0...39 priority range so that:
15395 + *
15396 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
15397 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
15398 + *    unless that context is far exceeding its CPU allocation.
15399 + *
15400 + * Both properties are important to certain workloads.
15401 + */
15402 +static inline
15403 +int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
15404 +{
15405 +       int vavavoom, max;
15406 +
15407 +       /* lots of tokens = lots of vavavoom
15408 +        *      no tokens = no vavavoom      */
15409 +       if ((vavavoom = sched_pc->tokens) >= 0) {
15410 +               max = sched_pc->tokens_max;
15411 +               vavavoom = max - vavavoom;
15412 +               max = max * max;
15413 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
15414 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
15415 +               return vavavoom;
15416 +       }
15417 +       return 0;
15418 +}
15419 +
15420 +
15421 +static inline
15422 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
15423 +{
15424 +       struct vx_info *vxi = p->vx_info;
15425 +       struct _vx_sched_pc *sched_pc;
15426 +
15427 +       if (!vxi)
15428 +               return prio;
15429 +
15430 +       sched_pc = &vx_cpu(vxi, sched_pc);
15431 +       if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
15432 +               int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
15433 +
15434 +               sched_pc->vavavoom = vavavoom;
15435 +               prio += vavavoom;
15436 +       }
15437 +       prio += sched_pc->prio_bias;
15438 +       return prio;
15439 +}
15440 +
15441 +#else /* !CONFIG_VSERVER_HARDCPU */
15442 +
15443 +static inline
15444 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
15445 +{
15446 +       struct vx_info *vxi = p->vx_info;
15447 +
15448 +       if (vxi)
15449 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
15450 +       return prio;
15451 +}
15452 +
15453 +#endif /* CONFIG_VSERVER_HARDCPU */
15454 +
15455 +
15456 +static inline void vx_account_user(struct vx_info *vxi,
15457 +       cputime_t cputime, int nice)
15458 +{
15459 +       if (!vxi)
15460 +               return;
15461 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
15462 +}
15463 +
15464 +static inline void vx_account_system(struct vx_info *vxi,
15465 +       cputime_t cputime, int idle)
15466 +{
15467 +       if (!vxi)
15468 +               return;
15469 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
15470 +}
15471 +
15472 +#else
15473 +#warning duplicate inclusion
15474 +#endif
15475 diff -NurpP --minimal linux-2.6.25/include/linux/vs_socket.h linux-2.6.25-vs2.3.0.34.9/include/linux/vs_socket.h
15476 --- linux-2.6.25/include/linux/vs_socket.h      1969-12-31 19:00:00.000000000 -0500
15477 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vs_socket.h 2008-04-23 14:32:00.000000000 -0400
15478 @@ -0,0 +1,67 @@
15479 +#ifndef _VS_SOCKET_H
15480 +#define _VS_SOCKET_H
15481 +
15482 +#include "vserver/debug.h"
15483 +#include "vserver/base.h"
15484 +#include "vserver/cacct.h"
15485 +#include "vserver/context.h"
15486 +#include "vserver/tag.h"
15487 +
15488 +
15489 +/* socket accounting */
15490 +
15491 +#include <linux/socket.h>
15492 +
15493 +static inline int vx_sock_type(int family)
15494 +{
15495 +       switch (family) {
15496 +       case PF_UNSPEC:
15497 +               return VXA_SOCK_UNSPEC;
15498 +       case PF_UNIX:
15499 +               return VXA_SOCK_UNIX;
15500 +       case PF_INET:
15501 +               return VXA_SOCK_INET;
15502 +       case PF_INET6:
15503 +               return VXA_SOCK_INET6;
15504 +       case PF_PACKET:
15505 +               return VXA_SOCK_PACKET;
15506 +       default:
15507 +               return VXA_SOCK_OTHER;
15508 +       }
15509 +}
15510 +
15511 +#define vx_acc_sock(v, f, p, s) \
15512 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
15513 +
15514 +static inline void __vx_acc_sock(struct vx_info *vxi,
15515 +       int family, int pos, int size, char *file, int line)
15516 +{
15517 +       if (vxi) {
15518 +               int type = vx_sock_type(family);
15519 +
15520 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
15521 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
15522 +       }
15523 +}
15524 +
15525 +#define vx_sock_recv(sk, s) \
15526 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
15527 +#define vx_sock_send(sk, s) \
15528 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
15529 +#define vx_sock_fail(sk, s) \
15530 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
15531 +
15532 +
15533 +#define sock_vx_init(s) do {           \
15534 +       (s)->sk_xid = 0;                \
15535 +       (s)->sk_vx_info = NULL;         \
15536 +       } while (0)
15537 +
15538 +#define sock_nx_init(s) do {           \
15539 +       (s)->sk_nid = 0;                \
15540 +       (s)->sk_nx_info = NULL;         \
15541 +       } while (0)
15542 +
15543 +#else
15544 +#warning duplicate inclusion
15545 +#endif
15546 diff -NurpP --minimal linux-2.6.25/include/linux/vs_tag.h linux-2.6.25-vs2.3.0.34.9/include/linux/vs_tag.h
15547 --- linux-2.6.25/include/linux/vs_tag.h 1969-12-31 19:00:00.000000000 -0500
15548 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vs_tag.h    2008-04-19 15:14:52.000000000 -0400
15549 @@ -0,0 +1,43 @@
15550 +#ifndef _VS_TAG_H
15551 +#define _VS_TAG_H
15552 +
15553 +#include <linux/vserver/tag.h>
15554 +
15555 +/* check conditions */
15556 +
15557 +#define DX_ADMIN       0x0001
15558 +#define DX_WATCH       0x0002
15559 +#define DX_HOSTID      0x0008
15560 +
15561 +#define DX_IDENT       0x0010
15562 +
15563 +#define DX_ARG_MASK    0x0010
15564 +
15565 +
15566 +#define dx_task_tag(t) ((t)->tag)
15567 +
15568 +#define dx_current_tag() dx_task_tag(current)
15569 +
15570 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
15571 +
15572 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
15573 +
15574 +
15575 +/*
15576 + * check current context for ADMIN/WATCH and
15577 + * optionally against supplied argument
15578 + */
15579 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
15580 +{
15581 +       if (mode & DX_ARG_MASK) {
15582 +               if ((mode & DX_IDENT) && (id == cid))
15583 +                       return 1;
15584 +       }
15585 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
15586 +               ((mode & DX_WATCH) && (cid == 1)) ||
15587 +               ((mode & DX_HOSTID) && (id == 0)));
15588 +}
15589 +
15590 +#else
15591 +#warning duplicate inclusion
15592 +#endif
15593 diff -NurpP --minimal linux-2.6.25/include/linux/vs_time.h linux-2.6.25-vs2.3.0.34.9/include/linux/vs_time.h
15594 --- linux-2.6.25/include/linux/vs_time.h        1969-12-31 19:00:00.000000000 -0500
15595 +++ linux-2.6.25-vs2.3.0.34.9/include/linux/vs_time.h   2008-04-19 15:14:52.000000000 -0400
15596 @@ -0,0 +1,19 @@
15597 +#ifndef _VS_TIME_H
15598 +#define _VS_TIME_H
15599 +
15600 +
15601 +/* time faking stuff */
15602 +
15603 +#ifdef CONFIG_VSERVER_VTIME
15604 +
15605 +extern void vx_gettimeofday(struct timeval *tv);
15606 +extern int vx_settimeofday(struct timespec *ts);
15607 +
15608 +#else
15609 +#define        vx_gettimeofday(t)      do_gettimeofday(t)
15610 +#define        vx_settimeofday(t)      do_settimeofday(t)
15611 +#endif
15612 +
15613 +#else
15614 +#warning duplicate inclusion
15615 +#endif
15616 diff -NurpP --minimal linux-2.6.25/include/net/addrconf.h linux-2.6.25-vs2.3.0.34.9/include/net/addrconf.h
15617 --- linux-2.6.25/include/net/addrconf.h 2008-04-17 12:05:44.000000000 -0400
15618 +++ linux-2.6.25-vs2.3.0.34.9/include/net/addrconf.h    2008-04-19 15:14:52.000000000 -0400
15619 @@ -75,10 +75,12 @@ extern struct inet6_ifaddr      *ipv6_ge
15620  
15621  extern int                     ipv6_get_saddr(struct dst_entry *dst, 
15622                                                struct in6_addr *daddr,
15623 -                                              struct in6_addr *saddr);
15624 +                                              struct in6_addr *saddr,
15625 +                                              struct nx_info *nxi);
15626  extern int                     ipv6_dev_get_saddr(struct net_device *dev, 
15627                                                struct in6_addr *daddr,
15628 -                                              struct in6_addr *saddr);
15629 +                                              struct in6_addr *saddr,
15630 +                                              struct nx_info *nxi);
15631  extern int                     ipv6_get_lladdr(struct net_device *dev,
15632                                                 struct in6_addr *addr,
15633                                                 unsigned char banned_flags);
15634 diff -NurpP --minimal linux-2.6.25/include/net/af_unix.h linux-2.6.25-vs2.3.0.34.9/include/net/af_unix.h
15635 --- linux-2.6.25/include/net/af_unix.h  2008-04-17 12:05:44.000000000 -0400
15636 +++ linux-2.6.25-vs2.3.0.34.9/include/net/af_unix.h     2008-04-19 15:14:52.000000000 -0400
15637 @@ -4,6 +4,7 @@
15638  #include <linux/socket.h>
15639  #include <linux/un.h>
15640  #include <linux/mutex.h>
15641 +#include <linux/vs_base.h>
15642  #include <net/sock.h>
15643  
15644  extern void unix_inflight(struct file *fp);
15645 diff -NurpP --minimal linux-2.6.25/include/net/inet_sock.h linux-2.6.25-vs2.3.0.34.9/include/net/inet_sock.h
15646 --- linux-2.6.25/include/net/inet_sock.h        2008-04-17 12:05:44.000000000 -0400
15647 +++ linux-2.6.25-vs2.3.0.34.9/include/net/inet_sock.h   2008-04-19 15:14:52.000000000 -0400
15648 @@ -24,7 +24,7 @@
15649  #include <net/flow.h>
15650  #include <net/sock.h>
15651  #include <net/request_sock.h>
15652 -#include <net/route.h>
15653 +// #include <net/route.h>
15654  
15655  /** struct ip_options - IP Options
15656   *
15657 @@ -193,9 +193,4 @@ static inline int inet_sk_ehashfn(const 
15658  }
15659  
15660  
15661 -static inline int inet_iif(const struct sk_buff *skb)
15662 -{
15663 -       return ((struct rtable *)skb->dst)->rt_iif;
15664 -}
15665 -
15666  #endif /* _INET_SOCK_H */
15667 diff -NurpP --minimal linux-2.6.25/include/net/inet_timewait_sock.h linux-2.6.25-vs2.3.0.34.9/include/net/inet_timewait_sock.h
15668 --- linux-2.6.25/include/net/inet_timewait_sock.h       2008-04-17 12:05:44.000000000 -0400
15669 +++ linux-2.6.25-vs2.3.0.34.9/include/net/inet_timewait_sock.h  2008-04-19 15:25:34.000000000 -0400
15670 @@ -15,15 +15,14 @@
15671  #ifndef _INET_TIMEWAIT_SOCK_
15672  #define _INET_TIMEWAIT_SOCK_
15673  
15674 +// #include <net/inet_sock.h>
15675 +#include <net/sock.h>
15676  
15677  #include <linux/list.h>
15678  #include <linux/module.h>
15679  #include <linux/timer.h>
15680  #include <linux/types.h>
15681  #include <linux/workqueue.h>
15682 -
15683 -#include <net/inet_sock.h>
15684 -#include <net/sock.h>
15685  #include <net/tcp_states.h>
15686  #include <net/timewait_sock.h>
15687  
15688 @@ -116,6 +115,10 @@ struct inet_timewait_sock {
15689  #define tw_hash                        __tw_common.skc_hash
15690  #define tw_prot                        __tw_common.skc_prot
15691  #define tw_net                 __tw_common.skc_net
15692 +#define tw_xid                 __tw_common.skc_xid
15693 +#define tw_vx_info             __tw_common.skc_vx_info
15694 +#define tw_nid                 __tw_common.skc_nid
15695 +#define tw_nx_info             __tw_common.skc_nx_info
15696         int                     tw_timeout;
15697         volatile unsigned char  tw_substate;
15698         /* 3 bits hole, try to pack */
15699 diff -NurpP --minimal linux-2.6.25/include/net/route.h linux-2.6.25-vs2.3.0.34.9/include/net/route.h
15700 --- linux-2.6.25/include/net/route.h    2008-04-17 12:05:44.000000000 -0400
15701 +++ linux-2.6.25-vs2.3.0.34.9/include/net/route.h       2008-04-21 12:39:35.000000000 -0400
15702 @@ -34,7 +34,7 @@
15703  #include <linux/ip.h>
15704  #include <linux/cache.h>
15705  #include <linux/security.h>
15706 -#include <net/sock.h>
15707 +#include <linux/in.h>
15708  
15709  #ifndef __KERNEL__
15710  #warning This file is not supposed to be used outside of kernel.
15711 @@ -86,6 +86,11 @@ struct ip_rt_acct
15712         __u32   i_packets;
15713  };
15714  
15715 +static inline int inet_iif(const struct sk_buff *skb)
15716 +{
15717 +       return ((struct rtable *)skb->dst)->rt_iif;
15718 +}
15719 +
15720  struct rt_cache_stat 
15721  {
15722          unsigned int in_hit;
15723 @@ -136,6 +141,9 @@ static inline void ip_rt_put(struct rtab
15724                 dst_release(&rt->u.dst);
15725  }
15726  
15727 +#include <linux/vs_base.h>
15728 +#include <linux/vs_inet.h>
15729 +
15730  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
15731  
15732  extern const __u8 ip_tos2prio[16];
15733 @@ -145,6 +153,9 @@ static inline char rt_tos2priority(u8 to
15734         return ip_tos2prio[IPTOS_TOS(tos)>>1];
15735  }
15736  
15737 +extern int ip_v4_find_src(struct net *net, struct nx_info *,
15738 +       struct rtable **, struct flowi *);
15739 +
15740  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
15741                                    __be32 src, u32 tos, int oif, u8 protocol,
15742                                    __be16 sport, __be16 dport, struct sock *sk,
15743 @@ -162,7 +173,21 @@ static inline int ip_route_connect(struc
15744  
15745         int err;
15746         struct net *net = sk->sk_net;
15747 -       if (!dst || !src) {
15748 +       struct nx_info *nx_info = current->nx_info;
15749 +
15750 +       if (sk)
15751 +               nx_info = sk->sk_nx_info;
15752 +
15753 +       vxdprintk(VXD_CBIT(net, 4),
15754 +               "ip_route_connect(%p) %p,%p;%lx",
15755 +               sk, nx_info, sk->sk_socket,
15756 +               (sk->sk_socket?sk->sk_socket->flags:0));
15757 +
15758 +       err = ip_v4_find_src(net, nx_info, rp, &fl);
15759 +       if (err)
15760 +               return err;
15761 +
15762 +       if (!fl.fl4_dst || !fl.fl4_src) {
15763                 err = __ip_route_output_key(net, rp, &fl);
15764                 if (err)
15765                         return err;
15766 diff -NurpP --minimal linux-2.6.25/include/net/sock.h linux-2.6.25-vs2.3.0.34.9/include/net/sock.h
15767 --- linux-2.6.25/include/net/sock.h     2008-04-17 12:05:44.000000000 -0400
15768 +++ linux-2.6.25-vs2.3.0.34.9/include/net/sock.h        2008-04-19 15:14:52.000000000 -0400
15769 @@ -123,6 +123,10 @@ struct sock_common {
15770         unsigned int            skc_hash;
15771         struct proto            *skc_prot;
15772         struct net              *skc_net;
15773 +       xid_t                   skc_xid;
15774 +       struct vx_info          *skc_vx_info;
15775 +       nid_t                   skc_nid;
15776 +       struct nx_info          *skc_nx_info;
15777  };
15778  
15779  /**
15780 @@ -205,6 +209,10 @@ struct sock {
15781  #define sk_hash                        __sk_common.skc_hash
15782  #define sk_prot                        __sk_common.skc_prot
15783  #define sk_net                 __sk_common.skc_net
15784 +#define sk_xid                 __sk_common.skc_xid
15785 +#define sk_vx_info             __sk_common.skc_vx_info
15786 +#define sk_nid                 __sk_common.skc_nid
15787 +#define sk_nx_info             __sk_common.skc_nx_info
15788         unsigned char           sk_shutdown : 2,
15789                                 sk_no_check : 2,
15790                                 sk_userlocks : 4;
15791 diff -NurpP --minimal linux-2.6.25/init/main.c linux-2.6.25-vs2.3.0.34.9/init/main.c
15792 --- linux-2.6.25/init/main.c    2008-04-17 12:05:44.000000000 -0400
15793 +++ linux-2.6.25-vs2.3.0.34.9/init/main.c       2008-04-21 10:46:10.000000000 -0400
15794 @@ -58,6 +58,7 @@
15795  #include <linux/kthread.h>
15796  #include <linux/sched.h>
15797  #include <linux/signal.h>
15798 +#include <linux/vserver/percpu.h>
15799  
15800  #include <asm/io.h>
15801  #include <asm/bugs.h>
15802 @@ -370,12 +371,14 @@ EXPORT_SYMBOL(__per_cpu_offset);
15803  
15804  static void __init setup_per_cpu_areas(void)
15805  {
15806 -       unsigned long size, i;
15807 +       unsigned long size, vspc, i;
15808         char *ptr;
15809         unsigned long nr_possible_cpus = num_possible_cpus();
15810  
15811 +       vspc = PERCPU_PERCTX * CONFIG_VSERVER_CONTEXTS;
15812 +
15813         /* Copy section for each CPU (we discard the original) */
15814 -       size = ALIGN(PERCPU_ENOUGH_ROOM, PAGE_SIZE);
15815 +       size = ALIGN(PERCPU_ENOUGH_ROOM + vspc, PAGE_SIZE);
15816         ptr = alloc_bootmem_pages(size * nr_possible_cpus);
15817  
15818         for_each_possible_cpu(i) {
15819 diff -NurpP --minimal linux-2.6.25/ipc/mqueue.c linux-2.6.25-vs2.3.0.34.9/ipc/mqueue.c
15820 --- linux-2.6.25/ipc/mqueue.c   2008-04-17 12:05:44.000000000 -0400
15821 +++ linux-2.6.25-vs2.3.0.34.9/ipc/mqueue.c      2008-04-19 15:14:52.000000000 -0400
15822 @@ -31,6 +31,8 @@
15823  #include <linux/mutex.h>
15824  #include <linux/nsproxy.h>
15825  #include <linux/pid.h>
15826 +#include <linux/vs_context.h>
15827 +#include <linux/vs_limit.h>
15828  
15829  #include <net/sock.h>
15830  #include "util.h"
15831 @@ -71,6 +73,7 @@ struct mqueue_inode_info {
15832         struct sigevent notify;
15833         struct pid* notify_owner;
15834         struct user_struct *user;       /* user who created, for accounting */
15835 +       struct vx_info *vxi;
15836         struct sock *notify_sock;
15837         struct sk_buff *notify_cookie;
15838  
15839 @@ -119,6 +122,7 @@ static struct inode *mqueue_get_inode(st
15840                         struct mqueue_inode_info *info;
15841                         struct task_struct *p = current;
15842                         struct user_struct *u = p->user;
15843 +                       struct vx_info *vxi = p->vx_info;
15844                         unsigned long mq_bytes, mq_msg_tblsz;
15845  
15846                         inode->i_fop = &mqueue_file_operations;
15847 @@ -133,6 +137,7 @@ static struct inode *mqueue_get_inode(st
15848                         info->notify_owner = NULL;
15849                         info->qsize = 0;
15850                         info->user = NULL;      /* set when all is ok */
15851 +                       info->vxi = NULL;
15852                         memset(&info->attr, 0, sizeof(info->attr));
15853                         info->attr.mq_maxmsg = DFLT_MSGMAX;
15854                         info->attr.mq_msgsize = DFLT_MSGSIZEMAX;
15855 @@ -147,22 +152,26 @@ static struct inode *mqueue_get_inode(st
15856                         spin_lock(&mq_lock);
15857                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
15858                             u->mq_bytes + mq_bytes >
15859 -                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur) {
15860 +                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur ||
15861 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
15862                                 spin_unlock(&mq_lock);
15863                                 goto out_inode;
15864                         }
15865                         u->mq_bytes += mq_bytes;
15866 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
15867                         spin_unlock(&mq_lock);
15868  
15869                         info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
15870                         if (!info->messages) {
15871                                 spin_lock(&mq_lock);
15872                                 u->mq_bytes -= mq_bytes;
15873 +                               vx_ipcmsg_sub(vxi, u, mq_bytes);
15874                                 spin_unlock(&mq_lock);
15875                                 goto out_inode;
15876                         }
15877                         /* all is ok */
15878                         info->user = get_uid(u);
15879 +                       info->vxi = get_vx_info(vxi);
15880                 } else if (S_ISDIR(mode)) {
15881                         inc_nlink(inode);
15882                         /* Some things misbehave if size == 0 on a directory */
15883 @@ -253,10 +262,14 @@ static void mqueue_delete_inode(struct i
15884                    (info->attr.mq_maxmsg * info->attr.mq_msgsize));
15885         user = info->user;
15886         if (user) {
15887 +               struct vx_info *vxi = info->vxi;
15888 +
15889                 spin_lock(&mq_lock);
15890                 user->mq_bytes -= mq_bytes;
15891 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
15892                 queues_count--;
15893                 spin_unlock(&mq_lock);
15894 +               put_vx_info(vxi);
15895                 free_uid(user);
15896         }
15897  }
15898 @@ -743,7 +756,7 @@ asmlinkage long sys_mq_unlink(const char
15899         if (inode)
15900                 atomic_inc(&inode->i_count);
15901  
15902 -       err = vfs_unlink(dentry->d_parent->d_inode, dentry);
15903 +       err = vfs_unlink(dentry->d_parent->d_inode, dentry, NULL);
15904  out_err:
15905         dput(dentry);
15906  
15907 diff -NurpP --minimal linux-2.6.25/ipc/msg.c linux-2.6.25-vs2.3.0.34.9/ipc/msg.c
15908 --- linux-2.6.25/ipc/msg.c      2008-04-17 12:05:44.000000000 -0400
15909 +++ linux-2.6.25-vs2.3.0.34.9/ipc/msg.c 2008-04-21 10:41:47.000000000 -0400
15910 @@ -37,6 +37,7 @@
15911  #include <linux/rwsem.h>
15912  #include <linux/nsproxy.h>
15913  #include <linux/ipc_namespace.h>
15914 +#include <linux/vs_base.h>
15915  
15916  #include <asm/current.h>
15917  #include <asm/uaccess.h>
15918 @@ -168,6 +169,7 @@ static int newque(struct ipc_namespace *
15919  
15920         msq->q_perm.mode = msgflg & S_IRWXUGO;
15921         msq->q_perm.key = key;
15922 +       msq->q_perm.xid = vx_current_xid();
15923  
15924         msq->q_perm.security = NULL;
15925         retval = security_msg_queue_alloc(msq);
15926 diff -NurpP --minimal linux-2.6.25/ipc/namespace.c linux-2.6.25-vs2.3.0.34.9/ipc/namespace.c
15927 --- linux-2.6.25/ipc/namespace.c        2008-04-17 12:05:44.000000000 -0400
15928 +++ linux-2.6.25-vs2.3.0.34.9/ipc/namespace.c   2008-04-21 10:44:58.000000000 -0400
15929 @@ -9,6 +9,8 @@
15930  #include <linux/rcupdate.h>
15931  #include <linux/nsproxy.h>
15932  #include <linux/slab.h>
15933 +#include <linux/vs_base.h>
15934 +#include <linux/vserver/global.h>
15935  
15936  #include "util.h"
15937  
15938 @@ -25,6 +27,7 @@ static struct ipc_namespace *clone_ipc_n
15939         shm_init_ns(ns);
15940  
15941         kref_init(&ns->kref);
15942 +       atomic_inc(&vs_global_ipc_ns);
15943         return ns;
15944  }
15945  
15946 @@ -82,5 +85,6 @@ void free_ipc_ns(struct kref *kref)
15947         sem_exit_ns(ns);
15948         msg_exit_ns(ns);
15949         shm_exit_ns(ns);
15950 +       atomic_dec(&vs_global_ipc_ns);
15951         kfree(ns);
15952  }
15953 diff -NurpP --minimal linux-2.6.25/ipc/sem.c linux-2.6.25-vs2.3.0.34.9/ipc/sem.c
15954 --- linux-2.6.25/ipc/sem.c      2008-04-17 12:05:44.000000000 -0400
15955 +++ linux-2.6.25-vs2.3.0.34.9/ipc/sem.c 2008-04-21 10:45:22.000000000 -0400
15956 @@ -83,6 +83,8 @@
15957  #include <linux/rwsem.h>
15958  #include <linux/nsproxy.h>
15959  #include <linux/ipc_namespace.h>
15960 +#include <linux/vs_base.h>
15961 +#include <linux/vs_limit.h>
15962  
15963  #include <asm/uaccess.h>
15964  #include "util.h"
15965 @@ -252,6 +254,7 @@ static int newary(struct ipc_namespace *
15966  
15967         sma->sem_perm.mode = (semflg & S_IRWXUGO);
15968         sma->sem_perm.key = key;
15969 +       sma->sem_perm.xid = vx_current_xid();
15970  
15971         sma->sem_perm.security = NULL;
15972         retval = security_sem_alloc(sma);
15973 @@ -267,6 +270,9 @@ static int newary(struct ipc_namespace *
15974                 return id;
15975         }
15976         ns->used_sems += nsems;
15977 +       /* FIXME: obsoleted? */
15978 +       vx_semary_inc(sma);
15979 +       vx_nsems_add(sma, nsems);
15980  
15981         sma->sem_perm.id = sem_buildid(id, sma->sem_perm.seq);
15982         sma->sem_base = (struct sem *) &sma[1];
15983 diff -NurpP --minimal linux-2.6.25/ipc/shm.c linux-2.6.25-vs2.3.0.34.9/ipc/shm.c
15984 --- linux-2.6.25/ipc/shm.c      2008-04-17 12:05:44.000000000 -0400
15985 +++ linux-2.6.25-vs2.3.0.34.9/ipc/shm.c 2008-04-21 10:45:38.000000000 -0400
15986 @@ -39,6 +39,8 @@
15987  #include <linux/nsproxy.h>
15988  #include <linux/mount.h>
15989  #include <linux/ipc_namespace.h>
15990 +#include <linux/vs_context.h>
15991 +#include <linux/vs_limit.h>
15992  
15993  #include <asm/uaccess.h>
15994  
15995 @@ -202,7 +204,12 @@ static void shm_open(struct vm_area_stru
15996   */
15997  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
15998  {
15999 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
16000 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
16001 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
16002 +
16003 +       vx_ipcshm_sub(vxi, shp, numpages);
16004 +       ns->shm_tot -= numpages;
16005 +
16006         shm_rmid(ns, shp);
16007         shm_unlock(shp);
16008         if (!is_file_hugepages(shp->shm_file))
16009 @@ -212,6 +219,7 @@ static void shm_destroy(struct ipc_names
16010                                                 shp->mlock_user);
16011         fput (shp->shm_file);
16012         security_shm_free(shp);
16013 +       put_vx_info(vxi);
16014         ipc_rcu_putref(shp);
16015  }
16016  
16017 @@ -383,11 +391,15 @@ static int newseg(struct ipc_namespace *
16018         if (ns->shm_tot + numpages > ns->shm_ctlall)
16019                 return -ENOSPC;
16020  
16021 +       if (!vx_ipcshm_avail(current->vx_info, numpages))
16022 +               return -ENOSPC;
16023 +
16024         shp = ipc_rcu_alloc(sizeof(*shp));
16025         if (!shp)
16026                 return -ENOMEM;
16027  
16028         shp->shm_perm.key = key;
16029 +       shp->shm_perm.xid = vx_current_xid();
16030         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
16031         shp->mlock_user = NULL;
16032  
16033 @@ -441,6 +453,7 @@ static int newseg(struct ipc_namespace *
16034         ns->shm_tot += numpages;
16035         error = shp->shm_perm.id;
16036         shm_unlock(shp);
16037 +       vx_ipcshm_add(current->vx_info, key, numpages);
16038         return error;
16039  
16040  no_id:
16041 diff -NurpP --minimal linux-2.6.25/kernel/capability.c linux-2.6.25-vs2.3.0.34.9/kernel/capability.c
16042 --- linux-2.6.25/kernel/capability.c    2008-04-17 12:05:44.000000000 -0400
16043 +++ linux-2.6.25-vs2.3.0.34.9/kernel/capability.c       2008-04-19 15:14:52.000000000 -0400
16044 @@ -13,6 +13,7 @@
16045  #include <linux/security.h>
16046  #include <linux/syscalls.h>
16047  #include <linux/pid_namespace.h>
16048 +#include <linux/vs_context.h>
16049  #include <asm/uaccess.h>
16050  
16051  /*
16052 @@ -171,6 +172,8 @@ static inline int cap_set_pg(int pgrp_nr
16053  
16054         pgrp = find_vpid(pgrp_nr);
16055         do_each_pid_task(pgrp, PIDTYPE_PGID, g) {
16056 +               if (!vx_check(g->xid, VS_ADMIN_P | VS_IDENT))
16057 +                       continue;
16058                 target = g;
16059                 while_each_thread(g, target) {
16060                         if (!security_capset_check(target, effective,
16061 @@ -335,8 +338,12 @@ int __capable(struct task_struct *t, int
16062         return 0;
16063  }
16064  
16065 +#include <linux/vserver/base.h>
16066  int capable(int cap)
16067  {
16068 +       /* here for now so we don't require task locking */
16069 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
16070 +               return 0;
16071         return __capable(current, cap);
16072  }
16073  EXPORT_SYMBOL(capable);
16074 diff -NurpP --minimal linux-2.6.25/kernel/cgroup.c linux-2.6.25-vs2.3.0.34.9/kernel/cgroup.c
16075 --- linux-2.6.25/kernel/cgroup.c        2008-04-17 12:05:44.000000000 -0400
16076 +++ linux-2.6.25-vs2.3.0.34.9/kernel/cgroup.c   2008-04-19 15:14:52.000000000 -0400
16077 @@ -2828,7 +2828,7 @@ int cgroup_clone(struct task_struct *tsk
16078         }
16079  
16080         /* Create the cgroup directory, which also creates the cgroup */
16081 -       ret = vfs_mkdir(inode, dentry, S_IFDIR | 0755);
16082 +       ret = vfs_mkdir(inode, dentry, S_IFDIR | 0755, NULL);
16083         child = __d_cgrp(dentry);
16084         dput(dentry);
16085         if (ret) {
16086 diff -NurpP --minimal linux-2.6.25/kernel/compat.c linux-2.6.25-vs2.3.0.34.9/kernel/compat.c
16087 --- linux-2.6.25/kernel/compat.c        2008-04-17 12:05:44.000000000 -0400
16088 +++ linux-2.6.25-vs2.3.0.34.9/kernel/compat.c   2008-04-19 15:14:52.000000000 -0400
16089 @@ -846,7 +846,7 @@ asmlinkage long compat_sys_time(compat_t
16090         compat_time_t i;
16091         struct timeval tv;
16092  
16093 -       do_gettimeofday(&tv);
16094 +       vx_gettimeofday(&tv);
16095         i = tv.tv_sec;
16096  
16097         if (tloc) {
16098 @@ -870,7 +870,7 @@ asmlinkage long compat_sys_stime(compat_
16099         if (err)
16100                 return err;
16101  
16102 -       do_settimeofday(&tv);
16103 +       vx_settimeofday(&tv);
16104         return 0;
16105  }
16106  
16107 diff -NurpP --minimal linux-2.6.25/kernel/exit.c linux-2.6.25-vs2.3.0.34.9/kernel/exit.c
16108 --- linux-2.6.25/kernel/exit.c  2008-04-17 12:05:44.000000000 -0400
16109 +++ linux-2.6.25-vs2.3.0.34.9/kernel/exit.c     2008-04-19 15:14:52.000000000 -0400
16110 @@ -44,6 +44,11 @@
16111  #include <linux/resource.h>
16112  #include <linux/blkdev.h>
16113  #include <linux/task_io_accounting_ops.h>
16114 +#include <linux/vs_limit.h>
16115 +#include <linux/vs_context.h>
16116 +#include <linux/vs_network.h>
16117 +#include <linux/vs_pid.h>
16118 +#include <linux/vserver/global.h>
16119  
16120  #include <asm/uaccess.h>
16121  #include <asm/unistd.h>
16122 @@ -468,9 +473,11 @@ static void close_files(struct files_str
16123                                         filp_close(file, files);
16124                                         cond_resched();
16125                                 }
16126 +                               vx_openfd_dec(i);
16127                         }
16128                         i++;
16129                         set >>= 1;
16130 +                       cond_resched();
16131                 }
16132         }
16133  }
16134 @@ -1014,6 +1021,10 @@ NORET_TYPE void do_exit(long code)
16135         if (tsk->splice_pipe)
16136                 __free_pipe_info(tsk->splice_pipe);
16137  
16138 +       /* needs to stay after exit_notify() */
16139 +       exit_vx_info(tsk, code);
16140 +       exit_nx_info(tsk);
16141 +
16142         preempt_disable();
16143         /* causes final put_task_struct in finish_task_switch(). */
16144         tsk->state = TASK_DEAD;
16145 diff -NurpP --minimal linux-2.6.25/kernel/fork.c linux-2.6.25-vs2.3.0.34.9/kernel/fork.c
16146 --- linux-2.6.25/kernel/fork.c  2008-04-17 12:05:44.000000000 -0400
16147 +++ linux-2.6.25-vs2.3.0.34.9/kernel/fork.c     2008-04-21 11:09:01.000000000 -0400
16148 @@ -53,6 +53,11 @@
16149  #include <linux/tty.h>
16150  #include <linux/proc_fs.h>
16151  #include <linux/blkdev.h>
16152 +#include <linux/vs_context.h>
16153 +#include <linux/vs_network.h>
16154 +#include <linux/vs_limit.h>
16155 +#include <linux/vs_memory.h>
16156 +#include <linux/vserver/global.h>
16157  
16158  #include <asm/pgtable.h>
16159  #include <asm/pgalloc.h>
16160 @@ -113,6 +118,8 @@ void free_task(struct task_struct *tsk)
16161         prop_local_destroy_single(&tsk->dirties);
16162         free_thread_info(tsk->stack);
16163         rt_mutex_debug_task_free(tsk);
16164 +       clr_vx_info(&tsk->vx_info);
16165 +       clr_nx_info(&tsk->nx_info);
16166         free_task_struct(tsk);
16167  }
16168  EXPORT_SYMBOL(free_task);
16169 @@ -229,6 +236,8 @@ static int dup_mmap(struct mm_struct *mm
16170         mm->free_area_cache = oldmm->mmap_base;
16171         mm->cached_hole_size = ~0UL;
16172         mm->map_count = 0;
16173 +       __set_mm_counter(mm, file_rss, 0);
16174 +       __set_mm_counter(mm, anon_rss, 0);
16175         cpus_clear(mm->cpu_vm_mask);
16176         mm->mm_rb = RB_ROOT;
16177         rb_link = &mm->mm_rb.rb_node;
16178 @@ -240,7 +249,7 @@ static int dup_mmap(struct mm_struct *mm
16179  
16180                 if (mpnt->vm_flags & VM_DONTCOPY) {
16181                         long pages = vma_pages(mpnt);
16182 -                       mm->total_vm -= pages;
16183 +                       vx_vmpages_sub(mm, pages);
16184                         vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
16185                                                                 -pages);
16186                         continue;
16187 @@ -351,8 +360,8 @@ static struct mm_struct * mm_init(struct
16188                                   : MMF_DUMP_FILTER_DEFAULT;
16189         mm->core_waiters = 0;
16190         mm->nr_ptes = 0;
16191 -       set_mm_counter(mm, file_rss, 0);
16192 -       set_mm_counter(mm, anon_rss, 0);
16193 +       __set_mm_counter(mm, file_rss, 0);
16194 +       __set_mm_counter(mm, anon_rss, 0);
16195         spin_lock_init(&mm->page_table_lock);
16196         rwlock_init(&mm->ioctx_list_lock);
16197         mm->ioctx_list = NULL;
16198 @@ -362,6 +371,7 @@ static struct mm_struct * mm_init(struct
16199  
16200         if (likely(!mm_alloc_pgd(mm))) {
16201                 mm->def_flags = 0;
16202 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
16203                 return mm;
16204         }
16205  
16206 @@ -395,6 +405,7 @@ void __mmdrop(struct mm_struct *mm)
16207         BUG_ON(mm == &init_mm);
16208         mm_free_pgd(mm);
16209         destroy_context(mm);
16210 +       clr_vx_info(&mm->mm_vx_info);
16211         free_mm(mm);
16212  }
16213  EXPORT_SYMBOL_GPL(__mmdrop);
16214 @@ -511,6 +522,7 @@ static struct mm_struct *dup_mm(struct t
16215                 goto fail_nomem;
16216  
16217         memcpy(mm, oldmm, sizeof(*mm));
16218 +       mm->mm_vx_info = NULL;
16219  
16220         /* Initializing for Swap token stuff */
16221         mm->token_priority = 0;
16222 @@ -542,6 +554,7 @@ fail_nocontext:
16223          * If init_new_context() failed, we cannot use mmput() to free the mm
16224          * because it calls destroy_context()
16225          */
16226 +       clr_vx_info(&mm->mm_vx_info);
16227         mm_free_pgd(mm);
16228         free_mm(mm);
16229         return NULL;
16230 @@ -612,6 +625,7 @@ static struct fs_struct *__copy_fs_struc
16231                         fs->altroot.dentry = NULL;
16232                 }
16233                 read_unlock(&old->lock);
16234 +               atomic_inc(&vs_global_fs);
16235         }
16236         return fs;
16237  }
16238 @@ -730,6 +744,8 @@ static struct files_struct *dup_fd(struc
16239                 struct file *f = *old_fds++;
16240                 if (f) {
16241                         get_file(f);
16242 +                       /* TODO: sum it first for check and performance */
16243 +                       vx_openfd_inc(open_files - i);
16244                 } else {
16245                         /*
16246                          * The fd may be claimed in the fd bitmap but not yet
16247 @@ -1011,6 +1027,8 @@ static struct task_struct *copy_process(
16248         int retval;
16249         struct task_struct *p;
16250         int cgroup_callbacks_done = 0;
16251 +       struct vx_info *vxi;
16252 +       struct nx_info *nxi;
16253  
16254         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
16255                 return ERR_PTR(-EINVAL);
16256 @@ -1045,12 +1063,28 @@ static struct task_struct *copy_process(
16257         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
16258         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
16259  #endif
16260 +       init_vx_info(&p->vx_info, current->vx_info);
16261 +       init_nx_info(&p->nx_info, current->nx_info);
16262 +
16263 +       /* check vserver memory */
16264 +       if (p->mm && !(clone_flags & CLONE_VM)) {
16265 +               if (vx_vmpages_avail(p->mm, p->mm->total_vm))
16266 +                       vx_pages_add(p->vx_info, RLIMIT_AS, p->mm->total_vm);
16267 +               else
16268 +                       goto bad_fork_free;
16269 +       }
16270 +       if (p->mm && vx_flags(VXF_FORK_RSS, 0)) {
16271 +               if (!vx_rss_avail(p->mm, get_mm_counter(p->mm, file_rss)))
16272 +                       goto bad_fork_cleanup_vm;
16273 +       }
16274         retval = -EAGAIN;
16275 +       if (!vx_nproc_avail(1))
16276 +               goto bad_fork_cleanup_vm;
16277         if (atomic_read(&p->user->processes) >=
16278                         p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
16279                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
16280                     p->user != current->nsproxy->user_ns->root_user)
16281 -                       goto bad_fork_free;
16282 +                       goto bad_fork_cleanup_vm;
16283         }
16284  
16285         atomic_inc(&p->user->__count);
16286 @@ -1352,6 +1386,18 @@ static struct task_struct *copy_process(
16287  
16288         total_forks++;
16289         spin_unlock(&current->sighand->siglock);
16290 +
16291 +       /* p is copy of current */
16292 +       vxi = p->vx_info;
16293 +       if (vxi) {
16294 +               claim_vx_info(vxi, p);
16295 +               atomic_inc(&vxi->cvirt.nr_threads);
16296 +               atomic_inc(&vxi->cvirt.total_forks);
16297 +               vx_nproc_inc(p);
16298 +       }
16299 +       nxi = p->nx_info;
16300 +       if (nxi)
16301 +               claim_nx_info(nxi, p);
16302         write_unlock_irq(&tasklist_lock);
16303         proc_fork_connector(p);
16304         cgroup_post_fork(p);
16305 @@ -1398,6 +1444,9 @@ bad_fork_cleanup_count:
16306         put_group_info(p->group_info);
16307         atomic_dec(&p->user->processes);
16308         free_uid(p->user);
16309 +bad_fork_cleanup_vm:
16310 +       if (p->mm && !(clone_flags & CLONE_VM))
16311 +               vx_pages_sub(p->vx_info, RLIMIT_AS, p->mm->total_vm);
16312  bad_fork_free:
16313         free_task(p);
16314  fork_out:
16315 diff -NurpP --minimal linux-2.6.25/kernel/kthread.c linux-2.6.25-vs2.3.0.34.9/kernel/kthread.c
16316 --- linux-2.6.25/kernel/kthread.c       2008-04-17 12:05:44.000000000 -0400
16317 +++ linux-2.6.25-vs2.3.0.34.9/kernel/kthread.c  2008-04-19 15:14:52.000000000 -0400
16318 @@ -13,6 +13,7 @@
16319  #include <linux/file.h>
16320  #include <linux/module.h>
16321  #include <linux/mutex.h>
16322 +#include <linux/vs_pid.h>
16323  #include <asm/semaphore.h>
16324  
16325  #define KTHREAD_NICE_LEVEL (-5)
16326 @@ -99,7 +100,7 @@ static void create_kthread(struct kthrea
16327                 struct sched_param param = { .sched_priority = 0 };
16328                 wait_for_completion(&create->started);
16329                 read_lock(&tasklist_lock);
16330 -               create->result = find_task_by_pid(pid);
16331 +               create->result = find_task_by_real_pid(pid);
16332                 read_unlock(&tasklist_lock);
16333                 /*
16334                  * root may have changed our (kthreadd's) priority or CPU mask.
16335 diff -NurpP --minimal linux-2.6.25/kernel/Makefile linux-2.6.25-vs2.3.0.34.9/kernel/Makefile
16336 --- linux-2.6.25/kernel/Makefile        2008-04-17 12:05:44.000000000 -0400
16337 +++ linux-2.6.25-vs2.3.0.34.9/kernel/Makefile   2008-04-19 15:14:52.000000000 -0400
16338 @@ -11,6 +11,8 @@ obj-y     = sched.o fork.o exec_domain.o
16339             hrtimer.o rwsem.o nsproxy.o srcu.o \
16340             notifier.o ksysfs.o pm_qos_params.o
16341  
16342 +obj-y += vserver/
16343 +
16344  obj-$(CONFIG_SYSCTL) += sysctl_check.o
16345  obj-$(CONFIG_STACKTRACE) += stacktrace.o
16346  obj-y += time/
16347 diff -NurpP --minimal linux-2.6.25/kernel/nsproxy.c linux-2.6.25-vs2.3.0.34.9/kernel/nsproxy.c
16348 --- linux-2.6.25/kernel/nsproxy.c       2008-04-17 12:05:44.000000000 -0400
16349 +++ linux-2.6.25-vs2.3.0.34.9/kernel/nsproxy.c  2008-04-19 15:14:52.000000000 -0400
16350 @@ -20,6 +20,8 @@
16351  #include <linux/mnt_namespace.h>
16352  #include <linux/utsname.h>
16353  #include <linux/pid_namespace.h>
16354 +#include <linux/vserver/global.h>
16355 +#include <linux/vserver/debug.h>
16356  #include <net/net_namespace.h>
16357  #include <linux/ipc_namespace.h>
16358  
16359 @@ -38,6 +40,9 @@ static inline struct nsproxy *clone_nspr
16360         if (ns) {
16361                 memcpy(ns, orig, sizeof(struct nsproxy));
16362                 atomic_set(&ns->count, 1);
16363 +               vxdprintk(VXD_CBIT(space, 2), "clone_nsproxy(%p[%u] = %p[1]",
16364 +                       orig, atomic_read(&orig->count), ns);
16365 +               atomic_inc(&vs_global_nsproxy);
16366         }
16367         return ns;
16368  }
16369 @@ -47,47 +52,51 @@ static inline struct nsproxy *clone_nspr
16370   * Return the newly created nsproxy.  Do not attach this to the task,
16371   * leave it to the caller to do proper locking and attach it to task.
16372   */
16373 -static struct nsproxy *create_new_namespaces(unsigned long flags,
16374 -                       struct task_struct *tsk, struct fs_struct *new_fs)
16375 +static struct nsproxy *unshare_namespaces(unsigned long flags,
16376 +                       struct nsproxy *orig, struct fs_struct *new_fs)
16377  {
16378         struct nsproxy *new_nsp;
16379         int err;
16380  
16381 -       new_nsp = clone_nsproxy(tsk->nsproxy);
16382 +       vxdprintk(VXD_CBIT(space, 4),
16383 +               "unshare_namespaces(0x%08lx,%p,%p)",
16384 +               flags, orig, new_fs);
16385 +
16386 +       new_nsp = clone_nsproxy(orig);
16387         if (!new_nsp)
16388                 return ERR_PTR(-ENOMEM);
16389  
16390 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
16391 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
16392         if (IS_ERR(new_nsp->mnt_ns)) {
16393                 err = PTR_ERR(new_nsp->mnt_ns);
16394                 goto out_ns;
16395         }
16396  
16397 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
16398 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
16399         if (IS_ERR(new_nsp->uts_ns)) {
16400                 err = PTR_ERR(new_nsp->uts_ns);
16401                 goto out_uts;
16402         }
16403  
16404 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
16405 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
16406         if (IS_ERR(new_nsp->ipc_ns)) {
16407                 err = PTR_ERR(new_nsp->ipc_ns);
16408                 goto out_ipc;
16409         }
16410  
16411 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
16412 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
16413         if (IS_ERR(new_nsp->pid_ns)) {
16414                 err = PTR_ERR(new_nsp->pid_ns);
16415                 goto out_pid;
16416         }
16417  
16418 -       new_nsp->user_ns = copy_user_ns(flags, tsk->nsproxy->user_ns);
16419 +       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
16420         if (IS_ERR(new_nsp->user_ns)) {
16421                 err = PTR_ERR(new_nsp->user_ns);
16422                 goto out_user;
16423         }
16424  
16425 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
16426 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
16427         if (IS_ERR(new_nsp->net_ns)) {
16428                 err = PTR_ERR(new_nsp->net_ns);
16429                 goto out_net;
16430 @@ -115,6 +124,37 @@ out_ns:
16431         return ERR_PTR(err);
16432  }
16433  
16434 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
16435 +                       struct fs_struct *new_fs)
16436 +{
16437 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
16438 +}
16439 +
16440 +/*
16441 + * copies the nsproxy, setting refcount to 1, and grabbing a
16442 + * reference to all contained namespaces.
16443 + */
16444 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
16445 +{
16446 +       struct nsproxy *ns = clone_nsproxy(orig);
16447 +
16448 +       if (ns) {
16449 +               if (ns->mnt_ns)
16450 +                       get_mnt_ns(ns->mnt_ns);
16451 +               if (ns->uts_ns)
16452 +                       get_uts_ns(ns->uts_ns);
16453 +               if (ns->ipc_ns)
16454 +                       get_ipc_ns(ns->ipc_ns);
16455 +               if (ns->pid_ns)
16456 +                       get_pid_ns(ns->pid_ns);
16457 +               if (ns->user_ns)
16458 +                       get_user_ns(ns->user_ns);
16459 +               if (ns->net_ns)
16460 +                       get_net(ns->net_ns);
16461 +       }
16462 +       return ns;
16463 +}
16464 +
16465  /*
16466   * called from clone.  This now handles copy for nsproxy and all
16467   * namespaces therein.
16468 @@ -122,9 +162,12 @@ out_ns:
16469  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
16470  {
16471         struct nsproxy *old_ns = tsk->nsproxy;
16472 -       struct nsproxy *new_ns;
16473 +       struct nsproxy *new_ns = NULL;
16474         int err = 0;
16475  
16476 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
16477 +               flags, tsk, old_ns);
16478 +
16479         if (!old_ns)
16480                 return 0;
16481  
16482 @@ -155,6 +198,9 @@ int copy_namespaces(unsigned long flags,
16483  
16484  out:
16485         put_nsproxy(old_ns);
16486 +       vxdprintk(VXD_CBIT(space, 3),
16487 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
16488 +               flags, tsk, old_ns, err, new_ns);
16489         return err;
16490  }
16491  
16492 @@ -171,6 +217,7 @@ void free_nsproxy(struct nsproxy *ns)
16493         if (ns->user_ns)
16494                 put_user_ns(ns->user_ns);
16495         put_net(ns->net_ns);
16496 +       atomic_dec(&vs_global_nsproxy);
16497         kmem_cache_free(nsproxy_cachep, ns);
16498  }
16499  
16500 @@ -183,6 +230,10 @@ int unshare_nsproxy_namespaces(unsigned 
16501  {
16502         int err = 0;
16503  
16504 +       vxdprintk(VXD_CBIT(space, 4),
16505 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
16506 +               unshare_flags, current->nsproxy);
16507 +
16508         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
16509                                CLONE_NEWUSER | CLONE_NEWNET)))
16510                 return 0;
16511 diff -NurpP --minimal linux-2.6.25/kernel/pid.c linux-2.6.25-vs2.3.0.34.9/kernel/pid.c
16512 --- linux-2.6.25/kernel/pid.c   2008-04-17 12:05:44.000000000 -0400
16513 +++ linux-2.6.25-vs2.3.0.34.9/kernel/pid.c      2008-04-29 17:56:00.000000000 -0400
16514 @@ -35,6 +35,8 @@
16515  #include <linux/pid_namespace.h>
16516  #include <linux/init_task.h>
16517  #include <linux/syscalls.h>
16518 +#include <linux/vs_pid.h>
16519 +#include <linux/vserver/global.h>
16520  
16521  #define pid_hashfn(nr, ns)     \
16522         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
16523 @@ -303,7 +305,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
16524  
16525  struct pid *find_vpid(int nr)
16526  {
16527 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
16528 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
16529  }
16530  EXPORT_SYMBOL_GPL(find_vpid);
16531  
16532 @@ -359,6 +361,9 @@ void transfer_pid(struct task_struct *ol
16533  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
16534  {
16535         struct task_struct *result = NULL;
16536 +
16537 +       if (type == PIDTYPE_REALPID)
16538 +               type = PIDTYPE_PID;
16539         if (pid) {
16540                 struct hlist_node *first;
16541                 first = rcu_dereference(pid->tasks[type].first);
16542 @@ -388,14 +393,14 @@ EXPORT_SYMBOL(find_task_by_pid);
16543  
16544  struct task_struct *find_task_by_vpid(pid_t vnr)
16545  {
16546 -       return find_task_by_pid_type_ns(PIDTYPE_PID, vnr,
16547 +       return find_task_by_pid_type_ns(PIDTYPE_PID, vx_rmap_pid(vnr),
16548                         current->nsproxy->pid_ns);
16549  }
16550  EXPORT_SYMBOL(find_task_by_vpid);
16551  
16552  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
16553  {
16554 -       return find_task_by_pid_type_ns(PIDTYPE_PID, nr, ns);
16555 +       return find_task_by_pid_type_ns(PIDTYPE_PID, vx_rmap_pid(nr), ns);
16556  }
16557  EXPORT_SYMBOL(find_task_by_pid_ns);
16558  
16559 @@ -430,7 +435,7 @@ struct pid *find_get_pid(pid_t nr)
16560         return pid;
16561  }
16562  
16563 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
16564 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
16565  {
16566         struct upid *upid;
16567         pid_t nr = 0;
16568 @@ -443,6 +448,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
16569         return nr;
16570  }
16571  
16572 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
16573 +{
16574 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
16575 +}
16576 +
16577  pid_t pid_vnr(struct pid *pid)
16578  {
16579         return pid_nr_ns(pid, current->nsproxy->pid_ns);
16580 diff -NurpP --minimal linux-2.6.25/kernel/pid_namespace.c linux-2.6.25-vs2.3.0.34.9/kernel/pid_namespace.c
16581 --- linux-2.6.25/kernel/pid_namespace.c 2008-04-17 12:05:44.000000000 -0400
16582 +++ linux-2.6.25-vs2.3.0.34.9/kernel/pid_namespace.c    2008-04-23 11:52:08.000000000 -0400
16583 @@ -12,6 +12,7 @@
16584  #include <linux/pid_namespace.h>
16585  #include <linux/syscalls.h>
16586  #include <linux/err.h>
16587 +#include <linux/vserver/global.h>
16588  
16589  #define BITS_PER_PAGE          (PAGE_SIZE*8)
16590  
16591 @@ -84,6 +85,7 @@ static struct pid_namespace *create_pid_
16592                 goto out_free_map;
16593  
16594         kref_init(&ns->kref);
16595 +       atomic_inc(&vs_global_pid_ns);
16596         ns->last_pid = 0;
16597         ns->child_reaper = NULL;
16598         ns->level = level;
16599 @@ -112,6 +114,7 @@ static void destroy_pid_namespace(struct
16600  
16601         for (i = 0; i < PIDMAP_ENTRIES; i++)
16602                 kfree(ns->pidmap[i].page);
16603 +       atomic_dec(&vs_global_pid_ns);
16604         kmem_cache_free(pid_ns_cachep, ns);
16605  }
16606  
16607 diff -NurpP --minimal linux-2.6.25/kernel/posix-timers.c linux-2.6.25-vs2.3.0.34.9/kernel/posix-timers.c
16608 --- linux-2.6.25/kernel/posix-timers.c  2008-04-17 12:05:44.000000000 -0400
16609 +++ linux-2.6.25-vs2.3.0.34.9/kernel/posix-timers.c     2008-04-19 15:14:52.000000000 -0400
16610 @@ -47,6 +47,7 @@
16611  #include <linux/wait.h>
16612  #include <linux/workqueue.h>
16613  #include <linux/module.h>
16614 +#include <linux/vs_context.h>
16615  
16616  /*
16617   * Management arrays for POSIX timers.  Timers are kept in slab memory
16618 @@ -299,6 +300,12 @@ void do_schedule_next_timer(struct sigin
16619  
16620  int posix_timer_event(struct k_itimer *timr,int si_private)
16621  {
16622 +       struct vx_info_save vxis;
16623 +       struct vx_info *vxi;
16624 +       int ret;
16625 +
16626 +       vxi = task_get_vx_info(timr->it_process);
16627 +       enter_vx_info(vxi, &vxis);
16628         memset(&timr->sigq->info, 0, sizeof(siginfo_t));
16629         timr->sigq->info.si_sys_private = si_private;
16630         /* Send signal to the process that owns this timer.*/
16631 @@ -311,11 +318,11 @@ int posix_timer_event(struct k_itimer *t
16632  
16633         if (timr->it_sigev_notify & SIGEV_THREAD_ID) {
16634                 struct task_struct *leader;
16635 -               int ret = send_sigqueue(timr->it_sigev_signo, timr->sigq,
16636 -                                       timr->it_process);
16637  
16638 +               ret = send_sigqueue(timr->it_sigev_signo, timr->sigq,
16639 +                                   timr->it_process);
16640                 if (likely(ret >= 0))
16641 -                       return ret;
16642 +                       goto out;
16643  
16644                 timr->it_sigev_notify = SIGEV_SIGNAL;
16645                 leader = timr->it_process->group_leader;
16646 @@ -323,8 +330,12 @@ int posix_timer_event(struct k_itimer *t
16647                 timr->it_process = leader;
16648         }
16649  
16650 -       return send_group_sigqueue(timr->it_sigev_signo, timr->sigq,
16651 +       ret = send_group_sigqueue(timr->it_sigev_signo, timr->sigq,
16652                                    timr->it_process);
16653 +out:
16654 +       leave_vx_info(&vxis);
16655 +       put_vx_info(vxi);
16656 +       return ret;
16657  }
16658  EXPORT_SYMBOL_GPL(posix_timer_event);
16659  
16660 diff -NurpP --minimal linux-2.6.25/kernel/printk.c linux-2.6.25-vs2.3.0.34.9/kernel/printk.c
16661 --- linux-2.6.25/kernel/printk.c        2008-04-17 12:05:44.000000000 -0400
16662 +++ linux-2.6.25-vs2.3.0.34.9/kernel/printk.c   2008-04-21 10:59:28.000000000 -0400
16663 @@ -32,6 +32,7 @@
16664  #include <linux/security.h>
16665  #include <linux/bootmem.h>
16666  #include <linux/syscalls.h>
16667 +#include <linux/vs_cvirt.h>
16668  
16669  #include <asm/uaccess.h>
16670  
16671 @@ -297,18 +298,13 @@ int do_syslog(int type, char __user *buf
16672         unsigned i, j, limit, count;
16673         int do_clear = 0;
16674         char c;
16675 -       int error = 0;
16676 +       int error;
16677  
16678         error = security_syslog(type);
16679         if (error)
16680                 return error;
16681  
16682 -       switch (type) {
16683 -       case 0:         /* Close log */
16684 -               break;
16685 -       case 1:         /* Open log */
16686 -               break;
16687 -       case 2:         /* Read from log */
16688 +       if ((type >= 2) && (type <= 4)) {
16689                 error = -EINVAL;
16690                 if (!buf || len < 0)
16691                         goto out;
16692 @@ -319,6 +315,16 @@ int do_syslog(int type, char __user *buf
16693                         error = -EFAULT;
16694                         goto out;
16695                 }
16696 +       }
16697 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
16698 +               return vx_do_syslog(type, buf, len);
16699 +
16700 +       switch (type) {
16701 +       case 0:         /* Close log */
16702 +               break;
16703 +       case 1:         /* Open log */
16704 +               break;
16705 +       case 2:         /* Read from log */
16706                 error = wait_event_interruptible(log_wait,
16707                                                         (log_start - log_end));
16708                 if (error)
16709 @@ -343,16 +349,6 @@ int do_syslog(int type, char __user *buf
16710                 do_clear = 1;
16711                 /* FALL THRU */
16712         case 3:         /* Read last kernel messages */
16713 -               error = -EINVAL;
16714 -               if (!buf || len < 0)
16715 -                       goto out;
16716 -               error = 0;
16717 -               if (!len)
16718 -                       goto out;
16719 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
16720 -                       error = -EFAULT;
16721 -                       goto out;
16722 -               }
16723                 count = len;
16724                 if (count > log_buf_len)
16725                         count = log_buf_len;
16726 diff -NurpP --minimal linux-2.6.25/kernel/ptrace.c linux-2.6.25-vs2.3.0.34.9/kernel/ptrace.c
16727 --- linux-2.6.25/kernel/ptrace.c        2008-04-17 12:05:44.000000000 -0400
16728 +++ linux-2.6.25-vs2.3.0.34.9/kernel/ptrace.c   2008-04-21 10:50:28.000000000 -0400
16729 @@ -21,6 +21,7 @@
16730  #include <linux/audit.h>
16731  #include <linux/pid_namespace.h>
16732  #include <linux/syscalls.h>
16733 +#include <linux/vs_context.h>
16734  
16735  #include <asm/pgtable.h>
16736  #include <asm/uaccess.h>
16737 @@ -147,6 +148,11 @@ int __ptrace_may_attach(struct task_stru
16738                 dumpable = get_dumpable(task->mm);
16739         if (!dumpable && !capable(CAP_SYS_PTRACE))
16740                 return -EPERM;
16741 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
16742 +               return -EPERM;
16743 +       if (!vx_check(task->xid, VS_IDENT) &&
16744 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
16745 +               return -EACCES;
16746  
16747         return security_ptrace(current, task);
16748  }
16749 @@ -562,6 +568,10 @@ asmlinkage long sys_ptrace(long request,
16750                 goto out;
16751         }
16752  
16753 +       ret = -EPERM;
16754 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
16755 +               goto out_put_task_struct;
16756 +
16757         if (request == PTRACE_ATTACH) {
16758                 ret = ptrace_attach(child);
16759                 /*
16760 diff -NurpP --minimal linux-2.6.25/kernel/sched.c linux-2.6.25-vs2.3.0.34.9/kernel/sched.c
16761 --- linux-2.6.25/kernel/sched.c 2008-04-17 12:05:44.000000000 -0400
16762 +++ linux-2.6.25-vs2.3.0.34.9/kernel/sched.c    2008-04-21 10:51:59.000000000 -0400
16763 @@ -66,6 +66,8 @@
16764  #include <linux/unistd.h>
16765  #include <linux/pagemap.h>
16766  #include <linux/hrtimer.h>
16767 +#include <linux/vs_sched.h>
16768 +#include <linux/vs_cvirt.h>
16769  
16770  #include <asm/tlb.h>
16771  #include <asm/irq_regs.h>
16772 @@ -375,6 +377,16 @@ struct root_domain {
16773  static struct root_domain def_root_domain;
16774  
16775  #endif
16776 +       unsigned long norm_time;
16777 +       unsigned long idle_time;
16778 +#ifdef CONFIG_VSERVER_IDLETIME
16779 +       int idle_skip;
16780 +#endif
16781 +#ifdef CONFIG_VSERVER_HARDCPU
16782 +       struct list_head hold_queue;
16783 +       unsigned long nr_onhold;
16784 +       int idle_tokens;
16785 +#endif
16786  
16787  /*
16788   * This is the main, per-CPU runqueue data structure.
16789 @@ -1303,6 +1315,7 @@ static void set_load_weight(struct task_
16790  
16791  static void enqueue_task(struct rq *rq, struct task_struct *p, int wakeup)
16792  {
16793 +       // BUG_ON(p->state & TASK_ONHOLD);
16794         sched_info_queued(p);
16795         p->sched_class->enqueue_task(rq, p, wakeup);
16796         p->se.on_rq = 1;
16797 @@ -1493,6 +1506,9 @@ struct migration_req {
16798         struct completion done;
16799  };
16800  
16801 +#include "sched_mon.h"
16802 +
16803 +
16804  /*
16805   * The task's runqueue lock must be held.
16806   * Returns true if you have to wait for migration thread.
16807 @@ -1502,6 +1518,7 @@ migrate_task(struct task_struct *p, int 
16808  {
16809         struct rq *rq = task_rq(p);
16810  
16811 +       vxm_migrate_task(p, rq, dest_cpu);
16812         /*
16813          * If the task is not on a runqueue (and not running), then
16814          * it is sufficient to simply update the task's cpu field.
16815 @@ -1863,6 +1880,12 @@ static int try_to_wake_up(struct task_st
16816                 /* might preempt at this point */
16817                 rq = task_rq_lock(p, &flags);
16818                 old_state = p->state;
16819 +
16820 +       /* we need to unhold suspended tasks
16821 +       if (old_state & TASK_ONHOLD) {
16822 +               vx_unhold_task(p, rq);
16823 +               old_state = p->state;
16824 +       } */
16825                 if (!(old_state & state))
16826                         goto out;
16827                 if (p->se.on_rq)
16828 @@ -3634,13 +3657,16 @@ unsigned long long task_sched_runtime(st
16829  void account_user_time(struct task_struct *p, cputime_t cputime)
16830  {
16831         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16832 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16833         cputime64_t tmp;
16834 +       int nice = (TASK_NICE(p) > 0);
16835  
16836         p->utime = cputime_add(p->utime, cputime);
16837 +       vx_account_user(vxi, cputime, nice);
16838  
16839         /* Add user time to cpustat. */
16840         tmp = cputime_to_cputime64(cputime);
16841 -       if (TASK_NICE(p) > 0)
16842 +       if (nice)
16843                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
16844         else
16845                 cpustat->user = cputime64_add(cpustat->user, tmp);
16846 @@ -3685,6 +3711,7 @@ void account_system_time(struct task_str
16847                          cputime_t cputime)
16848  {
16849         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16850 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16851         struct rq *rq = this_rq();
16852         cputime64_t tmp;
16853  
16854 @@ -3692,6 +3719,7 @@ void account_system_time(struct task_str
16855                 return account_guest_time(p, cputime);
16856  
16857         p->stime = cputime_add(p->stime, cputime);
16858 +       vx_account_system(vxi, cputime, (p == rq->idle));
16859  
16860         /* Add system time to cpustat. */
16861         tmp = cputime_to_cputime64(cputime);
16862 @@ -4437,7 +4465,7 @@ asmlinkage long sys_nice(int increment)
16863                 nice = 19;
16864  
16865         if (increment < 0 && !can_nice(current, nice))
16866 -               return -EPERM;
16867 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
16868  
16869         retval = security_task_setnice(current, nice);
16870         if (retval)
16871 diff -NurpP --minimal linux-2.6.25/kernel/sched_fair.c linux-2.6.25-vs2.3.0.34.9/kernel/sched_fair.c
16872 --- linux-2.6.25/kernel/sched_fair.c    2008-04-17 12:05:44.000000000 -0400
16873 +++ linux-2.6.25-vs2.3.0.34.9/kernel/sched_fair.c       2008-04-19 15:14:52.000000000 -0400
16874 @@ -537,6 +537,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
16875         check_spread(cfs_rq, se);
16876         if (se != cfs_rq->curr)
16877                 __enqueue_entity(cfs_rq, se);
16878 +       if (entity_is_task(se))
16879 +               vx_activate_task(task_of(se));
16880         account_entity_enqueue(cfs_rq, se);
16881  }
16882  
16883 @@ -580,6 +582,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
16884  
16885         if (se != cfs_rq->curr)
16886                 __dequeue_entity(cfs_rq, se);
16887 +       if (entity_is_task(se))
16888 +               vx_deactivate_task(task_of(se));
16889         account_entity_dequeue(cfs_rq, se);
16890  }
16891  
16892 diff -NurpP --minimal linux-2.6.25/kernel/sched_hard.h linux-2.6.25-vs2.3.0.34.9/kernel/sched_hard.h
16893 --- linux-2.6.25/kernel/sched_hard.h    1969-12-31 19:00:00.000000000 -0500
16894 +++ linux-2.6.25-vs2.3.0.34.9/kernel/sched_hard.h       2008-04-19 15:14:52.000000000 -0400
16895 @@ -0,0 +1,324 @@
16896 +
16897 +#ifdef CONFIG_VSERVER_IDLELIMIT
16898 +
16899 +/*
16900 + * vx_idle_resched - reschedule after maxidle
16901 + */
16902 +static inline
16903 +void vx_idle_resched(struct rq *rq)
16904 +{
16905 +       /* maybe have a better criterion for paused */
16906 +       if (!--rq->idle_tokens && !list_empty(&rq->hold_queue))
16907 +               set_need_resched();
16908 +}
16909 +
16910 +#else /* !CONFIG_VSERVER_IDLELIMIT */
16911 +
16912 +#define vx_idle_resched(rq)
16913 +
16914 +#endif /* CONFIG_VSERVER_IDLELIMIT */
16915 +
16916 +
16917 +
16918 +#ifdef CONFIG_VSERVER_IDLETIME
16919 +
16920 +#define vx_set_rq_min_skip(rq, min)            \
16921 +       (rq)->idle_skip = (min)
16922 +
16923 +#define vx_save_min_skip(ret, min, val)                \
16924 +       __vx_save_min_skip(ret, min, val)
16925 +
16926 +static inline
16927 +void __vx_save_min_skip(int ret, int *min, int val)
16928 +{
16929 +       if (ret > -2)
16930 +               return;
16931 +       if ((*min > val) || !*min)
16932 +               *min = val;
16933 +}
16934 +
16935 +static inline
16936 +int vx_try_skip(struct rq *rq, int cpu)
16937 +{
16938 +       /* artificially advance time */
16939 +       if (rq->idle_skip > 0) {
16940 +               vxdprintk(list_empty(&rq->hold_queue),
16941 +                       "hold queue empty on cpu %d", cpu);
16942 +               rq->idle_time += rq->idle_skip;
16943 +               vxm_idle_skip(rq, cpu);
16944 +               return 1;
16945 +       }
16946 +       return 0;
16947 +}
16948 +
16949 +#else /* !CONFIG_VSERVER_IDLETIME */
16950 +
16951 +#define vx_set_rq_min_skip(rq, min)            \
16952 +       ({ int dummy = (min); dummy; })
16953 +
16954 +#define vx_save_min_skip(ret, min, val)
16955 +
16956 +static inline
16957 +int vx_try_skip(struct rq *rq, int cpu)
16958 +{
16959 +       return 0;
16960 +}
16961 +
16962 +#endif /* CONFIG_VSERVER_IDLETIME */
16963 +
16964 +
16965 +
16966 +#ifdef CONFIG_VSERVER_HARDCPU
16967 +
16968 +#define vx_set_rq_max_idle(rq, max)            \
16969 +       (rq)->idle_tokens = (max)
16970 +
16971 +#define vx_save_max_idle(ret, min, val)                \
16972 +       __vx_save_max_idle(ret, min, val)
16973 +
16974 +static inline
16975 +void __vx_save_max_idle(int ret, int *min, int val)
16976 +{
16977 +       if (*min > val)
16978 +               *min = val;
16979 +}
16980 +
16981 +
16982 +/*
16983 + * vx_hold_task - put a task on the hold queue
16984 + */
16985 +static inline
16986 +void vx_hold_task(struct task_struct *p, struct rq *rq)
16987 +{
16988 +       __deactivate_task(p, rq);
16989 +       p->state |= TASK_ONHOLD;
16990 +       /* a new one on hold */
16991 +       rq->nr_onhold++;
16992 +       vxm_hold_task(p, rq);
16993 +       list_add_tail(&p->run_list, &rq->hold_queue);
16994 +}
16995 +
16996 +/*
16997 + * vx_unhold_task - put a task back to the runqueue
16998 + */
16999 +static inline
17000 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
17001 +{
17002 +       list_del(&p->run_list);
17003 +       /* one less waiting */
17004 +       rq->nr_onhold--;
17005 +       p->state &= ~TASK_ONHOLD;
17006 +       enqueue_task(p, rq->expired);
17007 +       inc_nr_running(p, rq);
17008 +       vxm_unhold_task(p, rq);
17009 +
17010 +       if (p->static_prio < rq->best_expired_prio)
17011 +               rq->best_expired_prio = p->static_prio;
17012 +}
17013 +
17014 +unsigned long nr_onhold(void)
17015 +{
17016 +       unsigned long i, sum = 0;
17017 +
17018 +       for_each_online_cpu(i)
17019 +               sum += cpu_rq(i)->nr_onhold;
17020 +
17021 +       return sum;
17022 +}
17023 +
17024 +
17025 +
17026 +static inline
17027 +int __vx_tokens_avail(struct _vx_sched_pc *sched_pc)
17028 +{
17029 +       return sched_pc->tokens;
17030 +}
17031 +
17032 +static inline
17033 +void __vx_consume_token(struct _vx_sched_pc *sched_pc)
17034 +{
17035 +       sched_pc->tokens--;
17036 +}
17037 +
17038 +static inline
17039 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
17040 +{
17041 +       struct vx_info *vxi = p->vx_info;
17042 +
17043 +       if (vx_info_flags(vxi, VXF_SCHED_HARD|VXF_SCHED_PRIO, 0)) {
17044 +               struct _vx_sched_pc *sched_pc =
17045 +                       &vx_per_cpu(vxi, sched_pc, cpu);
17046 +               int tokens;
17047 +
17048 +               /* maybe we can simplify that to decrement
17049 +                  the token counter unconditional? */
17050 +
17051 +               if ((tokens = __vx_tokens_avail(sched_pc)) > 0)
17052 +                       __vx_consume_token(sched_pc);
17053 +
17054 +               /* for tokens > 0, one token was consumed */
17055 +               if (tokens < 2)
17056 +                       slice = 0;
17057 +       }
17058 +       vxm_need_resched(p, slice, cpu);
17059 +       return (slice == 0);
17060 +}
17061 +
17062 +
17063 +#define vx_set_rq_time(rq, time) do {  \
17064 +       rq->norm_time = time;           \
17065 +} while (0)
17066 +
17067 +
17068 +static inline
17069 +void vx_try_unhold(struct rq *rq, int cpu)
17070 +{
17071 +       struct vx_info *vxi = NULL;
17072 +       struct list_head *l, *n;
17073 +       int maxidle = HZ;
17074 +       int minskip = 0;
17075 +
17076 +       /* nothing to do? what about pause? */
17077 +       if (list_empty(&rq->hold_queue))
17078 +               return;
17079 +
17080 +       list_for_each_safe(l, n, &rq->hold_queue) {
17081 +               int ret, delta_min[2];
17082 +               struct _vx_sched_pc *sched_pc;
17083 +               struct task_struct *p;
17084 +
17085 +               p = list_entry(l, struct task_struct, run_list);
17086 +               /* don't bother with same context */
17087 +               if (vxi == p->vx_info)
17088 +                       continue;
17089 +
17090 +               vxi = p->vx_info;
17091 +               /* ignore paused contexts */
17092 +               if (vx_info_flags(vxi, VXF_SCHED_PAUSE, 0))
17093 +                       continue;
17094 +
17095 +               sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
17096 +
17097 +               /* recalc tokens */
17098 +               vxm_sched_info(sched_pc, vxi, cpu);
17099 +               ret = vx_tokens_recalc(sched_pc,
17100 +                       &rq->norm_time, &rq->idle_time, delta_min);
17101 +               vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
17102 +
17103 +               if (ret > 0) {
17104 +                       /* we found a runable context */
17105 +                       vx_unhold_task(p, rq);
17106 +                       break;
17107 +               }
17108 +               vx_save_max_idle(ret, &maxidle, delta_min[0]);
17109 +               vx_save_min_skip(ret, &minskip, delta_min[1]);
17110 +       }
17111 +       vx_set_rq_max_idle(rq, maxidle);
17112 +       vx_set_rq_min_skip(rq, minskip);
17113 +       vxm_rq_max_min(rq, cpu);
17114 +}
17115 +
17116 +
17117 +static inline
17118 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
17119 +{
17120 +       struct vx_info *vxi = next->vx_info;
17121 +       struct _vx_sched_pc *sched_pc;
17122 +       int delta_min[2];
17123 +       int flags, ret;
17124 +
17125 +       if (!vxi)
17126 +               return 1;
17127 +
17128 +       flags = vxi->vx_flags;
17129 +
17130 +       if (unlikely(vs_check_flags(flags, VXF_SCHED_PAUSE, 0)))
17131 +               goto put_on_hold;
17132 +       if (!vs_check_flags(flags, VXF_SCHED_HARD | VXF_SCHED_PRIO, 0))
17133 +               return 1;
17134 +
17135 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
17136 +#ifdef CONFIG_SMP
17137 +       /* update scheduler params */
17138 +       if (cpu_isset(cpu, vxi->sched.update)) {
17139 +               vx_update_sched_param(&vxi->sched, sched_pc);
17140 +               vxm_update_sched(sched_pc, vxi, cpu);
17141 +               cpu_clear(cpu, vxi->sched.update);
17142 +       }
17143 +#endif
17144 +       vxm_sched_info(sched_pc, vxi, cpu);
17145 +       ret  = vx_tokens_recalc(sched_pc,
17146 +               &rq->norm_time, &rq->idle_time, delta_min);
17147 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
17148 +
17149 +       if (!vs_check_flags(flags, VXF_SCHED_HARD, 0))
17150 +               return 1;
17151 +
17152 +       if (unlikely(ret < 0)) {
17153 +               vx_save_max_idle(ret, &rq->idle_tokens, delta_min[0]);
17154 +               vx_save_min_skip(ret, &rq->idle_skip, delta_min[1]);
17155 +               vxm_rq_max_min(rq, cpu);
17156 +       put_on_hold:
17157 +               vx_hold_task(next, rq);
17158 +               return 0;
17159 +       }
17160 +       return 1;
17161 +}
17162 +
17163 +
17164 +#else /* CONFIG_VSERVER_HARDCPU */
17165 +
17166 +static inline
17167 +void vx_hold_task(struct task_struct *p, struct rq *rq)
17168 +{
17169 +       return;
17170 +}
17171 +
17172 +static inline
17173 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
17174 +{
17175 +       return;
17176 +}
17177 +
17178 +unsigned long nr_onhold(void)
17179 +{
17180 +       return 0;
17181 +}
17182 +
17183 +
17184 +static inline
17185 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
17186 +{
17187 +       return (slice == 0);
17188 +}
17189 +
17190 +
17191 +#define vx_set_rq_time(rq, time)
17192 +
17193 +static inline
17194 +void vx_try_unhold(struct rq *rq, int cpu)
17195 +{
17196 +       return;
17197 +}
17198 +
17199 +static inline
17200 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
17201 +{
17202 +       struct vx_info *vxi = next->vx_info;
17203 +       struct _vx_sched_pc *sched_pc;
17204 +       int delta_min[2];
17205 +       int ret;
17206 +
17207 +       if (!vx_info_flags(vxi, VXF_SCHED_PRIO, 0))
17208 +               return 1;
17209 +
17210 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
17211 +       vxm_sched_info(sched_pc, vxi, cpu);
17212 +       ret  = vx_tokens_recalc(sched_pc,
17213 +               &rq->norm_time, &rq->idle_time, delta_min);
17214 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
17215 +       return 1;
17216 +}
17217 +
17218 +#endif /* CONFIG_VSERVER_HARDCPU */
17219 +
17220 diff -NurpP --minimal linux-2.6.25/kernel/sched_mon.h linux-2.6.25-vs2.3.0.34.9/kernel/sched_mon.h
17221 --- linux-2.6.25/kernel/sched_mon.h     1969-12-31 19:00:00.000000000 -0500
17222 +++ linux-2.6.25-vs2.3.0.34.9/kernel/sched_mon.h        2008-04-19 15:14:52.000000000 -0400
17223 @@ -0,0 +1,200 @@
17224 +
17225 +#include <linux/vserver/monitor.h>
17226 +
17227 +#ifdef  CONFIG_VSERVER_MONITOR
17228 +
17229 +#ifdef CONFIG_VSERVER_HARDCPU
17230 +#define HARDCPU(x) (x)
17231 +#else
17232 +#define HARDCPU(x) (0)
17233 +#endif
17234 +
17235 +#ifdef CONFIG_VSERVER_IDLETIME
17236 +#define IDLETIME(x) (x)
17237 +#else
17238 +#define IDLETIME(x) (0)
17239 +#endif
17240 +
17241 +struct _vx_mon_entry *vxm_advance(int cpu);
17242 +
17243 +
17244 +static inline
17245 +void   __vxm_basic(struct _vx_mon_entry *entry, xid_t xid, int type)
17246 +{
17247 +       entry->type = type;
17248 +       entry->xid = xid;
17249 +}
17250 +
17251 +static inline
17252 +void   __vxm_sync(int cpu)
17253 +{
17254 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
17255 +
17256 +       __vxm_basic(entry, 0, VXM_SYNC);
17257 +       entry->ev.sec = xtime.tv_sec;
17258 +       entry->ev.nsec = xtime.tv_nsec;
17259 +}
17260 +
17261 +static inline
17262 +void   __vxm_task(struct task_struct *p, int type)
17263 +{
17264 +       struct _vx_mon_entry *entry = vxm_advance(task_cpu(p));
17265 +
17266 +       __vxm_basic(entry, p->xid, type);
17267 +       entry->ev.tsk.pid = p->pid;
17268 +       entry->ev.tsk.state = p->state;
17269 +}
17270 +
17271 +static inline
17272 +void   __vxm_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
17273 +{
17274 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
17275 +
17276 +       __vxm_basic(entry, vxi->vx_id, (VXM_SCHED | s->flags));
17277 +       entry->sd.tokens = s->tokens;
17278 +       entry->sd.norm_time = s->norm_time;
17279 +       entry->sd.idle_time = s->idle_time;
17280 +}
17281 +
17282 +static inline
17283 +void   __vxm_rqinfo1(struct rq *q, int cpu)
17284 +{
17285 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
17286 +
17287 +       entry->type = VXM_RQINFO_1;
17288 +       entry->xid = ((unsigned long)q >> 16) & 0xffff;
17289 +       entry->q1.running = q->nr_running;
17290 +       entry->q1.onhold = HARDCPU(q->nr_onhold);
17291 +       entry->q1.iowait = atomic_read(&q->nr_iowait);
17292 +       entry->q1.uintr = q->nr_uninterruptible;
17293 +       entry->q1.idle_tokens = IDLETIME(q->idle_tokens);
17294 +}
17295 +
17296 +static inline
17297 +void   __vxm_rqinfo2(struct rq *q, int cpu)
17298 +{
17299 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
17300 +
17301 +       entry->type = VXM_RQINFO_2;
17302 +       entry->xid = (unsigned long)q & 0xffff;
17303 +       entry->q2.norm_time = q->norm_time;
17304 +       entry->q2.idle_time = q->idle_time;
17305 +       entry->q2.idle_skip = IDLETIME(q->idle_skip);
17306 +}
17307 +
17308 +static inline
17309 +void   __vxm_update(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
17310 +{
17311 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
17312 +
17313 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE);
17314 +       entry->ev.tokens = s->tokens;
17315 +}
17316 +
17317 +static inline
17318 +void   __vxm_update1(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
17319 +{
17320 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
17321 +
17322 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_1);
17323 +       entry->u1.tokens_max = s->tokens_max;
17324 +       entry->u1.fill_rate = s->fill_rate[0];
17325 +       entry->u1.interval = s->interval[0];
17326 +}
17327 +
17328 +static inline
17329 +void   __vxm_update2(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
17330 +{
17331 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
17332 +
17333 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_2);
17334 +       entry->u2.tokens_min = s->tokens_min;
17335 +       entry->u2.fill_rate = s->fill_rate[1];
17336 +       entry->u2.interval = s->interval[1];
17337 +}
17338 +
17339 +
17340 +#define        vxm_activate_task(p,q)          __vxm_task(p, VXM_ACTIVATE)
17341 +#define        vxm_activate_idle(p,q)          __vxm_task(p, VXM_IDLE)
17342 +#define        vxm_deactivate_task(p,q)        __vxm_task(p, VXM_DEACTIVATE)
17343 +#define        vxm_hold_task(p,q)              __vxm_task(p, VXM_HOLD)
17344 +#define        vxm_unhold_task(p,q)            __vxm_task(p, VXM_UNHOLD)
17345 +
17346 +static inline
17347 +void   vxm_migrate_task(struct task_struct *p, struct rq *rq, int dest)
17348 +{
17349 +       __vxm_task(p, VXM_MIGRATE);
17350 +       __vxm_rqinfo1(rq, task_cpu(p));
17351 +       __vxm_rqinfo2(rq, task_cpu(p));
17352 +}
17353 +
17354 +static inline
17355 +void   vxm_idle_skip(struct rq *rq, int cpu)
17356 +{
17357 +       __vxm_rqinfo1(rq, cpu);
17358 +       __vxm_rqinfo2(rq, cpu);
17359 +}
17360 +
17361 +static inline
17362 +void   vxm_need_resched(struct task_struct *p, int slice, int cpu)
17363 +{
17364 +       if (slice)
17365 +               return;
17366 +
17367 +       __vxm_task(p, VXM_RESCHED);
17368 +}
17369 +
17370 +static inline
17371 +void   vxm_sync(unsigned long now, int cpu)
17372 +{
17373 +       if (!CONFIG_VSERVER_MONITOR_SYNC ||
17374 +               (now % CONFIG_VSERVER_MONITOR_SYNC))
17375 +               return;
17376 +
17377 +       __vxm_sync(cpu);
17378 +}
17379 +
17380 +#define        vxm_sched_info(s,v,c)           __vxm_sched(s,v,c)
17381 +
17382 +static inline
17383 +void   vxm_tokens_recalc(struct _vx_sched_pc *s, struct rq *rq,
17384 +       struct vx_info *vxi, int cpu)
17385 +{
17386 +       __vxm_sched(s, vxi, cpu);
17387 +       __vxm_rqinfo2(rq, cpu);
17388 +}
17389 +
17390 +static inline
17391 +void   vxm_update_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
17392 +{
17393 +       __vxm_sched(s, vxi, cpu);
17394 +       __vxm_update(s, vxi, cpu);
17395 +       __vxm_update1(s, vxi, cpu);
17396 +       __vxm_update2(s, vxi, cpu);
17397 +}
17398 +
17399 +static inline
17400 +void   vxm_rq_max_min(struct rq *rq, int cpu)
17401 +{
17402 +       __vxm_rqinfo1(rq, cpu);
17403 +       __vxm_rqinfo2(rq, cpu);
17404 +}
17405 +
17406 +#else  /* CONFIG_VSERVER_MONITOR */
17407 +
17408 +#define        vxm_activate_task(t,q)          do { } while (0)
17409 +#define        vxm_activate_idle(t,q)          do { } while (0)
17410 +#define        vxm_deactivate_task(t,q)        do { } while (0)
17411 +#define        vxm_hold_task(t,q)              do { } while (0)
17412 +#define        vxm_unhold_task(t,q)            do { } while (0)
17413 +#define        vxm_migrate_task(t,q,d)         do { } while (0)
17414 +#define        vxm_idle_skip(q,c)              do { } while (0)
17415 +#define        vxm_need_resched(t,s,c)         do { } while (0)
17416 +#define        vxm_sync(s,c)                   do { } while (0)
17417 +#define        vxm_sched_info(s,v,c)           do { } while (0)
17418 +#define        vxm_tokens_recalc(s,q,v,c)      do { } while (0)
17419 +#define        vxm_update_sched(s,v,c)         do { } while (0)
17420 +#define        vxm_rq_max_min(q,c)             do { } while (0)
17421 +
17422 +#endif /* CONFIG_VSERVER_MONITOR */
17423 +
17424 diff -NurpP --minimal linux-2.6.25/kernel/signal.c linux-2.6.25-vs2.3.0.34.9/kernel/signal.c
17425 --- linux-2.6.25/kernel/signal.c        2008-04-17 12:05:44.000000000 -0400
17426 +++ linux-2.6.25-vs2.3.0.34.9/kernel/signal.c   2008-04-21 11:51:23.000000000 -0400
17427 @@ -26,6 +26,8 @@
17428  #include <linux/freezer.h>
17429  #include <linux/pid_namespace.h>
17430  #include <linux/nsproxy.h>
17431 +#include <linux/vs_context.h>
17432 +#include <linux/vs_pid.h>
17433  
17434  #include <asm/param.h>
17435  #include <asm/uaccess.h>
17436 @@ -530,6 +532,14 @@ static int check_kill_permission(int sig
17437         if (!valid_signal(sig))
17438                 return error;
17439  
17440 +       if ((info != SEND_SIG_NOINFO) &&
17441 +               (is_si_special(info) || !SI_FROMUSER(info)))
17442 +               goto skip;
17443 +
17444 +       vxdprintk(VXD_CBIT(misc, 7),
17445 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
17446 +               sig, info, t, vx_task_xid(t), t->pid);
17447 +
17448         if (info == SEND_SIG_NOINFO || (!is_si_special(info) && SI_FROMUSER(info))) {
17449                 error = audit_signal_info(sig, t); /* Let audit system see the signal */
17450                 if (error)
17451 @@ -543,6 +553,14 @@ static int check_kill_permission(int sig
17452                 return error;
17453         }
17454  
17455 +       error = -ESRCH;
17456 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
17457 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
17458 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
17459 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
17460 +               return error;
17461 +       }
17462 +skip:
17463         return security_task_kill(t, info, sig, 0);
17464  }
17465  
17466 @@ -1088,7 +1106,7 @@ int kill_pid_info_as_uid(int sig, struct
17467  
17468         read_lock(&tasklist_lock);
17469         p = pid_task(pid, PIDTYPE_PID);
17470 -       if (!p) {
17471 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
17472                 ret = -ESRCH;
17473                 goto out_unlock;
17474         }
17475 @@ -1140,7 +1158,9 @@ static int kill_something_info(int sig, 
17476                 struct task_struct * p;
17477  
17478                 for_each_process(p) {
17479 -                       if (p->pid > 1 && !same_thread_group(p, current)) {
17480 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
17481 +                               p->pid > 1 && !same_thread_group(p, current) &&
17482 +                               !vx_current_initpid(p->pid)) {
17483                                 int err = group_send_sig_info(sig, info, p);
17484                                 ++count;
17485                                 if (err != -EPERM)
17486 @@ -1842,6 +1862,11 @@ relock:
17487                 if (is_global_init(current))
17488                         continue;
17489  
17490 +               /* virtual init is protected against user signals */
17491 +               if ((info->si_code == SI_USER) &&
17492 +                       vx_current_initpid(current->pid))
17493 +                       continue;
17494 +
17495                 if (sig_kernel_stop(signr)) {
17496                         /*
17497                          * The default action is to stop all threads in
17498 diff -NurpP --minimal linux-2.6.25/kernel/softirq.c linux-2.6.25-vs2.3.0.34.9/kernel/softirq.c
17499 --- linux-2.6.25/kernel/softirq.c       2008-04-17 12:05:44.000000000 -0400
17500 +++ linux-2.6.25-vs2.3.0.34.9/kernel/softirq.c  2008-04-19 15:14:52.000000000 -0400
17501 @@ -21,6 +21,7 @@
17502  #include <linux/rcupdate.h>
17503  #include <linux/smp.h>
17504  #include <linux/tick.h>
17505 +#include <linux/vs_context.h>
17506  
17507  #include <asm/irq.h>
17508  /*
17509 diff -NurpP --minimal linux-2.6.25/kernel/sys.c linux-2.6.25-vs2.3.0.34.9/kernel/sys.c
17510 --- linux-2.6.25/kernel/sys.c   2008-04-17 12:05:44.000000000 -0400
17511 +++ linux-2.6.25-vs2.3.0.34.9/kernel/sys.c      2008-04-19 15:14:52.000000000 -0400
17512 @@ -38,6 +38,7 @@
17513  #include <linux/syscalls.h>
17514  #include <linux/kprobes.h>
17515  #include <linux/user_namespace.h>
17516 +#include <linux/vs_pid.h>
17517  
17518  #include <asm/uaccess.h>
17519  #include <asm/io.h>
17520 @@ -116,7 +117,10 @@ static int set_one_prio(struct task_stru
17521                 goto out;
17522         }
17523         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
17524 -               error = -EACCES;
17525 +               if (vx_flags(VXF_IGNEG_NICE, 0))
17526 +                       error = 0;
17527 +               else
17528 +                       error = -EACCES;
17529                 goto out;
17530         }
17531         no_nice = security_task_setnice(p, niceval);
17532 @@ -164,6 +168,8 @@ asmlinkage long sys_setpriority(int whic
17533                         else
17534                                 pgrp = task_pgrp(current);
17535                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
17536 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
17537 +                                       continue;
17538                                 error = set_one_prio(p, niceval, error);
17539                         } while_each_pid_task(pgrp, PIDTYPE_PGID, p);
17540                         break;
17541 @@ -224,6 +230,8 @@ asmlinkage long sys_getpriority(int whic
17542                         else
17543                                 pgrp = task_pgrp(current);
17544                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
17545 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
17546 +                                       continue;
17547                                 niceval = 20 - task_nice(p);
17548                                 if (niceval > retval)
17549                                         retval = niceval;
17550 @@ -353,6 +361,9 @@ void kernel_power_off(void)
17551         machine_power_off();
17552  }
17553  EXPORT_SYMBOL_GPL(kernel_power_off);
17554 +
17555 +long vs_reboot(unsigned int, void __user *);
17556 +
17557  /*
17558   * Reboot system call: for obvious reasons only root may call it,
17559   * and even root needs to set up some magic numbers in the registers
17560 @@ -383,6 +394,9 @@ asmlinkage long sys_reboot(int magic1, i
17561         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
17562                 cmd = LINUX_REBOOT_CMD_HALT;
17563  
17564 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
17565 +               return vs_reboot(cmd, arg);
17566 +
17567         lock_kernel();
17568         switch (cmd) {
17569         case LINUX_REBOOT_CMD_RESTART:
17570 @@ -1343,7 +1357,7 @@ asmlinkage long sys_sethostname(char __u
17571         int errno;
17572         char tmp[__NEW_UTS_LEN];
17573  
17574 -       if (!capable(CAP_SYS_ADMIN))
17575 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
17576                 return -EPERM;
17577         if (len < 0 || len > __NEW_UTS_LEN)
17578                 return -EINVAL;
17579 @@ -1388,7 +1402,7 @@ asmlinkage long sys_setdomainname(char _
17580         int errno;
17581         char tmp[__NEW_UTS_LEN];
17582  
17583 -       if (!capable(CAP_SYS_ADMIN))
17584 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
17585                 return -EPERM;
17586         if (len < 0 || len > __NEW_UTS_LEN)
17587                 return -EINVAL;
17588 @@ -1455,7 +1469,7 @@ asmlinkage long sys_setrlimit(unsigned i
17589                 return -EINVAL;
17590         old_rlim = current->signal->rlim + resource;
17591         if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
17592 -           !capable(CAP_SYS_RESOURCE))
17593 +           !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
17594                 return -EPERM;
17595         if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)
17596                 return -EPERM;
17597 diff -NurpP --minimal linux-2.6.25/kernel/sysctl.c linux-2.6.25-vs2.3.0.34.9/kernel/sysctl.c
17598 --- linux-2.6.25/kernel/sysctl.c        2008-04-17 12:05:44.000000000 -0400
17599 +++ linux-2.6.25-vs2.3.0.34.9/kernel/sysctl.c   2008-04-19 15:14:52.000000000 -0400
17600 @@ -107,6 +107,7 @@ static int ngroups_max = NGROUPS_MAX;
17601  #ifdef CONFIG_KMOD
17602  extern char modprobe_path[];
17603  #endif
17604 +extern char vshelper_path[];
17605  #ifdef CONFIG_CHR_DEV_SG
17606  extern int sg_big_buff;
17607  #endif
17608 @@ -492,6 +493,15 @@ static struct ctl_table kern_table[] = {
17609                 .strategy       = &sysctl_string,
17610         },
17611  #endif
17612 +       {
17613 +               .ctl_name       = KERN_VSHELPER,
17614 +               .procname       = "vshelper",
17615 +               .data           = &vshelper_path,
17616 +               .maxlen         = 256,
17617 +               .mode           = 0644,
17618 +               .proc_handler   = &proc_dostring,
17619 +               .strategy       = &sysctl_string,
17620 +       },
17621  #ifdef CONFIG_CHR_DEV_SG
17622         {
17623                 .ctl_name       = KERN_SG_BIG_BUFF,
17624 diff -NurpP --minimal linux-2.6.25/kernel/sysctl_check.c linux-2.6.25-vs2.3.0.34.9/kernel/sysctl_check.c
17625 --- linux-2.6.25/kernel/sysctl_check.c  2008-04-17 12:05:44.000000000 -0400
17626 +++ linux-2.6.25-vs2.3.0.34.9/kernel/sysctl_check.c     2008-04-21 13:42:56.000000000 -0400
17627 @@ -39,6 +39,7 @@ static const struct trans_ctl_table tran
17628  
17629         { KERN_PANIC,                   "panic" },
17630         { KERN_REALROOTDEV,             "real-root-dev" },
17631 +       { KERN_VSHELPER,                "vshelper", },
17632  
17633         { KERN_SPARC_REBOOT,            "reboot-cmd" },
17634         { KERN_CTLALTDEL,               "ctrl-alt-del" },
17635 @@ -1217,6 +1218,22 @@ static const struct trans_ctl_table tran
17636         {}
17637  };
17638  
17639 +static struct trans_ctl_table trans_vserver_table[] = {
17640 +       { 1,    "debug_switch" },
17641 +       { 2,    "debug_xid" },
17642 +       { 3,    "debug_nid" },
17643 +       { 4,    "debug_tag" },
17644 +       { 5,    "debug_net" },
17645 +       { 6,    "debug_limit" },
17646 +       { 7,    "debug_cres" },
17647 +       { 8,    "debug_dlim" },
17648 +       { 9,    "debug_quota" },
17649 +       { 10,   "debug_cvirt" },
17650 +       { 11,   "debug_space" },
17651 +       { 12,   "debug_misc" },
17652 +       {}
17653 +};
17654 +
17655  static const struct trans_ctl_table trans_root_table[] = {
17656         { CTL_KERN,     "kernel",       trans_kern_table },
17657         { CTL_VM,       "vm",           trans_vm_table },
17658 @@ -1233,6 +1250,7 @@ static const struct trans_ctl_table tran
17659         { CTL_SUNRPC,   "sunrpc",       trans_sunrpc_table },
17660         { CTL_PM,       "pm",           trans_pm_table },
17661         { CTL_FRV,      "frv",          trans_frv_table },
17662 +       { CTL_VSERVER,  "vserver",      trans_vserver_table },
17663         {}
17664  };
17665  
17666 diff -NurpP --minimal linux-2.6.25/kernel/time.c linux-2.6.25-vs2.3.0.34.9/kernel/time.c
17667 --- linux-2.6.25/kernel/time.c  2008-04-17 12:05:44.000000000 -0400
17668 +++ linux-2.6.25-vs2.3.0.34.9/kernel/time.c     2008-04-19 15:14:52.000000000 -0400
17669 @@ -60,6 +60,7 @@ EXPORT_SYMBOL(sys_tz);
17670  asmlinkage long sys_time(time_t __user * tloc)
17671  {
17672         time_t i = get_seconds();
17673 +/*     FIXME: do_gettimeofday(&tv) -> vx_gettimeofday(&tv) */
17674  
17675         if (tloc) {
17676                 if (put_user(i,tloc))
17677 @@ -89,7 +90,7 @@ asmlinkage long sys_stime(time_t __user 
17678         if (err)
17679                 return err;
17680  
17681 -       do_settimeofday(&tv);
17682 +       vx_settimeofday(&tv);
17683         return 0;
17684  }
17685  
17686 @@ -100,7 +101,7 @@ asmlinkage long sys_gettimeofday(struct 
17687  {
17688         if (likely(tv != NULL)) {
17689                 struct timeval ktv;
17690 -               do_gettimeofday(&ktv);
17691 +               vx_gettimeofday(&ktv);
17692                 if (copy_to_user(tv, &ktv, sizeof(ktv)))
17693                         return -EFAULT;
17694         }
17695 @@ -175,7 +176,7 @@ int do_sys_settimeofday(struct timespec 
17696                 /* SMP safe, again the code in arch/foo/time.c should
17697                  * globally block out interrupts when it runs.
17698                  */
17699 -               return do_settimeofday(tv);
17700 +               return vx_settimeofday(tv);
17701         }
17702         return 0;
17703  }
17704 @@ -307,7 +308,7 @@ void getnstimeofday(struct timespec *tv)
17705  {
17706         struct timeval x;
17707  
17708 -       do_gettimeofday(&x);
17709 +       vx_gettimeofday(&x);
17710         tv->tv_sec = x.tv_sec;
17711         tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
17712  }
17713 diff -NurpP --minimal linux-2.6.25/kernel/timer.c linux-2.6.25-vs2.3.0.34.9/kernel/timer.c
17714 --- linux-2.6.25/kernel/timer.c 2008-04-17 12:05:44.000000000 -0400
17715 +++ linux-2.6.25-vs2.3.0.34.9/kernel/timer.c    2008-04-19 15:14:52.000000000 -0400
17716 @@ -37,6 +37,10 @@
17717  #include <linux/delay.h>
17718  #include <linux/tick.h>
17719  #include <linux/kallsyms.h>
17720 +#include <linux/vs_base.h>
17721 +#include <linux/vs_cvirt.h>
17722 +#include <linux/vs_pid.h>
17723 +#include <linux/vserver/sched.h>
17724  
17725  #include <asm/uaccess.h>
17726  #include <asm/unistd.h>
17727 @@ -955,12 +959,6 @@ asmlinkage unsigned long sys_alarm(unsig
17728  
17729  #endif
17730  
17731 -#ifndef __alpha__
17732 -
17733 -/*
17734 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
17735 - * should be moved into arch/i386 instead?
17736 - */
17737  
17738  /**
17739   * sys_getpid - return the thread group id of the current process
17740 @@ -989,10 +987,23 @@ asmlinkage long sys_getppid(void)
17741         rcu_read_lock();
17742         pid = task_tgid_vnr(current->real_parent);
17743         rcu_read_unlock();
17744 +       return vx_map_pid(pid);
17745 +}
17746  
17747 -       return pid;
17748 +#ifdef __alpha__
17749 +
17750 +/*
17751 + * The Alpha uses getxpid, getxuid, and getxgid instead.
17752 + */
17753 +
17754 +asmlinkage long do_getxpid(long *ppid)
17755 +{
17756 +       *ppid = sys_getppid();
17757 +       return sys_getpid();
17758  }
17759  
17760 +#else /* _alpha_ */
17761 +
17762  asmlinkage long sys_getuid(void)
17763  {
17764         /* Only we change this so SMP safe */
17765 @@ -1160,6 +1171,8 @@ int do_sysinfo(struct sysinfo *info)
17766                         tp.tv_nsec = tp.tv_nsec - NSEC_PER_SEC;
17767                         tp.tv_sec++;
17768                 }
17769 +               if (vx_flags(VXF_VIRT_UPTIME, 0))
17770 +                       vx_vsi_uptime(&tp, NULL);
17771                 info->uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0);
17772  
17773                 info->loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
17774 diff -NurpP --minimal linux-2.6.25/kernel/user.c linux-2.6.25-vs2.3.0.34.9/kernel/user.c
17775 --- linux-2.6.25/kernel/user.c  2008-04-17 12:05:44.000000000 -0400
17776 +++ linux-2.6.25-vs2.3.0.34.9/kernel/user.c     2008-04-23 16:24:56.000000000 -0400
17777 @@ -219,14 +219,15 @@ static struct kobj_type uids_ktype = {
17778  };
17779  
17780  /* create /sys/kernel/uids/<uid>/cpu_share file for this user */
17781 -static int uids_user_create(struct user_struct *up)
17782 +static int uids_user_create(struct user_namespace *ns, struct user_struct *up)
17783  {
17784         struct kobject *kobj = &up->kobj;
17785         int error;
17786  
17787         memset(kobj, 0, sizeof(struct kobject));
17788         kobj->kset = uids_kset;
17789 -       error = kobject_init_and_add(kobj, &uids_ktype, NULL, "%d", up->uid);
17790 +       error = kobject_init_and_add(kobj, &uids_ktype, NULL,
17791 +               "%p:%d", ns, up->uid);
17792         if (error) {
17793                 kobject_put(kobj);
17794                 goto done;
17795 @@ -248,7 +249,7 @@ int __init uids_sysfs_init(void)
17796         if (!uids_kset)
17797                 return -ENOMEM;
17798  
17799 -       return uids_user_create(&root_user);
17800 +       return uids_user_create(NULL, &root_user);
17801  }
17802  
17803  /* work function to remove sysfs directory for a user and free up
17804 @@ -308,7 +309,8 @@ static inline void free_user(struct user
17805  #else  /* CONFIG_USER_SCHED && CONFIG_SYSFS */
17806  
17807  int uids_sysfs_init(void) { return 0; }
17808 -static inline int uids_user_create(struct user_struct *up) { return 0; }
17809 +static inline int uids_user_create(struct user_namespace *ns,
17810 +       struct user_struct *up) { return 0; }
17811  static inline void uids_mutex_lock(void) { }
17812  static inline void uids_mutex_unlock(void) { }
17813  
17814 @@ -399,7 +401,7 @@ struct user_struct * alloc_uid(struct us
17815                 if (sched_create_user(new) < 0)
17816                         goto out_put_keys;
17817  
17818 -               if (uids_user_create(new))
17819 +               if (uids_user_create(ns, new))
17820                         goto out_destoy_sched;
17821  
17822                 /*
17823 diff -NurpP --minimal linux-2.6.25/kernel/user_namespace.c linux-2.6.25-vs2.3.0.34.9/kernel/user_namespace.c
17824 --- linux-2.6.25/kernel/user_namespace.c        2008-04-17 12:05:44.000000000 -0400
17825 +++ linux-2.6.25-vs2.3.0.34.9/kernel/user_namespace.c   2008-04-19 15:14:52.000000000 -0400
17826 @@ -9,6 +9,7 @@
17827  #include <linux/version.h>
17828  #include <linux/nsproxy.h>
17829  #include <linux/user_namespace.h>
17830 +#include <linux/vserver/global.h>
17831  
17832  /*
17833   * Clone a new ns copying an original user ns, setting refcount to 1
17834 @@ -26,6 +27,7 @@ static struct user_namespace *clone_user
17835                 return ERR_PTR(-ENOMEM);
17836  
17837         kref_init(&ns->kref);
17838 +       atomic_inc(&vs_global_user_ns);
17839  
17840         for (n = 0; n < UIDHASH_SZ; ++n)
17841                 INIT_HLIST_HEAD(ns->uidhash_table + n);
17842 @@ -71,5 +73,6 @@ void free_user_ns(struct kref *kref)
17843  
17844         ns = container_of(kref, struct user_namespace, kref);
17845         release_uids(ns);
17846 +       atomic_dec(&vs_global_user_ns);
17847         kfree(ns);
17848  }
17849 diff -NurpP --minimal linux-2.6.25/kernel/utsname.c linux-2.6.25-vs2.3.0.34.9/kernel/utsname.c
17850 --- linux-2.6.25/kernel/utsname.c       2008-04-17 10:37:25.000000000 -0400
17851 +++ linux-2.6.25-vs2.3.0.34.9/kernel/utsname.c  2008-04-19 15:14:52.000000000 -0400
17852 @@ -14,6 +14,7 @@
17853  #include <linux/utsname.h>
17854  #include <linux/version.h>
17855  #include <linux/err.h>
17856 +#include <linux/vserver/global.h>
17857  
17858  /*
17859   * Clone a new ns copying an original utsname, setting refcount to 1
17860 @@ -32,6 +33,7 @@ static struct uts_namespace *clone_uts_n
17861         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
17862         up_read(&uts_sem);
17863         kref_init(&ns->kref);
17864 +       atomic_inc(&vs_global_uts_ns);
17865         return ns;
17866  }
17867  
17868 @@ -62,5 +64,6 @@ void free_uts_ns(struct kref *kref)
17869         struct uts_namespace *ns;
17870  
17871         ns = container_of(kref, struct uts_namespace, kref);
17872 +       atomic_dec(&vs_global_uts_ns);
17873         kfree(ns);
17874  }
17875 diff -NurpP --minimal linux-2.6.25/kernel/vserver/cacct.c linux-2.6.25-vs2.3.0.34.9/kernel/vserver/cacct.c
17876 --- linux-2.6.25/kernel/vserver/cacct.c 1969-12-31 19:00:00.000000000 -0500
17877 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/cacct.c    2008-04-19 15:14:52.000000000 -0400
17878 @@ -0,0 +1,42 @@
17879 +/*
17880 + *  linux/kernel/vserver/cacct.c
17881 + *
17882 + *  Virtual Server: Context Accounting
17883 + *
17884 + *  Copyright (C) 2006-2007 Herbert Pötzl
17885 + *
17886 + *  V0.01  added accounting stats
17887 + *
17888 + */
17889 +
17890 +#include <linux/types.h>
17891 +#include <linux/vs_context.h>
17892 +#include <linux/vserver/cacct_cmd.h>
17893 +#include <linux/vserver/cacct_int.h>
17894 +
17895 +#include <asm/errno.h>
17896 +#include <asm/uaccess.h>
17897 +
17898 +
17899 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
17900 +{
17901 +       struct vcmd_sock_stat_v0 vc_data;
17902 +       int j, field;
17903 +
17904 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17905 +               return -EFAULT;
17906 +
17907 +       field = vc_data.field;
17908 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
17909 +               return -EINVAL;
17910 +
17911 +       for (j = 0; j < 3; j++) {
17912 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
17913 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
17914 +       }
17915 +
17916 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17917 +               return -EFAULT;
17918 +       return 0;
17919 +}
17920 +
17921 diff -NurpP --minimal linux-2.6.25/kernel/vserver/cacct_init.h linux-2.6.25-vs2.3.0.34.9/kernel/vserver/cacct_init.h
17922 --- linux-2.6.25/kernel/vserver/cacct_init.h    1969-12-31 19:00:00.000000000 -0500
17923 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/cacct_init.h       2008-04-19 15:14:52.000000000 -0400
17924 @@ -0,0 +1,25 @@
17925 +
17926 +
17927 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
17928 +{
17929 +       int i, j;
17930 +
17931 +
17932 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17933 +               for (j = 0; j < 3; j++) {
17934 +                       atomic_set(&cacct->sock[i][j].count, 0);
17935 +                       atomic_set(&cacct->sock[i][j].total, 0);
17936 +               }
17937 +       }
17938 +       for (i = 0; i < 8; i++)
17939 +               atomic_set(&cacct->slab[i], 0);
17940 +       for (i = 0; i < 5; i++)
17941 +               for (j = 0; j < 4; j++)
17942 +                       atomic_set(&cacct->page[i][j], 0);
17943 +}
17944 +
17945 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
17946 +{
17947 +       return;
17948 +}
17949 +
17950 diff -NurpP --minimal linux-2.6.25/kernel/vserver/cacct_proc.h linux-2.6.25-vs2.3.0.34.9/kernel/vserver/cacct_proc.h
17951 --- linux-2.6.25/kernel/vserver/cacct_proc.h    1969-12-31 19:00:00.000000000 -0500
17952 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/cacct_proc.h       2008-04-19 15:14:52.000000000 -0400
17953 @@ -0,0 +1,53 @@
17954 +#ifndef _VX_CACCT_PROC_H
17955 +#define _VX_CACCT_PROC_H
17956 +
17957 +#include <linux/vserver/cacct_int.h>
17958 +
17959 +
17960 +#define VX_SOCKA_TOP   \
17961 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
17962 +
17963 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
17964 +{
17965 +       int i, j, length = 0;
17966 +       static char *type[VXA_SOCK_SIZE] = {
17967 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
17968 +       };
17969 +
17970 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
17971 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17972 +               length += sprintf(buffer + length, "%s:", type[i]);
17973 +               for (j = 0; j < 3; j++) {
17974 +                       length += sprintf(buffer + length,
17975 +                               "\t%10lu/%-10lu",
17976 +                               vx_sock_count(cacct, i, j),
17977 +                               vx_sock_total(cacct, i, j));
17978 +               }
17979 +               buffer[length++] = '\n';
17980 +       }
17981 +
17982 +       length += sprintf(buffer + length, "\n");
17983 +       length += sprintf(buffer + length,
17984 +               "slab:\t %8u %8u %8u %8u\n",
17985 +               atomic_read(&cacct->slab[1]),
17986 +               atomic_read(&cacct->slab[4]),
17987 +               atomic_read(&cacct->slab[0]),
17988 +               atomic_read(&cacct->slab[2]));
17989 +
17990 +       length += sprintf(buffer + length, "\n");
17991 +       for (i = 0; i < 5; i++) {
17992 +               length += sprintf(buffer + length,
17993 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
17994 +                       atomic_read(&cacct->page[i][0]),
17995 +                       atomic_read(&cacct->page[i][1]),
17996 +                       atomic_read(&cacct->page[i][2]),
17997 +                       atomic_read(&cacct->page[i][3]),
17998 +                       atomic_read(&cacct->page[i][4]),
17999 +                       atomic_read(&cacct->page[i][5]),
18000 +                       atomic_read(&cacct->page[i][6]),
18001 +                       atomic_read(&cacct->page[i][7]));
18002 +       }
18003 +       return length;
18004 +}
18005 +
18006 +#endif /* _VX_CACCT_PROC_H */
18007 diff -NurpP --minimal linux-2.6.25/kernel/vserver/context.c linux-2.6.25-vs2.3.0.34.9/kernel/vserver/context.c
18008 --- linux-2.6.25/kernel/vserver/context.c       1969-12-31 19:00:00.000000000 -0500
18009 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/context.c  2008-04-23 22:26:24.000000000 -0400
18010 @@ -0,0 +1,1005 @@
18011 +/*
18012 + *  linux/kernel/vserver/context.c
18013 + *
18014 + *  Virtual Server: Context Support
18015 + *
18016 + *  Copyright (C) 2003-2007  Herbert Pötzl
18017 + *
18018 + *  V0.01  context helper
18019 + *  V0.02  vx_ctx_kill syscall command
18020 + *  V0.03  replaced context_info calls
18021 + *  V0.04  redesign of struct (de)alloc
18022 + *  V0.05  rlimit basic implementation
18023 + *  V0.06  task_xid and info commands
18024 + *  V0.07  context flags and caps
18025 + *  V0.08  switch to RCU based hash
18026 + *  V0.09  revert to non RCU for now
18027 + *  V0.10  and back to working RCU hash
18028 + *  V0.11  and back to locking again
18029 + *  V0.12  referenced context store
18030 + *  V0.13  separate per cpu data
18031 + *  V0.14  changed vcmds to vxi arg
18032 + *  V0.15  added context stat
18033 + *  V0.16  have __create claim() the vxi
18034 + *  V0.17  removed older and legacy stuff
18035 + *
18036 + */
18037 +
18038 +#include <linux/slab.h>
18039 +#include <linux/types.h>
18040 +#include <linux/security.h>
18041 +#include <linux/pid_namespace.h>
18042 +
18043 +#include <linux/vserver/context.h>
18044 +#include <linux/vserver/network.h>
18045 +#include <linux/vserver/debug.h>
18046 +#include <linux/vserver/limit.h>
18047 +#include <linux/vserver/limit_int.h>
18048 +#include <linux/vserver/space.h>
18049 +
18050 +#include <linux/vs_context.h>
18051 +#include <linux/vs_limit.h>
18052 +#include <linux/vs_pid.h>
18053 +#include <linux/vserver/context_cmd.h>
18054 +
18055 +#include "cvirt_init.h"
18056 +#include "cacct_init.h"
18057 +#include "limit_init.h"
18058 +#include "sched_init.h"
18059 +
18060 +
18061 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
18062 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
18063 +
18064 +
18065 +/*     now inactive context structures */
18066 +
18067 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
18068 +
18069 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
18070 +
18071 +
18072 +/*     __alloc_vx_info()
18073 +
18074 +       * allocate an initialized vx_info struct
18075 +       * doesn't make it visible (hash)                        */
18076 +
18077 +static struct vx_info *__alloc_vx_info(xid_t xid)
18078 +{
18079 +       struct vx_info *new = NULL;
18080 +       int cpu;
18081 +
18082 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
18083 +
18084 +       /* would this benefit from a slab cache? */
18085 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
18086 +       if (!new)
18087 +               return 0;
18088 +
18089 +       memset(new, 0, sizeof(struct vx_info));
18090 +#ifdef CONFIG_SMP
18091 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
18092 +       if (!new->ptr_pc)
18093 +               goto error;
18094 +#endif
18095 +       new->vx_id = xid;
18096 +       INIT_HLIST_NODE(&new->vx_hlist);
18097 +       atomic_set(&new->vx_usecnt, 0);
18098 +       atomic_set(&new->vx_tasks, 0);
18099 +       new->vx_parent = NULL;
18100 +       new->vx_state = 0;
18101 +       init_waitqueue_head(&new->vx_wait);
18102 +
18103 +       /* prepare reaper */
18104 +       get_task_struct(init_pid_ns.child_reaper);
18105 +       new->vx_reaper = init_pid_ns.child_reaper;
18106 +       new->vx_badness_bias = 0;
18107 +
18108 +       /* rest of init goes here */
18109 +       vx_info_init_limit(&new->limit);
18110 +       vx_info_init_sched(&new->sched);
18111 +       vx_info_init_cvirt(&new->cvirt);
18112 +       vx_info_init_cacct(&new->cacct);
18113 +
18114 +       /* per cpu data structures */
18115 +       for_each_possible_cpu(cpu) {
18116 +               vx_info_init_sched_pc(
18117 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
18118 +               vx_info_init_cvirt_pc(
18119 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
18120 +       }
18121 +
18122 +       new->vx_flags = VXF_INIT_SET;
18123 +       cap_set_init_eff(new->vx_bcaps);
18124 +       new->vx_ccaps = 0;
18125 +       // new->vx_cap_bset = current->cap_bset;
18126 +
18127 +       new->reboot_cmd = 0;
18128 +       new->exit_code = 0;
18129 +
18130 +       vxdprintk(VXD_CBIT(xid, 0),
18131 +               "alloc_vx_info(%d) = %p", xid, new);
18132 +       vxh_alloc_vx_info(new);
18133 +       atomic_inc(&vx_global_ctotal);
18134 +       return new;
18135 +#ifdef CONFIG_SMP
18136 +error:
18137 +       kfree(new);
18138 +       return 0;
18139 +#endif
18140 +}
18141 +
18142 +/*     __dealloc_vx_info()
18143 +
18144 +       * final disposal of vx_info                             */
18145 +
18146 +static void __dealloc_vx_info(struct vx_info *vxi)
18147 +{
18148 +       int cpu;
18149 +
18150 +       vxdprintk(VXD_CBIT(xid, 0),
18151 +               "dealloc_vx_info(%p)", vxi);
18152 +       vxh_dealloc_vx_info(vxi);
18153 +
18154 +       vxi->vx_id = -1;
18155 +
18156 +       vx_info_exit_limit(&vxi->limit);
18157 +       vx_info_exit_sched(&vxi->sched);
18158 +       vx_info_exit_cvirt(&vxi->cvirt);
18159 +       vx_info_exit_cacct(&vxi->cacct);
18160 +
18161 +       for_each_possible_cpu(cpu) {
18162 +               vx_info_exit_sched_pc(
18163 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
18164 +               vx_info_exit_cvirt_pc(
18165 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
18166 +       }
18167 +
18168 +       vxi->vx_state |= VXS_RELEASED;
18169 +
18170 +#ifdef CONFIG_SMP
18171 +       free_percpu(vxi->ptr_pc);
18172 +#endif
18173 +       kfree(vxi);
18174 +       atomic_dec(&vx_global_ctotal);
18175 +}
18176 +
18177 +static void __shutdown_vx_info(struct vx_info *vxi)
18178 +{
18179 +       struct nsproxy *nsproxy;
18180 +       struct fs_struct *fs;
18181 +
18182 +       might_sleep();
18183 +
18184 +       vxi->vx_state |= VXS_SHUTDOWN;
18185 +       vs_state_change(vxi, VSC_SHUTDOWN);
18186 +
18187 +       nsproxy = xchg(&vxi->vx_nsproxy, NULL);
18188 +       fs = xchg(&vxi->vx_fs, NULL);
18189 +
18190 +       if (nsproxy)
18191 +               put_nsproxy(nsproxy);
18192 +       if (fs)
18193 +               put_fs_struct(fs);
18194 +}
18195 +
18196 +/* exported stuff */
18197 +
18198 +void free_vx_info(struct vx_info *vxi)
18199 +{
18200 +       unsigned long flags;
18201 +
18202 +       /* check for reference counts first */
18203 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
18204 +       BUG_ON(atomic_read(&vxi->vx_tasks));
18205 +
18206 +       /* context must not be hashed */
18207 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
18208 +
18209 +       /* context shutdown is mandatory */
18210 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
18211 +
18212 +       BUG_ON(vxi->vx_nsproxy);
18213 +       BUG_ON(vxi->vx_fs);
18214 +
18215 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
18216 +       hlist_del(&vxi->vx_hlist);
18217 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
18218 +
18219 +       __dealloc_vx_info(vxi);
18220 +}
18221 +
18222 +
18223 +/*     hash table for vx_info hash */
18224 +
18225 +#define VX_HASH_SIZE   13
18226 +
18227 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
18228 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
18229 +
18230 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
18231 +
18232 +
18233 +static inline unsigned int __hashval(xid_t xid)
18234 +{
18235 +       return (xid % VX_HASH_SIZE);
18236 +}
18237 +
18238 +
18239 +
18240 +/*     __hash_vx_info()
18241 +
18242 +       * add the vxi to the global hash table
18243 +       * requires the hash_lock to be held                     */
18244 +
18245 +static inline void __hash_vx_info(struct vx_info *vxi)
18246 +{
18247 +       struct hlist_head *head;
18248 +
18249 +       vxd_assert_lock(&vx_info_hash_lock);
18250 +       vxdprintk(VXD_CBIT(xid, 4),
18251 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
18252 +       vxh_hash_vx_info(vxi);
18253 +
18254 +       /* context must not be hashed */
18255 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
18256 +
18257 +       vxi->vx_state |= VXS_HASHED;
18258 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
18259 +       hlist_add_head(&vxi->vx_hlist, head);
18260 +       atomic_inc(&vx_global_cactive);
18261 +}
18262 +
18263 +/*     __unhash_vx_info()
18264 +
18265 +       * remove the vxi from the global hash table
18266 +       * requires the hash_lock to be held                     */
18267 +
18268 +static inline void __unhash_vx_info(struct vx_info *vxi)
18269 +{
18270 +       unsigned long flags;
18271 +
18272 +       vxd_assert_lock(&vx_info_hash_lock);
18273 +       vxdprintk(VXD_CBIT(xid, 4),
18274 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
18275 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
18276 +       vxh_unhash_vx_info(vxi);
18277 +
18278 +       /* context must be hashed */
18279 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
18280 +       /* but without tasks */
18281 +       BUG_ON(atomic_read(&vxi->vx_tasks));
18282 +
18283 +       vxi->vx_state &= ~VXS_HASHED;
18284 +       hlist_del_init(&vxi->vx_hlist);
18285 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
18286 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
18287 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
18288 +       atomic_dec(&vx_global_cactive);
18289 +}
18290 +
18291 +
18292 +/*     __lookup_vx_info()
18293 +
18294 +       * requires the hash_lock to be held
18295 +       * doesn't increment the vx_refcnt                       */
18296 +
18297 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
18298 +{
18299 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
18300 +       struct hlist_node *pos;
18301 +       struct vx_info *vxi;
18302 +
18303 +       vxd_assert_lock(&vx_info_hash_lock);
18304 +       hlist_for_each(pos, head) {
18305 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
18306 +
18307 +               if (vxi->vx_id == xid)
18308 +                       goto found;
18309 +       }
18310 +       vxi = NULL;
18311 +found:
18312 +       vxdprintk(VXD_CBIT(xid, 0),
18313 +               "__lookup_vx_info(#%u): %p[#%u]",
18314 +               xid, vxi, vxi ? vxi->vx_id : 0);
18315 +       vxh_lookup_vx_info(vxi, xid);
18316 +       return vxi;
18317 +}
18318 +
18319 +
18320 +/*     __create_vx_info()
18321 +
18322 +       * create the requested context
18323 +       * get(), claim() and hash it                            */
18324 +
18325 +static struct vx_info *__create_vx_info(int id)
18326 +{
18327 +       struct vx_info *new, *vxi = NULL;
18328 +
18329 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
18330 +
18331 +       if (!(new = __alloc_vx_info(id)))
18332 +               return ERR_PTR(-ENOMEM);
18333 +
18334 +       /* required to make dynamic xids unique */
18335 +       spin_lock(&vx_info_hash_lock);
18336 +
18337 +       /* static context requested */
18338 +       if ((vxi = __lookup_vx_info(id))) {
18339 +               vxdprintk(VXD_CBIT(xid, 0),
18340 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
18341 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
18342 +                       vxi = ERR_PTR(-EBUSY);
18343 +               else
18344 +                       vxi = ERR_PTR(-EEXIST);
18345 +               goto out_unlock;
18346 +       }
18347 +       /* new context */
18348 +       vxdprintk(VXD_CBIT(xid, 0),
18349 +               "create_vx_info(%d) = %p (new)", id, new);
18350 +       claim_vx_info(new, NULL);
18351 +       __hash_vx_info(get_vx_info(new));
18352 +       vxi = new, new = NULL;
18353 +
18354 +out_unlock:
18355 +       spin_unlock(&vx_info_hash_lock);
18356 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
18357 +       if (new)
18358 +               __dealloc_vx_info(new);
18359 +       return vxi;
18360 +}
18361 +
18362 +
18363 +/*     exported stuff                                          */
18364 +
18365 +
18366 +void unhash_vx_info(struct vx_info *vxi)
18367 +{
18368 +       __shutdown_vx_info(vxi);
18369 +       spin_lock(&vx_info_hash_lock);
18370 +       __unhash_vx_info(vxi);
18371 +       spin_unlock(&vx_info_hash_lock);
18372 +       __wakeup_vx_info(vxi);
18373 +}
18374 +
18375 +
18376 +/*     lookup_vx_info()
18377 +
18378 +       * search for a vx_info and get() it
18379 +       * negative id means current                             */
18380 +
18381 +struct vx_info *lookup_vx_info(int id)
18382 +{
18383 +       struct vx_info *vxi = NULL;
18384 +
18385 +       if (id < 0) {
18386 +               vxi = get_vx_info(current->vx_info);
18387 +       } else if (id > 1) {
18388 +               spin_lock(&vx_info_hash_lock);
18389 +               vxi = get_vx_info(__lookup_vx_info(id));
18390 +               spin_unlock(&vx_info_hash_lock);
18391 +       }
18392 +       return vxi;
18393 +}
18394 +
18395 +/*     xid_is_hashed()
18396 +
18397 +       * verify that xid is still hashed                       */
18398 +
18399 +int xid_is_hashed(xid_t xid)
18400 +{
18401 +       int hashed;
18402 +
18403 +       spin_lock(&vx_info_hash_lock);
18404 +       hashed = (__lookup_vx_info(xid) != NULL);
18405 +       spin_unlock(&vx_info_hash_lock);
18406 +       return hashed;
18407 +}
18408 +
18409 +#ifdef CONFIG_PROC_FS
18410 +
18411 +/*     get_xid_list()
18412 +
18413 +       * get a subset of hashed xids for proc
18414 +       * assumes size is at least one                          */
18415 +
18416 +int get_xid_list(int index, unsigned int *xids, int size)
18417 +{
18418 +       int hindex, nr_xids = 0;
18419 +
18420 +       /* only show current and children */
18421 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
18422 +               if (index > 0)
18423 +                       return 0;
18424 +               xids[nr_xids] = vx_current_xid();
18425 +               return 1;
18426 +       }
18427 +
18428 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
18429 +               struct hlist_head *head = &vx_info_hash[hindex];
18430 +               struct hlist_node *pos;
18431 +
18432 +               spin_lock(&vx_info_hash_lock);
18433 +               hlist_for_each(pos, head) {
18434 +                       struct vx_info *vxi;
18435 +
18436 +                       if (--index > 0)
18437 +                               continue;
18438 +
18439 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
18440 +                       xids[nr_xids] = vxi->vx_id;
18441 +                       if (++nr_xids >= size) {
18442 +                               spin_unlock(&vx_info_hash_lock);
18443 +                               goto out;
18444 +                       }
18445 +               }
18446 +               /* keep the lock time short */
18447 +               spin_unlock(&vx_info_hash_lock);
18448 +       }
18449 +out:
18450 +       return nr_xids;
18451 +}
18452 +#endif
18453 +
18454 +#ifdef CONFIG_VSERVER_DEBUG
18455 +
18456 +void   dump_vx_info_inactive(int level)
18457 +{
18458 +       struct hlist_node *entry, *next;
18459 +
18460 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
18461 +               struct vx_info *vxi =
18462 +                       list_entry(entry, struct vx_info, vx_hlist);
18463 +
18464 +               dump_vx_info(vxi, level);
18465 +       }
18466 +}
18467 +
18468 +#endif
18469 +
18470 +#if 0
18471 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
18472 +{
18473 +       struct user_struct *new_user, *old_user;
18474 +
18475 +       if (!p || !vxi)
18476 +               BUG();
18477 +
18478 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
18479 +               return -EACCES;
18480 +
18481 +       new_user = alloc_uid(vxi->vx_id, p->uid);
18482 +       if (!new_user)
18483 +               return -ENOMEM;
18484 +
18485 +       old_user = p->user;
18486 +       if (new_user != old_user) {
18487 +               atomic_inc(&new_user->processes);
18488 +               atomic_dec(&old_user->processes);
18489 +               p->user = new_user;
18490 +       }
18491 +       free_uid(old_user);
18492 +       return 0;
18493 +}
18494 +#endif
18495 +
18496 +#if 0
18497 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
18498 +{
18499 +       // p->cap_effective &= vxi->vx_cap_bset;
18500 +       p->cap_effective =
18501 +               cap_intersect(p->cap_effective, vxi->cap_bset);
18502 +       // p->cap_inheritable &= vxi->vx_cap_bset;
18503 +       p->cap_inheritable =
18504 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
18505 +       // p->cap_permitted &= vxi->vx_cap_bset;
18506 +       p->cap_permitted =
18507 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
18508 +}
18509 +#endif
18510 +
18511 +
18512 +#include <linux/file.h>
18513 +
18514 +static int vx_openfd_task(struct task_struct *tsk)
18515 +{
18516 +       struct files_struct *files = tsk->files;
18517 +       struct fdtable *fdt;
18518 +       const unsigned long *bptr;
18519 +       int count, total;
18520 +
18521 +       /* no rcu_read_lock() because of spin_lock() */
18522 +       spin_lock(&files->file_lock);
18523 +       fdt = files_fdtable(files);
18524 +       bptr = fdt->open_fds->fds_bits;
18525 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
18526 +       for (total = 0; count > 0; count--) {
18527 +               if (*bptr)
18528 +                       total += hweight_long(*bptr);
18529 +               bptr++;
18530 +       }
18531 +       spin_unlock(&files->file_lock);
18532 +       return total;
18533 +}
18534 +
18535 +
18536 +/*     for *space compatibility */
18537 +
18538 +asmlinkage long sys_unshare(unsigned long);
18539 +
18540 +/*
18541 + *     migrate task to new context
18542 + *     gets vxi, puts old_vxi on change
18543 + *     optionally unshares namespaces (hack)
18544 + */
18545 +
18546 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
18547 +{
18548 +       struct vx_info *old_vxi;
18549 +       int ret = 0;
18550 +
18551 +       if (!p || !vxi)
18552 +               BUG();
18553 +
18554 +       vxdprintk(VXD_CBIT(xid, 5),
18555 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
18556 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
18557 +
18558 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
18559 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
18560 +               return -EACCES;
18561 +
18562 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
18563 +               return -EFAULT;
18564 +
18565 +       old_vxi = task_get_vx_info(p);
18566 +       if (old_vxi == vxi)
18567 +               goto out;
18568 +
18569 +//     if (!(ret = vx_migrate_user(p, vxi))) {
18570 +       {
18571 +               int openfd;
18572 +
18573 +               task_lock(p);
18574 +               openfd = vx_openfd_task(p);
18575 +
18576 +               if (old_vxi) {
18577 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
18578 +                       atomic_dec(&old_vxi->cvirt.nr_running);
18579 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
18580 +                       /* FIXME: what about the struct files here? */
18581 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
18582 +                       /* account for the executable */
18583 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
18584 +               }
18585 +               atomic_inc(&vxi->cvirt.nr_threads);
18586 +               atomic_inc(&vxi->cvirt.nr_running);
18587 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
18588 +               /* FIXME: what about the struct files here? */
18589 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
18590 +               /* account for the executable */
18591 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
18592 +
18593 +               if (old_vxi) {
18594 +                       release_vx_info(old_vxi, p);
18595 +                       clr_vx_info(&p->vx_info);
18596 +               }
18597 +               claim_vx_info(vxi, p);
18598 +               set_vx_info(&p->vx_info, vxi);
18599 +               p->xid = vxi->vx_id;
18600 +
18601 +               vxdprintk(VXD_CBIT(xid, 5),
18602 +                       "moved task %p into vxi:%p[#%d]",
18603 +                       p, vxi, vxi->vx_id);
18604 +
18605 +               // vx_mask_cap_bset(vxi, p);
18606 +               task_unlock(p);
18607 +
18608 +               /* hack for *spaces to provide compatibility */
18609 +               if (unshare) {
18610 +                       struct nsproxy *old_nsp, *new_nsp;
18611 +
18612 +                       ret = unshare_nsproxy_namespaces(
18613 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
18614 +                               &new_nsp, NULL);
18615 +                       if (ret)
18616 +                               goto out;
18617 +
18618 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
18619 +                       vx_set_space(vxi, CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER);
18620 +                       put_nsproxy(old_nsp);
18621 +               }
18622 +       }
18623 +out:
18624 +       put_vx_info(old_vxi);
18625 +       return ret;
18626 +}
18627 +
18628 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
18629 +{
18630 +       struct task_struct *old_reaper;
18631 +
18632 +       if (!vxi)
18633 +               return -EINVAL;
18634 +
18635 +       vxdprintk(VXD_CBIT(xid, 6),
18636 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
18637 +               vxi, vxi->vx_id, p, p->xid, p->pid);
18638 +
18639 +       old_reaper = vxi->vx_reaper;
18640 +       if (old_reaper == p)
18641 +               return 0;
18642 +
18643 +       /* set new child reaper */
18644 +       get_task_struct(p);
18645 +       vxi->vx_reaper = p;
18646 +       put_task_struct(old_reaper);
18647 +       return 0;
18648 +}
18649 +
18650 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
18651 +{
18652 +       if (!vxi)
18653 +               return -EINVAL;
18654 +
18655 +       vxdprintk(VXD_CBIT(xid, 6),
18656 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
18657 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
18658 +
18659 +       vxi->vx_flags &= ~VXF_STATE_INIT;
18660 +       vxi->vx_initpid = p->tgid;
18661 +       return 0;
18662 +}
18663 +
18664 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
18665 +{
18666 +       vxdprintk(VXD_CBIT(xid, 6),
18667 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
18668 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
18669 +
18670 +       vxi->exit_code = code;
18671 +       vxi->vx_initpid = 0;
18672 +}
18673 +
18674 +
18675 +void vx_set_persistent(struct vx_info *vxi)
18676 +{
18677 +       vxdprintk(VXD_CBIT(xid, 6),
18678 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
18679 +
18680 +       get_vx_info(vxi);
18681 +       claim_vx_info(vxi, NULL);
18682 +}
18683 +
18684 +void vx_clear_persistent(struct vx_info *vxi)
18685 +{
18686 +       vxdprintk(VXD_CBIT(xid, 6),
18687 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
18688 +
18689 +       release_vx_info(vxi, NULL);
18690 +       put_vx_info(vxi);
18691 +}
18692 +
18693 +void vx_update_persistent(struct vx_info *vxi)
18694 +{
18695 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
18696 +               vx_set_persistent(vxi);
18697 +       else
18698 +               vx_clear_persistent(vxi);
18699 +}
18700 +
18701 +
18702 +/*     task must be current or locked          */
18703 +
18704 +void   exit_vx_info(struct task_struct *p, int code)
18705 +{
18706 +       struct vx_info *vxi = p->vx_info;
18707 +
18708 +       if (vxi) {
18709 +               atomic_dec(&vxi->cvirt.nr_threads);
18710 +               vx_nproc_dec(p);
18711 +
18712 +               vxi->exit_code = code;
18713 +               release_vx_info(vxi, p);
18714 +       }
18715 +}
18716 +
18717 +void   exit_vx_info_early(struct task_struct *p, int code)
18718 +{
18719 +       struct vx_info *vxi = p->vx_info;
18720 +
18721 +       if (vxi) {
18722 +               if (vxi->vx_initpid == p->tgid)
18723 +                       vx_exit_init(vxi, p, code);
18724 +               if (vxi->vx_reaper == p)
18725 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
18726 +       }
18727 +}
18728 +
18729 +
18730 +/* vserver syscall commands below here */
18731 +
18732 +/* taks xid and vx_info functions */
18733 +
18734 +#include <asm/uaccess.h>
18735 +
18736 +
18737 +int vc_task_xid(uint32_t id)
18738 +{
18739 +       xid_t xid;
18740 +
18741 +       if (id) {
18742 +               struct task_struct *tsk;
18743 +
18744 +               read_lock(&tasklist_lock);
18745 +               tsk = find_task_by_real_pid(id);
18746 +               xid = (tsk) ? tsk->xid : -ESRCH;
18747 +               read_unlock(&tasklist_lock);
18748 +       } else
18749 +               xid = vx_current_xid();
18750 +       return xid;
18751 +}
18752 +
18753 +
18754 +int vc_vx_info(struct vx_info *vxi, void __user *data)
18755 +{
18756 +       struct vcmd_vx_info_v0 vc_data;
18757 +
18758 +       vc_data.xid = vxi->vx_id;
18759 +       vc_data.initpid = vxi->vx_initpid;
18760 +
18761 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18762 +               return -EFAULT;
18763 +       return 0;
18764 +}
18765 +
18766 +
18767 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
18768 +{
18769 +       struct vcmd_ctx_stat_v0 vc_data;
18770 +
18771 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
18772 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
18773 +
18774 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18775 +               return -EFAULT;
18776 +       return 0;
18777 +}
18778 +
18779 +
18780 +/* context functions */
18781 +
18782 +int vc_ctx_create(uint32_t xid, void __user *data)
18783 +{
18784 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
18785 +       struct vx_info *new_vxi;
18786 +       int ret;
18787 +
18788 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18789 +               return -EFAULT;
18790 +
18791 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
18792 +               return -EINVAL;
18793 +
18794 +       new_vxi = __create_vx_info(xid);
18795 +       if (IS_ERR(new_vxi))
18796 +               return PTR_ERR(new_vxi);
18797 +
18798 +       /* initial flags */
18799 +       new_vxi->vx_flags = vc_data.flagword;
18800 +
18801 +       ret = -ENOEXEC;
18802 +       if (vs_state_change(new_vxi, VSC_STARTUP))
18803 +               goto out;
18804 +
18805 +       ret = vx_migrate_task(current, new_vxi, (!data));
18806 +       if (ret)
18807 +               goto out;
18808 +
18809 +       /* return context id on success */
18810 +       ret = new_vxi->vx_id;
18811 +
18812 +       /* get a reference for persistent contexts */
18813 +       if ((vc_data.flagword & VXF_PERSISTENT))
18814 +               vx_set_persistent(new_vxi);
18815 +out:
18816 +       release_vx_info(new_vxi, NULL);
18817 +       put_vx_info(new_vxi);
18818 +       return ret;
18819 +}
18820 +
18821 +
18822 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
18823 +{
18824 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
18825 +       int ret;
18826 +
18827 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18828 +               return -EFAULT;
18829 +
18830 +       ret = vx_migrate_task(current, vxi, 0);
18831 +       if (ret)
18832 +               return ret;
18833 +       if (vc_data.flagword & VXM_SET_INIT)
18834 +               ret = vx_set_init(vxi, current);
18835 +       if (ret)
18836 +               return ret;
18837 +       if (vc_data.flagword & VXM_SET_REAPER)
18838 +               ret = vx_set_reaper(vxi, current);
18839 +       return ret;
18840 +}
18841 +
18842 +
18843 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
18844 +{
18845 +       struct vcmd_ctx_flags_v0 vc_data;
18846 +
18847 +       vc_data.flagword = vxi->vx_flags;
18848 +
18849 +       /* special STATE flag handling */
18850 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
18851 +
18852 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18853 +               return -EFAULT;
18854 +       return 0;
18855 +}
18856 +
18857 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
18858 +{
18859 +       struct vcmd_ctx_flags_v0 vc_data;
18860 +       uint64_t mask, trigger;
18861 +
18862 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18863 +               return -EFAULT;
18864 +
18865 +       /* special STATE flag handling */
18866 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
18867 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
18868 +
18869 +       if (vxi == current->vx_info) {
18870 +               /* if (trigger & VXF_STATE_SETUP)
18871 +                       vx_mask_cap_bset(vxi, current); */
18872 +               if (trigger & VXF_STATE_INIT) {
18873 +                       int ret;
18874 +
18875 +                       ret = vx_set_init(vxi, current);
18876 +                       if (ret)
18877 +                               return ret;
18878 +                       ret = vx_set_reaper(vxi, current);
18879 +                       if (ret)
18880 +                               return ret;
18881 +               }
18882 +       }
18883 +
18884 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
18885 +               vc_data.flagword, mask);
18886 +       if (trigger & VXF_PERSISTENT)
18887 +               vx_update_persistent(vxi);
18888 +
18889 +       return 0;
18890 +}
18891 +
18892 +
18893 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
18894 +{
18895 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
18896 +
18897 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
18898 +       return v;
18899 +}
18900 +
18901 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
18902 +{
18903 +       kernel_cap_t c = __cap_empty_set;
18904 +
18905 +       c.cap[0] = v & 0xFFFFFFFF;
18906 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
18907 +
18908 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
18909 +       return c;
18910 +}
18911 +
18912 +
18913 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
18914 +{
18915 +       if (bcaps)
18916 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
18917 +       if (ccaps)
18918 +               *ccaps = vxi->vx_ccaps;
18919 +
18920 +       return 0;
18921 +}
18922 +
18923 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
18924 +{
18925 +       struct vcmd_ctx_caps_v1 vc_data;
18926 +       int ret;
18927 +
18928 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
18929 +       if (ret)
18930 +               return ret;
18931 +       vc_data.cmask = ~0ULL;
18932 +
18933 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18934 +               return -EFAULT;
18935 +       return 0;
18936 +}
18937 +
18938 +static int do_set_caps(struct vx_info *vxi,
18939 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
18940 +{
18941 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
18942 +
18943 +#if 0
18944 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
18945 +               bcaps, bmask, ccaps, cmask);
18946 +#endif
18947 +       vxi->vx_bcaps = cap_t_from_caps(
18948 +               vs_mask_flags(bcold, bcaps, bmask));
18949 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
18950 +
18951 +       return 0;
18952 +}
18953 +
18954 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
18955 +{
18956 +       struct vcmd_ctx_caps_v1 vc_data;
18957 +
18958 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18959 +               return -EFAULT;
18960 +
18961 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
18962 +}
18963 +
18964 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
18965 +{
18966 +       struct vcmd_bcaps vc_data;
18967 +       int ret;
18968 +
18969 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
18970 +       if (ret)
18971 +               return ret;
18972 +       vc_data.bmask = ~0ULL;
18973 +
18974 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18975 +               return -EFAULT;
18976 +       return 0;
18977 +}
18978 +
18979 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
18980 +{
18981 +       struct vcmd_bcaps vc_data;
18982 +
18983 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18984 +               return -EFAULT;
18985 +
18986 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
18987 +}
18988 +
18989 +
18990 +int vc_get_badness(struct vx_info *vxi, void __user *data)
18991 +{
18992 +       struct vcmd_badness_v0 vc_data;
18993 +
18994 +       vc_data.bias = vxi->vx_badness_bias;
18995 +
18996 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18997 +               return -EFAULT;
18998 +       return 0;
18999 +}
19000 +
19001 +int vc_set_badness(struct vx_info *vxi, void __user *data)
19002 +{
19003 +       struct vcmd_badness_v0 vc_data;
19004 +
19005 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19006 +               return -EFAULT;
19007 +
19008 +       vxi->vx_badness_bias = vc_data.bias;
19009 +       return 0;
19010 +}
19011 +
19012 +#include <linux/module.h>
19013 +
19014 +EXPORT_SYMBOL_GPL(free_vx_info);
19015 +
19016 diff -NurpP --minimal linux-2.6.25/kernel/vserver/cvirt.c linux-2.6.25-vs2.3.0.34.9/kernel/vserver/cvirt.c
19017 --- linux-2.6.25/kernel/vserver/cvirt.c 1969-12-31 19:00:00.000000000 -0500
19018 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/cvirt.c    2008-04-19 15:14:52.000000000 -0400
19019 @@ -0,0 +1,301 @@
19020 +/*
19021 + *  linux/kernel/vserver/cvirt.c
19022 + *
19023 + *  Virtual Server: Context Virtualization
19024 + *
19025 + *  Copyright (C) 2004-2007  Herbert Pötzl
19026 + *
19027 + *  V0.01  broken out from limit.c
19028 + *  V0.02  added utsname stuff
19029 + *  V0.03  changed vcmds to vxi arg
19030 + *
19031 + */
19032 +
19033 +#include <linux/types.h>
19034 +#include <linux/utsname.h>
19035 +#include <linux/vs_cvirt.h>
19036 +#include <linux/vserver/switch.h>
19037 +#include <linux/vserver/cvirt_cmd.h>
19038 +
19039 +#include <asm/uaccess.h>
19040 +
19041 +
19042 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
19043 +{
19044 +       struct vx_info *vxi = current->vx_info;
19045 +
19046 +       set_normalized_timespec(uptime,
19047 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
19048 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
19049 +       if (!idle)
19050 +               return;
19051 +       set_normalized_timespec(idle,
19052 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
19053 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
19054 +       return;
19055 +}
19056 +
19057 +uint64_t vx_idle_jiffies(void)
19058 +{
19059 +       return init_task.utime + init_task.stime;
19060 +}
19061 +
19062 +
19063 +
19064 +static inline uint32_t __update_loadavg(uint32_t load,
19065 +       int wsize, int delta, int n)
19066 +{
19067 +       unsigned long long calc, prev;
19068 +
19069 +       /* just set it to n */
19070 +       if (unlikely(delta >= wsize))
19071 +               return (n << FSHIFT);
19072 +
19073 +       calc = delta * n;
19074 +       calc <<= FSHIFT;
19075 +       prev = (wsize - delta);
19076 +       prev *= load;
19077 +       calc += prev;
19078 +       do_div(calc, wsize);
19079 +       return calc;
19080 +}
19081 +
19082 +
19083 +void vx_update_load(struct vx_info *vxi)
19084 +{
19085 +       uint32_t now, last, delta;
19086 +       unsigned int nr_running, nr_uninterruptible;
19087 +       unsigned int total;
19088 +       unsigned long flags;
19089 +
19090 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
19091 +
19092 +       now = jiffies;
19093 +       last = vxi->cvirt.load_last;
19094 +       delta = now - last;
19095 +
19096 +       if (delta < 5*HZ)
19097 +               goto out;
19098 +
19099 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
19100 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
19101 +       total = nr_running + nr_uninterruptible;
19102 +
19103 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
19104 +               60*HZ, delta, total);
19105 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
19106 +               5*60*HZ, delta, total);
19107 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
19108 +               15*60*HZ, delta, total);
19109 +
19110 +       vxi->cvirt.load_last = now;
19111 +out:
19112 +       atomic_inc(&vxi->cvirt.load_updates);
19113 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
19114 +}
19115 +
19116 +
19117 +/*
19118 + * Commands to do_syslog:
19119 + *
19120 + *      0 -- Close the log.  Currently a NOP.
19121 + *      1 -- Open the log. Currently a NOP.
19122 + *      2 -- Read from the log.
19123 + *      3 -- Read all messages remaining in the ring buffer.
19124 + *      4 -- Read and clear all messages remaining in the ring buffer
19125 + *      5 -- Clear ring buffer.
19126 + *      6 -- Disable printk's to console
19127 + *      7 -- Enable printk's to console
19128 + *      8 -- Set level of messages printed to console
19129 + *      9 -- Return number of unread characters in the log buffer
19130 + *     10 -- Return size of the log buffer
19131 + */
19132 +int vx_do_syslog(int type, char __user *buf, int len)
19133 +{
19134 +       int error = 0;
19135 +       int do_clear = 0;
19136 +       struct vx_info *vxi = current->vx_info;
19137 +       struct _vx_syslog *log;
19138 +
19139 +       if (!vxi)
19140 +               return -EINVAL;
19141 +       log = &vxi->cvirt.syslog;
19142 +
19143 +       switch (type) {
19144 +       case 0:         /* Close log */
19145 +       case 1:         /* Open log */
19146 +               break;
19147 +       case 2:         /* Read from log */
19148 +               error = wait_event_interruptible(log->log_wait,
19149 +                       (log->log_start - log->log_end));
19150 +               if (error)
19151 +                       break;
19152 +               spin_lock_irq(&log->logbuf_lock);
19153 +               spin_unlock_irq(&log->logbuf_lock);
19154 +               break;
19155 +       case 4:         /* Read/clear last kernel messages */
19156 +               do_clear = 1;
19157 +               /* fall through */
19158 +       case 3:         /* Read last kernel messages */
19159 +               return 0;
19160 +
19161 +       case 5:         /* Clear ring buffer */
19162 +               return 0;
19163 +
19164 +       case 6:         /* Disable logging to console */
19165 +       case 7:         /* Enable logging to console */
19166 +       case 8:         /* Set level of messages printed to console */
19167 +               break;
19168 +
19169 +       case 9:         /* Number of chars in the log buffer */
19170 +               return 0;
19171 +       case 10:        /* Size of the log buffer */
19172 +               return 0;
19173 +       default:
19174 +               error = -EINVAL;
19175 +               break;
19176 +       }
19177 +       return error;
19178 +}
19179 +
19180 +
19181 +/* virtual host info names */
19182 +
19183 +static char *vx_vhi_name(struct vx_info *vxi, int id)
19184 +{
19185 +       struct nsproxy *nsproxy;
19186 +       struct uts_namespace *uts;
19187 +
19188 +
19189 +       if (id == VHIN_CONTEXT)
19190 +               return vxi->vx_name;
19191 +
19192 +       nsproxy = vxi->vx_nsproxy;
19193 +       if (!nsproxy)
19194 +               return NULL;
19195 +
19196 +       uts = nsproxy->uts_ns;
19197 +       if (!uts)
19198 +               return NULL;
19199 +
19200 +       switch (id) {
19201 +       case VHIN_SYSNAME:
19202 +               return uts->name.sysname;
19203 +       case VHIN_NODENAME:
19204 +               return uts->name.nodename;
19205 +       case VHIN_RELEASE:
19206 +               return uts->name.release;
19207 +       case VHIN_VERSION:
19208 +               return uts->name.version;
19209 +       case VHIN_MACHINE:
19210 +               return uts->name.machine;
19211 +       case VHIN_DOMAINNAME:
19212 +               return uts->name.domainname;
19213 +       default:
19214 +               return NULL;
19215 +       }
19216 +       return NULL;
19217 +}
19218 +
19219 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
19220 +{
19221 +       struct vcmd_vhi_name_v0 vc_data;
19222 +       char *name;
19223 +
19224 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19225 +               return -EFAULT;
19226 +
19227 +       name = vx_vhi_name(vxi, vc_data.field);
19228 +       if (!name)
19229 +               return -EINVAL;
19230 +
19231 +       memcpy(name, vc_data.name, 65);
19232 +       return 0;
19233 +}
19234 +
19235 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
19236 +{
19237 +       struct vcmd_vhi_name_v0 vc_data;
19238 +       char *name;
19239 +
19240 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19241 +               return -EFAULT;
19242 +
19243 +       name = vx_vhi_name(vxi, vc_data.field);
19244 +       if (!name)
19245 +               return -EINVAL;
19246 +
19247 +       memcpy(vc_data.name, name, 65);
19248 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19249 +               return -EFAULT;
19250 +       return 0;
19251 +}
19252 +
19253 +
19254 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
19255 +{
19256 +       struct vcmd_virt_stat_v0 vc_data;
19257 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
19258 +       struct timespec uptime;
19259 +
19260 +       do_posix_clock_monotonic_gettime(&uptime);
19261 +       set_normalized_timespec(&uptime,
19262 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
19263 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
19264 +
19265 +       vc_data.offset = timeval_to_ns(&cvirt->bias_tv);
19266 +       vc_data.uptime = timespec_to_ns(&uptime);
19267 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
19268 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
19269 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
19270 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
19271 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
19272 +       vc_data.load[0] = cvirt->load[0];
19273 +       vc_data.load[1] = cvirt->load[1];
19274 +       vc_data.load[2] = cvirt->load[2];
19275 +
19276 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19277 +               return -EFAULT;
19278 +       return 0;
19279 +}
19280 +
19281 +
19282 +#ifdef CONFIG_VSERVER_VTIME
19283 +
19284 +/* virtualized time base */
19285 +
19286 +void vx_gettimeofday(struct timeval *tv)
19287 +{
19288 +       do_gettimeofday(tv);
19289 +       if (!vx_flags(VXF_VIRT_TIME, 0))
19290 +               return;
19291 +
19292 +       tv->tv_sec += current->vx_info->cvirt.bias_tv.tv_sec;
19293 +       tv->tv_usec += current->vx_info->cvirt.bias_tv.tv_usec;
19294 +
19295 +       if (tv->tv_usec >= USEC_PER_SEC) {
19296 +               tv->tv_sec++;
19297 +               tv->tv_usec -= USEC_PER_SEC;
19298 +       } else if (tv->tv_usec < 0) {
19299 +               tv->tv_sec--;
19300 +               tv->tv_usec += USEC_PER_SEC;
19301 +       }
19302 +}
19303 +
19304 +int vx_settimeofday(struct timespec *ts)
19305 +{
19306 +       struct timeval tv;
19307 +
19308 +       if (!vx_flags(VXF_VIRT_TIME, 0))
19309 +               return do_settimeofday(ts);
19310 +
19311 +       do_gettimeofday(&tv);
19312 +       current->vx_info->cvirt.bias_tv.tv_sec =
19313 +               ts->tv_sec - tv.tv_sec;
19314 +       current->vx_info->cvirt.bias_tv.tv_usec =
19315 +               (ts->tv_nsec/NSEC_PER_USEC) - tv.tv_usec;
19316 +       return 0;
19317 +}
19318 +
19319 +#endif
19320 +
19321 diff -NurpP --minimal linux-2.6.25/kernel/vserver/cvirt_init.h linux-2.6.25-vs2.3.0.34.9/kernel/vserver/cvirt_init.h
19322 --- linux-2.6.25/kernel/vserver/cvirt_init.h    1969-12-31 19:00:00.000000000 -0500
19323 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/cvirt_init.h       2008-04-19 15:14:52.000000000 -0400
19324 @@ -0,0 +1,69 @@
19325 +
19326 +
19327 +extern uint64_t vx_idle_jiffies(void);
19328 +
19329 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
19330 +{
19331 +       uint64_t idle_jiffies = vx_idle_jiffies();
19332 +       uint64_t nsuptime;
19333 +
19334 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
19335 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
19336 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
19337 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
19338 +       cvirt->bias_tv.tv_sec = 0;
19339 +       cvirt->bias_tv.tv_usec = 0;
19340 +
19341 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
19342 +       atomic_set(&cvirt->nr_threads, 0);
19343 +       atomic_set(&cvirt->nr_running, 0);
19344 +       atomic_set(&cvirt->nr_uninterruptible, 0);
19345 +       atomic_set(&cvirt->nr_onhold, 0);
19346 +
19347 +       spin_lock_init(&cvirt->load_lock);
19348 +       cvirt->load_last = jiffies;
19349 +       atomic_set(&cvirt->load_updates, 0);
19350 +       cvirt->load[0] = 0;
19351 +       cvirt->load[1] = 0;
19352 +       cvirt->load[2] = 0;
19353 +       atomic_set(&cvirt->total_forks, 0);
19354 +
19355 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
19356 +       init_waitqueue_head(&cvirt->syslog.log_wait);
19357 +       cvirt->syslog.log_start = 0;
19358 +       cvirt->syslog.log_end = 0;
19359 +       cvirt->syslog.con_start = 0;
19360 +       cvirt->syslog.logged_chars = 0;
19361 +}
19362 +
19363 +static inline
19364 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
19365 +{
19366 +       // cvirt_pc->cpustat = { 0 };
19367 +}
19368 +
19369 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
19370 +{
19371 +       int value;
19372 +
19373 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
19374 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
19375 +               cvirt, value);
19376 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
19377 +               "!!! cvirt: %p[nr_running] = %d on exit.",
19378 +               cvirt, value);
19379 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
19380 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
19381 +               cvirt, value);
19382 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
19383 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
19384 +               cvirt, value);
19385 +       return;
19386 +}
19387 +
19388 +static inline
19389 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
19390 +{
19391 +       return;
19392 +}
19393 +
19394 diff -NurpP --minimal linux-2.6.25/kernel/vserver/cvirt_proc.h linux-2.6.25-vs2.3.0.34.9/kernel/vserver/cvirt_proc.h
19395 --- linux-2.6.25/kernel/vserver/cvirt_proc.h    1969-12-31 19:00:00.000000000 -0500
19396 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/cvirt_proc.h       2008-04-21 13:01:29.000000000 -0400
19397 @@ -0,0 +1,135 @@
19398 +#ifndef _VX_CVIRT_PROC_H
19399 +#define _VX_CVIRT_PROC_H
19400 +
19401 +#include <linux/nsproxy.h>
19402 +#include <linux/mnt_namespace.h>
19403 +#include <linux/ipc_namespace.h>
19404 +#include <linux/utsname.h>
19405 +#include <linux/ipc.h>
19406 +
19407 +
19408 +static inline
19409 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
19410 +{
19411 +       struct mnt_namespace *ns;
19412 +       struct uts_namespace *uts;
19413 +       struct ipc_namespace *ipc;
19414 +       struct path path;
19415 +       char *pstr, *root;
19416 +       int length = 0;
19417 +
19418 +       if (!nsproxy)
19419 +               goto out;
19420 +
19421 +       length += sprintf(buffer + length,
19422 +               "NSProxy:\t%p [%p,%p,%p]\n",
19423 +               nsproxy, nsproxy->mnt_ns,
19424 +               nsproxy->uts_ns, nsproxy->ipc_ns);
19425 +
19426 +       ns = nsproxy->mnt_ns;
19427 +       if (!ns)
19428 +               goto skip_ns;
19429 +
19430 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
19431 +       if (!pstr)
19432 +               goto skip_ns;
19433 +
19434 +       path.mnt = ns->root;
19435 +       path.dentry = ns->root->mnt_root;
19436 +       root = d_path(&path, pstr, PATH_MAX - 2);
19437 +       length += sprintf(buffer + length,
19438 +               "Namespace:\t%p [#%u]\n"
19439 +               "RootPath:\t%s\n",
19440 +               ns, atomic_read(&ns->count),
19441 +               root);
19442 +       kfree(pstr);
19443 +skip_ns:
19444 +
19445 +       uts = nsproxy->uts_ns;
19446 +       if (!uts)
19447 +               goto skip_uts;
19448 +
19449 +       length += sprintf(buffer + length,
19450 +               "SysName:\t%.*s\n"
19451 +               "NodeName:\t%.*s\n"
19452 +               "Release:\t%.*s\n"
19453 +               "Version:\t%.*s\n"
19454 +               "Machine:\t%.*s\n"
19455 +               "DomainName:\t%.*s\n",
19456 +               __NEW_UTS_LEN, uts->name.sysname,
19457 +               __NEW_UTS_LEN, uts->name.nodename,
19458 +               __NEW_UTS_LEN, uts->name.release,
19459 +               __NEW_UTS_LEN, uts->name.version,
19460 +               __NEW_UTS_LEN, uts->name.machine,
19461 +               __NEW_UTS_LEN, uts->name.domainname);
19462 +skip_uts:
19463 +
19464 +       ipc = nsproxy->ipc_ns;
19465 +       if (!ipc)
19466 +               goto skip_ipc;
19467 +
19468 +       length += sprintf(buffer + length,
19469 +               "SEMS:\t\t%d %d %d %d  %d\n"
19470 +               "MSG:\t\t%d %d %d\n"
19471 +               "SHM:\t\t%lu %lu  %d %d\n",
19472 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
19473 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
19474 +               ipc->used_sems,
19475 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
19476 +               (unsigned long)ipc->shm_ctlmax,
19477 +               (unsigned long)ipc->shm_ctlall,
19478 +               ipc->shm_ctlmni, ipc->shm_tot);
19479 +skip_ipc:
19480 +out:
19481 +       return length;
19482 +}
19483 +
19484 +
19485 +#include <linux/sched.h>
19486 +
19487 +#define LOAD_INT(x) ((x) >> FSHIFT)
19488 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
19489 +
19490 +static inline
19491 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
19492 +{
19493 +       int length = 0;
19494 +       int a, b, c;
19495 +
19496 +       length += sprintf(buffer + length,
19497 +               "BiasUptime:\t%lu.%02lu\n",
19498 +               (unsigned long)cvirt->bias_uptime.tv_sec,
19499 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
19500 +
19501 +       a = cvirt->load[0] + (FIXED_1 / 200);
19502 +       b = cvirt->load[1] + (FIXED_1 / 200);
19503 +       c = cvirt->load[2] + (FIXED_1 / 200);
19504 +       length += sprintf(buffer + length,
19505 +               "nr_threads:\t%d\n"
19506 +               "nr_running:\t%d\n"
19507 +               "nr_unintr:\t%d\n"
19508 +               "nr_onhold:\t%d\n"
19509 +               "load_updates:\t%d\n"
19510 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
19511 +               "total_forks:\t%d\n",
19512 +               atomic_read(&cvirt->nr_threads),
19513 +               atomic_read(&cvirt->nr_running),
19514 +               atomic_read(&cvirt->nr_uninterruptible),
19515 +               atomic_read(&cvirt->nr_onhold),
19516 +               atomic_read(&cvirt->load_updates),
19517 +               LOAD_INT(a), LOAD_FRAC(a),
19518 +               LOAD_INT(b), LOAD_FRAC(b),
19519 +               LOAD_INT(c), LOAD_FRAC(c),
19520 +               atomic_read(&cvirt->total_forks));
19521 +       return length;
19522 +}
19523 +
19524 +static inline
19525 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
19526 +       char *buffer, int cpu)
19527 +{
19528 +       int length = 0;
19529 +       return length;
19530 +}
19531 +
19532 +#endif /* _VX_CVIRT_PROC_H */
19533 diff -NurpP --minimal linux-2.6.25/kernel/vserver/debug.c linux-2.6.25-vs2.3.0.34.9/kernel/vserver/debug.c
19534 --- linux-2.6.25/kernel/vserver/debug.c 1969-12-31 19:00:00.000000000 -0500
19535 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/debug.c    2008-04-19 15:14:52.000000000 -0400
19536 @@ -0,0 +1,32 @@
19537 +/*
19538 + *  kernel/vserver/debug.c
19539 + *
19540 + *  Copyright (C) 2005-2007 Herbert Pötzl
19541 + *
19542 + *  V0.01  vx_info dump support
19543 + *
19544 + */
19545 +
19546 +#include <linux/module.h>
19547 +
19548 +#include <linux/vserver/context.h>
19549 +
19550 +
19551 +void   dump_vx_info(struct vx_info *vxi, int level)
19552 +{
19553 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
19554 +               atomic_read(&vxi->vx_usecnt),
19555 +               atomic_read(&vxi->vx_tasks),
19556 +               vxi->vx_state);
19557 +       if (level > 0) {
19558 +               __dump_vx_limit(&vxi->limit);
19559 +               __dump_vx_sched(&vxi->sched);
19560 +               __dump_vx_cvirt(&vxi->cvirt);
19561 +               __dump_vx_cacct(&vxi->cacct);
19562 +       }
19563 +       printk("---\n");
19564 +}
19565 +
19566 +
19567 +EXPORT_SYMBOL_GPL(dump_vx_info);
19568 +
19569 diff -NurpP --minimal linux-2.6.25/kernel/vserver/device.c linux-2.6.25-vs2.3.0.34.9/kernel/vserver/device.c
19570 --- linux-2.6.25/kernel/vserver/device.c        1969-12-31 19:00:00.000000000 -0500
19571 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/device.c   2008-04-21 12:35:24.000000000 -0400
19572 @@ -0,0 +1,443 @@
19573 +/*
19574 + *  linux/kernel/vserver/device.c
19575 + *
19576 + *  Linux-VServer: Device Support
19577 + *
19578 + *  Copyright (C) 2006  Herbert Pötzl
19579 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
19580 + *
19581 + *  V0.01  device mapping basics
19582 + *  V0.02  added defaults
19583 + *
19584 + */
19585 +
19586 +#include <linux/slab.h>
19587 +#include <linux/rcupdate.h>
19588 +#include <linux/fs.h>
19589 +#include <linux/namei.h>
19590 +#include <linux/hash.h>
19591 +
19592 +#include <asm/errno.h>
19593 +#include <asm/uaccess.h>
19594 +#include <linux/vserver/base.h>
19595 +#include <linux/vserver/debug.h>
19596 +#include <linux/vserver/context.h>
19597 +#include <linux/vserver/device.h>
19598 +#include <linux/vserver/device_cmd.h>
19599 +
19600 +
19601 +#define DMAP_HASH_BITS 4
19602 +
19603 +
19604 +struct vs_mapping {
19605 +       union {
19606 +               struct hlist_node hlist;
19607 +               struct list_head list;
19608 +       } u;
19609 +#define dm_hlist       u.hlist
19610 +#define dm_list                u.list
19611 +       xid_t xid;
19612 +       dev_t device;
19613 +       struct vx_dmap_target target;
19614 +};
19615 +
19616 +
19617 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
19618 +
19619 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
19620 +
19621 +static struct vx_dmap_target dmap_defaults[2] = {
19622 +       { .flags = DATTR_OPEN },
19623 +       { .flags = DATTR_OPEN },
19624 +};
19625 +
19626 +
19627 +struct kmem_cache *dmap_cachep __read_mostly;
19628 +
19629 +int __init dmap_cache_init(void)
19630 +{
19631 +       dmap_cachep = kmem_cache_create("dmap_cache",
19632 +               sizeof(struct vs_mapping), 0,
19633 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19634 +       return 0;
19635 +}
19636 +
19637 +__initcall(dmap_cache_init);
19638 +
19639 +
19640 +static inline unsigned int __hashval(dev_t dev, int bits)
19641 +{
19642 +       return hash_long((unsigned long)dev, bits);
19643 +}
19644 +
19645 +
19646 +/*     __hash_mapping()
19647 + *     add the mapping to the hash table
19648 + */
19649 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
19650 +{
19651 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19652 +       struct hlist_head *head, *hash = dmap_main_hash;
19653 +       int device = vdm->device;
19654 +
19655 +       spin_lock(hash_lock);
19656 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
19657 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
19658 +
19659 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
19660 +       hlist_add_head(&vdm->dm_hlist, head);
19661 +       spin_unlock(hash_lock);
19662 +}
19663 +
19664 +
19665 +static inline int __mode_to_default(umode_t mode)
19666 +{
19667 +       switch (mode) {
19668 +       case S_IFBLK:
19669 +               return 0;
19670 +       case S_IFCHR:
19671 +               return 1;
19672 +       default:
19673 +               BUG();
19674 +       }
19675 +}
19676 +
19677 +
19678 +/*     __set_default()
19679 + *     set a default
19680 + */
19681 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
19682 +       struct vx_dmap_target *vdmt)
19683 +{
19684 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19685 +       spin_lock(hash_lock);
19686 +
19687 +       if (vxi)
19688 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
19689 +       else
19690 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
19691 +
19692 +
19693 +       spin_unlock(hash_lock);
19694 +
19695 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
19696 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
19697 +}
19698 +
19699 +
19700 +/*     __remove_default()
19701 + *     remove a default
19702 + */
19703 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
19704 +{
19705 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19706 +       spin_lock(hash_lock);
19707 +
19708 +       if (vxi)
19709 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
19710 +       else    /* remove == reset */
19711 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
19712 +
19713 +       spin_unlock(hash_lock);
19714 +       return 0;
19715 +}
19716 +
19717 +
19718 +/*     __find_mapping()
19719 + *     find a mapping in the hash table
19720 + *
19721 + *     caller must hold hash_lock
19722 + */
19723 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
19724 +       struct vs_mapping **local, struct vs_mapping **global)
19725 +{
19726 +       struct hlist_head *hash = dmap_main_hash;
19727 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
19728 +       struct hlist_node *pos;
19729 +       struct vs_mapping *vdm;
19730 +
19731 +       *local = NULL;
19732 +       if (global)
19733 +               *global = NULL;
19734 +
19735 +       hlist_for_each(pos, head) {
19736 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
19737 +
19738 +               if ((vdm->device == device) &&
19739 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
19740 +                       if (vdm->xid == xid) {
19741 +                               *local = vdm;
19742 +                               return 1;
19743 +                       } else if (global && vdm->xid == 0)
19744 +                               *global = vdm;
19745 +               }
19746 +       }
19747 +
19748 +       if (global && *global)
19749 +               return 0;
19750 +       else
19751 +               return -ENOENT;
19752 +}
19753 +
19754 +
19755 +/*     __lookup_mapping()
19756 + *     find a mapping and store the result in target and flags
19757 + */
19758 +static inline int __lookup_mapping(struct vx_info *vxi,
19759 +       dev_t device, dev_t *target, int *flags, umode_t mode)
19760 +{
19761 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19762 +       struct vs_mapping *vdm, *global;
19763 +       struct vx_dmap_target *vdmt;
19764 +       int ret = 0;
19765 +       xid_t xid = vxi->vx_id;
19766 +       int index;
19767 +
19768 +       spin_lock(hash_lock);
19769 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
19770 +               ret = 1;
19771 +               vdmt = &vdm->target;
19772 +               goto found;
19773 +       }
19774 +
19775 +       index = __mode_to_default(mode);
19776 +       if (vxi && vxi->dmap.targets[index].flags) {
19777 +               ret = 2;
19778 +               vdmt = &vxi->dmap.targets[index];
19779 +       } else if (global) {
19780 +               ret = 3;
19781 +               vdmt = &global->target;
19782 +               goto found;
19783 +       } else {
19784 +               ret = 4;
19785 +               vdmt = &dmap_defaults[index];
19786 +       }
19787 +
19788 +found:
19789 +       if (target && (vdmt->flags & DATTR_REMAP))
19790 +               *target = vdmt->target;
19791 +       else if (target)
19792 +               *target = device;
19793 +       if (flags)
19794 +               *flags = vdmt->flags;
19795 +
19796 +       spin_unlock(hash_lock);
19797 +
19798 +       return ret;
19799 +}
19800 +
19801 +
19802 +/*     __remove_mapping()
19803 + *     remove a mapping from the hash table
19804 + */
19805 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
19806 +       umode_t mode)
19807 +{
19808 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19809 +       struct vs_mapping *vdm = NULL;
19810 +       int ret = 0;
19811 +
19812 +       spin_lock(hash_lock);
19813 +
19814 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
19815 +               NULL);
19816 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
19817 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
19818 +       if (ret < 0)
19819 +               goto out;
19820 +       hlist_del(&vdm->dm_hlist);
19821 +
19822 +out:
19823 +       spin_unlock(hash_lock);
19824 +       if (vdm)
19825 +               kmem_cache_free(dmap_cachep, vdm);
19826 +       return ret;
19827 +}
19828 +
19829 +
19830 +
19831 +int vs_map_device(struct vx_info *vxi,
19832 +       dev_t device, dev_t *target, umode_t mode)
19833 +{
19834 +       int ret, flags = DATTR_MASK;
19835 +
19836 +       if (!vxi) {
19837 +               if (target)
19838 +                       *target = device;
19839 +               goto out;
19840 +       }
19841 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
19842 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
19843 +               device, target ? *target : 0, flags, mode, ret);
19844 +out:
19845 +       return (flags & DATTR_MASK);
19846 +}
19847 +
19848 +
19849 +
19850 +static int do_set_mapping(struct vx_info *vxi,
19851 +       dev_t device, dev_t target, int flags, umode_t mode)
19852 +{
19853 +       if (device) {
19854 +               struct vs_mapping *new;
19855 +
19856 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
19857 +               if (!new)
19858 +                       return -ENOMEM;
19859 +
19860 +               INIT_HLIST_NODE(&new->dm_hlist);
19861 +               new->device = device;
19862 +               new->target.target = target;
19863 +               new->target.flags = flags | mode;
19864 +               new->xid = (vxi ? vxi->vx_id : 0);
19865 +
19866 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
19867 +               __hash_mapping(vxi, new);
19868 +       } else {
19869 +               struct vx_dmap_target new = {
19870 +                       .target = target,
19871 +                       .flags = flags | mode,
19872 +               };
19873 +               __set_default(vxi, mode, &new);
19874 +       }
19875 +       return 0;
19876 +}
19877 +
19878 +
19879 +static int do_unset_mapping(struct vx_info *vxi,
19880 +       dev_t device, dev_t target, int flags, umode_t mode)
19881 +{
19882 +       int ret = -EINVAL;
19883 +
19884 +       if (device) {
19885 +               ret = __remove_mapping(vxi, device, mode);
19886 +               if (ret < 0)
19887 +                       goto out;
19888 +       } else {
19889 +               ret = __remove_default(vxi, mode);
19890 +               if (ret < 0)
19891 +                       goto out;
19892 +       }
19893 +
19894 +out:
19895 +       return ret;
19896 +}
19897 +
19898 +
19899 +static inline int __user_device(const char __user *name, dev_t *dev,
19900 +       umode_t *mode)
19901 +{
19902 +       struct nameidata nd;
19903 +       int ret;
19904 +
19905 +       if (!name) {
19906 +               *dev = 0;
19907 +               return 0;
19908 +       }
19909 +       ret = user_path_walk_link(name, &nd);
19910 +       if (ret)
19911 +               return ret;
19912 +       if (nd.path.dentry->d_inode) {
19913 +               *dev = nd.path.dentry->d_inode->i_rdev;
19914 +               *mode = nd.path.dentry->d_inode->i_mode;
19915 +       }
19916 +       path_put(&nd.path);
19917 +       return 0;
19918 +}
19919 +
19920 +static inline int __mapping_mode(dev_t device, dev_t target,
19921 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
19922 +{
19923 +       if (device)
19924 +               *mode = device_mode & S_IFMT;
19925 +       else if (target)
19926 +               *mode = target_mode & S_IFMT;
19927 +       else
19928 +               return -EINVAL;
19929 +
19930 +       /* if both given, device and target mode have to match */
19931 +       if (device && target &&
19932 +               ((device_mode ^ target_mode) & S_IFMT))
19933 +               return -EINVAL;
19934 +       return 0;
19935 +}
19936 +
19937 +
19938 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
19939 +       const char __user *target_path, int flags, int set)
19940 +{
19941 +       dev_t device = ~0, target = ~0;
19942 +       umode_t device_mode = 0, target_mode = 0, mode;
19943 +       int ret;
19944 +
19945 +       ret = __user_device(device_path, &device, &device_mode);
19946 +       if (ret)
19947 +               return ret;
19948 +       ret = __user_device(target_path, &target, &target_mode);
19949 +       if (ret)
19950 +               return ret;
19951 +
19952 +       ret = __mapping_mode(device, target,
19953 +               device_mode, target_mode, &mode);
19954 +       if (ret)
19955 +               return ret;
19956 +
19957 +       if (set)
19958 +               return do_set_mapping(vxi, device, target,
19959 +                       flags, mode);
19960 +       else
19961 +               return do_unset_mapping(vxi, device, target,
19962 +                       flags, mode);
19963 +}
19964 +
19965 +
19966 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
19967 +{
19968 +       struct vcmd_set_mapping_v0 vc_data;
19969 +
19970 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19971 +               return -EFAULT;
19972 +
19973 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19974 +               vc_data.flags, 1);
19975 +}
19976 +
19977 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
19978 +{
19979 +       struct vcmd_set_mapping_v0 vc_data;
19980 +
19981 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19982 +               return -EFAULT;
19983 +
19984 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19985 +               vc_data.flags, 0);
19986 +}
19987 +
19988 +
19989 +#ifdef CONFIG_COMPAT
19990 +
19991 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
19992 +{
19993 +       struct vcmd_set_mapping_v0_x32 vc_data;
19994 +
19995 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19996 +               return -EFAULT;
19997 +
19998 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19999 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
20000 +}
20001 +
20002 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
20003 +{
20004 +       struct vcmd_set_mapping_v0_x32 vc_data;
20005 +
20006 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20007 +               return -EFAULT;
20008 +
20009 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
20010 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
20011 +}
20012 +
20013 +#endif /* CONFIG_COMPAT */
20014 +
20015 +
20016 diff -NurpP --minimal linux-2.6.25/kernel/vserver/dlimit.c linux-2.6.25-vs2.3.0.34.9/kernel/vserver/dlimit.c
20017 --- linux-2.6.25/kernel/vserver/dlimit.c        1969-12-31 19:00:00.000000000 -0500
20018 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/dlimit.c   2008-04-21 12:36:09.000000000 -0400
20019 @@ -0,0 +1,521 @@
20020 +/*
20021 + *  linux/kernel/vserver/dlimit.c
20022 + *
20023 + *  Virtual Server: Context Disk Limits
20024 + *
20025 + *  Copyright (C) 2004-2007  Herbert Pötzl
20026 + *
20027 + *  V0.01  initial version
20028 + *  V0.02  compat32 splitup
20029 + *
20030 + */
20031 +
20032 +#include <linux/statfs.h>
20033 +#include <linux/sched.h>
20034 +#include <linux/vs_tag.h>
20035 +#include <linux/vs_dlimit.h>
20036 +#include <linux/vserver/dlimit_cmd.h>
20037 +
20038 +#include <asm/uaccess.h>
20039 +
20040 +/*     __alloc_dl_info()
20041 +
20042 +       * allocate an initialized dl_info struct
20043 +       * doesn't make it visible (hash)                        */
20044 +
20045 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
20046 +{
20047 +       struct dl_info *new = NULL;
20048 +
20049 +       vxdprintk(VXD_CBIT(dlim, 5),
20050 +               "alloc_dl_info(%p,%d)*", sb, tag);
20051 +
20052 +       /* would this benefit from a slab cache? */
20053 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
20054 +       if (!new)
20055 +               return 0;
20056 +
20057 +       memset(new, 0, sizeof(struct dl_info));
20058 +       new->dl_tag = tag;
20059 +       new->dl_sb = sb;
20060 +       INIT_RCU_HEAD(&new->dl_rcu);
20061 +       INIT_HLIST_NODE(&new->dl_hlist);
20062 +       spin_lock_init(&new->dl_lock);
20063 +       atomic_set(&new->dl_refcnt, 0);
20064 +       atomic_set(&new->dl_usecnt, 0);
20065 +
20066 +       /* rest of init goes here */
20067 +
20068 +       vxdprintk(VXD_CBIT(dlim, 4),
20069 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
20070 +       return new;
20071 +}
20072 +
20073 +/*     __dealloc_dl_info()
20074 +
20075 +       * final disposal of dl_info                             */
20076 +
20077 +static void __dealloc_dl_info(struct dl_info *dli)
20078 +{
20079 +       vxdprintk(VXD_CBIT(dlim, 4),
20080 +               "dealloc_dl_info(%p)", dli);
20081 +
20082 +       dli->dl_hlist.next = LIST_POISON1;
20083 +       dli->dl_tag = -1;
20084 +       dli->dl_sb = 0;
20085 +
20086 +       BUG_ON(atomic_read(&dli->dl_usecnt));
20087 +       BUG_ON(atomic_read(&dli->dl_refcnt));
20088 +
20089 +       kfree(dli);
20090 +}
20091 +
20092 +
20093 +/*     hash table for dl_info hash */
20094 +
20095 +#define DL_HASH_SIZE   13
20096 +
20097 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
20098 +
20099 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
20100 +
20101 +
20102 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
20103 +{
20104 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
20105 +}
20106 +
20107 +
20108 +
20109 +/*     __hash_dl_info()
20110 +
20111 +       * add the dli to the global hash table
20112 +       * requires the hash_lock to be held                     */
20113 +
20114 +static inline void __hash_dl_info(struct dl_info *dli)
20115 +{
20116 +       struct hlist_head *head;
20117 +
20118 +       vxdprintk(VXD_CBIT(dlim, 6),
20119 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
20120 +       get_dl_info(dli);
20121 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
20122 +       hlist_add_head_rcu(&dli->dl_hlist, head);
20123 +}
20124 +
20125 +/*     __unhash_dl_info()
20126 +
20127 +       * remove the dli from the global hash table
20128 +       * requires the hash_lock to be held                     */
20129 +
20130 +static inline void __unhash_dl_info(struct dl_info *dli)
20131 +{
20132 +       vxdprintk(VXD_CBIT(dlim, 6),
20133 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
20134 +       hlist_del_rcu(&dli->dl_hlist);
20135 +       put_dl_info(dli);
20136 +}
20137 +
20138 +
20139 +/*     __lookup_dl_info()
20140 +
20141 +       * requires the rcu_read_lock()
20142 +       * doesn't increment the dl_refcnt                       */
20143 +
20144 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
20145 +{
20146 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
20147 +       struct hlist_node *pos;
20148 +       struct dl_info *dli;
20149 +
20150 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
20151 +
20152 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
20153 +                       return dli;
20154 +               }
20155 +       }
20156 +       return NULL;
20157 +}
20158 +
20159 +
20160 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
20161 +{
20162 +       struct dl_info *dli;
20163 +
20164 +       rcu_read_lock();
20165 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
20166 +       vxdprintk(VXD_CBIT(dlim, 7),
20167 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
20168 +       rcu_read_unlock();
20169 +       return dli;
20170 +}
20171 +
20172 +void rcu_free_dl_info(struct rcu_head *head)
20173 +{
20174 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
20175 +       int usecnt, refcnt;
20176 +
20177 +       BUG_ON(!dli || !head);
20178 +
20179 +       usecnt = atomic_read(&dli->dl_usecnt);
20180 +       BUG_ON(usecnt < 0);
20181 +
20182 +       refcnt = atomic_read(&dli->dl_refcnt);
20183 +       BUG_ON(refcnt < 0);
20184 +
20185 +       vxdprintk(VXD_CBIT(dlim, 3),
20186 +               "rcu_free_dl_info(%p)", dli);
20187 +       if (!usecnt)
20188 +               __dealloc_dl_info(dli);
20189 +       else
20190 +               printk("!!! rcu didn't free\n");
20191 +}
20192 +
20193 +
20194 +
20195 +
20196 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
20197 +       uint32_t flags, int add)
20198 +{
20199 +       struct nameidata nd;
20200 +       int ret;
20201 +
20202 +       ret = user_path_walk_link(name, &nd);
20203 +       if (!ret) {
20204 +               struct super_block *sb;
20205 +               struct dl_info *dli;
20206 +
20207 +               ret = -EINVAL;
20208 +               if (!nd.path.dentry->d_inode)
20209 +                       goto out_release;
20210 +               if (!(sb = nd.path.dentry->d_inode->i_sb))
20211 +                       goto out_release;
20212 +
20213 +               if (add) {
20214 +                       dli = __alloc_dl_info(sb, id);
20215 +                       spin_lock(&dl_info_hash_lock);
20216 +
20217 +                       ret = -EEXIST;
20218 +                       if (__lookup_dl_info(sb, id))
20219 +                               goto out_unlock;
20220 +                       __hash_dl_info(dli);
20221 +                       dli = NULL;
20222 +               } else {
20223 +                       spin_lock(&dl_info_hash_lock);
20224 +                       dli = __lookup_dl_info(sb, id);
20225 +
20226 +                       ret = -ESRCH;
20227 +                       if (!dli)
20228 +                               goto out_unlock;
20229 +                       __unhash_dl_info(dli);
20230 +               }
20231 +               ret = 0;
20232 +       out_unlock:
20233 +               spin_unlock(&dl_info_hash_lock);
20234 +               if (add && dli)
20235 +                       __dealloc_dl_info(dli);
20236 +       out_release:
20237 +               path_put(&nd.path);
20238 +       }
20239 +       return ret;
20240 +}
20241 +
20242 +int vc_add_dlimit(uint32_t id, void __user *data)
20243 +{
20244 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
20245 +
20246 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20247 +               return -EFAULT;
20248 +
20249 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
20250 +}
20251 +
20252 +int vc_rem_dlimit(uint32_t id, void __user *data)
20253 +{
20254 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
20255 +
20256 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20257 +               return -EFAULT;
20258 +
20259 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
20260 +}
20261 +
20262 +#ifdef CONFIG_COMPAT
20263 +
20264 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
20265 +{
20266 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
20267 +
20268 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20269 +               return -EFAULT;
20270 +
20271 +       return do_addrem_dlimit(id,
20272 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
20273 +}
20274 +
20275 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
20276 +{
20277 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
20278 +
20279 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20280 +               return -EFAULT;
20281 +
20282 +       return do_addrem_dlimit(id,
20283 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
20284 +}
20285 +
20286 +#endif /* CONFIG_COMPAT */
20287 +
20288 +
20289 +static inline
20290 +int do_set_dlimit(uint32_t id, const char __user *name,
20291 +       uint32_t space_used, uint32_t space_total,
20292 +       uint32_t inodes_used, uint32_t inodes_total,
20293 +       uint32_t reserved, uint32_t flags)
20294 +{
20295 +       struct nameidata nd;
20296 +       int ret;
20297 +
20298 +       ret = user_path_walk_link(name, &nd);
20299 +       if (!ret) {
20300 +               struct super_block *sb;
20301 +               struct dl_info *dli;
20302 +
20303 +               ret = -EINVAL;
20304 +               if (!nd.path.dentry->d_inode)
20305 +                       goto out_release;
20306 +               if (!(sb = nd.path.dentry->d_inode->i_sb))
20307 +                       goto out_release;
20308 +               if ((reserved != CDLIM_KEEP &&
20309 +                       reserved > 100) ||
20310 +                       (inodes_used != CDLIM_KEEP &&
20311 +                       inodes_used > inodes_total) ||
20312 +                       (space_used != CDLIM_KEEP &&
20313 +                       space_used > space_total))
20314 +                       goto out_release;
20315 +
20316 +               ret = -ESRCH;
20317 +               dli = locate_dl_info(sb, id);
20318 +               if (!dli)
20319 +                       goto out_release;
20320 +
20321 +               spin_lock(&dli->dl_lock);
20322 +
20323 +               if (inodes_used != CDLIM_KEEP)
20324 +                       dli->dl_inodes_used = inodes_used;
20325 +               if (inodes_total != CDLIM_KEEP)
20326 +                       dli->dl_inodes_total = inodes_total;
20327 +               if (space_used != CDLIM_KEEP) {
20328 +                       dli->dl_space_used = space_used;
20329 +                       dli->dl_space_used <<= 10;
20330 +               }
20331 +               if (space_total == CDLIM_INFINITY)
20332 +                       dli->dl_space_total = DLIM_INFINITY;
20333 +               else if (space_total != CDLIM_KEEP) {
20334 +                       dli->dl_space_total = space_total;
20335 +                       dli->dl_space_total <<= 10;
20336 +               }
20337 +               if (reserved != CDLIM_KEEP)
20338 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
20339 +
20340 +               spin_unlock(&dli->dl_lock);
20341 +
20342 +               put_dl_info(dli);
20343 +               ret = 0;
20344 +
20345 +       out_release:
20346 +               path_put(&nd.path);
20347 +       }
20348 +       return ret;
20349 +}
20350 +
20351 +int vc_set_dlimit(uint32_t id, void __user *data)
20352 +{
20353 +       struct vcmd_ctx_dlimit_v0 vc_data;
20354 +
20355 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20356 +               return -EFAULT;
20357 +
20358 +       return do_set_dlimit(id, vc_data.name,
20359 +               vc_data.space_used, vc_data.space_total,
20360 +               vc_data.inodes_used, vc_data.inodes_total,
20361 +               vc_data.reserved, vc_data.flags);
20362 +}
20363 +
20364 +#ifdef CONFIG_COMPAT
20365 +
20366 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
20367 +{
20368 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
20369 +
20370 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20371 +               return -EFAULT;
20372 +
20373 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
20374 +               vc_data.space_used, vc_data.space_total,
20375 +               vc_data.inodes_used, vc_data.inodes_total,
20376 +               vc_data.reserved, vc_data.flags);
20377 +}
20378 +
20379 +#endif /* CONFIG_COMPAT */
20380 +
20381 +
20382 +static inline
20383 +int do_get_dlimit(uint32_t id, const char __user *name,
20384 +       uint32_t *space_used, uint32_t *space_total,
20385 +       uint32_t *inodes_used, uint32_t *inodes_total,
20386 +       uint32_t *reserved, uint32_t *flags)
20387 +{
20388 +       struct nameidata nd;
20389 +       int ret;
20390 +
20391 +       ret = user_path_walk_link(name, &nd);
20392 +       if (!ret) {
20393 +               struct super_block *sb;
20394 +               struct dl_info *dli;
20395 +
20396 +               ret = -EINVAL;
20397 +               if (!nd.path.dentry->d_inode)
20398 +                       goto out_release;
20399 +               if (!(sb = nd.path.dentry->d_inode->i_sb))
20400 +                       goto out_release;
20401 +
20402 +               ret = -ESRCH;
20403 +               dli = locate_dl_info(sb, id);
20404 +               if (!dli)
20405 +                       goto out_release;
20406 +
20407 +               spin_lock(&dli->dl_lock);
20408 +               *inodes_used = dli->dl_inodes_used;
20409 +               *inodes_total = dli->dl_inodes_total;
20410 +               *space_used = dli->dl_space_used >> 10;
20411 +               if (dli->dl_space_total == DLIM_INFINITY)
20412 +                       *space_total = CDLIM_INFINITY;
20413 +               else
20414 +                       *space_total = dli->dl_space_total >> 10;
20415 +
20416 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
20417 +               spin_unlock(&dli->dl_lock);
20418 +
20419 +               put_dl_info(dli);
20420 +               ret = -EFAULT;
20421 +
20422 +               ret = 0;
20423 +       out_release:
20424 +               path_put(&nd.path);
20425 +       }
20426 +       return ret;
20427 +}
20428 +
20429 +
20430 +int vc_get_dlimit(uint32_t id, void __user *data)
20431 +{
20432 +       struct vcmd_ctx_dlimit_v0 vc_data;
20433 +       int ret;
20434 +
20435 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20436 +               return -EFAULT;
20437 +
20438 +       ret = do_get_dlimit(id, vc_data.name,
20439 +               &vc_data.space_used, &vc_data.space_total,
20440 +               &vc_data.inodes_used, &vc_data.inodes_total,
20441 +               &vc_data.reserved, &vc_data.flags);
20442 +       if (ret)
20443 +               return ret;
20444 +
20445 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20446 +               return -EFAULT;
20447 +       return 0;
20448 +}
20449 +
20450 +#ifdef CONFIG_COMPAT
20451 +
20452 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
20453 +{
20454 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
20455 +       int ret;
20456 +
20457 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20458 +               return -EFAULT;
20459 +
20460 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
20461 +               &vc_data.space_used, &vc_data.space_total,
20462 +               &vc_data.inodes_used, &vc_data.inodes_total,
20463 +               &vc_data.reserved, &vc_data.flags);
20464 +       if (ret)
20465 +               return ret;
20466 +
20467 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20468 +               return -EFAULT;
20469 +       return 0;
20470 +}
20471 +
20472 +#endif /* CONFIG_COMPAT */
20473 +
20474 +
20475 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
20476 +{
20477 +       struct dl_info *dli;
20478 +       __u64 blimit, bfree, bavail;
20479 +       __u32 ifree;
20480 +
20481 +       dli = locate_dl_info(sb, dx_current_tag());
20482 +       if (!dli)
20483 +               return;
20484 +
20485 +       spin_lock(&dli->dl_lock);
20486 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
20487 +               goto no_ilim;
20488 +
20489 +       /* reduce max inodes available to limit */
20490 +       if (buf->f_files > dli->dl_inodes_total)
20491 +               buf->f_files = dli->dl_inodes_total;
20492 +
20493 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
20494 +       /* reduce free inodes to min */
20495 +       if (ifree < buf->f_ffree)
20496 +               buf->f_ffree = ifree;
20497 +
20498 +no_ilim:
20499 +       if (dli->dl_space_total == DLIM_INFINITY)
20500 +               goto no_blim;
20501 +
20502 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
20503 +
20504 +       if (dli->dl_space_total < dli->dl_space_used)
20505 +               bfree = 0;
20506 +       else
20507 +               bfree = (dli->dl_space_total - dli->dl_space_used)
20508 +                       >> sb->s_blocksize_bits;
20509 +
20510 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
20511 +       if (bavail < dli->dl_space_used)
20512 +               bavail = 0;
20513 +       else
20514 +               bavail = (bavail - dli->dl_space_used)
20515 +                       >> sb->s_blocksize_bits;
20516 +
20517 +       /* reduce max space available to limit */
20518 +       if (buf->f_blocks > blimit)
20519 +               buf->f_blocks = blimit;
20520 +
20521 +       /* reduce free space to min */
20522 +       if (bfree < buf->f_bfree)
20523 +               buf->f_bfree = bfree;
20524 +
20525 +       /* reduce avail space to min */
20526 +       if (bavail < buf->f_bavail)
20527 +               buf->f_bavail = bavail;
20528 +
20529 +no_blim:
20530 +       spin_unlock(&dli->dl_lock);
20531 +       put_dl_info(dli);
20532 +
20533 +       return;
20534 +}
20535 +
20536 +#include <linux/module.h>
20537 +
20538 +EXPORT_SYMBOL_GPL(locate_dl_info);
20539 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
20540 +
20541 diff -NurpP --minimal linux-2.6.25/kernel/vserver/helper.c linux-2.6.25-vs2.3.0.34.9/kernel/vserver/helper.c
20542 --- linux-2.6.25/kernel/vserver/helper.c        1969-12-31 19:00:00.000000000 -0500
20543 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/helper.c   2008-04-19 15:14:52.000000000 -0400
20544 @@ -0,0 +1,199 @@
20545 +/*
20546 + *  linux/kernel/vserver/helper.c
20547 + *
20548 + *  Virtual Context Support
20549 + *
20550 + *  Copyright (C) 2004-2007  Herbert Pötzl
20551 + *
20552 + *  V0.01  basic helper
20553 + *
20554 + */
20555 +
20556 +#include <linux/kmod.h>
20557 +#include <linux/reboot.h>
20558 +#include <linux/vs_context.h>
20559 +#include <linux/vs_network.h>
20560 +#include <linux/vserver/signal.h>
20561 +
20562 +
20563 +char vshelper_path[255] = "/sbin/vshelper";
20564 +
20565 +
20566 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
20567 +{
20568 +       int ret;
20569 +
20570 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
20571 +               printk( KERN_WARNING
20572 +                       "%s: (%s %s) returned %s with %d\n",
20573 +                       name, argv[1], argv[2],
20574 +                       sync ? "sync" : "async", ret);
20575 +       }
20576 +       vxdprintk(VXD_CBIT(switch, 4),
20577 +               "%s: (%s %s) returned %s with %d",
20578 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
20579 +       return ret;
20580 +}
20581 +
20582 +/*
20583 + *      vshelper path is set via /proc/sys
20584 + *      invoked by vserver sys_reboot(), with
20585 + *      the following arguments
20586 + *
20587 + *      argv [0] = vshelper_path;
20588 + *      argv [1] = action: "restart", "halt", "poweroff", ...
20589 + *      argv [2] = context identifier
20590 + *
20591 + *      envp [*] = type-specific parameters
20592 + */
20593 +
20594 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
20595 +{
20596 +       char id_buf[8], cmd_buf[16];
20597 +       char uid_buf[16], pid_buf[16];
20598 +       int ret;
20599 +
20600 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20601 +       char *envp[] = {"HOME=/", "TERM=linux",
20602 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
20603 +                       uid_buf, pid_buf, cmd_buf, 0};
20604 +
20605 +       if (vx_info_state(vxi, VXS_HELPER))
20606 +               return -EAGAIN;
20607 +       vxi->vx_state |= VXS_HELPER;
20608 +
20609 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20610 +
20611 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20612 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current->uid);
20613 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
20614 +
20615 +       switch (cmd) {
20616 +       case LINUX_REBOOT_CMD_RESTART:
20617 +               argv[1] = "restart";
20618 +               break;
20619 +
20620 +       case LINUX_REBOOT_CMD_HALT:
20621 +               argv[1] = "halt";
20622 +               break;
20623 +
20624 +       case LINUX_REBOOT_CMD_POWER_OFF:
20625 +               argv[1] = "poweroff";
20626 +               break;
20627 +
20628 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
20629 +               argv[1] = "swsusp";
20630 +               break;
20631 +
20632 +       default:
20633 +               vxi->vx_state &= ~VXS_HELPER;
20634 +               return 0;
20635 +       }
20636 +
20637 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
20638 +       vxi->vx_state &= ~VXS_HELPER;
20639 +       __wakeup_vx_info(vxi);
20640 +       return (ret) ? -EPERM : 0;
20641 +}
20642 +
20643 +
20644 +long vs_reboot(unsigned int cmd, void __user *arg)
20645 +{
20646 +       struct vx_info *vxi = current->vx_info;
20647 +       long ret = 0;
20648 +
20649 +       vxdprintk(VXD_CBIT(misc, 5),
20650 +               "vs_reboot(%p[#%d],%d)",
20651 +               vxi, vxi ? vxi->vx_id : 0, cmd);
20652 +
20653 +       ret = vs_reboot_helper(vxi, cmd, arg);
20654 +       if (ret)
20655 +               return ret;
20656 +
20657 +       vxi->reboot_cmd = cmd;
20658 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
20659 +               switch (cmd) {
20660 +               case LINUX_REBOOT_CMD_RESTART:
20661 +               case LINUX_REBOOT_CMD_HALT:
20662 +               case LINUX_REBOOT_CMD_POWER_OFF:
20663 +                       vx_info_kill(vxi, 0, SIGKILL);
20664 +                       vx_info_kill(vxi, 1, SIGKILL);
20665 +               default:
20666 +                       break;
20667 +               }
20668 +       }
20669 +       return 0;
20670 +}
20671 +
20672 +
20673 +/*
20674 + *      argv [0] = vshelper_path;
20675 + *      argv [1] = action: "startup", "shutdown"
20676 + *      argv [2] = context identifier
20677 + *
20678 + *      envp [*] = type-specific parameters
20679 + */
20680 +
20681 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
20682 +{
20683 +       char id_buf[8], cmd_buf[16];
20684 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20685 +       char *envp[] = {"HOME=/", "TERM=linux",
20686 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20687 +
20688 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
20689 +               return 0;
20690 +
20691 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20692 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20693 +
20694 +       switch (cmd) {
20695 +       case VSC_STARTUP:
20696 +               argv[1] = "startup";
20697 +               break;
20698 +       case VSC_SHUTDOWN:
20699 +               argv[1] = "shutdown";
20700 +               break;
20701 +       default:
20702 +               return 0;
20703 +       }
20704 +
20705 +       return do_vshelper(vshelper_path, argv, envp, 1);
20706 +}
20707 +
20708 +
20709 +/*
20710 + *      argv [0] = vshelper_path;
20711 + *      argv [1] = action: "netup", "netdown"
20712 + *      argv [2] = context identifier
20713 + *
20714 + *      envp [*] = type-specific parameters
20715 + */
20716 +
20717 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
20718 +{
20719 +       char id_buf[8], cmd_buf[16];
20720 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20721 +       char *envp[] = {"HOME=/", "TERM=linux",
20722 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20723 +
20724 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
20725 +               return 0;
20726 +
20727 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
20728 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20729 +
20730 +       switch (cmd) {
20731 +       case VSC_NETUP:
20732 +               argv[1] = "netup";
20733 +               break;
20734 +       case VSC_NETDOWN:
20735 +               argv[1] = "netdown";
20736 +               break;
20737 +       default:
20738 +               return 0;
20739 +       }
20740 +
20741 +       return do_vshelper(vshelper_path, argv, envp, 1);
20742 +}
20743 +
20744 diff -NurpP --minimal linux-2.6.25/kernel/vserver/history.c linux-2.6.25-vs2.3.0.34.9/kernel/vserver/history.c
20745 --- linux-2.6.25/kernel/vserver/history.c       1969-12-31 19:00:00.000000000 -0500
20746 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/history.c  2008-04-19 15:14:52.000000000 -0400
20747 @@ -0,0 +1,258 @@
20748 +/*
20749 + *  kernel/vserver/history.c
20750 + *
20751 + *  Virtual Context History Backtrace
20752 + *
20753 + *  Copyright (C) 2004-2007  Herbert Pötzl
20754 + *
20755 + *  V0.01  basic structure
20756 + *  V0.02  hash/unhash and trace
20757 + *  V0.03  preemption fixes
20758 + *
20759 + */
20760 +
20761 +#include <linux/module.h>
20762 +#include <asm/uaccess.h>
20763 +
20764 +#include <linux/vserver/context.h>
20765 +#include <linux/vserver/debug.h>
20766 +#include <linux/vserver/debug_cmd.h>
20767 +#include <linux/vserver/history.h>
20768 +
20769 +
20770 +#ifdef CONFIG_VSERVER_HISTORY
20771 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
20772 +#else
20773 +#define VXH_SIZE       64
20774 +#endif
20775 +
20776 +struct _vx_history {
20777 +       unsigned int counter;
20778 +
20779 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
20780 +};
20781 +
20782 +
20783 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
20784 +
20785 +unsigned volatile int vxh_active = 1;
20786 +
20787 +static atomic_t sequence = ATOMIC_INIT(0);
20788 +
20789 +
20790 +/*     vxh_advance()
20791 +
20792 +       * requires disabled preemption                          */
20793 +
20794 +struct _vx_hist_entry *vxh_advance(void *loc)
20795 +{
20796 +       unsigned int cpu = smp_processor_id();
20797 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20798 +       struct _vx_hist_entry *entry;
20799 +       unsigned int index;
20800 +
20801 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
20802 +       entry = &hist->entry[index];
20803 +
20804 +       entry->seq = atomic_inc_return(&sequence);
20805 +       entry->loc = loc;
20806 +       return entry;
20807 +}
20808 +
20809 +EXPORT_SYMBOL_GPL(vxh_advance);
20810 +
20811 +
20812 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
20813 +
20814 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
20815 +
20816 +
20817 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
20818 +
20819 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
20820 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
20821 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
20822 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
20823 +
20824 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
20825 +{
20826 +       switch (e->type) {
20827 +       case VXH_THROW_OOPS:
20828 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
20829 +               break;
20830 +
20831 +       case VXH_GET_VX_INFO:
20832 +       case VXH_PUT_VX_INFO:
20833 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20834 +                       VXH_LOC_ARGS(e),
20835 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
20836 +                       VXH_VXI_ARGS(e));
20837 +               break;
20838 +
20839 +       case VXH_INIT_VX_INFO:
20840 +       case VXH_SET_VX_INFO:
20841 +       case VXH_CLR_VX_INFO:
20842 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20843 +                       VXH_LOC_ARGS(e),
20844 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
20845 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
20846 +                       VXH_VXI_ARGS(e), e->sc.data);
20847 +               break;
20848 +
20849 +       case VXH_CLAIM_VX_INFO:
20850 +       case VXH_RELEASE_VX_INFO:
20851 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20852 +                       VXH_LOC_ARGS(e),
20853 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
20854 +                       VXH_VXI_ARGS(e), e->sc.data);
20855 +               break;
20856 +
20857 +       case VXH_ALLOC_VX_INFO:
20858 +       case VXH_DEALLOC_VX_INFO:
20859 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20860 +                       VXH_LOC_ARGS(e),
20861 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
20862 +                       VXH_VXI_ARGS(e));
20863 +               break;
20864 +
20865 +       case VXH_HASH_VX_INFO:
20866 +       case VXH_UNHASH_VX_INFO:
20867 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
20868 +                       VXH_LOC_ARGS(e),
20869 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
20870 +                       VXH_VXI_ARGS(e));
20871 +               break;
20872 +
20873 +       case VXH_LOC_VX_INFO:
20874 +       case VXH_LOOKUP_VX_INFO:
20875 +       case VXH_CREATE_VX_INFO:
20876 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
20877 +                       VXH_LOC_ARGS(e),
20878 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
20879 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
20880 +                       e->ll.arg, VXH_VXI_ARGS(e));
20881 +               break;
20882 +       }
20883 +}
20884 +
20885 +static void __vxh_dump_history(void)
20886 +{
20887 +       unsigned int i, cpu;
20888 +
20889 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
20890 +               atomic_read(&sequence), NR_CPUS);
20891 +
20892 +       for (i = 0; i < VXH_SIZE; i++) {
20893 +               for_each_online_cpu(cpu) {
20894 +                       struct _vx_history *hist =
20895 +                               &per_cpu(vx_history_buffer, cpu);
20896 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
20897 +                       struct _vx_hist_entry *entry = &hist->entry[index];
20898 +
20899 +                       vxh_dump_entry(entry, cpu);
20900 +               }
20901 +       }
20902 +}
20903 +
20904 +void   vxh_dump_history(void)
20905 +{
20906 +       vxh_active = 0;
20907 +#ifdef CONFIG_SMP
20908 +       local_irq_enable();
20909 +       smp_send_stop();
20910 +       local_irq_disable();
20911 +#endif
20912 +       __vxh_dump_history();
20913 +}
20914 +
20915 +
20916 +/* vserver syscall commands below here */
20917 +
20918 +
20919 +int vc_dump_history(uint32_t id)
20920 +{
20921 +       vxh_active = 0;
20922 +       __vxh_dump_history();
20923 +       vxh_active = 1;
20924 +
20925 +       return 0;
20926 +}
20927 +
20928 +
20929 +int do_read_history(struct __user _vx_hist_entry *data,
20930 +       int cpu, uint32_t *index, uint32_t *count)
20931 +{
20932 +       int pos, ret = 0;
20933 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20934 +       int end = hist->counter;
20935 +       int start = end - VXH_SIZE + 2;
20936 +       int idx = *index;
20937 +
20938 +       /* special case: get current pos */
20939 +       if (!*count) {
20940 +               *index = end;
20941 +               return 0;
20942 +       }
20943 +
20944 +       /* have we lost some data? */
20945 +       if (idx < start)
20946 +               idx = start;
20947 +
20948 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
20949 +               struct _vx_hist_entry *entry =
20950 +                       &hist->entry[idx % VXH_SIZE];
20951 +
20952 +               /* send entry to userspace */
20953 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
20954 +               if (ret)
20955 +                       break;
20956 +       }
20957 +       /* save new index and count */
20958 +       *index = idx;
20959 +       *count = pos;
20960 +       return ret ? ret : (*index < end);
20961 +}
20962 +
20963 +int vc_read_history(uint32_t id, void __user *data)
20964 +{
20965 +       struct vcmd_read_history_v0 vc_data;
20966 +       int ret;
20967 +
20968 +       if (id >= NR_CPUS)
20969 +               return -EINVAL;
20970 +
20971 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20972 +               return -EFAULT;
20973 +
20974 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
20975 +               id, &vc_data.index, &vc_data.count);
20976 +
20977 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20978 +               return -EFAULT;
20979 +       return ret;
20980 +}
20981 +
20982 +#ifdef CONFIG_COMPAT
20983 +
20984 +int vc_read_history_x32(uint32_t id, void __user *data)
20985 +{
20986 +       struct vcmd_read_history_v0_x32 vc_data;
20987 +       int ret;
20988 +
20989 +       if (id >= NR_CPUS)
20990 +               return -EINVAL;
20991 +
20992 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20993 +               return -EFAULT;
20994 +
20995 +       ret = do_read_history((struct __user _vx_hist_entry *)
20996 +               compat_ptr(vc_data.data_ptr),
20997 +               id, &vc_data.index, &vc_data.count);
20998 +
20999 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21000 +               return -EFAULT;
21001 +       return ret;
21002 +}
21003 +
21004 +#endif /* CONFIG_COMPAT */
21005 +
21006 diff -NurpP --minimal linux-2.6.25/kernel/vserver/inet.c linux-2.6.25-vs2.3.0.34.9/kernel/vserver/inet.c
21007 --- linux-2.6.25/kernel/vserver/inet.c  1969-12-31 19:00:00.000000000 -0500
21008 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/inet.c     2008-04-21 12:49:53.000000000 -0400
21009 @@ -0,0 +1,225 @@
21010 +
21011 +#include <linux/in.h>
21012 +#include <linux/inetdevice.h>
21013 +#include <linux/vs_inet.h>
21014 +#include <linux/vs_inet6.h>
21015 +#include <linux/vserver/debug.h>
21016 +#include <net/route.h>
21017 +#include <net/addrconf.h>
21018 +
21019 +
21020 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
21021 +{
21022 +       int ret = 0;
21023 +
21024 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
21025 +               ret = 1;
21026 +       else {
21027 +               struct nx_addr_v4 *ptr;
21028 +
21029 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
21030 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
21031 +                               ret = 1;
21032 +                               break;
21033 +                       }
21034 +               }
21035 +       }
21036 +
21037 +       vxdprintk(VXD_CBIT(net, 2),
21038 +               "nx_v4_addr_conflict(%p,%p): %d",
21039 +               nxi1, nxi2, ret);
21040 +
21041 +       return ret;
21042 +}
21043 +
21044 +
21045 +#ifdef CONFIG_IPV6
21046 +
21047 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
21048 +{
21049 +       int ret = 0;
21050 +
21051 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
21052 +               ret = 1;
21053 +       else {
21054 +               struct nx_addr_v6 *ptr;
21055 +
21056 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
21057 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
21058 +                               ret = 1;
21059 +                               break;
21060 +                       }
21061 +               }
21062 +       }
21063 +
21064 +       vxdprintk(VXD_CBIT(net, 2),
21065 +               "nx_v6_addr_conflict(%p,%p): %d",
21066 +               nxi1, nxi2, ret);
21067 +
21068 +       return ret;
21069 +}
21070 +
21071 +#endif
21072 +
21073 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
21074 +{
21075 +       struct in_device *in_dev;
21076 +       struct in_ifaddr **ifap;
21077 +       struct in_ifaddr *ifa;
21078 +       int ret = 0;
21079 +
21080 +       if (!dev)
21081 +               goto out;
21082 +       in_dev = in_dev_get(dev);
21083 +       if (!in_dev)
21084 +               goto out;
21085 +
21086 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
21087 +               ifap = &ifa->ifa_next) {
21088 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
21089 +                       ret = 1;
21090 +                       break;
21091 +               }
21092 +       }
21093 +       in_dev_put(in_dev);
21094 +out:
21095 +       return ret;
21096 +}
21097 +
21098 +
21099 +#ifdef CONFIG_IPV6
21100 +
21101 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
21102 +{
21103 +       struct inet6_dev *in_dev;
21104 +       struct inet6_ifaddr **ifap;
21105 +       struct inet6_ifaddr *ifa;
21106 +       int ret = 0;
21107 +
21108 +       if (!dev)
21109 +               goto out;
21110 +       in_dev = in6_dev_get(dev);
21111 +       if (!in_dev)
21112 +               goto out;
21113 +
21114 +       for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
21115 +               ifap = &ifa->if_next) {
21116 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
21117 +                       ret = 1;
21118 +                       break;
21119 +               }
21120 +       }
21121 +       in6_dev_put(in_dev);
21122 +out:
21123 +       return ret;
21124 +}
21125 +
21126 +#endif
21127 +
21128 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
21129 +{
21130 +       int ret = 1;
21131 +
21132 +       if (!nxi)
21133 +               goto out;
21134 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
21135 +               goto out;
21136 +#ifdef CONFIG_IPV6
21137 +       ret = 2;
21138 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
21139 +               goto out;
21140 +#endif
21141 +       ret = 0;
21142 +out:
21143 +       vxdprintk(VXD_CBIT(net, 3),
21144 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
21145 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
21146 +       return ret;
21147 +}
21148 +
21149 +int ip_v4_find_src(struct net *net, struct nx_info *nxi,
21150 +       struct rtable **rp, struct flowi *fl)
21151 +{
21152 +       if (!nxi)
21153 +               return 0;
21154 +
21155 +       /* FIXME: handle lback only case */
21156 +       if (!NX_IPV4(nxi))
21157 +               return -EPERM;
21158 +
21159 +       vxdprintk(VXD_CBIT(net, 4),
21160 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
21161 +               nxi, nxi ? nxi->nx_id : 0,
21162 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
21163 +
21164 +       /* single IP is unconditional */
21165 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
21166 +               (fl->fl4_src == INADDR_ANY))
21167 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
21168 +
21169 +       if (fl->fl4_src == INADDR_ANY) {
21170 +               struct nx_addr_v4 *ptr;
21171 +               __be32 found = 0;
21172 +               int err;
21173 +
21174 +               err = __ip_route_output_key(net, rp, fl);
21175 +               if (!err) {
21176 +                       found = (*rp)->rt_src;
21177 +                       ip_rt_put(*rp);
21178 +                       vxdprintk(VXD_CBIT(net, 4),
21179 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
21180 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
21181 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
21182 +                               goto found;
21183 +               }
21184 +
21185 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
21186 +                       __be32 primary = ptr->ip[0].s_addr;
21187 +                       __be32 mask = ptr->mask.s_addr;
21188 +                       __be32 neta = primary & mask;
21189 +
21190 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
21191 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
21192 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
21193 +                               NIPQUAD(mask), NIPQUAD(neta));
21194 +                       if ((found & mask) != neta)
21195 +                               continue;
21196 +
21197 +                       fl->fl4_src = primary;
21198 +                       err = __ip_route_output_key(net, rp, fl);
21199 +                       vxdprintk(VXD_CBIT(net, 4),
21200 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
21201 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
21202 +                       if (!err) {
21203 +                               found = (*rp)->rt_src;
21204 +                               ip_rt_put(*rp);
21205 +                               if (found == primary)
21206 +                                       goto found;
21207 +                       }
21208 +               }
21209 +               /* still no source ip? */
21210 +               found = IN_LOOPBACK(fl->fl4_dst)
21211 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
21212 +       found:
21213 +               /* assign src ip to flow */
21214 +               fl->fl4_src = found;
21215 +
21216 +       } else {
21217 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
21218 +                       return -EPERM;
21219 +       }
21220 +
21221 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
21222 +               if (IN_LOOPBACK(fl->fl4_dst))
21223 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
21224 +               if (IN_LOOPBACK(fl->fl4_src))
21225 +                       fl->fl4_src = nxi->v4_lback.s_addr;
21226 +       } else if (IN_LOOPBACK(fl->fl4_dst) &&
21227 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
21228 +               return -EPERM;
21229 +
21230 +       return 0;
21231 +}
21232 +
21233 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
21234 +
21235 diff -NurpP --minimal linux-2.6.25/kernel/vserver/init.c linux-2.6.25-vs2.3.0.34.9/kernel/vserver/init.c
21236 --- linux-2.6.25/kernel/vserver/init.c  1969-12-31 19:00:00.000000000 -0500
21237 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/init.c     2008-04-19 15:14:52.000000000 -0400
21238 @@ -0,0 +1,45 @@
21239 +/*
21240 + *  linux/kernel/init.c
21241 + *
21242 + *  Virtual Server Init
21243 + *
21244 + *  Copyright (C) 2004-2007  Herbert Pötzl
21245 + *
21246 + *  V0.01  basic structure
21247 + *
21248 + */
21249 +
21250 +#include <linux/init.h>
21251 +
21252 +int    vserver_register_sysctl(void);
21253 +void   vserver_unregister_sysctl(void);
21254 +
21255 +
21256 +static int __init init_vserver(void)
21257 +{
21258 +       int ret = 0;
21259 +
21260 +#ifdef CONFIG_VSERVER_DEBUG
21261 +       vserver_register_sysctl();
21262 +#endif
21263 +       return ret;
21264 +}
21265 +
21266 +
21267 +static void __exit exit_vserver(void)
21268 +{
21269 +
21270 +#ifdef CONFIG_VSERVER_DEBUG
21271 +       vserver_unregister_sysctl();
21272 +#endif
21273 +       return;
21274 +}
21275 +
21276 +/* FIXME: GFP_ZONETYPES gone
21277 +long vx_slab[GFP_ZONETYPES]; */
21278 +long vx_area;
21279 +
21280 +
21281 +module_init(init_vserver);
21282 +module_exit(exit_vserver);
21283 +
21284 diff -NurpP --minimal linux-2.6.25/kernel/vserver/inode.c linux-2.6.25-vs2.3.0.34.9/kernel/vserver/inode.c
21285 --- linux-2.6.25/kernel/vserver/inode.c 1969-12-31 19:00:00.000000000 -0500
21286 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/inode.c    2008-04-21 16:52:16.000000000 -0400
21287 @@ -0,0 +1,409 @@
21288 +/*
21289 + *  linux/kernel/vserver/inode.c
21290 + *
21291 + *  Virtual Server: File System Support
21292 + *
21293 + *  Copyright (C) 2004-2007  Herbert Pötzl
21294 + *
21295 + *  V0.01  separated from vcontext V0.05
21296 + *  V0.02  moved to tag (instead of xid)
21297 + *
21298 + */
21299 +
21300 +#include <linux/tty.h>
21301 +#include <linux/proc_fs.h>
21302 +#include <linux/devpts_fs.h>
21303 +#include <linux/fs.h>
21304 +#include <linux/file.h>
21305 +#include <linux/mount.h>
21306 +#include <linux/parser.h>
21307 +#include <linux/vserver/inode.h>
21308 +#include <linux/vserver/inode_cmd.h>
21309 +#include <linux/vs_base.h>
21310 +#include <linux/vs_tag.h>
21311 +
21312 +#include <asm/uaccess.h>
21313 +
21314 +
21315 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
21316 +{
21317 +       struct proc_dir_entry *entry;
21318 +
21319 +       if (!in || !in->i_sb)
21320 +               return -ESRCH;
21321 +
21322 +       *flags = IATTR_TAG
21323 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
21324 +               | (IS_IUNLINK(in) ? IATTR_IUNLINK : 0)
21325 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0);
21326 +       *mask = IATTR_IUNLINK | IATTR_IMMUTABLE;
21327 +
21328 +       if (S_ISDIR(in->i_mode))
21329 +               *mask |= IATTR_BARRIER;
21330 +
21331 +       if (IS_TAGGED(in)) {
21332 +               *tag = in->i_tag;
21333 +               *mask |= IATTR_TAG;
21334 +       }
21335 +
21336 +       switch (in->i_sb->s_magic) {
21337 +       case PROC_SUPER_MAGIC:
21338 +               entry = PROC_I(in)->pde;
21339 +
21340 +               /* check for specific inodes? */
21341 +               if (entry)
21342 +                       *mask |= IATTR_FLAGS;
21343 +               if (entry)
21344 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
21345 +               else
21346 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
21347 +               break;
21348 +
21349 +       case DEVPTS_SUPER_MAGIC:
21350 +               *tag = in->i_tag;
21351 +               *mask |= IATTR_TAG;
21352 +               break;
21353 +
21354 +       default:
21355 +               break;
21356 +       }
21357 +       return 0;
21358 +}
21359 +
21360 +int vc_get_iattr(void __user *data)
21361 +{
21362 +       struct nameidata nd;
21363 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
21364 +       int ret;
21365 +
21366 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21367 +               return -EFAULT;
21368 +
21369 +       ret = user_path_walk_link(vc_data.name, &nd);
21370 +       if (!ret) {
21371 +               ret = __vc_get_iattr(nd.path.dentry->d_inode,
21372 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21373 +               path_put(&nd.path);
21374 +       }
21375 +       if (ret)
21376 +               return ret;
21377 +
21378 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21379 +               ret = -EFAULT;
21380 +       return ret;
21381 +}
21382 +
21383 +#ifdef CONFIG_COMPAT
21384 +
21385 +int vc_get_iattr_x32(void __user *data)
21386 +{
21387 +       struct nameidata nd;
21388 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
21389 +       int ret;
21390 +
21391 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21392 +               return -EFAULT;
21393 +
21394 +       ret = user_path_walk_link(compat_ptr(vc_data.name_ptr), &nd);
21395 +       if (!ret) {
21396 +               ret = __vc_get_iattr(nd.path.dentry->d_inode,
21397 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21398 +               path_put(&nd.path);
21399 +       }
21400 +       if (ret)
21401 +               return ret;
21402 +
21403 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21404 +               ret = -EFAULT;
21405 +       return ret;
21406 +}
21407 +
21408 +#endif /* CONFIG_COMPAT */
21409 +
21410 +
21411 +int vc_fget_iattr(uint32_t fd, void __user *data)
21412 +{
21413 +       struct file *filp;
21414 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
21415 +       int ret;
21416 +
21417 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21418 +               return -EFAULT;
21419 +
21420 +       filp = fget(fd);
21421 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
21422 +               return -EBADF;
21423 +
21424 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
21425 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
21426 +
21427 +       fput(filp);
21428 +
21429 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21430 +               ret = -EFAULT;
21431 +       return ret;
21432 +}
21433 +
21434 +
21435 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
21436 +{
21437 +       struct inode *in = de->d_inode;
21438 +       int error = 0, is_proc = 0, has_tag = 0;
21439 +       struct iattr attr = { 0 };
21440 +
21441 +       if (!in || !in->i_sb)
21442 +               return -ESRCH;
21443 +
21444 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
21445 +       if ((*mask & IATTR_FLAGS) && !is_proc)
21446 +               return -EINVAL;
21447 +
21448 +       has_tag = IS_TAGGED(in) ||
21449 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
21450 +       if ((*mask & IATTR_TAG) && !has_tag)
21451 +               return -EINVAL;
21452 +
21453 +       mutex_lock(&in->i_mutex);
21454 +       if (*mask & IATTR_TAG) {
21455 +               attr.ia_tag = *tag;
21456 +               attr.ia_valid |= ATTR_TAG;
21457 +       }
21458 +
21459 +       if (*mask & IATTR_FLAGS) {
21460 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
21461 +               unsigned int iflags = PROC_I(in)->vx_flags;
21462 +
21463 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
21464 +                       | (*flags & IATTR_FLAGS);
21465 +               PROC_I(in)->vx_flags = iflags;
21466 +               if (entry)
21467 +                       entry->vx_flags = iflags;
21468 +       }
21469 +
21470 +       if (*mask & (IATTR_BARRIER | IATTR_IUNLINK | IATTR_IMMUTABLE)) {
21471 +               if (*mask & IATTR_IMMUTABLE) {
21472 +                       if (*flags & IATTR_IMMUTABLE)
21473 +                               in->i_flags |= S_IMMUTABLE;
21474 +                       else
21475 +                               in->i_flags &= ~S_IMMUTABLE;
21476 +               }
21477 +               if (*mask & IATTR_IUNLINK) {
21478 +                       if (*flags & IATTR_IUNLINK)
21479 +                               in->i_flags |= S_IUNLINK;
21480 +                       else
21481 +                               in->i_flags &= ~S_IUNLINK;
21482 +               }
21483 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
21484 +                       if (*flags & IATTR_BARRIER)
21485 +                               in->i_flags |= S_BARRIER;
21486 +                       else
21487 +                               in->i_flags &= ~S_BARRIER;
21488 +               }
21489 +               if (in->i_op && in->i_op->sync_flags) {
21490 +                       error = in->i_op->sync_flags(in);
21491 +                       if (error)
21492 +                               goto out;
21493 +               }
21494 +       }
21495 +
21496 +       if (attr.ia_valid) {
21497 +               if (in->i_op && in->i_op->setattr)
21498 +                       error = in->i_op->setattr(de, &attr);
21499 +               else {
21500 +                       error = inode_change_ok(in, &attr);
21501 +                       if (!error)
21502 +                               error = inode_setattr(in, &attr);
21503 +               }
21504 +       }
21505 +
21506 +out:
21507 +       mutex_unlock(&in->i_mutex);
21508 +       return error;
21509 +}
21510 +
21511 +int vc_set_iattr(void __user *data)
21512 +{
21513 +       struct nameidata nd;
21514 +       struct vcmd_ctx_iattr_v1 vc_data;
21515 +       int ret;
21516 +
21517 +       if (!capable(CAP_LINUX_IMMUTABLE))
21518 +               return -EPERM;
21519 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21520 +               return -EFAULT;
21521 +
21522 +       ret = user_path_walk_link(vc_data.name, &nd);
21523 +       if (!ret) {
21524 +               ret = __vc_set_iattr(nd.path.dentry,
21525 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21526 +               path_put(&nd.path);
21527 +       }
21528 +
21529 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21530 +               ret = -EFAULT;
21531 +       return ret;
21532 +}
21533 +
21534 +#ifdef CONFIG_COMPAT
21535 +
21536 +int vc_set_iattr_x32(void __user *data)
21537 +{
21538 +       struct nameidata nd;
21539 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
21540 +       int ret;
21541 +
21542 +       if (!capable(CAP_LINUX_IMMUTABLE))
21543 +               return -EPERM;
21544 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21545 +               return -EFAULT;
21546 +
21547 +       ret = user_path_walk_link(compat_ptr(vc_data.name_ptr), &nd);
21548 +       if (!ret) {
21549 +               ret = __vc_set_iattr(nd.path.dentry,
21550 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21551 +               path_put(&nd.path);
21552 +       }
21553 +
21554 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21555 +               ret = -EFAULT;
21556 +       return ret;
21557 +}
21558 +
21559 +#endif /* CONFIG_COMPAT */
21560 +
21561 +int vc_fset_iattr(uint32_t fd, void __user *data)
21562 +{
21563 +       struct file *filp;
21564 +       struct vcmd_ctx_fiattr_v0 vc_data;
21565 +       int ret;
21566 +
21567 +       if (!capable(CAP_LINUX_IMMUTABLE))
21568 +               return -EPERM;
21569 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21570 +               return -EFAULT;
21571 +
21572 +       filp = fget(fd);
21573 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
21574 +               return -EBADF;
21575 +
21576 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
21577 +               &vc_data.flags, &vc_data.mask);
21578 +
21579 +       fput(filp);
21580 +
21581 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21582 +               return -EFAULT;
21583 +       return ret;
21584 +}
21585 +
21586 +
21587 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
21588 +
21589 +static match_table_t tokens = {
21590 +       {Opt_notagcheck, "notagcheck"},
21591 +#ifdef CONFIG_PROPAGATE
21592 +       {Opt_notag, "notag"},
21593 +       {Opt_tag, "tag"},
21594 +       {Opt_tagid, "tagid=%u"},
21595 +#endif
21596 +       {Opt_err, NULL}
21597 +};
21598 +
21599 +
21600 +static void __dx_parse_remove(char *string, char *opt)
21601 +{
21602 +       char *p = strstr(string, opt);
21603 +       char *q = p;
21604 +
21605 +       if (p) {
21606 +               while (*q != '\0' && *q != ',')
21607 +                       q++;
21608 +               while (*q)
21609 +                       *p++ = *q++;
21610 +               while (*p)
21611 +                       *p++ = '\0';
21612 +       }
21613 +}
21614 +
21615 +static inline
21616 +int __dx_parse_tag(char *string, tag_t *tag, int remove)
21617 +{
21618 +       substring_t args[MAX_OPT_ARGS];
21619 +       int token, option = 0;
21620 +
21621 +       if (!string)
21622 +               return 0;
21623 +
21624 +       token = match_token(string, tokens, args);
21625 +
21626 +       vxdprintk(VXD_CBIT(tag, 7),
21627 +               "dx_parse_tag(»%s«): %d:#%d",
21628 +               string, token, option);
21629 +
21630 +       switch (token) {
21631 +       case Opt_tag:
21632 +               if (tag)
21633 +                       *tag = 0;
21634 +               if (remove)
21635 +                       __dx_parse_remove(string, "tag");
21636 +               return MNT_TAGID;
21637 +       case Opt_notag:
21638 +               if (remove)
21639 +                       __dx_parse_remove(string, "notag");
21640 +               return MNT_NOTAG;
21641 +       case Opt_notagcheck:
21642 +               if (remove)
21643 +                       __dx_parse_remove(string, "notagcheck");
21644 +               return MNT_NOTAGCHECK;
21645 +       case Opt_tagid:
21646 +               if (tag && !match_int(args, &option))
21647 +                       *tag = option;
21648 +               if (remove)
21649 +                       __dx_parse_remove(string, "tagid");
21650 +               return MNT_TAGID;
21651 +       }
21652 +       return 0;
21653 +}
21654 +
21655 +int dx_parse_tag(char *string, tag_t *tag, int remove)
21656 +{
21657 +       int retval, flags = 0;
21658 +
21659 +       while ((retval = __dx_parse_tag(string, tag, remove)))
21660 +               flags |= retval;
21661 +       return flags;
21662 +}
21663 +
21664 +#ifdef CONFIG_PROPAGATE
21665 +
21666 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
21667 +{
21668 +       tag_t new_tag = 0;
21669 +       struct vfsmount *mnt;
21670 +       int propagate;
21671 +
21672 +       if (!nd)
21673 +               return;
21674 +       mnt = nd->path.mnt;
21675 +       if (!mnt)
21676 +               return;
21677 +
21678 +       propagate = (mnt->mnt_flags & MNT_TAGID);
21679 +       if (propagate)
21680 +               new_tag = mnt->mnt_tag;
21681 +
21682 +       vxdprintk(VXD_CBIT(tag, 7),
21683 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
21684 +               inode, inode->i_ino, inode->i_tag,
21685 +               new_tag, (propagate) ? 1 : 0);
21686 +
21687 +       if (propagate)
21688 +               inode->i_tag = new_tag;
21689 +}
21690 +
21691 +#include <linux/module.h>
21692 +
21693 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
21694 +
21695 +#endif /* CONFIG_PROPAGATE */
21696 +
21697 diff -NurpP --minimal linux-2.6.25/kernel/vserver/Kconfig linux-2.6.25-vs2.3.0.34.9/kernel/vserver/Kconfig
21698 --- linux-2.6.25/kernel/vserver/Kconfig 1969-12-31 19:00:00.000000000 -0500
21699 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/Kconfig    2008-04-23 16:33:22.000000000 -0400
21700 @@ -0,0 +1,252 @@
21701 +#
21702 +# Linux VServer configuration
21703 +#
21704 +
21705 +menu "Linux VServer"
21706 +
21707 +config VSERVER_AUTO_LBACK
21708 +       bool    "Automatically Assign Loopback IP"
21709 +       default y
21710 +       help
21711 +         Automatically assign a guest specific loopback
21712 +         IP and add it to the kernel network stack on
21713 +         startup.
21714 +
21715 +config VSERVER_AUTO_SINGLE
21716 +       bool    "Automatic Single IP Special Casing"
21717 +       depends on EXPERIMENTAL
21718 +       default y
21719 +       help
21720 +         This allows network contexts with a single IP to
21721 +         automatically remap 0.0.0.0 bindings to that IP,
21722 +         avoiding further network checks and improving
21723 +         performance.
21724 +
21725 +         (note: such guests do not allow to change the ip
21726 +          on the fly and do not show loopback addresses)
21727 +
21728 +config VSERVER_COWBL
21729 +       bool    "Enable COW Immutable Link Breaking"
21730 +       default y
21731 +       help
21732 +         This enables the COW (Copy-On-Write) link break code.
21733 +         It allows you to treat unified files like normal files
21734 +         when writing to them (which will implicitely break the
21735 +         link and create a copy of the unified file)
21736 +
21737 +config VSERVER_VTIME
21738 +       bool    "Enable Virtualized Guest Time"
21739 +       depends on EXPERIMENTAL
21740 +       default n
21741 +       help
21742 +         This enables per guest time offsets to allow for
21743 +         adjusting the system clock individually per guest.
21744 +         this adds some overhead to the time functions and
21745 +         therefore should not be enabled without good reason.
21746 +
21747 +config VSERVER_DEVICE
21748 +       bool    "Enable Guest Device Mapping"
21749 +       depends on EXPERIMENTAL
21750 +       default n
21751 +       help
21752 +         This enables generic device remapping.
21753 +
21754 +config VSERVER_PROC_SECURE
21755 +       bool    "Enable Proc Security"
21756 +       depends on PROC_FS
21757 +       default y
21758 +       help
21759 +         This configures ProcFS security to initially hide
21760 +         non-process entries for all contexts except the main and
21761 +         spectator context (i.e. for all guests), which is a secure
21762 +         default.
21763 +
21764 +         (note: on 1.2x the entries were visible by default)
21765 +
21766 +config VSERVER_HARDCPU
21767 +       bool    "Enable Hard CPU Limits"
21768 +       default y
21769 +       help
21770 +         Activate the Hard CPU Limits
21771 +
21772 +         This will compile in code that allows the Token Bucket
21773 +         Scheduler to put processes on hold when a context's
21774 +         tokens are depleted (provided that its per-context
21775 +         sched_hard flag is set).
21776 +
21777 +         Processes belonging to that context will not be able
21778 +         to consume CPU resources again until a per-context
21779 +         configured minimum of tokens has been reached.
21780 +
21781 +config VSERVER_IDLETIME
21782 +       bool    "Avoid idle CPUs by skipping Time"
21783 +       depends on VSERVER_HARDCPU
21784 +       default y
21785 +       help
21786 +         This option allows the scheduler to artificially
21787 +         advance time (per cpu) when otherwise the idle
21788 +         task would be scheduled, thus keeping the cpu
21789 +         busy and sharing the available resources among
21790 +         certain contexts.
21791 +
21792 +config VSERVER_IDLELIMIT
21793 +       bool    "Limit the IDLE task"
21794 +       depends on VSERVER_HARDCPU
21795 +       default n
21796 +       help
21797 +         Limit the idle slices, so the the next context
21798 +         will be scheduled as soon as possible.
21799 +
21800 +         This might improve interactivity and latency, but
21801 +         will also marginally increase scheduling overhead.
21802 +
21803 +choice
21804 +       prompt  "Persistent Inode Tagging"
21805 +       default TAGGING_ID24
21806 +       help
21807 +         This adds persistent context information to filesystems
21808 +         mounted with the tagxid option. Tagging is a requirement
21809 +         for per-context disk limits and per-context quota.
21810 +
21811 +
21812 +config TAGGING_NONE
21813 +       bool    "Disabled"
21814 +       help
21815 +         do not store per-context information in inodes.
21816 +
21817 +config TAGGING_UID16
21818 +       bool    "UID16/GID32"
21819 +       help
21820 +         reduces UID to 16 bit, but leaves GID at 32 bit.
21821 +
21822 +config TAGGING_GID16
21823 +       bool    "UID32/GID16"
21824 +       help
21825 +         reduces GID to 16 bit, but leaves UID at 32 bit.
21826 +
21827 +config TAGGING_ID24
21828 +       bool    "UID24/GID24"
21829 +       help
21830 +         uses the upper 8bit from UID and GID for XID tagging
21831 +         which leaves 24bit for UID/GID each, which should be
21832 +         more than sufficient for normal use.
21833 +
21834 +config TAGGING_INTERN
21835 +       bool    "UID32/GID32"
21836 +       help
21837 +         this uses otherwise reserved inode fields in the on
21838 +         disk representation, which limits the use to a few
21839 +         filesystems (currently ext2 and ext3)
21840 +
21841 +endchoice
21842 +
21843 +config TAG_NFSD
21844 +       bool    "Tag NFSD User Auth and Files"
21845 +       default n
21846 +       help
21847 +         Enable this if you do want the in-kernel NFS
21848 +         Server to use the tagging specified above.
21849 +         (will require patched clients too)
21850 +
21851 +config VSERVER_PRIVACY
21852 +       bool    "Honor Privacy Aspects of Guests"
21853 +       default n
21854 +       help
21855 +         When enabled, most context checks will disallow
21856 +         access to structures assigned to a specific context,
21857 +         like ptys or loop devices.
21858 +
21859 +config VSERVER_CONTEXTS
21860 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
21861 +       range 1 65533
21862 +       default "768"   if 64BIT
21863 +       default "256"
21864 +       help
21865 +         This setting will optimize certain data structures
21866 +         and memory allocations according to the expected
21867 +         maximum.
21868 +
21869 +         note: this is not a strict upper limit.
21870 +
21871 +config VSERVER_WARN
21872 +       bool    "VServer Warnings"
21873 +       default y
21874 +       help
21875 +         This enables various runtime warnings, which will
21876 +         notify about potential manipulation attempts or
21877 +         resource shortage. It is generally considered to
21878 +         be a good idea to have that enabled.
21879 +
21880 +config VSERVER_DEBUG
21881 +       bool    "VServer Debugging Code"
21882 +       default n
21883 +       help
21884 +         Set this to yes if you want to be able to activate
21885 +         debugging output at runtime. It adds a very small
21886 +         overhead to all vserver related functions and
21887 +         increases the kernel size by about 20k.
21888 +
21889 +config VSERVER_HISTORY
21890 +       bool    "VServer History Tracing"
21891 +       depends on VSERVER_DEBUG
21892 +       default n
21893 +       help
21894 +         Set this to yes if you want to record the history of
21895 +         linux-vserver activities, so they can be replayed in
21896 +         the event of a kernel panic or oops.
21897 +
21898 +config VSERVER_HISTORY_SIZE
21899 +       int     "Per-CPU History Size (32-65536)"
21900 +       depends on VSERVER_HISTORY
21901 +       range 32 65536
21902 +       default 64
21903 +       help
21904 +         This allows you to specify the number of entries in
21905 +         the per-CPU history buffer.
21906 +
21907 +config VSERVER_MONITOR
21908 +       bool    "VServer Scheduling Monitor"
21909 +       depends on VSERVER_DEBUG
21910 +       default n
21911 +       help
21912 +         Set this to yes if you want to record the scheduling
21913 +         decisions, so that they can be relayed to userspace
21914 +         for detailed analysis.
21915 +
21916 +config VSERVER_MONITOR_SIZE
21917 +       int     "Per-CPU Monitor Queue Size (32-65536)"
21918 +       depends on VSERVER_MONITOR
21919 +       range 32 65536
21920 +       default 1024
21921 +       help
21922 +         This allows you to specify the number of entries in
21923 +         the per-CPU scheduling monitor buffer.
21924 +
21925 +config VSERVER_MONITOR_SYNC
21926 +       int     "Per-CPU Monitor Sync Interval (0-65536)"
21927 +       depends on VSERVER_MONITOR
21928 +       range 0 65536
21929 +       default 256
21930 +       help
21931 +         This allows you to specify the interval in ticks
21932 +         when a time sync entry is inserted.
21933 +
21934 +endmenu
21935 +
21936 +
21937 +config VSERVER
21938 +       bool
21939 +       default y
21940 +       select NAMESPACES
21941 +       select UTS_NS
21942 +       select IPC_NS
21943 +       select PID_NS
21944 +       select USER_NS
21945 +       select SYSVIPC
21946 +
21947 +config VSERVER_SECURITY
21948 +       bool
21949 +       depends on SECURITY
21950 +       default y
21951 +       select SECURITY_CAPABILITIES
21952 +
21953 diff -NurpP --minimal linux-2.6.25/kernel/vserver/limit.c linux-2.6.25-vs2.3.0.34.9/kernel/vserver/limit.c
21954 --- linux-2.6.25/kernel/vserver/limit.c 1969-12-31 19:00:00.000000000 -0500
21955 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/limit.c    2008-04-19 15:14:52.000000000 -0400
21956 @@ -0,0 +1,319 @@
21957 +/*
21958 + *  linux/kernel/vserver/limit.c
21959 + *
21960 + *  Virtual Server: Context Limits
21961 + *
21962 + *  Copyright (C) 2004-2007  Herbert Pötzl
21963 + *
21964 + *  V0.01  broken out from vcontext V0.05
21965 + *  V0.02  changed vcmds to vxi arg
21966 + *
21967 + */
21968 +
21969 +#include <linux/sched.h>
21970 +#include <linux/module.h>
21971 +#include <linux/vs_limit.h>
21972 +#include <linux/vserver/limit.h>
21973 +#include <linux/vserver/limit_cmd.h>
21974 +
21975 +#include <asm/uaccess.h>
21976 +
21977 +
21978 +const char *vlimit_name[NUM_LIMITS] = {
21979 +       [RLIMIT_CPU]            = "CPU",
21980 +       [RLIMIT_RSS]            = "RSS",
21981 +       [RLIMIT_NPROC]          = "NPROC",
21982 +       [RLIMIT_NOFILE]         = "NOFILE",
21983 +       [RLIMIT_MEMLOCK]        = "VML",
21984 +       [RLIMIT_AS]             = "VM",
21985 +       [RLIMIT_LOCKS]          = "LOCKS",
21986 +       [RLIMIT_SIGPENDING]     = "SIGP",
21987 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
21988 +
21989 +       [VLIMIT_NSOCK]          = "NSOCK",
21990 +       [VLIMIT_OPENFD]         = "OPENFD",
21991 +       [VLIMIT_ANON]           = "ANON",
21992 +       [VLIMIT_SHMEM]          = "SHMEM",
21993 +       [VLIMIT_DENTRY]         = "DENTRY",
21994 +};
21995 +
21996 +EXPORT_SYMBOL_GPL(vlimit_name);
21997 +
21998 +#define MASK_ENTRY(x)  (1 << (x))
21999 +
22000 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
22001 +               /* minimum */
22002 +       0
22003 +       ,       /* softlimit */
22004 +       MASK_ENTRY( RLIMIT_RSS          ) |
22005 +       MASK_ENTRY( VLIMIT_ANON         ) |
22006 +       0
22007 +       ,       /* maximum */
22008 +       MASK_ENTRY( RLIMIT_RSS          ) |
22009 +       MASK_ENTRY( RLIMIT_NPROC        ) |
22010 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
22011 +       MASK_ENTRY( RLIMIT_MEMLOCK      ) |
22012 +       MASK_ENTRY( RLIMIT_AS           ) |
22013 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
22014 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
22015 +
22016 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
22017 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
22018 +       MASK_ENTRY( VLIMIT_ANON         ) |
22019 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
22020 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
22021 +       0
22022 +};
22023 +               /* accounting only */
22024 +uint32_t account_mask =
22025 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
22026 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
22027 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
22028 +       0;
22029 +
22030 +
22031 +static int is_valid_vlimit(int id)
22032 +{
22033 +       uint32_t mask = vlimit_mask.minimum |
22034 +               vlimit_mask.softlimit | vlimit_mask.maximum;
22035 +       return mask & (1 << id);
22036 +}
22037 +
22038 +static int is_accounted_vlimit(int id)
22039 +{
22040 +       if (is_valid_vlimit(id))
22041 +               return 1;
22042 +       return account_mask & (1 << id);
22043 +}
22044 +
22045 +
22046 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
22047 +{
22048 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
22049 +       return VX_VLIM(limit);
22050 +}
22051 +
22052 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
22053 +{
22054 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
22055 +       return VX_VLIM(limit);
22056 +}
22057 +
22058 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
22059 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
22060 +{
22061 +       if (!is_valid_vlimit(id))
22062 +               return -EINVAL;
22063 +
22064 +       if (minimum)
22065 +               *minimum = CRLIM_UNSET;
22066 +       if (softlimit)
22067 +               *softlimit = vc_get_soft(vxi, id);
22068 +       if (maximum)
22069 +               *maximum = vc_get_hard(vxi, id);
22070 +       return 0;
22071 +}
22072 +
22073 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
22074 +{
22075 +       struct vcmd_ctx_rlimit_v0 vc_data;
22076 +       int ret;
22077 +
22078 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22079 +               return -EFAULT;
22080 +
22081 +       ret = do_get_rlimit(vxi, vc_data.id,
22082 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
22083 +       if (ret)
22084 +               return ret;
22085 +
22086 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22087 +               return -EFAULT;
22088 +       return 0;
22089 +}
22090 +
22091 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
22092 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
22093 +{
22094 +       if (!is_valid_vlimit(id))
22095 +               return -EINVAL;
22096 +
22097 +       if (maximum != CRLIM_KEEP)
22098 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
22099 +       if (softlimit != CRLIM_KEEP)
22100 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
22101 +
22102 +       /* clamp soft limit */
22103 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
22104 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
22105 +
22106 +       return 0;
22107 +}
22108 +
22109 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
22110 +{
22111 +       struct vcmd_ctx_rlimit_v0 vc_data;
22112 +
22113 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22114 +               return -EFAULT;
22115 +
22116 +       return do_set_rlimit(vxi, vc_data.id,
22117 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
22118 +}
22119 +
22120 +#ifdef CONFIG_IA32_EMULATION
22121 +
22122 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
22123 +{
22124 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
22125 +
22126 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22127 +               return -EFAULT;
22128 +
22129 +       return do_set_rlimit(vxi, vc_data.id,
22130 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
22131 +}
22132 +
22133 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
22134 +{
22135 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
22136 +       int ret;
22137 +
22138 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22139 +               return -EFAULT;
22140 +
22141 +       ret = do_get_rlimit(vxi, vc_data.id,
22142 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
22143 +       if (ret)
22144 +               return ret;
22145 +
22146 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22147 +               return -EFAULT;
22148 +       return 0;
22149 +}
22150 +
22151 +#endif /* CONFIG_IA32_EMULATION */
22152 +
22153 +
22154 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
22155 +{
22156 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
22157 +               return -EFAULT;
22158 +       return 0;
22159 +}
22160 +
22161 +
22162 +static inline void vx_reset_minmax(struct _vx_limit *limit)
22163 +{
22164 +       rlim_t value;
22165 +       int lim;
22166 +
22167 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
22168 +               value = __rlim_get(limit, lim);
22169 +               __rlim_rmax(limit, lim) = value;
22170 +               __rlim_rmin(limit, lim) = value;
22171 +       }
22172 +}
22173 +
22174 +
22175 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
22176 +{
22177 +       vx_reset_minmax(&vxi->limit);
22178 +       return 0;
22179 +}
22180 +
22181 +
22182 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
22183 +{
22184 +       struct vcmd_rlimit_stat_v0 vc_data;
22185 +       struct _vx_limit *limit = &vxi->limit;
22186 +       int id;
22187 +
22188 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22189 +               return -EFAULT;
22190 +
22191 +       id = vc_data.id;
22192 +       if (!is_accounted_vlimit(id))
22193 +               return -EINVAL;
22194 +
22195 +       vx_limit_fixup(limit, id);
22196 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
22197 +       vc_data.value = __rlim_get(limit, id);
22198 +       vc_data.minimum = __rlim_rmin(limit, id);
22199 +       vc_data.maximum = __rlim_rmax(limit, id);
22200 +
22201 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22202 +               return -EFAULT;
22203 +       return 0;
22204 +}
22205 +
22206 +
22207 +void vx_vsi_meminfo(struct sysinfo *val)
22208 +{
22209 +       struct vx_info *vxi = current->vx_info;
22210 +       unsigned long totalram, freeram;
22211 +       rlim_t v;
22212 +
22213 +       /* we blindly accept the max */
22214 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
22215 +       totalram = (v != RLIM_INFINITY) ? v : val->totalram;
22216 +
22217 +       /* total minus used equals free */
22218 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
22219 +       freeram = (v < totalram) ? totalram - v : 0;
22220 +
22221 +       val->totalram = totalram;
22222 +       val->freeram = freeram;
22223 +       val->bufferram = 0;
22224 +       val->totalhigh = 0;
22225 +       val->freehigh = 0;
22226 +       return;
22227 +}
22228 +
22229 +void vx_vsi_swapinfo(struct sysinfo *val)
22230 +{
22231 +       struct vx_info *vxi = current->vx_info;
22232 +       unsigned long totalswap, freeswap;
22233 +       rlim_t v, w;
22234 +
22235 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
22236 +       if (v == RLIM_INFINITY) {
22237 +               val->freeswap = val->totalswap;
22238 +               return;
22239 +       }
22240 +
22241 +       /* we blindly accept the max */
22242 +       w = __rlim_hard(&vxi->limit, RLIMIT_RSS);
22243 +       totalswap = (w != RLIM_INFINITY) ? (w - v) : val->totalswap;
22244 +
22245 +       /* currently 'used' swap */
22246 +       w = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
22247 +       w -= (w > v) ? v : w;
22248 +
22249 +       /* total minus used equals free */
22250 +       freeswap = (w < totalswap) ? totalswap - w : 0;
22251 +
22252 +       val->totalswap = totalswap;
22253 +       val->freeswap = freeswap;
22254 +       return;
22255 +}
22256 +
22257 +
22258 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
22259 +{
22260 +       struct vx_info *vxi = mm->mm_vx_info;
22261 +       unsigned long points;
22262 +       rlim_t v, w;
22263 +
22264 +       if (!vxi)
22265 +               return 0;
22266 +
22267 +       points = vxi->vx_badness_bias;
22268 +
22269 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
22270 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
22271 +       points += (v > w) ? (v - w) : 0;
22272 +
22273 +       return points;
22274 +}
22275 +
22276 diff -NurpP --minimal linux-2.6.25/kernel/vserver/limit_init.h linux-2.6.25-vs2.3.0.34.9/kernel/vserver/limit_init.h
22277 --- linux-2.6.25/kernel/vserver/limit_init.h    1969-12-31 19:00:00.000000000 -0500
22278 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/limit_init.h       2008-04-19 15:14:52.000000000 -0400
22279 @@ -0,0 +1,33 @@
22280 +
22281 +
22282 +static inline void vx_info_init_limit(struct _vx_limit *limit)
22283 +{
22284 +       int lim;
22285 +
22286 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
22287 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
22288 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
22289 +               __rlim_set(limit, lim, 0);
22290 +               atomic_set(&__rlim_lhit(limit, lim), 0);
22291 +               __rlim_rmin(limit, lim) = 0;
22292 +               __rlim_rmax(limit, lim) = 0;
22293 +       }
22294 +}
22295 +
22296 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
22297 +{
22298 +#ifdef CONFIG_VSERVER_WARN
22299 +       rlim_t value;
22300 +       int lim;
22301 +
22302 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
22303 +               if ((1 << lim) & VLIM_NOCHECK)
22304 +                       continue;
22305 +               value = __rlim_get(limit, lim);
22306 +               vxwprintk_xid(value,
22307 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
22308 +                       limit, vlimit_name[lim], lim, (long)value);
22309 +       }
22310 +#endif
22311 +}
22312 +
22313 diff -NurpP --minimal linux-2.6.25/kernel/vserver/limit_proc.h linux-2.6.25-vs2.3.0.34.9/kernel/vserver/limit_proc.h
22314 --- linux-2.6.25/kernel/vserver/limit_proc.h    1969-12-31 19:00:00.000000000 -0500
22315 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/limit_proc.h       2008-04-19 15:14:52.000000000 -0400
22316 @@ -0,0 +1,57 @@
22317 +#ifndef _VX_LIMIT_PROC_H
22318 +#define _VX_LIMIT_PROC_H
22319 +
22320 +#include <linux/vserver/limit_int.h>
22321 +
22322 +
22323 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
22324 +#define VX_LIMIT_TOP   \
22325 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
22326 +
22327 +#define VX_LIMIT_ARG(r)                                \
22328 +       (unsigned long)__rlim_get(limit, r),    \
22329 +       (unsigned long)__rlim_rmin(limit, r),   \
22330 +       (unsigned long)__rlim_rmax(limit, r),   \
22331 +       VX_VLIM(__rlim_soft(limit, r)),         \
22332 +       VX_VLIM(__rlim_hard(limit, r)),         \
22333 +       atomic_read(&__rlim_lhit(limit, r))
22334 +
22335 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
22336 +{
22337 +       vx_limit_fixup(limit, -1);
22338 +       return sprintf(buffer, VX_LIMIT_TOP
22339 +               "PROC"  VX_LIMIT_FMT
22340 +               "VM"    VX_LIMIT_FMT
22341 +               "VML"   VX_LIMIT_FMT
22342 +               "RSS"   VX_LIMIT_FMT
22343 +               "ANON"  VX_LIMIT_FMT
22344 +               "RMAP"  VX_LIMIT_FMT
22345 +               "FILES" VX_LIMIT_FMT
22346 +               "OFD"   VX_LIMIT_FMT
22347 +               "LOCKS" VX_LIMIT_FMT
22348 +               "SOCK"  VX_LIMIT_FMT
22349 +               "MSGQ"  VX_LIMIT_FMT
22350 +               "SHM"   VX_LIMIT_FMT
22351 +               "SEMA"  VX_LIMIT_FMT
22352 +               "SEMS"  VX_LIMIT_FMT
22353 +               "DENT"  VX_LIMIT_FMT,
22354 +               VX_LIMIT_ARG(RLIMIT_NPROC),
22355 +               VX_LIMIT_ARG(RLIMIT_AS),
22356 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
22357 +               VX_LIMIT_ARG(RLIMIT_RSS),
22358 +               VX_LIMIT_ARG(VLIMIT_ANON),
22359 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
22360 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
22361 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
22362 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
22363 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
22364 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
22365 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
22366 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
22367 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
22368 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
22369 +}
22370 +
22371 +#endif /* _VX_LIMIT_PROC_H */
22372 +
22373 +
22374 diff -NurpP --minimal linux-2.6.25/kernel/vserver/Makefile linux-2.6.25-vs2.3.0.34.9/kernel/vserver/Makefile
22375 --- linux-2.6.25/kernel/vserver/Makefile        1969-12-31 19:00:00.000000000 -0500
22376 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/Makefile   2008-04-19 15:14:52.000000000 -0400
22377 @@ -0,0 +1,18 @@
22378 +#
22379 +# Makefile for the Linux vserver routines.
22380 +#
22381 +
22382 +
22383 +obj-y          += vserver.o
22384 +
22385 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
22386 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
22387 +                  dlimit.o tag.o
22388 +
22389 +vserver-$(CONFIG_INET) += inet.o
22390 +vserver-$(CONFIG_PROC_FS) += proc.o
22391 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
22392 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
22393 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
22394 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
22395 +
22396 diff -NurpP --minimal linux-2.6.25/kernel/vserver/monitor.c linux-2.6.25-vs2.3.0.34.9/kernel/vserver/monitor.c
22397 --- linux-2.6.25/kernel/vserver/monitor.c       1969-12-31 19:00:00.000000000 -0500
22398 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/monitor.c  2008-04-19 15:14:52.000000000 -0400
22399 @@ -0,0 +1,138 @@
22400 +/*
22401 + *  kernel/vserver/monitor.c
22402 + *
22403 + *  Virtual Context Scheduler Monitor
22404 + *
22405 + *  Copyright (C) 2006-2007 Herbert Pötzl
22406 + *
22407 + *  V0.01  basic design
22408 + *
22409 + */
22410 +
22411 +#include <linux/module.h>
22412 +#include <linux/jiffies.h>
22413 +#include <asm/uaccess.h>
22414 +#include <asm/atomic.h>
22415 +
22416 +#include <linux/vserver/monitor.h>
22417 +#include <linux/vserver/debug_cmd.h>
22418 +
22419 +
22420 +#ifdef CONFIG_VSERVER_MONITOR
22421 +#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
22422 +#else
22423 +#define VXM_SIZE       64
22424 +#endif
22425 +
22426 +struct _vx_monitor {
22427 +       unsigned int counter;
22428 +
22429 +       struct _vx_mon_entry entry[VXM_SIZE+1];
22430 +};
22431 +
22432 +
22433 +DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
22434 +
22435 +unsigned volatile int vxm_active = 1;
22436 +
22437 +static atomic_t sequence = ATOMIC_INIT(0);
22438 +
22439 +
22440 +/*     vxm_advance()
22441 +
22442 +       * requires disabled preemption                          */
22443 +
22444 +struct _vx_mon_entry *vxm_advance(int cpu)
22445 +{
22446 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
22447 +       struct _vx_mon_entry *entry;
22448 +       unsigned int index;
22449 +
22450 +       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
22451 +       entry = &mon->entry[index];
22452 +
22453 +       entry->ev.seq = atomic_inc_return(&sequence);
22454 +       entry->ev.jif = jiffies;
22455 +       return entry;
22456 +}
22457 +
22458 +EXPORT_SYMBOL_GPL(vxm_advance);
22459 +
22460 +
22461 +int do_read_monitor(struct __user _vx_mon_entry *data,
22462 +       int cpu, uint32_t *index, uint32_t *count)
22463 +{
22464 +       int pos, ret = 0;
22465 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
22466 +       int end = mon->counter;
22467 +       int start = end - VXM_SIZE + 2;
22468 +       int idx = *index;
22469 +
22470 +       /* special case: get current pos */
22471 +       if (!*count) {
22472 +               *index = end;
22473 +               return 0;
22474 +       }
22475 +
22476 +       /* have we lost some data? */
22477 +       if (idx < start)
22478 +               idx = start;
22479 +
22480 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
22481 +               struct _vx_mon_entry *entry =
22482 +                       &mon->entry[idx % VXM_SIZE];
22483 +
22484 +               /* send entry to userspace */
22485 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
22486 +               if (ret)
22487 +                       break;
22488 +       }
22489 +       /* save new index and count */
22490 +       *index = idx;
22491 +       *count = pos;
22492 +       return ret ? ret : (*index < end);
22493 +}
22494 +
22495 +int vc_read_monitor(uint32_t id, void __user *data)
22496 +{
22497 +       struct vcmd_read_monitor_v0 vc_data;
22498 +       int ret;
22499 +
22500 +       if (id >= NR_CPUS)
22501 +               return -EINVAL;
22502 +
22503 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22504 +               return -EFAULT;
22505 +
22506 +       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
22507 +               id, &vc_data.index, &vc_data.count);
22508 +
22509 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22510 +               return -EFAULT;
22511 +       return ret;
22512 +}
22513 +
22514 +#ifdef CONFIG_COMPAT
22515 +
22516 +int vc_read_monitor_x32(uint32_t id, void __user *data)
22517 +{
22518 +       struct vcmd_read_monitor_v0_x32 vc_data;
22519 +       int ret;
22520 +
22521 +       if (id >= NR_CPUS)
22522 +               return -EINVAL;
22523 +
22524 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22525 +               return -EFAULT;
22526 +
22527 +       ret = do_read_monitor((struct __user _vx_mon_entry *)
22528 +               compat_ptr(vc_data.data_ptr),
22529 +               id, &vc_data.index, &vc_data.count);
22530 +
22531 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22532 +               return -EFAULT;
22533 +       return ret;
22534 +}
22535 +
22536 +#endif /* CONFIG_COMPAT */
22537 +
22538 diff -NurpP --minimal linux-2.6.25/kernel/vserver/network.c linux-2.6.25-vs2.3.0.34.9/kernel/vserver/network.c
22539 --- linux-2.6.25/kernel/vserver/network.c       1969-12-31 19:00:00.000000000 -0500
22540 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/network.c  2008-04-19 15:14:52.000000000 -0400
22541 @@ -0,0 +1,864 @@
22542 +/*
22543 + *  linux/kernel/vserver/network.c
22544 + *
22545 + *  Virtual Server: Network Support
22546 + *
22547 + *  Copyright (C) 2003-2007  Herbert Pötzl
22548 + *
22549 + *  V0.01  broken out from vcontext V0.05
22550 + *  V0.02  cleaned up implementation
22551 + *  V0.03  added equiv nx commands
22552 + *  V0.04  switch to RCU based hash
22553 + *  V0.05  and back to locking again
22554 + *  V0.06  changed vcmds to nxi arg
22555 + *  V0.07  have __create claim() the nxi
22556 + *
22557 + */
22558 +
22559 +#include <linux/err.h>
22560 +#include <linux/slab.h>
22561 +#include <linux/rcupdate.h>
22562 +
22563 +#include <linux/vs_network.h>
22564 +#include <linux/vs_pid.h>
22565 +#include <linux/vserver/network_cmd.h>
22566 +
22567 +
22568 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
22569 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
22570 +
22571 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
22572 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
22573 +
22574 +
22575 +static int __init init_network(void)
22576 +{
22577 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
22578 +               sizeof(struct nx_addr_v4), 0,
22579 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
22580 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
22581 +               sizeof(struct nx_addr_v6), 0,
22582 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
22583 +       return 0;
22584 +}
22585 +
22586 +
22587 +/*     __alloc_nx_addr_v4()                                    */
22588 +
22589 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
22590 +{
22591 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
22592 +               nx_addr_v4_cachep, GFP_KERNEL);
22593 +
22594 +       if (!IS_ERR(nxa))
22595 +               memset(nxa, 0, sizeof(*nxa));
22596 +       return nxa;
22597 +}
22598 +
22599 +/*     __dealloc_nx_addr_v4()                                  */
22600 +
22601 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
22602 +{
22603 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
22604 +}
22605 +
22606 +/*     __dealloc_nx_addr_v4_all()                              */
22607 +
22608 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
22609 +{
22610 +       while (nxa) {
22611 +               struct nx_addr_v4 *next = nxa->next;
22612 +
22613 +               __dealloc_nx_addr_v4(nxa);
22614 +               nxa = next;
22615 +       }
22616 +}
22617 +
22618 +
22619 +#ifdef CONFIG_IPV6
22620 +
22621 +/*     __alloc_nx_addr_v6()                                    */
22622 +
22623 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
22624 +{
22625 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
22626 +               nx_addr_v6_cachep, GFP_KERNEL);
22627 +
22628 +       if (!IS_ERR(nxa))
22629 +               memset(nxa, 0, sizeof(*nxa));
22630 +       return nxa;
22631 +}
22632 +
22633 +/*     __dealloc_nx_addr_v6()                                  */
22634 +
22635 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
22636 +{
22637 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
22638 +}
22639 +
22640 +/*     __dealloc_nx_addr_v6_all()                              */
22641 +
22642 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
22643 +{
22644 +       while (nxa) {
22645 +               struct nx_addr_v6 *next = nxa->next;
22646 +
22647 +               __dealloc_nx_addr_v6(nxa);
22648 +               nxa = next;
22649 +       }
22650 +}
22651 +
22652 +#endif /* CONFIG_IPV6 */
22653 +
22654 +/*     __alloc_nx_info()
22655 +
22656 +       * allocate an initialized nx_info struct
22657 +       * doesn't make it visible (hash)                        */
22658 +
22659 +static struct nx_info *__alloc_nx_info(nid_t nid)
22660 +{
22661 +       struct nx_info *new = NULL;
22662 +
22663 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
22664 +
22665 +       /* would this benefit from a slab cache? */
22666 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
22667 +       if (!new)
22668 +               return 0;
22669 +
22670 +       memset(new, 0, sizeof(struct nx_info));
22671 +       new->nx_id = nid;
22672 +       INIT_HLIST_NODE(&new->nx_hlist);
22673 +       atomic_set(&new->nx_usecnt, 0);
22674 +       atomic_set(&new->nx_tasks, 0);
22675 +       new->nx_state = 0;
22676 +
22677 +       new->nx_flags = NXF_INIT_SET;
22678 +
22679 +       /* rest of init goes here */
22680 +
22681 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
22682 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
22683 +
22684 +       vxdprintk(VXD_CBIT(nid, 0),
22685 +               "alloc_nx_info(%d) = %p", nid, new);
22686 +       atomic_inc(&nx_global_ctotal);
22687 +       return new;
22688 +}
22689 +
22690 +/*     __dealloc_nx_info()
22691 +
22692 +       * final disposal of nx_info                             */
22693 +
22694 +static void __dealloc_nx_info(struct nx_info *nxi)
22695 +{
22696 +       vxdprintk(VXD_CBIT(nid, 0),
22697 +               "dealloc_nx_info(%p)", nxi);
22698 +
22699 +       nxi->nx_hlist.next = LIST_POISON1;
22700 +       nxi->nx_id = -1;
22701 +
22702 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22703 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22704 +
22705 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
22706 +
22707 +       nxi->nx_state |= NXS_RELEASED;
22708 +       kfree(nxi);
22709 +       atomic_dec(&nx_global_ctotal);
22710 +}
22711 +
22712 +static void __shutdown_nx_info(struct nx_info *nxi)
22713 +{
22714 +       nxi->nx_state |= NXS_SHUTDOWN;
22715 +       vs_net_change(nxi, VSC_NETDOWN);
22716 +}
22717 +
22718 +/*     exported stuff                                          */
22719 +
22720 +void free_nx_info(struct nx_info *nxi)
22721 +{
22722 +       /* context shutdown is mandatory */
22723 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
22724 +
22725 +       /* context must not be hashed */
22726 +       BUG_ON(nxi->nx_state & NXS_HASHED);
22727 +
22728 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22729 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22730 +
22731 +       __dealloc_nx_info(nxi);
22732 +}
22733 +
22734 +
22735 +void __nx_set_lback(struct nx_info *nxi)
22736 +{
22737 +       int nid = nxi->nx_id;
22738 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
22739 +
22740 +       nxi->v4_lback.s_addr = lback;
22741 +}
22742 +
22743 +extern int __nx_inet_add_lback(__be32 addr);
22744 +extern int __nx_inet_del_lback(__be32 addr);
22745 +
22746 +
22747 +/*     hash table for nx_info hash */
22748 +
22749 +#define NX_HASH_SIZE   13
22750 +
22751 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
22752 +
22753 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
22754 +
22755 +
22756 +static inline unsigned int __hashval(nid_t nid)
22757 +{
22758 +       return (nid % NX_HASH_SIZE);
22759 +}
22760 +
22761 +
22762 +
22763 +/*     __hash_nx_info()
22764 +
22765 +       * add the nxi to the global hash table
22766 +       * requires the hash_lock to be held                     */
22767 +
22768 +static inline void __hash_nx_info(struct nx_info *nxi)
22769 +{
22770 +       struct hlist_head *head;
22771 +
22772 +       vxd_assert_lock(&nx_info_hash_lock);
22773 +       vxdprintk(VXD_CBIT(nid, 4),
22774 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
22775 +
22776 +       /* context must not be hashed */
22777 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
22778 +
22779 +       nxi->nx_state |= NXS_HASHED;
22780 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
22781 +       hlist_add_head(&nxi->nx_hlist, head);
22782 +       atomic_inc(&nx_global_cactive);
22783 +}
22784 +
22785 +/*     __unhash_nx_info()
22786 +
22787 +       * remove the nxi from the global hash table
22788 +       * requires the hash_lock to be held                     */
22789 +
22790 +static inline void __unhash_nx_info(struct nx_info *nxi)
22791 +{
22792 +       vxd_assert_lock(&nx_info_hash_lock);
22793 +       vxdprintk(VXD_CBIT(nid, 4),
22794 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
22795 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
22796 +
22797 +       /* context must be hashed */
22798 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
22799 +       /* but without tasks */
22800 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22801 +
22802 +       nxi->nx_state &= ~NXS_HASHED;
22803 +       hlist_del(&nxi->nx_hlist);
22804 +       atomic_dec(&nx_global_cactive);
22805 +}
22806 +
22807 +
22808 +/*     __lookup_nx_info()
22809 +
22810 +       * requires the hash_lock to be held
22811 +       * doesn't increment the nx_refcnt                       */
22812 +
22813 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
22814 +{
22815 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
22816 +       struct hlist_node *pos;
22817 +       struct nx_info *nxi;
22818 +
22819 +       vxd_assert_lock(&nx_info_hash_lock);
22820 +       hlist_for_each(pos, head) {
22821 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22822 +
22823 +               if (nxi->nx_id == nid)
22824 +                       goto found;
22825 +       }
22826 +       nxi = NULL;
22827 +found:
22828 +       vxdprintk(VXD_CBIT(nid, 0),
22829 +               "__lookup_nx_info(#%u): %p[#%u]",
22830 +               nid, nxi, nxi ? nxi->nx_id : 0);
22831 +       return nxi;
22832 +}
22833 +
22834 +
22835 +/*     __create_nx_info()
22836 +
22837 +       * create the requested context
22838 +       * get(), claim() and hash it                            */
22839 +
22840 +static struct nx_info *__create_nx_info(int id)
22841 +{
22842 +       struct nx_info *new, *nxi = NULL;
22843 +
22844 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
22845 +
22846 +       if (!(new = __alloc_nx_info(id)))
22847 +               return ERR_PTR(-ENOMEM);
22848 +
22849 +       /* required to make dynamic xids unique */
22850 +       spin_lock(&nx_info_hash_lock);
22851 +
22852 +       /* static context requested */
22853 +       if ((nxi = __lookup_nx_info(id))) {
22854 +               vxdprintk(VXD_CBIT(nid, 0),
22855 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
22856 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22857 +                       nxi = ERR_PTR(-EBUSY);
22858 +               else
22859 +                       nxi = ERR_PTR(-EEXIST);
22860 +               goto out_unlock;
22861 +       }
22862 +       /* new context */
22863 +       vxdprintk(VXD_CBIT(nid, 0),
22864 +               "create_nx_info(%d) = %p (new)", id, new);
22865 +       claim_nx_info(new, NULL);
22866 +       __nx_set_lback(new);
22867 +       __hash_nx_info(get_nx_info(new));
22868 +       nxi = new, new = NULL;
22869 +
22870 +out_unlock:
22871 +       spin_unlock(&nx_info_hash_lock);
22872 +       if (new)
22873 +               __dealloc_nx_info(new);
22874 +       return nxi;
22875 +}
22876 +
22877 +
22878 +
22879 +/*     exported stuff                                          */
22880 +
22881 +
22882 +void unhash_nx_info(struct nx_info *nxi)
22883 +{
22884 +       __shutdown_nx_info(nxi);
22885 +       spin_lock(&nx_info_hash_lock);
22886 +       __unhash_nx_info(nxi);
22887 +       spin_unlock(&nx_info_hash_lock);
22888 +}
22889 +
22890 +/*     lookup_nx_info()
22891 +
22892 +       * search for a nx_info and get() it
22893 +       * negative id means current                             */
22894 +
22895 +struct nx_info *lookup_nx_info(int id)
22896 +{
22897 +       struct nx_info *nxi = NULL;
22898 +
22899 +       if (id < 0) {
22900 +               nxi = get_nx_info(current->nx_info);
22901 +       } else if (id > 1) {
22902 +               spin_lock(&nx_info_hash_lock);
22903 +               nxi = get_nx_info(__lookup_nx_info(id));
22904 +               spin_unlock(&nx_info_hash_lock);
22905 +       }
22906 +       return nxi;
22907 +}
22908 +
22909 +/*     nid_is_hashed()
22910 +
22911 +       * verify that nid is still hashed                       */
22912 +
22913 +int nid_is_hashed(nid_t nid)
22914 +{
22915 +       int hashed;
22916 +
22917 +       spin_lock(&nx_info_hash_lock);
22918 +       hashed = (__lookup_nx_info(nid) != NULL);
22919 +       spin_unlock(&nx_info_hash_lock);
22920 +       return hashed;
22921 +}
22922 +
22923 +
22924 +#ifdef CONFIG_PROC_FS
22925 +
22926 +/*     get_nid_list()
22927 +
22928 +       * get a subset of hashed nids for proc
22929 +       * assumes size is at least one                          */
22930 +
22931 +int get_nid_list(int index, unsigned int *nids, int size)
22932 +{
22933 +       int hindex, nr_nids = 0;
22934 +
22935 +       /* only show current and children */
22936 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
22937 +               if (index > 0)
22938 +                       return 0;
22939 +               nids[nr_nids] = nx_current_nid();
22940 +               return 1;
22941 +       }
22942 +
22943 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
22944 +               struct hlist_head *head = &nx_info_hash[hindex];
22945 +               struct hlist_node *pos;
22946 +
22947 +               spin_lock(&nx_info_hash_lock);
22948 +               hlist_for_each(pos, head) {
22949 +                       struct nx_info *nxi;
22950 +
22951 +                       if (--index > 0)
22952 +                               continue;
22953 +
22954 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22955 +                       nids[nr_nids] = nxi->nx_id;
22956 +                       if (++nr_nids >= size) {
22957 +                               spin_unlock(&nx_info_hash_lock);
22958 +                               goto out;
22959 +                       }
22960 +               }
22961 +               /* keep the lock time short */
22962 +               spin_unlock(&nx_info_hash_lock);
22963 +       }
22964 +out:
22965 +       return nr_nids;
22966 +}
22967 +#endif
22968 +
22969 +
22970 +/*
22971 + *     migrate task to new network
22972 + *     gets nxi, puts old_nxi on change
22973 + */
22974 +
22975 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
22976 +{
22977 +       struct nx_info *old_nxi;
22978 +       int ret = 0;
22979 +
22980 +       if (!p || !nxi)
22981 +               BUG();
22982 +
22983 +       vxdprintk(VXD_CBIT(nid, 5),
22984 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
22985 +               p, nxi, nxi->nx_id,
22986 +               atomic_read(&nxi->nx_usecnt),
22987 +               atomic_read(&nxi->nx_tasks));
22988 +
22989 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
22990 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22991 +               return -EACCES;
22992 +
22993 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
22994 +               return -EFAULT;
22995 +
22996 +       /* maybe disallow this completely? */
22997 +       old_nxi = task_get_nx_info(p);
22998 +       if (old_nxi == nxi)
22999 +               goto out;
23000 +
23001 +       task_lock(p);
23002 +       if (old_nxi)
23003 +               clr_nx_info(&p->nx_info);
23004 +       claim_nx_info(nxi, p);
23005 +       set_nx_info(&p->nx_info, nxi);
23006 +       p->nid = nxi->nx_id;
23007 +       task_unlock(p);
23008 +
23009 +       vxdprintk(VXD_CBIT(nid, 5),
23010 +               "moved task %p into nxi:%p[#%d]",
23011 +               p, nxi, nxi->nx_id);
23012 +
23013 +       if (old_nxi)
23014 +               release_nx_info(old_nxi, p);
23015 +       ret = 0;
23016 +out:
23017 +       put_nx_info(old_nxi);
23018 +       return ret;
23019 +}
23020 +
23021 +
23022 +void nx_set_persistent(struct nx_info *nxi)
23023 +{
23024 +       vxdprintk(VXD_CBIT(nid, 6),
23025 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
23026 +
23027 +       get_nx_info(nxi);
23028 +       claim_nx_info(nxi, NULL);
23029 +}
23030 +
23031 +void nx_clear_persistent(struct nx_info *nxi)
23032 +{
23033 +       vxdprintk(VXD_CBIT(nid, 6),
23034 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
23035 +
23036 +       release_nx_info(nxi, NULL);
23037 +       put_nx_info(nxi);
23038 +}
23039 +
23040 +void nx_update_persistent(struct nx_info *nxi)
23041 +{
23042 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
23043 +               nx_set_persistent(nxi);
23044 +       else
23045 +               nx_clear_persistent(nxi);
23046 +}
23047 +
23048 +/* vserver syscall commands below here */
23049 +
23050 +/* taks nid and nx_info functions */
23051 +
23052 +#include <asm/uaccess.h>
23053 +
23054 +
23055 +int vc_task_nid(uint32_t id)
23056 +{
23057 +       nid_t nid;
23058 +
23059 +       if (id) {
23060 +               struct task_struct *tsk;
23061 +
23062 +               read_lock(&tasklist_lock);
23063 +               tsk = find_task_by_real_pid(id);
23064 +               nid = (tsk) ? tsk->nid : -ESRCH;
23065 +               read_unlock(&tasklist_lock);
23066 +       } else
23067 +               nid = nx_current_nid();
23068 +       return nid;
23069 +}
23070 +
23071 +
23072 +int vc_nx_info(struct nx_info *nxi, void __user *data)
23073 +{
23074 +       struct vcmd_nx_info_v0 vc_data;
23075 +
23076 +       vc_data.nid = nxi->nx_id;
23077 +
23078 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23079 +               return -EFAULT;
23080 +       return 0;
23081 +}
23082 +
23083 +
23084 +/* network functions */
23085 +
23086 +int vc_net_create(uint32_t nid, void __user *data)
23087 +{
23088 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
23089 +       struct nx_info *new_nxi;
23090 +       int ret;
23091 +
23092 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23093 +               return -EFAULT;
23094 +
23095 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
23096 +               return -EINVAL;
23097 +
23098 +       new_nxi = __create_nx_info(nid);
23099 +       if (IS_ERR(new_nxi))
23100 +               return PTR_ERR(new_nxi);
23101 +
23102 +       /* initial flags */
23103 +       new_nxi->nx_flags = vc_data.flagword;
23104 +
23105 +       ret = -ENOEXEC;
23106 +       if (vs_net_change(new_nxi, VSC_NETUP))
23107 +               goto out;
23108 +
23109 +       ret = nx_migrate_task(current, new_nxi);
23110 +       if (ret)
23111 +               goto out;
23112 +
23113 +       /* return context id on success */
23114 +       ret = new_nxi->nx_id;
23115 +
23116 +       /* get a reference for persistent contexts */
23117 +       if ((vc_data.flagword & NXF_PERSISTENT))
23118 +               nx_set_persistent(new_nxi);
23119 +out:
23120 +       release_nx_info(new_nxi, NULL);
23121 +       put_nx_info(new_nxi);
23122 +       return ret;
23123 +}
23124 +
23125 +
23126 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
23127 +{
23128 +       return nx_migrate_task(current, nxi);
23129 +}
23130 +
23131 +
23132 +
23133 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
23134 +       uint16_t type, uint16_t flags)
23135 +{
23136 +       struct nx_addr_v4 *nxa = &nxi->v4;
23137 +
23138 +       if (NX_IPV4(nxi)) {
23139 +               /* locate last entry */
23140 +               for (; nxa->next; nxa = nxa->next);
23141 +               nxa->next = __alloc_nx_addr_v4();
23142 +               nxa = nxa->next;
23143 +
23144 +               if (IS_ERR(nxa))
23145 +                       return PTR_ERR(nxa);
23146 +       }
23147 +
23148 +       if (nxi->v4.next)
23149 +               /* remove single ip for ip list */
23150 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
23151 +
23152 +       nxa->ip[0].s_addr = ip;
23153 +       nxa->ip[1].s_addr = ip2;
23154 +       nxa->mask.s_addr = mask;
23155 +       nxa->type = type;
23156 +       nxa->flags = flags;
23157 +       return 0;
23158 +}
23159 +
23160 +
23161 +int vc_net_add(struct nx_info *nxi, void __user *data)
23162 +{
23163 +       struct vcmd_net_addr_v0 vc_data;
23164 +       int index, ret = 0;
23165 +
23166 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23167 +               return -EFAULT;
23168 +
23169 +       switch (vc_data.type) {
23170 +       case NXA_TYPE_IPV4:
23171 +               if ((vc_data.count < 1) || (vc_data.count > 4))
23172 +                       return -EINVAL;
23173 +
23174 +               index = 0;
23175 +               while (index < vc_data.count) {
23176 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
23177 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
23178 +                       if (ret)
23179 +                               return ret;
23180 +                       index++;
23181 +               }
23182 +               ret = index;
23183 +               break;
23184 +
23185 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
23186 +               nxi->v4_bcast = vc_data.ip[0];
23187 +               ret = 1;
23188 +               break;
23189 +
23190 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
23191 +               nxi->v4_lback = vc_data.ip[0];
23192 +               ret = 1;
23193 +               break;
23194 +
23195 +       default:
23196 +               ret = -EINVAL;
23197 +               break;
23198 +       }
23199 +       return ret;
23200 +}
23201 +
23202 +int vc_net_remove(struct nx_info *nxi, void __user *data)
23203 +{
23204 +       struct vcmd_net_addr_v0 vc_data;
23205 +
23206 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23207 +               return -EFAULT;
23208 +
23209 +       switch (vc_data.type) {
23210 +       case NXA_TYPE_ANY:
23211 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
23212 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
23213 +               break;
23214 +
23215 +       default:
23216 +               return -EINVAL;
23217 +       }
23218 +       return 0;
23219 +}
23220 +
23221 +
23222 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
23223 +{
23224 +       struct vcmd_net_addr_ipv4_v1 vc_data;
23225 +
23226 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23227 +               return -EFAULT;
23228 +
23229 +       switch (vc_data.type) {
23230 +       case NXA_TYPE_ADDR:
23231 +       case NXA_TYPE_RANGE:
23232 +       case NXA_TYPE_MASK:
23233 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
23234 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
23235 +
23236 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
23237 +               nxi->v4_bcast = vc_data.ip;
23238 +               break;
23239 +
23240 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
23241 +               nxi->v4_lback = vc_data.ip;
23242 +               break;
23243 +
23244 +       default:
23245 +               return -EINVAL;
23246 +       }
23247 +       return 0;
23248 +}
23249 +
23250 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
23251 +{
23252 +       struct vcmd_net_addr_ipv4_v1 vc_data;
23253 +
23254 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23255 +               return -EFAULT;
23256 +
23257 +       switch (vc_data.type) {
23258 +/*     case NXA_TYPE_ADDR:
23259 +               break;          */
23260 +
23261 +       case NXA_TYPE_ANY:
23262 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
23263 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
23264 +               break;
23265 +
23266 +       default:
23267 +               return -EINVAL;
23268 +       }
23269 +       return 0;
23270 +}
23271 +
23272 +
23273 +#ifdef CONFIG_IPV6
23274 +
23275 +int do_add_v6_addr(struct nx_info *nxi,
23276 +       struct in6_addr *ip, struct in6_addr *mask,
23277 +       uint32_t prefix, uint16_t type, uint16_t flags)
23278 +{
23279 +       struct nx_addr_v6 *nxa = &nxi->v6;
23280 +
23281 +       if (NX_IPV6(nxi)) {
23282 +               /* locate last entry */
23283 +               for (; nxa->next; nxa = nxa->next);
23284 +               nxa->next = __alloc_nx_addr_v6();
23285 +               nxa = nxa->next;
23286 +
23287 +               if (IS_ERR(nxa))
23288 +                       return PTR_ERR(nxa);
23289 +       }
23290 +
23291 +       nxa->ip = *ip;
23292 +       nxa->mask = *mask;
23293 +       nxa->prefix = prefix;
23294 +       nxa->type = type;
23295 +       nxa->flags = flags;
23296 +       return 0;
23297 +}
23298 +
23299 +
23300 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
23301 +{
23302 +       struct vcmd_net_addr_ipv6_v1 vc_data;
23303 +
23304 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23305 +               return -EFAULT;
23306 +
23307 +       switch (vc_data.type) {
23308 +       case NXA_TYPE_ADDR:
23309 +       case NXA_TYPE_MASK:
23310 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
23311 +                       vc_data.prefix, vc_data.type, vc_data.flags);
23312 +       default:
23313 +               return -EINVAL;
23314 +       }
23315 +       return 0;
23316 +}
23317 +
23318 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
23319 +{
23320 +       struct vcmd_net_addr_ipv6_v1 vc_data;
23321 +
23322 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23323 +               return -EFAULT;
23324 +
23325 +       switch (vc_data.type) {
23326 +       case NXA_TYPE_ANY:
23327 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
23328 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
23329 +               break;
23330 +
23331 +       default:
23332 +               return -EINVAL;
23333 +       }
23334 +       return 0;
23335 +}
23336 +
23337 +#endif /* CONFIG_IPV6 */
23338 +
23339 +
23340 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
23341 +{
23342 +       struct vcmd_net_flags_v0 vc_data;
23343 +
23344 +       vc_data.flagword = nxi->nx_flags;
23345 +
23346 +       /* special STATE flag handling */
23347 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
23348 +
23349 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23350 +               return -EFAULT;
23351 +       return 0;
23352 +}
23353 +
23354 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
23355 +{
23356 +       struct vcmd_net_flags_v0 vc_data;
23357 +       uint64_t mask, trigger;
23358 +
23359 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23360 +               return -EFAULT;
23361 +
23362 +       /* special STATE flag handling */
23363 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
23364 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
23365 +
23366 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
23367 +               vc_data.flagword, mask);
23368 +       if (trigger & NXF_PERSISTENT)
23369 +               nx_update_persistent(nxi);
23370 +
23371 +       return 0;
23372 +}
23373 +
23374 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
23375 +{
23376 +       struct vcmd_net_caps_v0 vc_data;
23377 +
23378 +       vc_data.ncaps = nxi->nx_ncaps;
23379 +       vc_data.cmask = ~0ULL;
23380 +
23381 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23382 +               return -EFAULT;
23383 +       return 0;
23384 +}
23385 +
23386 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
23387 +{
23388 +       struct vcmd_net_caps_v0 vc_data;
23389 +
23390 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23391 +               return -EFAULT;
23392 +
23393 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
23394 +               vc_data.ncaps, vc_data.cmask);
23395 +       return 0;
23396 +}
23397 +
23398 +
23399 +#include <linux/module.h>
23400 +
23401 +module_init(init_network);
23402 +
23403 +EXPORT_SYMBOL_GPL(free_nx_info);
23404 +EXPORT_SYMBOL_GPL(unhash_nx_info);
23405 +
23406 diff -NurpP --minimal linux-2.6.25/kernel/vserver/proc.c linux-2.6.25-vs2.3.0.34.9/kernel/vserver/proc.c
23407 --- linux-2.6.25/kernel/vserver/proc.c  1969-12-31 19:00:00.000000000 -0500
23408 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/proc.c     2008-04-21 13:42:34.000000000 -0400
23409 @@ -0,0 +1,1086 @@
23410 +/*
23411 + *  linux/kernel/vserver/proc.c
23412 + *
23413 + *  Virtual Context Support
23414 + *
23415 + *  Copyright (C) 2003-2007  Herbert Pötzl
23416 + *
23417 + *  V0.01  basic structure
23418 + *  V0.02  adaptation vs1.3.0
23419 + *  V0.03  proc permissions
23420 + *  V0.04  locking/generic
23421 + *  V0.05  next generation procfs
23422 + *  V0.06  inode validation
23423 + *  V0.07  generic rewrite vid
23424 + *  V0.08  remove inode type
23425 + *
23426 + */
23427 +
23428 +#include <linux/proc_fs.h>
23429 +#include <asm/unistd.h>
23430 +
23431 +#include <linux/vs_context.h>
23432 +#include <linux/vs_network.h>
23433 +#include <linux/vs_cvirt.h>
23434 +
23435 +#include <linux/in.h>
23436 +#include <linux/inetdevice.h>
23437 +#include <linux/vs_inet.h>
23438 +#include <linux/vs_inet6.h>
23439 +
23440 +#include <linux/vserver/global.h>
23441 +
23442 +#include "cvirt_proc.h"
23443 +#include "cacct_proc.h"
23444 +#include "limit_proc.h"
23445 +#include "sched_proc.h"
23446 +#include "vci_config.h"
23447 +
23448 +
23449 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
23450 +{
23451 +       unsigned __capi;
23452 +
23453 +       CAP_FOR_EACH_U32(__capi) {
23454 +               buffer += sprintf(buffer, "%08x",
23455 +                       c->cap[(_LINUX_CAPABILITY_U32S-1) - __capi]);
23456 +       }
23457 +       return buffer;
23458 +}
23459 +
23460 +
23461 +static struct proc_dir_entry *proc_virtual;
23462 +
23463 +static struct proc_dir_entry *proc_virtnet;
23464 +
23465 +
23466 +/* first the actual feeds */
23467 +
23468 +
23469 +static int proc_vci(char *buffer)
23470 +{
23471 +       return sprintf(buffer,
23472 +               "VCIVersion:\t%04x:%04x\n"
23473 +               "VCISyscall:\t%d\n"
23474 +               "VCIKernel:\t%08x\n",
23475 +               VCI_VERSION >> 16,
23476 +               VCI_VERSION & 0xFFFF,
23477 +               __NR_vserver,
23478 +               vci_kernel_config());
23479 +}
23480 +
23481 +static int proc_virtual_info(char *buffer)
23482 +{
23483 +       return proc_vci(buffer);
23484 +}
23485 +
23486 +static int proc_virtual_status(char *buffer)
23487 +{
23488 +       return sprintf(buffer,
23489 +               "#CTotal:\t%d\n"
23490 +               "#CActive:\t%d\n"
23491 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n",
23492 +               atomic_read(&vx_global_ctotal),
23493 +               atomic_read(&vx_global_cactive),
23494 +               atomic_read(&vs_global_nsproxy),
23495 +               atomic_read(&vs_global_fs),
23496 +               atomic_read(&vs_global_mnt_ns),
23497 +               atomic_read(&vs_global_uts_ns),
23498 +               atomic_read(&vs_global_ipc_ns),
23499 +               atomic_read(&vs_global_user_ns),
23500 +               atomic_read(&vs_global_pid_ns));
23501 +}
23502 +
23503 +
23504 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
23505 +{
23506 +       int length;
23507 +
23508 +       length = sprintf(buffer,
23509 +               "ID:\t%d\n"
23510 +               "Info:\t%p\n"
23511 +               "Init:\t%d\n"
23512 +               "OOM:\t%lld\n",
23513 +               vxi->vx_id,
23514 +               vxi,
23515 +               vxi->vx_initpid,
23516 +               vxi->vx_badness_bias);
23517 +       return length;
23518 +}
23519 +
23520 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
23521 +{
23522 +       char *orig = buffer;
23523 +
23524 +       buffer += sprintf(buffer,
23525 +               "UseCnt:\t%d\n"
23526 +               "Tasks:\t%d\n"
23527 +               "Flags:\t%016llx\n",
23528 +               atomic_read(&vxi->vx_usecnt),
23529 +               atomic_read(&vxi->vx_tasks),
23530 +               (unsigned long long)vxi->vx_flags);
23531 +
23532 +       buffer += sprintf(buffer, "BCaps:\t");
23533 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
23534 +       buffer += sprintf(buffer, "\n");
23535 +
23536 +       buffer += sprintf(buffer,
23537 +               "CCaps:\t%016llx\n"
23538 +               "Spaces:\t%08lx\n",
23539 +               (unsigned long long)vxi->vx_ccaps,
23540 +               vxi->vx_nsmask);
23541 +       return buffer - orig;
23542 +}
23543 +
23544 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
23545 +{
23546 +       return vx_info_proc_limit(&vxi->limit, buffer);
23547 +}
23548 +
23549 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
23550 +{
23551 +       int cpu, length;
23552 +
23553 +       length = vx_info_proc_sched(&vxi->sched, buffer);
23554 +       for_each_online_cpu(cpu) {
23555 +               length += vx_info_proc_sched_pc(
23556 +                       &vx_per_cpu(vxi, sched_pc, cpu),
23557 +                       buffer + length, cpu);
23558 +       }
23559 +       return length;
23560 +}
23561 +
23562 +int proc_vxi_nsproxy(struct vx_info *vxi, char *buffer)
23563 +{
23564 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy, buffer);
23565 +}
23566 +
23567 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
23568 +{
23569 +       int cpu, length;
23570 +
23571 +       vx_update_load(vxi);
23572 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
23573 +       for_each_online_cpu(cpu) {
23574 +               length += vx_info_proc_cvirt_pc(
23575 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
23576 +                       buffer + length, cpu);
23577 +       }
23578 +       return length;
23579 +}
23580 +
23581 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
23582 +{
23583 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
23584 +}
23585 +
23586 +
23587 +static int proc_virtnet_info(char *buffer)
23588 +{
23589 +       return proc_vci(buffer);
23590 +}
23591 +
23592 +static int proc_virtnet_status(char *buffer)
23593 +{
23594 +       return sprintf(buffer,
23595 +               "#CTotal:\t%d\n"
23596 +               "#CActive:\t%d\n",
23597 +               atomic_read(&nx_global_ctotal),
23598 +               atomic_read(&nx_global_cactive));
23599 +}
23600 +
23601 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
23602 +{
23603 +       struct nx_addr_v4 *v4a;
23604 +#ifdef CONFIG_IPV6
23605 +       struct nx_addr_v6 *v6a;
23606 +#endif
23607 +       int length, i;
23608 +
23609 +       length = sprintf(buffer,
23610 +               "ID:\t%d\n"
23611 +               "Info:\t%p\n"
23612 +               "Bcast:\t" NIPQUAD_FMT "\n"
23613 +               "Lback:\t" NIPQUAD_FMT "\n",
23614 +               nxi->nx_id,
23615 +               nxi,
23616 +               NIPQUAD(nxi->v4_bcast.s_addr),
23617 +               NIPQUAD(nxi->v4_lback.s_addr));
23618 +
23619 +       if (!NX_IPV4(nxi))
23620 +               goto skip_v4;
23621 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
23622 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
23623 +                       i, NXAV4(v4a));
23624 +skip_v4:
23625 +#ifdef CONFIG_IPV6
23626 +       if (!NX_IPV6(nxi))
23627 +               goto skip_v6;
23628 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
23629 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
23630 +                       i, NXAV6(v6a));
23631 +skip_v6:
23632 +#endif
23633 +       return length;
23634 +}
23635 +
23636 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
23637 +{
23638 +       int length;
23639 +
23640 +       length = sprintf(buffer,
23641 +               "UseCnt:\t%d\n"
23642 +               "Tasks:\t%d\n"
23643 +               "Flags:\t%016llx\n"
23644 +               "NCaps:\t%016llx\n",
23645 +               atomic_read(&nxi->nx_usecnt),
23646 +               atomic_read(&nxi->nx_tasks),
23647 +               (unsigned long long)nxi->nx_flags,
23648 +               (unsigned long long)nxi->nx_ncaps);
23649 +       return length;
23650 +}
23651 +
23652 +
23653 +
23654 +/* here the inode helpers */
23655 +
23656 +struct vs_entry {
23657 +       int len;
23658 +       char *name;
23659 +       mode_t mode;
23660 +       struct inode_operations *iop;
23661 +       struct file_operations *fop;
23662 +       union proc_op op;
23663 +};
23664 +
23665 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
23666 +{
23667 +       struct inode *inode = new_inode(sb);
23668 +
23669 +       if (!inode)
23670 +               goto out;
23671 +
23672 +       inode->i_mode = p->mode;
23673 +       if (p->iop)
23674 +               inode->i_op = p->iop;
23675 +       if (p->fop)
23676 +               inode->i_fop = p->fop;
23677 +
23678 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
23679 +       inode->i_flags |= S_IMMUTABLE;
23680 +
23681 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
23682 +
23683 +       inode->i_uid = 0;
23684 +       inode->i_gid = 0;
23685 +       inode->i_tag = 0;
23686 +out:
23687 +       return inode;
23688 +}
23689 +
23690 +static struct dentry *vs_proc_instantiate(struct inode *dir,
23691 +       struct dentry *dentry, int id, void *ptr)
23692 +{
23693 +       struct vs_entry *p = ptr;
23694 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
23695 +       struct dentry *error = ERR_PTR(-EINVAL);
23696 +
23697 +       if (!inode)
23698 +               goto out;
23699 +
23700 +       PROC_I(inode)->op = p->op;
23701 +       PROC_I(inode)->fd = id;
23702 +       d_add(dentry, inode);
23703 +       error = NULL;
23704 +out:
23705 +       return error;
23706 +}
23707 +
23708 +/* Lookups */
23709 +
23710 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
23711 +
23712 +/*
23713 + * Fill a directory entry.
23714 + *
23715 + * If possible create the dcache entry and derive our inode number and
23716 + * file type from dcache entry.
23717 + *
23718 + * Since all of the proc inode numbers are dynamically generated, the inode
23719 + * numbers do not exist until the inode is cache.  This means creating the
23720 + * the dcache entry in readdir is necessary to keep the inode numbers
23721 + * reported by readdir in sync with the inode numbers reported
23722 + * by stat.
23723 + */
23724 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
23725 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
23726 +{
23727 +       struct dentry *child, *dir = filp->f_dentry;
23728 +       struct inode *inode;
23729 +       struct qstr qname;
23730 +       ino_t ino = 0;
23731 +       unsigned type = DT_UNKNOWN;
23732 +
23733 +       qname.name = name;
23734 +       qname.len  = len;
23735 +       qname.hash = full_name_hash(name, len);
23736 +
23737 +       child = d_lookup(dir, &qname);
23738 +       if (!child) {
23739 +               struct dentry *new;
23740 +               new = d_alloc(dir, &qname);
23741 +               if (new) {
23742 +                       child = instantiate(dir->d_inode, new, id, ptr);
23743 +                       if (child)
23744 +                               dput(new);
23745 +                       else
23746 +                               child = new;
23747 +               }
23748 +       }
23749 +       if (!child || IS_ERR(child) || !child->d_inode)
23750 +               goto end_instantiate;
23751 +       inode = child->d_inode;
23752 +       if (inode) {
23753 +               ino = inode->i_ino;
23754 +               type = inode->i_mode >> 12;
23755 +       }
23756 +       dput(child);
23757 +end_instantiate:
23758 +       if (!ino)
23759 +               ino = find_inode_number(dir, &qname);
23760 +       if (!ino)
23761 +               ino = 1;
23762 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
23763 +}
23764 +
23765 +
23766 +
23767 +/* get and revalidate vx_info/xid */
23768 +
23769 +static inline
23770 +struct vx_info *get_proc_vx_info(struct inode *inode)
23771 +{
23772 +       return lookup_vx_info(PROC_I(inode)->fd);
23773 +}
23774 +
23775 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
23776 +{
23777 +       struct inode *inode = dentry->d_inode;
23778 +       xid_t xid = PROC_I(inode)->fd;
23779 +
23780 +       if (!xid || xid_is_hashed(xid))
23781 +               return 1;
23782 +       d_drop(dentry);
23783 +       return 0;
23784 +}
23785 +
23786 +
23787 +/* get and revalidate nx_info/nid */
23788 +
23789 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
23790 +{
23791 +       struct inode *inode = dentry->d_inode;
23792 +       nid_t nid = PROC_I(inode)->fd;
23793 +
23794 +       if (!nid || nid_is_hashed(nid))
23795 +               return 1;
23796 +       d_drop(dentry);
23797 +       return 0;
23798 +}
23799 +
23800 +
23801 +
23802 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
23803 +
23804 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
23805 +                         size_t count, loff_t *ppos)
23806 +{
23807 +       struct inode *inode = file->f_dentry->d_inode;
23808 +       unsigned long page;
23809 +       ssize_t length = 0;
23810 +
23811 +       if (count > PROC_BLOCK_SIZE)
23812 +               count = PROC_BLOCK_SIZE;
23813 +
23814 +       /* fade that out as soon as stable */
23815 +       WARN_ON(PROC_I(inode)->fd);
23816 +
23817 +       if (!(page = __get_free_page(GFP_KERNEL)))
23818 +               return -ENOMEM;
23819 +
23820 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
23821 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
23822 +
23823 +       if (length >= 0)
23824 +               length = simple_read_from_buffer(buf, count, ppos,
23825 +                       (char *)page, length);
23826 +
23827 +       free_page(page);
23828 +       return length;
23829 +}
23830 +
23831 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
23832 +                         size_t count, loff_t *ppos)
23833 +{
23834 +       struct inode *inode = file->f_dentry->d_inode;
23835 +       struct vx_info *vxi = NULL;
23836 +       xid_t xid = PROC_I(inode)->fd;
23837 +       unsigned long page;
23838 +       ssize_t length = 0;
23839 +
23840 +       if (count > PROC_BLOCK_SIZE)
23841 +               count = PROC_BLOCK_SIZE;
23842 +
23843 +       /* fade that out as soon as stable */
23844 +       WARN_ON(!xid);
23845 +       vxi = lookup_vx_info(xid);
23846 +       if (!vxi)
23847 +               goto out;
23848 +
23849 +       length = -ENOMEM;
23850 +       if (!(page = __get_free_page(GFP_KERNEL)))
23851 +               goto out_put;
23852 +
23853 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
23854 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
23855 +
23856 +       if (length >= 0)
23857 +               length = simple_read_from_buffer(buf, count, ppos,
23858 +                       (char *)page, length);
23859 +
23860 +       free_page(page);
23861 +out_put:
23862 +       put_vx_info(vxi);
23863 +out:
23864 +       return length;
23865 +}
23866 +
23867 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
23868 +                         size_t count, loff_t *ppos)
23869 +{
23870 +       struct inode *inode = file->f_dentry->d_inode;
23871 +       struct nx_info *nxi = NULL;
23872 +       nid_t nid = PROC_I(inode)->fd;
23873 +       unsigned long page;
23874 +       ssize_t length = 0;
23875 +
23876 +       if (count > PROC_BLOCK_SIZE)
23877 +               count = PROC_BLOCK_SIZE;
23878 +
23879 +       /* fade that out as soon as stable */
23880 +       WARN_ON(!nid);
23881 +       nxi = lookup_nx_info(nid);
23882 +       if (!nxi)
23883 +               goto out;
23884 +
23885 +       length = -ENOMEM;
23886 +       if (!(page = __get_free_page(GFP_KERNEL)))
23887 +               goto out_put;
23888 +
23889 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
23890 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
23891 +
23892 +       if (length >= 0)
23893 +               length = simple_read_from_buffer(buf, count, ppos,
23894 +                       (char *)page, length);
23895 +
23896 +       free_page(page);
23897 +out_put:
23898 +       put_nx_info(nxi);
23899 +out:
23900 +       return length;
23901 +}
23902 +
23903 +
23904 +
23905 +/* here comes the lower level */
23906 +
23907 +
23908 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
23909 +       .len  = sizeof(NAME) - 1,       \
23910 +       .name = (NAME),                 \
23911 +       .mode = MODE,                   \
23912 +       .iop  = IOP,                    \
23913 +       .fop  = FOP,                    \
23914 +       .op   = OP,                     \
23915 +}
23916 +
23917 +
23918 +#define DIR(NAME, MODE, OTYPE)                         \
23919 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
23920 +               &proc_ ## OTYPE ## _inode_operations,   \
23921 +               &proc_ ## OTYPE ## _file_operations, { } )
23922 +
23923 +#define INF(NAME, MODE, OTYPE)                         \
23924 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23925 +               &proc_vs_info_file_operations,          \
23926 +               { .proc_vs_read = &proc_##OTYPE } )
23927 +
23928 +#define VINF(NAME, MODE, OTYPE)                                \
23929 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23930 +               &proc_vx_info_file_operations,          \
23931 +               { .proc_vxi_read = &proc_##OTYPE } )
23932 +
23933 +#define NINF(NAME, MODE, OTYPE)                                \
23934 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23935 +               &proc_nx_info_file_operations,          \
23936 +               { .proc_nxi_read = &proc_##OTYPE } )
23937 +
23938 +
23939 +static struct file_operations proc_vs_info_file_operations = {
23940 +       .read =         proc_vs_info_read,
23941 +};
23942 +
23943 +static struct file_operations proc_vx_info_file_operations = {
23944 +       .read =         proc_vx_info_read,
23945 +};
23946 +
23947 +static struct dentry_operations proc_xid_dentry_operations = {
23948 +       .d_revalidate = proc_xid_revalidate,
23949 +};
23950 +
23951 +static struct vs_entry vx_base_stuff[] = {
23952 +       VINF("info",    S_IRUGO, vxi_info),
23953 +       VINF("status",  S_IRUGO, vxi_status),
23954 +       VINF("limit",   S_IRUGO, vxi_limit),
23955 +       VINF("sched",   S_IRUGO, vxi_sched),
23956 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy),
23957 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
23958 +       VINF("cacct",   S_IRUGO, vxi_cacct),
23959 +       {}
23960 +};
23961 +
23962 +
23963 +
23964 +
23965 +static struct dentry *proc_xid_instantiate(struct inode *dir,
23966 +       struct dentry *dentry, int id, void *ptr)
23967 +{
23968 +       dentry->d_op = &proc_xid_dentry_operations;
23969 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23970 +}
23971 +
23972 +static struct dentry *proc_xid_lookup(struct inode *dir,
23973 +       struct dentry *dentry, struct nameidata *nd)
23974 +{
23975 +       struct vs_entry *p = vx_base_stuff;
23976 +       struct dentry *error = ERR_PTR(-ENOENT);
23977 +
23978 +       for (; p->name; p++) {
23979 +               if (p->len != dentry->d_name.len)
23980 +                       continue;
23981 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23982 +                       break;
23983 +       }
23984 +       if (!p->name)
23985 +               goto out;
23986 +
23987 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23988 +out:
23989 +       return error;
23990 +}
23991 +
23992 +static int proc_xid_readdir(struct file *filp,
23993 +       void *dirent, filldir_t filldir)
23994 +{
23995 +       struct dentry *dentry = filp->f_dentry;
23996 +       struct inode *inode = dentry->d_inode;
23997 +       struct vs_entry *p = vx_base_stuff;
23998 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
23999 +       int pos, index;
24000 +       u64 ino;
24001 +
24002 +       pos = filp->f_pos;
24003 +       switch (pos) {
24004 +       case 0:
24005 +               ino = inode->i_ino;
24006 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
24007 +                       goto out;
24008 +               pos++;
24009 +               /* fall through */
24010 +       case 1:
24011 +               ino = parent_ino(dentry);
24012 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
24013 +                       goto out;
24014 +               pos++;
24015 +               /* fall through */
24016 +       default:
24017 +               index = pos - 2;
24018 +               if (index >= size)
24019 +                       goto out;
24020 +               for (p += index; p->name; p++) {
24021 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
24022 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
24023 +                               goto out;
24024 +                       pos++;
24025 +               }
24026 +       }
24027 +out:
24028 +       filp->f_pos = pos;
24029 +       return 1;
24030 +}
24031 +
24032 +
24033 +
24034 +static struct file_operations proc_nx_info_file_operations = {
24035 +       .read =         proc_nx_info_read,
24036 +};
24037 +
24038 +static struct dentry_operations proc_nid_dentry_operations = {
24039 +       .d_revalidate = proc_nid_revalidate,
24040 +};
24041 +
24042 +static struct vs_entry nx_base_stuff[] = {
24043 +       NINF("info",    S_IRUGO, nxi_info),
24044 +       NINF("status",  S_IRUGO, nxi_status),
24045 +       {}
24046 +};
24047 +
24048 +
24049 +static struct dentry *proc_nid_instantiate(struct inode *dir,
24050 +       struct dentry *dentry, int id, void *ptr)
24051 +{
24052 +       dentry->d_op = &proc_nid_dentry_operations;
24053 +       return vs_proc_instantiate(dir, dentry, id, ptr);
24054 +}
24055 +
24056 +static struct dentry *proc_nid_lookup(struct inode *dir,
24057 +       struct dentry *dentry, struct nameidata *nd)
24058 +{
24059 +       struct vs_entry *p = nx_base_stuff;
24060 +       struct dentry *error = ERR_PTR(-ENOENT);
24061 +
24062 +       for (; p->name; p++) {
24063 +               if (p->len != dentry->d_name.len)
24064 +                       continue;
24065 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
24066 +                       break;
24067 +       }
24068 +       if (!p->name)
24069 +               goto out;
24070 +
24071 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
24072 +out:
24073 +       return error;
24074 +}
24075 +
24076 +static int proc_nid_readdir(struct file *filp,
24077 +       void *dirent, filldir_t filldir)
24078 +{
24079 +       struct dentry *dentry = filp->f_dentry;
24080 +       struct inode *inode = dentry->d_inode;
24081 +       struct vs_entry *p = nx_base_stuff;
24082 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
24083 +       int pos, index;
24084 +       u64 ino;
24085 +
24086 +       pos = filp->f_pos;
24087 +       switch (pos) {
24088 +       case 0:
24089 +               ino = inode->i_ino;
24090 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
24091 +                       goto out;
24092 +               pos++;
24093 +               /* fall through */
24094 +       case 1:
24095 +               ino = parent_ino(dentry);
24096 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
24097 +                       goto out;
24098 +               pos++;
24099 +               /* fall through */
24100 +       default:
24101 +               index = pos - 2;
24102 +               if (index >= size)
24103 +                       goto out;
24104 +               for (p += index; p->name; p++) {
24105 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
24106 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
24107 +                               goto out;
24108 +                       pos++;
24109 +               }
24110 +       }
24111 +out:
24112 +       filp->f_pos = pos;
24113 +       return 1;
24114 +}
24115 +
24116 +
24117 +#define MAX_MULBY10    ((~0U - 9) / 10)
24118 +
24119 +static inline int atovid(const char *str, int len)
24120 +{
24121 +       int vid, c;
24122 +
24123 +       vid = 0;
24124 +       while (len-- > 0) {
24125 +               c = *str - '0';
24126 +               str++;
24127 +               if (c > 9)
24128 +                       return -1;
24129 +               if (vid >= MAX_MULBY10)
24130 +                       return -1;
24131 +               vid *= 10;
24132 +               vid += c;
24133 +               if (!vid)
24134 +                       return -1;
24135 +       }
24136 +       return vid;
24137 +}
24138 +
24139 +/* now the upper level (virtual) */
24140 +
24141 +
24142 +static struct file_operations proc_xid_file_operations = {
24143 +       .read =         generic_read_dir,
24144 +       .readdir =      proc_xid_readdir,
24145 +};
24146 +
24147 +static struct inode_operations proc_xid_inode_operations = {
24148 +       .lookup =       proc_xid_lookup,
24149 +};
24150 +
24151 +static struct vs_entry vx_virtual_stuff[] = {
24152 +       INF("info",     S_IRUGO, virtual_info),
24153 +       INF("status",   S_IRUGO, virtual_status),
24154 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
24155 +};
24156 +
24157 +
24158 +static struct dentry *proc_virtual_lookup(struct inode *dir,
24159 +       struct dentry *dentry, struct nameidata *nd)
24160 +{
24161 +       struct vs_entry *p = vx_virtual_stuff;
24162 +       struct dentry *error = ERR_PTR(-ENOENT);
24163 +       int id = 0;
24164 +
24165 +       for (; p->name; p++) {
24166 +               if (p->len != dentry->d_name.len)
24167 +                       continue;
24168 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
24169 +                       break;
24170 +       }
24171 +       if (p->name)
24172 +               goto instantiate;
24173 +
24174 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
24175 +       if ((id < 0) || !xid_is_hashed(id))
24176 +               goto out;
24177 +
24178 +instantiate:
24179 +       error = proc_xid_instantiate(dir, dentry, id, p);
24180 +out:
24181 +       return error;
24182 +}
24183 +
24184 +static struct file_operations proc_nid_file_operations = {
24185 +       .read =         generic_read_dir,
24186 +       .readdir =      proc_nid_readdir,
24187 +};
24188 +
24189 +static struct inode_operations proc_nid_inode_operations = {
24190 +       .lookup =       proc_nid_lookup,
24191 +};
24192 +
24193 +static struct vs_entry nx_virtnet_stuff[] = {
24194 +       INF("info",     S_IRUGO, virtnet_info),
24195 +       INF("status",   S_IRUGO, virtnet_status),
24196 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
24197 +};
24198 +
24199 +
24200 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
24201 +       struct dentry *dentry, struct nameidata *nd)
24202 +{
24203 +       struct vs_entry *p = nx_virtnet_stuff;
24204 +       struct dentry *error = ERR_PTR(-ENOENT);
24205 +       int id = 0;
24206 +
24207 +       for (; p->name; p++) {
24208 +               if (p->len != dentry->d_name.len)
24209 +                       continue;
24210 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
24211 +                       break;
24212 +       }
24213 +       if (p->name)
24214 +               goto instantiate;
24215 +
24216 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
24217 +       if ((id < 0) || !nid_is_hashed(id))
24218 +               goto out;
24219 +
24220 +instantiate:
24221 +       error = proc_nid_instantiate(dir, dentry, id, p);
24222 +out:
24223 +       return error;
24224 +}
24225 +
24226 +
24227 +#define PROC_MAXVIDS 32
24228 +
24229 +int proc_virtual_readdir(struct file *filp,
24230 +       void *dirent, filldir_t filldir)
24231 +{
24232 +       struct dentry *dentry = filp->f_dentry;
24233 +       struct inode *inode = dentry->d_inode;
24234 +       struct vs_entry *p = vx_virtual_stuff;
24235 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
24236 +       int pos, index;
24237 +       unsigned int xid_array[PROC_MAXVIDS];
24238 +       char buf[PROC_NUMBUF];
24239 +       unsigned int nr_xids, i;
24240 +       u64 ino;
24241 +
24242 +       pos = filp->f_pos;
24243 +       switch (pos) {
24244 +       case 0:
24245 +               ino = inode->i_ino;
24246 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
24247 +                       goto out;
24248 +               pos++;
24249 +               /* fall through */
24250 +       case 1:
24251 +               ino = parent_ino(dentry);
24252 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
24253 +                       goto out;
24254 +               pos++;
24255 +               /* fall through */
24256 +       default:
24257 +               index = pos - 2;
24258 +               if (index >= size)
24259 +                       goto entries;
24260 +               for (p += index; p->name; p++) {
24261 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
24262 +                               vs_proc_instantiate, 0, p))
24263 +                               goto out;
24264 +                       pos++;
24265 +               }
24266 +       entries:
24267 +               index = pos - size;
24268 +               p = &vx_virtual_stuff[size - 1];
24269 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
24270 +               for (i = 0; i < nr_xids; i++) {
24271 +                       int n, xid = xid_array[i];
24272 +                       unsigned int j = PROC_NUMBUF;
24273 +
24274 +                       n = xid;
24275 +                       do
24276 +                               buf[--j] = '0' + (n % 10);
24277 +                       while (n /= 10);
24278 +
24279 +                       if (proc_fill_cache(filp, dirent, filldir,
24280 +                               buf + j, PROC_NUMBUF - j,
24281 +                               vs_proc_instantiate, xid, p))
24282 +                               goto out;
24283 +                       pos++;
24284 +               }
24285 +       }
24286 +out:
24287 +       filp->f_pos = pos;
24288 +       return 0;
24289 +}
24290 +
24291 +static int proc_virtual_getattr(struct vfsmount *mnt,
24292 +       struct dentry *dentry, struct kstat *stat)
24293 +{
24294 +       struct inode *inode = dentry->d_inode;
24295 +
24296 +       generic_fillattr(inode, stat);
24297 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
24298 +       return 0;
24299 +}
24300 +
24301 +static struct file_operations proc_virtual_dir_operations = {
24302 +       .read =         generic_read_dir,
24303 +       .readdir =      proc_virtual_readdir,
24304 +};
24305 +
24306 +static struct inode_operations proc_virtual_dir_inode_operations = {
24307 +       .getattr =      proc_virtual_getattr,
24308 +       .lookup =       proc_virtual_lookup,
24309 +};
24310 +
24311 +
24312 +
24313 +
24314 +
24315 +int proc_virtnet_readdir(struct file *filp,
24316 +       void *dirent, filldir_t filldir)
24317 +{
24318 +       struct dentry *dentry = filp->f_dentry;
24319 +       struct inode *inode = dentry->d_inode;
24320 +       struct vs_entry *p = nx_virtnet_stuff;
24321 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
24322 +       int pos, index;
24323 +       unsigned int nid_array[PROC_MAXVIDS];
24324 +       char buf[PROC_NUMBUF];
24325 +       unsigned int nr_nids, i;
24326 +       u64 ino;
24327 +
24328 +       pos = filp->f_pos;
24329 +       switch (pos) {
24330 +       case 0:
24331 +               ino = inode->i_ino;
24332 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
24333 +                       goto out;
24334 +               pos++;
24335 +               /* fall through */
24336 +       case 1:
24337 +               ino = parent_ino(dentry);
24338 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
24339 +                       goto out;
24340 +               pos++;
24341 +               /* fall through */
24342 +       default:
24343 +               index = pos - 2;
24344 +               if (index >= size)
24345 +                       goto entries;
24346 +               for (p += index; p->name; p++) {
24347 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
24348 +                               vs_proc_instantiate, 0, p))
24349 +                               goto out;
24350 +                       pos++;
24351 +               }
24352 +       entries:
24353 +               index = pos - size;
24354 +               p = &nx_virtnet_stuff[size - 1];
24355 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
24356 +               for (i = 0; i < nr_nids; i++) {
24357 +                       int n, nid = nid_array[i];
24358 +                       unsigned int j = PROC_NUMBUF;
24359 +
24360 +                       n = nid;
24361 +                       do
24362 +                               buf[--j] = '0' + (n % 10);
24363 +                       while (n /= 10);
24364 +
24365 +                       if (proc_fill_cache(filp, dirent, filldir,
24366 +                               buf + j, PROC_NUMBUF - j,
24367 +                               vs_proc_instantiate, nid, p))
24368 +                               goto out;
24369 +                       pos++;
24370 +               }
24371 +       }
24372 +out:
24373 +       filp->f_pos = pos;
24374 +       return 0;
24375 +}
24376 +
24377 +static int proc_virtnet_getattr(struct vfsmount *mnt,
24378 +       struct dentry *dentry, struct kstat *stat)
24379 +{
24380 +       struct inode *inode = dentry->d_inode;
24381 +
24382 +       generic_fillattr(inode, stat);
24383 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
24384 +       return 0;
24385 +}
24386 +
24387 +static struct file_operations proc_virtnet_dir_operations = {
24388 +       .read =         generic_read_dir,
24389 +       .readdir =      proc_virtnet_readdir,
24390 +};
24391 +
24392 +static struct inode_operations proc_virtnet_dir_inode_operations = {
24393 +       .getattr =      proc_virtnet_getattr,
24394 +       .lookup =       proc_virtnet_lookup,
24395 +};
24396 +
24397 +
24398 +
24399 +void proc_vx_init(void)
24400 +{
24401 +       struct proc_dir_entry *ent;
24402 +
24403 +       ent = proc_mkdir("virtual", 0);
24404 +       if (ent) {
24405 +               ent->proc_fops = &proc_virtual_dir_operations;
24406 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
24407 +       }
24408 +       proc_virtual = ent;
24409 +
24410 +       ent = proc_mkdir("virtnet", 0);
24411 +       if (ent) {
24412 +               ent->proc_fops = &proc_virtnet_dir_operations;
24413 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
24414 +       }
24415 +       proc_virtnet = ent;
24416 +}
24417 +
24418 +
24419 +
24420 +
24421 +/* per pid info */
24422 +
24423 +
24424 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
24425 +{
24426 +       struct vx_info *vxi;
24427 +       char *orig = buffer;
24428 +
24429 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
24430 +
24431 +       vxi = task_get_vx_info(p);
24432 +       if (!vxi)
24433 +               goto out;
24434 +
24435 +       buffer += sprintf(buffer, "BCaps:\t");
24436 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
24437 +       buffer += sprintf(buffer, "\n");
24438 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
24439 +               (unsigned long long)vxi->vx_ccaps);
24440 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
24441 +               (unsigned long long)vxi->vx_flags);
24442 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
24443 +
24444 +       put_vx_info(vxi);
24445 +out:
24446 +       return buffer - orig;
24447 +}
24448 +
24449 +
24450 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
24451 +{
24452 +       struct nx_info *nxi;
24453 +       struct nx_addr_v4 *v4a;
24454 +#ifdef CONFIG_IPV6
24455 +       struct nx_addr_v6 *v6a;
24456 +#endif
24457 +       char *orig = buffer;
24458 +       int i;
24459 +
24460 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
24461 +
24462 +       nxi = task_get_nx_info(p);
24463 +       if (!nxi)
24464 +               goto out;
24465 +
24466 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
24467 +               (unsigned long long)nxi->nx_ncaps);
24468 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
24469 +               (unsigned long long)nxi->nx_flags);
24470 +
24471 +       buffer += sprintf(buffer,
24472 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
24473 +               NIPQUAD(nxi->v4_bcast.s_addr));
24474 +       buffer += sprintf (buffer,
24475 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
24476 +               NIPQUAD(nxi->v4_lback.s_addr));
24477 +       if (!NX_IPV4(nxi))
24478 +               goto skip_v4;
24479 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
24480 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
24481 +                       i, NXAV4(v4a));
24482 +skip_v4:
24483 +#ifdef CONFIG_IPV6
24484 +       if (!NX_IPV6(nxi))
24485 +               goto skip_v6;
24486 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
24487 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
24488 +                       i, NXAV6(v6a));
24489 +skip_v6:
24490 +#endif
24491 +       put_nx_info(nxi);
24492 +out:
24493 +       return buffer - orig;
24494 +}
24495 +
24496 diff -NurpP --minimal linux-2.6.25/kernel/vserver/sched.c linux-2.6.25-vs2.3.0.34.9/kernel/vserver/sched.c
24497 --- linux-2.6.25/kernel/vserver/sched.c 1969-12-31 19:00:00.000000000 -0500
24498 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/sched.c    2008-04-29 18:40:09.000000000 -0400
24499 @@ -0,0 +1,413 @@
24500 +/*
24501 + *  linux/kernel/vserver/sched.c
24502 + *
24503 + *  Virtual Server: Scheduler Support
24504 + *
24505 + *  Copyright (C) 2004-2007  Herbert Pötzl
24506 + *
24507 + *  V0.01  adapted Sam Vilains version to 2.6.3
24508 + *  V0.02  removed legacy interface
24509 + *  V0.03  changed vcmds to vxi arg
24510 + *  V0.04  removed older and legacy interfaces
24511 + *
24512 + */
24513 +
24514 +#include <linux/vs_context.h>
24515 +#include <linux/vs_sched.h>
24516 +#include <linux/vserver/sched_cmd.h>
24517 +
24518 +#include <asm/uaccess.h>
24519 +
24520 +
24521 +#define vxd_check_range(val, min, max) do {            \
24522 +       vxlprintk((val < min) || (val > max),           \
24523 +               "check_range(%ld,%ld,%ld)",             \
24524 +               (long)val, (long)min, (long)max,        \
24525 +               __FILE__, __LINE__);                    \
24526 +       } while (0)
24527 +
24528 +
24529 +void vx_update_sched_param(struct _vx_sched *sched,
24530 +       struct _vx_sched_pc *sched_pc)
24531 +{
24532 +       unsigned int set_mask = sched->update_mask;
24533 +
24534 +       if (set_mask & VXSM_FILL_RATE)
24535 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
24536 +       if (set_mask & VXSM_INTERVAL)
24537 +               sched_pc->interval[0] = sched->interval[0];
24538 +       if (set_mask & VXSM_FILL_RATE2)
24539 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
24540 +       if (set_mask & VXSM_INTERVAL2)
24541 +               sched_pc->interval[1] = sched->interval[1];
24542 +       if (set_mask & VXSM_TOKENS)
24543 +               sched_pc->tokens = sched->tokens;
24544 +       if (set_mask & VXSM_TOKENS_MIN)
24545 +               sched_pc->tokens_min = sched->tokens_min;
24546 +       if (set_mask & VXSM_TOKENS_MAX)
24547 +               sched_pc->tokens_max = sched->tokens_max;
24548 +       if (set_mask & VXSM_PRIO_BIAS)
24549 +               sched_pc->prio_bias = sched->prio_bias;
24550 +
24551 +       if (set_mask & VXSM_IDLE_TIME)
24552 +               sched_pc->flags |= VXSF_IDLE_TIME;
24553 +       else
24554 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
24555 +
24556 +       /* reset time */
24557 +       sched_pc->norm_time = jiffies;
24558 +}
24559 +
24560 +
24561 +/*
24562 + * recalculate the context's scheduling tokens
24563 + *
24564 + * ret > 0 : number of tokens available
24565 + * ret < 0 : on hold, check delta_min[]
24566 + *          -1 only jiffies
24567 + *          -2 also idle time
24568 + *
24569 + */
24570 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
24571 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
24572 +{
24573 +       long delta;
24574 +       long tokens = 0;
24575 +       int flags = sched_pc->flags;
24576 +
24577 +       /* how much time did pass? */
24578 +       delta = *norm_time - sched_pc->norm_time;
24579 +       vxd_check_range(delta, 0, INT_MAX);
24580 +
24581 +       if (delta >= sched_pc->interval[0]) {
24582 +               long tokens, integral;
24583 +
24584 +               /* calc integral token part */
24585 +               tokens = delta / sched_pc->interval[0];
24586 +               integral = tokens * sched_pc->interval[0];
24587 +               tokens *= sched_pc->fill_rate[0];
24588 +#ifdef CONFIG_VSERVER_HARDCPU
24589 +               delta_min[0] = delta - integral;
24590 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
24591 +#endif
24592 +               /* advance time */
24593 +               sched_pc->norm_time += delta;
24594 +
24595 +               /* add tokens */
24596 +               sched_pc->tokens += tokens;
24597 +               sched_pc->token_time += tokens;
24598 +       } else
24599 +               delta_min[0] = delta;
24600 +
24601 +#ifdef CONFIG_VSERVER_IDLETIME
24602 +       if (!(flags & VXSF_IDLE_TIME))
24603 +               goto skip_idle;
24604 +
24605 +       /* how much was the idle skip? */
24606 +       delta = *idle_time - sched_pc->idle_time;
24607 +       vxd_check_range(delta, 0, INT_MAX);
24608 +
24609 +       if (delta >= sched_pc->interval[1]) {
24610 +               long tokens, integral;
24611 +
24612 +               /* calc fair share token part */
24613 +               tokens = delta / sched_pc->interval[1];
24614 +               integral = tokens * sched_pc->interval[1];
24615 +               tokens *= sched_pc->fill_rate[1];
24616 +               delta_min[1] = delta - integral;
24617 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
24618 +
24619 +               /* advance idle time */
24620 +               sched_pc->idle_time += integral;
24621 +
24622 +               /* add tokens */
24623 +               sched_pc->tokens += tokens;
24624 +               sched_pc->token_time += tokens;
24625 +       } else
24626 +               delta_min[1] = delta;
24627 +skip_idle:
24628 +#endif
24629 +
24630 +       /* clip at maximum */
24631 +       if (sched_pc->tokens > sched_pc->tokens_max)
24632 +               sched_pc->tokens = sched_pc->tokens_max;
24633 +       tokens = sched_pc->tokens;
24634 +
24635 +       if ((flags & VXSF_ONHOLD)) {
24636 +               /* can we unhold? */
24637 +               if (tokens >= sched_pc->tokens_min) {
24638 +                       flags &= ~VXSF_ONHOLD;
24639 +                       sched_pc->hold_ticks +=
24640 +                               *norm_time - sched_pc->onhold;
24641 +               } else
24642 +                       goto on_hold;
24643 +       } else {
24644 +               /* put on hold? */
24645 +               if (tokens <= 0) {
24646 +                       flags |= VXSF_ONHOLD;
24647 +                       sched_pc->onhold = *norm_time;
24648 +                       goto on_hold;
24649 +               }
24650 +       }
24651 +       sched_pc->flags = flags;
24652 +       return tokens;
24653 +
24654 +on_hold:
24655 +       tokens = sched_pc->tokens_min - tokens;
24656 +       sched_pc->flags = flags;
24657 +       BUG_ON(tokens < 0);
24658 +
24659 +#ifdef CONFIG_VSERVER_HARDCPU
24660 +       /* next interval? */
24661 +       if (!sched_pc->fill_rate[0])
24662 +               delta_min[0] = HZ;
24663 +       else if (tokens > sched_pc->fill_rate[0])
24664 +               delta_min[0] += sched_pc->interval[0] *
24665 +                       tokens / sched_pc->fill_rate[0];
24666 +       else
24667 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
24668 +       vxd_check_range(delta_min[0], 0, INT_MAX);
24669 +
24670 +#ifdef CONFIG_VSERVER_IDLETIME
24671 +       if (!(flags & VXSF_IDLE_TIME))
24672 +               return -1;
24673 +
24674 +       /* next interval? */
24675 +       if (!sched_pc->fill_rate[1])
24676 +               delta_min[1] = HZ;
24677 +       else if (tokens > sched_pc->fill_rate[1])
24678 +               delta_min[1] += sched_pc->interval[1] *
24679 +                       tokens / sched_pc->fill_rate[1];
24680 +       else
24681 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
24682 +       vxd_check_range(delta_min[1], 0, INT_MAX);
24683 +
24684 +       return -2;
24685 +#else
24686 +       return -1;
24687 +#endif /* CONFIG_VSERVER_IDLETIME */
24688 +#else
24689 +       return 0;
24690 +#endif /* CONFIG_VSERVER_HARDCPU */
24691 +}
24692 +
24693 +static inline unsigned long msec_to_ticks(unsigned long msec)
24694 +{
24695 +       return msecs_to_jiffies(msec);
24696 +}
24697 +
24698 +static inline unsigned long ticks_to_msec(unsigned long ticks)
24699 +{
24700 +       return jiffies_to_msecs(ticks);
24701 +}
24702 +
24703 +static inline unsigned long ticks_to_usec(unsigned long ticks)
24704 +{
24705 +       return jiffies_to_usecs(ticks);
24706 +}
24707 +
24708 +
24709 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
24710 +{
24711 +       unsigned int set_mask = data->mask;
24712 +       unsigned int update_mask;
24713 +       int i, cpu;
24714 +
24715 +       /* Sanity check data values */
24716 +       if (data->tokens_max <= 0)
24717 +               data->tokens_max = HZ;
24718 +       if (data->tokens_min < 0)
24719 +               data->tokens_min = HZ / 3;
24720 +       if (data->tokens_min >= data->tokens_max)
24721 +               data->tokens_min = data->tokens_max;
24722 +
24723 +       if (data->prio_bias > MAX_PRIO_BIAS)
24724 +               data->prio_bias = MAX_PRIO_BIAS;
24725 +       if (data->prio_bias < MIN_PRIO_BIAS)
24726 +               data->prio_bias = MIN_PRIO_BIAS;
24727 +
24728 +       spin_lock(&vxi->sched.tokens_lock);
24729 +
24730 +       /* sync up on delayed updates */
24731 +       for_each_cpu_mask(cpu, vxi->sched.update)
24732 +               vx_update_sched_param(&vxi->sched,
24733 +                       &vx_per_cpu(vxi, sched_pc, cpu));
24734 +
24735 +       if (set_mask & VXSM_FILL_RATE)
24736 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
24737 +       if (set_mask & VXSM_FILL_RATE2)
24738 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
24739 +       if (set_mask & VXSM_INTERVAL)
24740 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
24741 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
24742 +       if (set_mask & VXSM_INTERVAL2)
24743 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
24744 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
24745 +       if (set_mask & VXSM_TOKENS)
24746 +               vxi->sched.tokens = data->tokens;
24747 +       if (set_mask & VXSM_TOKENS_MIN)
24748 +               vxi->sched.tokens_min = data->tokens_min;
24749 +       if (set_mask & VXSM_TOKENS_MAX)
24750 +               vxi->sched.tokens_max = data->tokens_max;
24751 +       if (set_mask & VXSM_PRIO_BIAS)
24752 +               vxi->sched.prio_bias = data->prio_bias;
24753 +
24754 +       /* Sanity check rate/interval */
24755 +       for (i = 0; i < 2; i++) {
24756 +               if (data->fill_rate[i] < 0)
24757 +                       data->fill_rate[i] = 0;
24758 +               if (data->interval[i] <= 0)
24759 +                       data->interval[i] = HZ;
24760 +       }
24761 +
24762 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
24763 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
24764 +       vxi->sched.update_mask = update_mask;
24765 +
24766 +#ifdef CONFIG_SMP
24767 +       rmb();
24768 +       if (set_mask & VXSM_CPU_ID) {
24769 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
24770 +               cpus_and(vxi->sched.update, cpu_online_map,
24771 +                       vxi->sched.update);
24772 +       } else
24773 +               vxi->sched.update = cpu_online_map;
24774 +
24775 +       /* forced reload? */
24776 +       if (set_mask & VXSM_FORCE) {
24777 +               for_each_cpu_mask(cpu, vxi->sched.update)
24778 +                       vx_update_sched_param(&vxi->sched,
24779 +                               &vx_per_cpu(vxi, sched_pc, cpu));
24780 +               vxi->sched.update = CPU_MASK_NONE;
24781 +       }
24782 +#else
24783 +       /* on UP we update immediately */
24784 +       vx_update_sched_param(&vxi->sched,
24785 +               &vx_per_cpu(vxi, sched_pc, 0));
24786 +#endif
24787 +
24788 +       spin_unlock(&vxi->sched.tokens_lock);
24789 +       return 0;
24790 +}
24791 +
24792 +
24793 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
24794 +#define COPY_PRI(C) C(prio_bias)
24795 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
24796 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
24797 +                   C(fill_rate[1]); C(interval[1]);
24798 +
24799 +#define COPY_VALUE(name) vc_data.name = data->name
24800 +
24801 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
24802 +{
24803 +       struct vcmd_sched_v5 vc_data;
24804 +
24805 +       vc_data.mask = data->set_mask;
24806 +       COPY_IDS(COPY_VALUE);
24807 +       COPY_PRI(COPY_VALUE);
24808 +       COPY_TOK(COPY_VALUE);
24809 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
24810 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
24811 +       return do_set_sched(vxi, &vc_data);
24812 +}
24813 +
24814 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
24815 +{
24816 +       struct vcmd_set_sched_v4 vc_data;
24817 +
24818 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24819 +               return -EFAULT;
24820 +
24821 +       return do_set_sched_v4(vxi, &vc_data);
24822 +}
24823 +
24824 +       /* latest interface is v5 */
24825 +
24826 +int vc_set_sched(struct vx_info *vxi, void __user *data)
24827 +{
24828 +       struct vcmd_sched_v5 vc_data;
24829 +
24830 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24831 +               return -EFAULT;
24832 +
24833 +       return do_set_sched(vxi, &vc_data);
24834 +}
24835 +
24836 +
24837 +#define COPY_PRI(C) C(prio_bias)
24838 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
24839 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);    \
24840 +                   C(fill_rate[1]); C(interval[1]);
24841 +
24842 +#define COPY_VALUE(name) vc_data.name = data->name
24843 +
24844 +
24845 +int vc_get_sched(struct vx_info *vxi, void __user *data)
24846 +{
24847 +       struct vcmd_sched_v5 vc_data;
24848 +
24849 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24850 +               return -EFAULT;
24851 +
24852 +       if (vc_data.mask & VXSM_CPU_ID) {
24853 +               int cpu = vc_data.cpu_id;
24854 +               struct _vx_sched_pc *data;
24855 +
24856 +               if (!cpu_possible(cpu))
24857 +                       return -EINVAL;
24858 +
24859 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
24860 +               COPY_TOK(COPY_VALUE);
24861 +               COPY_PRI(COPY_VALUE);
24862 +               COPY_FRI(COPY_VALUE);
24863 +
24864 +               if (data->flags & VXSF_IDLE_TIME)
24865 +                       vc_data.mask |= VXSM_IDLE_TIME;
24866 +       } else {
24867 +               struct _vx_sched *data = &vxi->sched;
24868 +
24869 +               COPY_TOK(COPY_VALUE);
24870 +               COPY_PRI(COPY_VALUE);
24871 +               COPY_FRI(COPY_VALUE);
24872 +       }
24873 +
24874 +       if (vc_data.mask & VXSM_MSEC) {
24875 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
24876 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
24877 +       }
24878 +
24879 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24880 +               return -EFAULT;
24881 +       return 0;
24882 +}
24883 +
24884 +
24885 +int vc_sched_info(struct vx_info *vxi, void __user *data)
24886 +{
24887 +       struct vcmd_sched_info vc_data;
24888 +       int cpu;
24889 +
24890 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24891 +               return -EFAULT;
24892 +
24893 +       cpu = vc_data.cpu_id;
24894 +       if (!cpu_possible(cpu))
24895 +               return -EINVAL;
24896 +
24897 +       if (vxi) {
24898 +               struct _vx_sched_pc *sched_pc =
24899 +                       &vx_per_cpu(vxi, sched_pc, cpu);
24900 +
24901 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
24902 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
24903 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
24904 +               vc_data.vavavoom = sched_pc->vavavoom;
24905 +       }
24906 +       vc_data.token_usec = ticks_to_usec(1);
24907 +
24908 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24909 +               return -EFAULT;
24910 +       return 0;
24911 +}
24912 +
24913 diff -NurpP --minimal linux-2.6.25/kernel/vserver/sched_init.h linux-2.6.25-vs2.3.0.34.9/kernel/vserver/sched_init.h
24914 --- linux-2.6.25/kernel/vserver/sched_init.h    1969-12-31 19:00:00.000000000 -0500
24915 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/sched_init.h       2008-04-19 15:14:52.000000000 -0400
24916 @@ -0,0 +1,50 @@
24917 +
24918 +static inline void vx_info_init_sched(struct _vx_sched *sched)
24919 +{
24920 +       static struct lock_class_key tokens_lock_key;
24921 +
24922 +       /* scheduling; hard code starting values as constants */
24923 +       sched->fill_rate[0]     = 1;
24924 +       sched->interval[0]      = 4;
24925 +       sched->fill_rate[1]     = 1;
24926 +       sched->interval[1]      = 8;
24927 +       sched->tokens           = HZ >> 2;
24928 +       sched->tokens_min       = HZ >> 4;
24929 +       sched->tokens_max       = HZ >> 1;
24930 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
24931 +       sched->prio_bias        = 0;
24932 +
24933 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
24934 +}
24935 +
24936 +static inline
24937 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24938 +{
24939 +       sched_pc->fill_rate[0]  = 1;
24940 +       sched_pc->interval[0]   = 4;
24941 +       sched_pc->fill_rate[1]  = 1;
24942 +       sched_pc->interval[1]   = 8;
24943 +       sched_pc->tokens        = HZ >> 2;
24944 +       sched_pc->tokens_min    = HZ >> 4;
24945 +       sched_pc->tokens_max    = HZ >> 1;
24946 +       sched_pc->prio_bias     = 0;
24947 +       sched_pc->vavavoom      = 0;
24948 +       sched_pc->token_time    = 0;
24949 +       sched_pc->idle_time     = 0;
24950 +       sched_pc->norm_time     = jiffies;
24951 +
24952 +       sched_pc->user_ticks = 0;
24953 +       sched_pc->sys_ticks = 0;
24954 +       sched_pc->hold_ticks = 0;
24955 +}
24956 +
24957 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
24958 +{
24959 +       return;
24960 +}
24961 +
24962 +static inline
24963 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24964 +{
24965 +       return;
24966 +}
24967 diff -NurpP --minimal linux-2.6.25/kernel/vserver/sched_proc.h linux-2.6.25-vs2.3.0.34.9/kernel/vserver/sched_proc.h
24968 --- linux-2.6.25/kernel/vserver/sched_proc.h    1969-12-31 19:00:00.000000000 -0500
24969 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/sched_proc.h       2008-04-19 15:14:52.000000000 -0400
24970 @@ -0,0 +1,57 @@
24971 +#ifndef _VX_SCHED_PROC_H
24972 +#define _VX_SCHED_PROC_H
24973 +
24974 +
24975 +static inline
24976 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
24977 +{
24978 +       int length = 0;
24979 +
24980 +       length += sprintf(buffer,
24981 +               "FillRate:\t%8d,%d\n"
24982 +               "Interval:\t%8d,%d\n"
24983 +               "TokensMin:\t%8d\n"
24984 +               "TokensMax:\t%8d\n"
24985 +               "PrioBias:\t%8d\n",
24986 +               sched->fill_rate[0],
24987 +               sched->fill_rate[1],
24988 +               sched->interval[0],
24989 +               sched->interval[1],
24990 +               sched->tokens_min,
24991 +               sched->tokens_max,
24992 +               sched->prio_bias);
24993 +       return length;
24994 +}
24995 +
24996 +static inline
24997 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
24998 +       char *buffer, int cpu)
24999 +{
25000 +       int length = 0;
25001 +
25002 +       length += sprintf(buffer + length,
25003 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
25004 +               (unsigned long long)sched_pc->user_ticks,
25005 +               (unsigned long long)sched_pc->sys_ticks,
25006 +               (unsigned long long)sched_pc->hold_ticks,
25007 +               sched_pc->token_time,
25008 +               sched_pc->idle_time);
25009 +       length += sprintf(buffer + length,
25010 +               " %c%c %d %d %d %d/%d %d/%d",
25011 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
25012 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
25013 +               sched_pc->tokens,
25014 +               sched_pc->tokens_min,
25015 +               sched_pc->tokens_max,
25016 +               sched_pc->fill_rate[0],
25017 +               sched_pc->interval[0],
25018 +               sched_pc->fill_rate[1],
25019 +               sched_pc->interval[1]);
25020 +       length += sprintf(buffer + length,
25021 +               " %d %d\n",
25022 +               sched_pc->prio_bias,
25023 +               sched_pc->vavavoom);
25024 +       return length;
25025 +}
25026 +
25027 +#endif /* _VX_SCHED_PROC_H */
25028 diff -NurpP --minimal linux-2.6.25/kernel/vserver/signal.c linux-2.6.25-vs2.3.0.34.9/kernel/vserver/signal.c
25029 --- linux-2.6.25/kernel/vserver/signal.c        1969-12-31 19:00:00.000000000 -0500
25030 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/signal.c   2008-04-19 15:14:52.000000000 -0400
25031 @@ -0,0 +1,132 @@
25032 +/*
25033 + *  linux/kernel/vserver/signal.c
25034 + *
25035 + *  Virtual Server: Signal Support
25036 + *
25037 + *  Copyright (C) 2003-2007  Herbert Pötzl
25038 + *
25039 + *  V0.01  broken out from vcontext V0.05
25040 + *  V0.02  changed vcmds to vxi arg
25041 + *  V0.03  adjusted siginfo for kill
25042 + *
25043 + */
25044 +
25045 +#include <asm/uaccess.h>
25046 +
25047 +#include <linux/vs_context.h>
25048 +#include <linux/vs_pid.h>
25049 +#include <linux/vserver/signal_cmd.h>
25050 +
25051 +
25052 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
25053 +{
25054 +       int retval, count = 0;
25055 +       struct task_struct *p;
25056 +       struct siginfo *sip = SEND_SIG_PRIV;
25057 +
25058 +       retval = -ESRCH;
25059 +       vxdprintk(VXD_CBIT(misc, 4),
25060 +               "vx_info_kill(%p[#%d],%d,%d)*",
25061 +               vxi, vxi->vx_id, pid, sig);
25062 +       read_lock(&tasklist_lock);
25063 +       switch (pid) {
25064 +       case  0:
25065 +       case -1:
25066 +               for_each_process(p) {
25067 +                       int err = 0;
25068 +
25069 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
25070 +                               (pid && vxi->vx_initpid == p->pid))
25071 +                               continue;
25072 +
25073 +                       err = group_send_sig_info(sig, sip, p);
25074 +                       ++count;
25075 +                       if (err != -EPERM)
25076 +                               retval = err;
25077 +               }
25078 +               break;
25079 +
25080 +       case 1:
25081 +               if (vxi->vx_initpid) {
25082 +                       pid = vxi->vx_initpid;
25083 +                       /* for now, only SIGINT to private init ... */
25084 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
25085 +                               /* ... as long as there are tasks left */
25086 +                               (atomic_read(&vxi->vx_tasks) > 1))
25087 +                               sig = SIGINT;
25088 +               }
25089 +               /* fallthrough */
25090 +       default:
25091 +               p = find_task_by_real_pid(pid);
25092 +               if (p) {
25093 +                       if (vx_task_xid(p) == vxi->vx_id)
25094 +                               retval = group_send_sig_info(sig, sip, p);
25095 +               }
25096 +               break;
25097 +       }
25098 +       read_unlock(&tasklist_lock);
25099 +       vxdprintk(VXD_CBIT(misc, 4),
25100 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
25101 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
25102 +       return retval;
25103 +}
25104 +
25105 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
25106 +{
25107 +       struct vcmd_ctx_kill_v0 vc_data;
25108 +
25109 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
25110 +               return -EFAULT;
25111 +
25112 +       /* special check to allow guest shutdown */
25113 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
25114 +               /* forbid killall pid=0 when init is present */
25115 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
25116 +               (vc_data.pid > 1)))
25117 +               return -EACCES;
25118 +
25119 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
25120 +}
25121 +
25122 +
25123 +static int __wait_exit(struct vx_info *vxi)
25124 +{
25125 +       DECLARE_WAITQUEUE(wait, current);
25126 +       int ret = 0;
25127 +
25128 +       add_wait_queue(&vxi->vx_wait, &wait);
25129 +       set_current_state(TASK_INTERRUPTIBLE);
25130 +
25131 +wait:
25132 +       if (vx_info_state(vxi,
25133 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
25134 +               goto out;
25135 +       if (signal_pending(current)) {
25136 +               ret = -ERESTARTSYS;
25137 +               goto out;
25138 +       }
25139 +       schedule();
25140 +       goto wait;
25141 +
25142 +out:
25143 +       set_current_state(TASK_RUNNING);
25144 +       remove_wait_queue(&vxi->vx_wait, &wait);
25145 +       return ret;
25146 +}
25147 +
25148 +
25149 +
25150 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
25151 +{
25152 +       struct vcmd_wait_exit_v0 vc_data;
25153 +       int ret;
25154 +
25155 +       ret = __wait_exit(vxi);
25156 +       vc_data.reboot_cmd = vxi->reboot_cmd;
25157 +       vc_data.exit_code = vxi->exit_code;
25158 +
25159 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
25160 +               ret = -EFAULT;
25161 +       return ret;
25162 +}
25163 +
25164 diff -NurpP --minimal linux-2.6.25/kernel/vserver/space.c linux-2.6.25-vs2.3.0.34.9/kernel/vserver/space.c
25165 --- linux-2.6.25/kernel/vserver/space.c 1969-12-31 19:00:00.000000000 -0500
25166 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/space.c    2008-04-21 12:26:27.000000000 -0400
25167 @@ -0,0 +1,304 @@
25168 +/*
25169 + *  linux/kernel/vserver/space.c
25170 + *
25171 + *  Virtual Server: Context Space Support
25172 + *
25173 + *  Copyright (C) 2003-2007  Herbert Pötzl
25174 + *
25175 + *  V0.01  broken out from context.c 0.07
25176 + *  V0.02  added task locking for namespace
25177 + *  V0.03  broken out vx_enter_namespace
25178 + *  V0.04  added *space support and commands
25179 + *
25180 + */
25181 +
25182 +#include <linux/utsname.h>
25183 +#include <linux/nsproxy.h>
25184 +#include <linux/err.h>
25185 +#include <asm/uaccess.h>
25186 +
25187 +#include <linux/vs_context.h>
25188 +#include <linux/vserver/space.h>
25189 +#include <linux/vserver/space_cmd.h>
25190 +
25191 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
25192 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
25193 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
25194 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
25195 +atomic_t vs_global_ipc_ns      = ATOMIC_INIT(0);
25196 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
25197 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
25198 +
25199 +
25200 +/* namespace functions */
25201 +
25202 +#include <linux/mnt_namespace.h>
25203 +#include <linux/user_namespace.h>
25204 +#include <linux/pid_namespace.h>
25205 +#include <linux/ipc_namespace.h>
25206 +
25207 +const struct vcmd_space_mask space_mask = {
25208 +       .mask = CLONE_NEWNS |
25209 +               CLONE_NEWUTS |
25210 +               CLONE_NEWIPC |
25211 +               CLONE_NEWUSER |
25212 +               CLONE_FS
25213 +};
25214 +
25215 +
25216 +/*
25217 + *     build a new nsproxy mix
25218 + *      assumes that both proxies are 'const'
25219 + *     does not touch nsproxy refcounts
25220 + *     will hold a reference on the result.
25221 + */
25222 +
25223 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
25224 +       struct nsproxy *new_nsproxy, unsigned long mask)
25225 +{
25226 +       struct mnt_namespace *old_ns;
25227 +       struct uts_namespace *old_uts;
25228 +       struct ipc_namespace *old_ipc;
25229 +       struct pid_namespace *old_pid;
25230 +       struct user_namespace *old_user;
25231 +       struct nsproxy *nsproxy;
25232 +
25233 +       nsproxy = copy_nsproxy(old_nsproxy);
25234 +       if (!nsproxy)
25235 +               goto out;
25236 +
25237 +       if (mask & CLONE_NEWNS) {
25238 +               old_ns = nsproxy->mnt_ns;
25239 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
25240 +               if (nsproxy->mnt_ns)
25241 +                       get_mnt_ns(nsproxy->mnt_ns);
25242 +       } else
25243 +               old_ns = NULL;
25244 +
25245 +       if (mask & CLONE_NEWUTS) {
25246 +               old_uts = nsproxy->uts_ns;
25247 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
25248 +               if (nsproxy->uts_ns)
25249 +                       get_uts_ns(nsproxy->uts_ns);
25250 +       } else
25251 +               old_uts = NULL;
25252 +
25253 +       if (mask & CLONE_NEWIPC) {
25254 +               old_ipc = nsproxy->ipc_ns;
25255 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
25256 +               if (nsproxy->ipc_ns)
25257 +                       get_ipc_ns(nsproxy->ipc_ns);
25258 +       } else
25259 +               old_ipc = NULL;
25260 +
25261 +       if (mask & CLONE_NEWUSER) {
25262 +               old_user = nsproxy->user_ns;
25263 +               nsproxy->user_ns = new_nsproxy->user_ns;
25264 +               if (nsproxy->user_ns)
25265 +                       get_user_ns(nsproxy->user_ns);
25266 +       } else
25267 +               old_user = NULL;
25268 +
25269 +       if (mask & CLONE_NEWPID) {
25270 +               old_pid = nsproxy->pid_ns;
25271 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
25272 +               if (nsproxy->pid_ns)
25273 +                       get_pid_ns(nsproxy->pid_ns);
25274 +       } else
25275 +               old_pid = NULL;
25276 +
25277 +       if (old_ns)
25278 +               put_mnt_ns(old_ns);
25279 +       if (old_uts)
25280 +               put_uts_ns(old_uts);
25281 +       if (old_ipc)
25282 +               put_ipc_ns(old_ipc);
25283 +       if (old_pid)
25284 +               put_pid_ns(old_pid);
25285 +       if (old_user)
25286 +               put_user_ns(old_user);
25287 +out:
25288 +       return nsproxy;
25289 +}
25290 +
25291 +
25292 +/*
25293 + *     merge two nsproxy structs into a new one.
25294 + *     will hold a reference on the result.
25295 + */
25296 +
25297 +static inline
25298 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
25299 +       struct nsproxy *proxy, unsigned long mask)
25300 +{
25301 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
25302 +
25303 +       if (!proxy)
25304 +               return NULL;
25305 +
25306 +       if (mask) {
25307 +               /* vs_mix_nsproxy returns with reference */
25308 +               return vs_mix_nsproxy(old ? old : &null_proxy,
25309 +                       proxy, mask);
25310 +       }
25311 +       get_nsproxy(proxy);
25312 +       return proxy;
25313 +}
25314 +
25315 +/*
25316 + *     merge two fs structs into a new one.
25317 + *     will take a reference on the result.
25318 + */
25319 +
25320 +static inline
25321 +struct fs_struct *__vs_merge_fs(struct fs_struct *old,
25322 +       struct fs_struct *fs, unsigned long mask)
25323 +{
25324 +       if (!(mask & CLONE_FS)) {
25325 +               if (old)
25326 +                       atomic_inc(&old->count);
25327 +               return old;
25328 +       }
25329 +
25330 +       if (!fs)
25331 +               return NULL;
25332 +
25333 +       return copy_fs_struct(fs);
25334 +}
25335 +
25336 +
25337 +int vx_enter_space(struct vx_info *vxi, unsigned long mask)
25338 +{
25339 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
25340 +       struct fs_struct *fs, *fs_cur, *fs_new;
25341 +       int ret;
25342 +
25343 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
25344 +               return -EACCES;
25345 +
25346 +       if (!mask)
25347 +               mask = vxi->vx_nsmask;
25348 +
25349 +       if ((mask & vxi->vx_nsmask) != mask)
25350 +               return -EINVAL;
25351 +
25352 +       proxy = vxi->vx_nsproxy;
25353 +       fs = vxi->vx_fs;
25354 +
25355 +       task_lock(current);
25356 +       fs_cur = current->fs;
25357 +       atomic_inc(&fs_cur->count);
25358 +       proxy_cur = current->nsproxy;
25359 +       get_nsproxy(proxy_cur);
25360 +       task_unlock(current);
25361 +
25362 +       fs_new = __vs_merge_fs(fs_cur, fs, mask);
25363 +       if (IS_ERR(fs_new)) {
25364 +               ret = PTR_ERR(fs_new);
25365 +               goto out_put;
25366 +       }
25367 +
25368 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
25369 +       if (IS_ERR(proxy_new)) {
25370 +               ret = PTR_ERR(proxy_new);
25371 +               goto out_put_fs;
25372 +       }
25373 +
25374 +       fs_new = xchg(&current->fs, fs_new);
25375 +       proxy_new = xchg(&current->nsproxy, proxy_new);
25376 +       ret = 0;
25377 +
25378 +       if (proxy_new)
25379 +               put_nsproxy(proxy_new);
25380 +out_put_fs:
25381 +       if (fs_new)
25382 +               put_fs_struct(fs_new);
25383 +out_put:
25384 +       if (proxy_cur)
25385 +               put_nsproxy(proxy_cur);
25386 +       if (fs_cur)
25387 +               put_fs_struct(fs_cur);
25388 +       return ret;
25389 +}
25390 +
25391 +
25392 +int vx_set_space(struct vx_info *vxi, unsigned long mask)
25393 +{
25394 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
25395 +       struct fs_struct *fs_vxi, *fs_cur, *fs_new;
25396 +       int ret;
25397 +
25398 +       if (!mask)
25399 +               mask = space_mask.mask;
25400 +
25401 +       if ((mask & space_mask.mask) != mask)
25402 +               return -EINVAL;
25403 +
25404 +       proxy_vxi = vxi->vx_nsproxy;
25405 +       fs_vxi = vxi->vx_fs;
25406 +
25407 +       task_lock(current);
25408 +       fs_cur = current->fs;
25409 +       atomic_inc(&fs_cur->count);
25410 +       proxy_cur = current->nsproxy;
25411 +       get_nsproxy(proxy_cur);
25412 +       task_unlock(current);
25413 +
25414 +       fs_new = __vs_merge_fs(fs_vxi, fs_cur, mask);
25415 +       if (IS_ERR(fs_new)) {
25416 +               ret = PTR_ERR(fs_new);
25417 +               goto out_put;
25418 +       }
25419 +
25420 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
25421 +       if (IS_ERR(proxy_new)) {
25422 +               ret = PTR_ERR(proxy_new);
25423 +               goto out_put_fs;
25424 +       }
25425 +
25426 +       fs_new = xchg(&vxi->vx_fs, fs_new);
25427 +       proxy_new = xchg(&vxi->vx_nsproxy, proxy_new);
25428 +       vxi->vx_nsmask |= mask;
25429 +       ret = 0;
25430 +
25431 +       if (proxy_new)
25432 +               put_nsproxy(proxy_new);
25433 +out_put_fs:
25434 +       if (fs_new)
25435 +               put_fs_struct(fs_new);
25436 +out_put:
25437 +       if (proxy_cur)
25438 +               put_nsproxy(proxy_cur);
25439 +       if (fs_cur)
25440 +               put_fs_struct(fs_cur);
25441 +       return ret;
25442 +}
25443 +
25444 +
25445 +int vc_enter_space(struct vx_info *vxi, void __user *data)
25446 +{
25447 +       struct vcmd_space_mask vc_data = { .mask = 0 };
25448 +
25449 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25450 +               return -EFAULT;
25451 +
25452 +       return vx_enter_space(vxi, vc_data.mask);
25453 +}
25454 +
25455 +int vc_set_space(struct vx_info *vxi, void __user *data)
25456 +{
25457 +       struct vcmd_space_mask vc_data = { .mask = 0 };
25458 +
25459 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25460 +               return -EFAULT;
25461 +
25462 +       return vx_set_space(vxi, vc_data.mask);
25463 +}
25464 +
25465 +int vc_get_space_mask(struct vx_info *vxi, void __user *data)
25466 +{
25467 +       if (copy_to_user(data, &space_mask, sizeof(space_mask)))
25468 +               return -EFAULT;
25469 +       return 0;
25470 +}
25471 +
25472 diff -NurpP --minimal linux-2.6.25/kernel/vserver/switch.c linux-2.6.25-vs2.3.0.34.9/kernel/vserver/switch.c
25473 --- linux-2.6.25/kernel/vserver/switch.c        1969-12-31 19:00:00.000000000 -0500
25474 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/switch.c   2008-04-29 18:40:18.000000000 -0400
25475 @@ -0,0 +1,529 @@
25476 +/*
25477 + *  linux/kernel/vserver/switch.c
25478 + *
25479 + *  Virtual Server: Syscall Switch
25480 + *
25481 + *  Copyright (C) 2003-2007  Herbert Pötzl
25482 + *
25483 + *  V0.01  syscall switch
25484 + *  V0.02  added signal to context
25485 + *  V0.03  added rlimit functions
25486 + *  V0.04  added iattr, task/xid functions
25487 + *  V0.05  added debug/history stuff
25488 + *  V0.06  added compat32 layer
25489 + *  V0.07  vcmd args and perms
25490 + *  V0.08  added status commands
25491 + *  V0.09  added tag commands
25492 + *  V0.10  added oom bias
25493 + *  V0.11  added device commands
25494 + *
25495 + */
25496 +
25497 +#include <linux/vs_context.h>
25498 +#include <linux/vs_network.h>
25499 +#include <linux/vserver/switch.h>
25500 +
25501 +#include "vci_config.h"
25502 +
25503 +
25504 +static inline
25505 +int vc_get_version(uint32_t id)
25506 +{
25507 +       return VCI_VERSION;
25508 +}
25509 +
25510 +static inline
25511 +int vc_get_vci(uint32_t id)
25512 +{
25513 +       return vci_kernel_config();
25514 +}
25515 +
25516 +#include <linux/vserver/context_cmd.h>
25517 +#include <linux/vserver/cvirt_cmd.h>
25518 +#include <linux/vserver/cacct_cmd.h>
25519 +#include <linux/vserver/limit_cmd.h>
25520 +#include <linux/vserver/network_cmd.h>
25521 +#include <linux/vserver/sched_cmd.h>
25522 +#include <linux/vserver/debug_cmd.h>
25523 +#include <linux/vserver/inode_cmd.h>
25524 +#include <linux/vserver/dlimit_cmd.h>
25525 +#include <linux/vserver/signal_cmd.h>
25526 +#include <linux/vserver/space_cmd.h>
25527 +#include <linux/vserver/tag_cmd.h>
25528 +#include <linux/vserver/device_cmd.h>
25529 +
25530 +#include <linux/vserver/inode.h>
25531 +#include <linux/vserver/dlimit.h>
25532 +
25533 +
25534 +#ifdef CONFIG_COMPAT
25535 +#define __COMPAT(name, id, data, compat)       \
25536 +       (compat) ? name ## _x32(id, data) : name(id, data)
25537 +#define __COMPAT_NO_ID(name, data, compat)     \
25538 +       (compat) ? name ## _x32(data) : name(data)
25539 +#else
25540 +#define __COMPAT(name, id, data, compat)       \
25541 +       name(id, data)
25542 +#define __COMPAT_NO_ID(name, data, compat)     \
25543 +       name(data)
25544 +#endif
25545 +
25546 +
25547 +static inline
25548 +long do_vcmd(uint32_t cmd, uint32_t id,
25549 +       struct vx_info *vxi, struct nx_info *nxi,
25550 +       void __user *data, int compat)
25551 +{
25552 +       switch (cmd) {
25553 +
25554 +       case VCMD_get_version:
25555 +               return vc_get_version(id);
25556 +       case VCMD_get_vci:
25557 +               return vc_get_vci(id);
25558 +
25559 +       case VCMD_task_xid:
25560 +               return vc_task_xid(id);
25561 +       case VCMD_vx_info:
25562 +               return vc_vx_info(vxi, data);
25563 +
25564 +       case VCMD_task_nid:
25565 +               return vc_task_nid(id);
25566 +       case VCMD_nx_info:
25567 +               return vc_nx_info(nxi, data);
25568 +
25569 +       case VCMD_task_tag:
25570 +               return vc_task_tag(id);
25571 +
25572 +       /* this is version 1 */
25573 +       case VCMD_set_space:
25574 +               return vc_set_space(vxi, data);
25575 +
25576 +       case VCMD_get_space_mask:
25577 +               return vc_get_space_mask(vxi, data);
25578 +
25579 +#ifdef CONFIG_IA32_EMULATION
25580 +       case VCMD_get_rlimit:
25581 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
25582 +       case VCMD_set_rlimit:
25583 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
25584 +#else
25585 +       case VCMD_get_rlimit:
25586 +               return vc_get_rlimit(vxi, data);
25587 +       case VCMD_set_rlimit:
25588 +               return vc_set_rlimit(vxi, data);
25589 +#endif
25590 +       case VCMD_get_rlimit_mask:
25591 +               return vc_get_rlimit_mask(id, data);
25592 +       case VCMD_reset_minmax:
25593 +               return vc_reset_minmax(vxi, data);
25594 +
25595 +       case VCMD_get_vhi_name:
25596 +               return vc_get_vhi_name(vxi, data);
25597 +       case VCMD_set_vhi_name:
25598 +               return vc_set_vhi_name(vxi, data);
25599 +
25600 +       case VCMD_ctx_stat:
25601 +               return vc_ctx_stat(vxi, data);
25602 +       case VCMD_virt_stat:
25603 +               return vc_virt_stat(vxi, data);
25604 +       case VCMD_sock_stat:
25605 +               return vc_sock_stat(vxi, data);
25606 +       case VCMD_rlimit_stat:
25607 +               return vc_rlimit_stat(vxi, data);
25608 +
25609 +       case VCMD_set_cflags:
25610 +               return vc_set_cflags(vxi, data);
25611 +       case VCMD_get_cflags:
25612 +               return vc_get_cflags(vxi, data);
25613 +
25614 +       /* this is version 1 */
25615 +       case VCMD_set_ccaps:
25616 +               return vc_set_ccaps(vxi, data);
25617 +       /* this is version 1 */
25618 +       case VCMD_get_ccaps:
25619 +               return vc_get_ccaps(vxi, data);
25620 +       case VCMD_set_bcaps:
25621 +               return vc_set_bcaps(vxi, data);
25622 +       case VCMD_get_bcaps:
25623 +               return vc_get_bcaps(vxi, data);
25624 +
25625 +       case VCMD_set_badness:
25626 +               return vc_set_badness(vxi, data);
25627 +       case VCMD_get_badness:
25628 +               return vc_get_badness(vxi, data);
25629 +
25630 +       case VCMD_set_nflags:
25631 +               return vc_set_nflags(nxi, data);
25632 +       case VCMD_get_nflags:
25633 +               return vc_get_nflags(nxi, data);
25634 +
25635 +       case VCMD_set_ncaps:
25636 +               return vc_set_ncaps(nxi, data);
25637 +       case VCMD_get_ncaps:
25638 +               return vc_get_ncaps(nxi, data);
25639 +
25640 +       case VCMD_set_sched_v4:
25641 +               return vc_set_sched_v4(vxi, data);
25642 +       /* this is version 5 */
25643 +       case VCMD_set_sched:
25644 +               return vc_set_sched(vxi, data);
25645 +       case VCMD_get_sched:
25646 +               return vc_get_sched(vxi, data);
25647 +       case VCMD_sched_info:
25648 +               return vc_sched_info(vxi, data);
25649 +
25650 +       case VCMD_add_dlimit:
25651 +               return __COMPAT(vc_add_dlimit, id, data, compat);
25652 +       case VCMD_rem_dlimit:
25653 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
25654 +       case VCMD_set_dlimit:
25655 +               return __COMPAT(vc_set_dlimit, id, data, compat);
25656 +       case VCMD_get_dlimit:
25657 +               return __COMPAT(vc_get_dlimit, id, data, compat);
25658 +
25659 +       case VCMD_ctx_kill:
25660 +               return vc_ctx_kill(vxi, data);
25661 +
25662 +       case VCMD_wait_exit:
25663 +               return vc_wait_exit(vxi, data);
25664 +
25665 +       case VCMD_get_iattr:
25666 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
25667 +       case VCMD_set_iattr:
25668 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
25669 +
25670 +       case VCMD_fget_iattr:
25671 +               return vc_fget_iattr(id, data);
25672 +       case VCMD_fset_iattr:
25673 +               return vc_fset_iattr(id, data);
25674 +
25675 +       case VCMD_enter_space_v0:
25676 +               return vc_enter_space(vxi, NULL);
25677 +       /* this is version 1 */
25678 +       case VCMD_enter_space:
25679 +               return vc_enter_space(vxi, data);
25680 +
25681 +       case VCMD_ctx_create_v0:
25682 +               return vc_ctx_create(id, NULL);
25683 +       case VCMD_ctx_create:
25684 +               return vc_ctx_create(id, data);
25685 +       case VCMD_ctx_migrate_v0:
25686 +               return vc_ctx_migrate(vxi, NULL);
25687 +       case VCMD_ctx_migrate:
25688 +               return vc_ctx_migrate(vxi, data);
25689 +
25690 +       case VCMD_net_create_v0:
25691 +               return vc_net_create(id, NULL);
25692 +       case VCMD_net_create:
25693 +               return vc_net_create(id, data);
25694 +       case VCMD_net_migrate:
25695 +               return vc_net_migrate(nxi, data);
25696 +
25697 +       case VCMD_tag_migrate:
25698 +               return vc_tag_migrate(id);
25699 +
25700 +       case VCMD_net_add:
25701 +               return vc_net_add(nxi, data);
25702 +       case VCMD_net_remove:
25703 +               return vc_net_remove(nxi, data);
25704 +
25705 +       case VCMD_net_add_ipv4:
25706 +               return vc_net_add_ipv4(nxi, data);
25707 +       case VCMD_net_remove_ipv4:
25708 +               return vc_net_remove_ipv4(nxi, data);
25709 +#ifdef CONFIG_IPV6
25710 +       case VCMD_net_add_ipv6:
25711 +               return vc_net_add_ipv6(nxi, data);
25712 +       case VCMD_net_remove_ipv6:
25713 +               return vc_net_remove_ipv6(nxi, data);
25714 +#endif
25715 +/*     case VCMD_add_match_ipv4:
25716 +               return vc_add_match_ipv4(nxi, data);
25717 +       case VCMD_get_match_ipv4:
25718 +               return vc_get_match_ipv4(nxi, data);
25719 +#ifdef CONFIG_IPV6
25720 +       case VCMD_add_match_ipv6:
25721 +               return vc_add_match_ipv6(nxi, data);
25722 +       case VCMD_get_match_ipv6:
25723 +               return vc_get_match_ipv6(nxi, data);
25724 +#endif */
25725 +
25726 +#ifdef CONFIG_VSERVER_DEVICE
25727 +       case VCMD_set_mapping:
25728 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
25729 +       case VCMD_unset_mapping:
25730 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
25731 +#endif
25732 +#ifdef CONFIG_VSERVER_HISTORY
25733 +       case VCMD_dump_history:
25734 +               return vc_dump_history(id);
25735 +       case VCMD_read_history:
25736 +               return __COMPAT(vc_read_history, id, data, compat);
25737 +#endif
25738 +#ifdef CONFIG_VSERVER_MONITOR
25739 +       case VCMD_read_monitor:
25740 +               return __COMPAT(vc_read_monitor, id, data, compat);
25741 +#endif
25742 +       default:
25743 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
25744 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
25745 +       }
25746 +       return -ENOSYS;
25747 +}
25748 +
25749 +
25750 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
25751 +       case VCMD_ ## vcmd: perm = _perm;               \
25752 +               args = _args; flags = _flags; break
25753 +
25754 +
25755 +#define VCA_NONE       0x00
25756 +#define VCA_VXI                0x01
25757 +#define VCA_NXI                0x02
25758 +
25759 +#define VCF_NONE       0x00
25760 +#define VCF_INFO       0x01
25761 +#define VCF_ADMIN      0x02
25762 +#define VCF_ARES       0x06    /* includes admin */
25763 +#define VCF_SETUP      0x08
25764 +
25765 +#define VCF_ZIDOK      0x10    /* zero id okay */
25766 +
25767 +
25768 +static inline
25769 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
25770 +{
25771 +       long ret;
25772 +       int permit = -1, state = 0;
25773 +       int perm = -1, args = 0, flags = 0;
25774 +       struct vx_info *vxi = NULL;
25775 +       struct nx_info *nxi = NULL;
25776 +
25777 +       switch (cmd) {
25778 +       /* unpriviledged commands */
25779 +       __VCMD(get_version,      0, VCA_NONE,   0);
25780 +       __VCMD(get_vci,          0, VCA_NONE,   0);
25781 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
25782 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
25783 +
25784 +       /* info commands */
25785 +       __VCMD(task_xid,         2, VCA_NONE,   0);
25786 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
25787 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
25788 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
25789 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
25790 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
25791 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
25792 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
25793 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
25794 +
25795 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
25796 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
25797 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
25798 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
25799 +
25800 +       __VCMD(task_nid,         2, VCA_NONE,   0);
25801 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
25802 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
25803 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
25804 +
25805 +       __VCMD(task_tag,         2, VCA_NONE,   0);
25806 +
25807 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
25808 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
25809 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
25810 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
25811 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
25812 +
25813 +       /* lower admin commands */
25814 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
25815 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
25816 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
25817 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
25818 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
25819 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
25820 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
25821 +
25822 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
25823 +       __VCMD(net_create,       5, VCA_NONE,   0);
25824 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
25825 +
25826 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
25827 +
25828 +       /* higher admin commands */
25829 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
25830 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25831 +
25832 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25833 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25834 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25835 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25836 +
25837 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25838 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25839 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25840 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25841 +
25842 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25843 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25844 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25845 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25846 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25847 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25848 +#ifdef CONFIG_IPV6
25849 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25850 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25851 +#endif
25852 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
25853 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
25854 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
25855 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
25856 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
25857 +
25858 +#ifdef CONFIG_VSERVER_DEVICE
25859 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25860 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25861 +#endif
25862 +       /* debug level admin commands */
25863 +#ifdef CONFIG_VSERVER_HISTORY
25864 +       __VCMD(dump_history,     9, VCA_NONE,   0);
25865 +       __VCMD(read_history,     9, VCA_NONE,   0);
25866 +#endif
25867 +#ifdef CONFIG_VSERVER_MONITOR
25868 +       __VCMD(read_monitor,     9, VCA_NONE,   0);
25869 +#endif
25870 +
25871 +       default:
25872 +               perm = -1;
25873 +       }
25874 +
25875 +       vxdprintk(VXD_CBIT(switch, 0),
25876 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
25877 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25878 +               VC_VERSION(cmd), id, data, compat,
25879 +               perm, args, flags);
25880 +
25881 +       ret = -ENOSYS;
25882 +       if (perm < 0)
25883 +               goto out;
25884 +
25885 +       state = 1;
25886 +       if (!capable(CAP_CONTEXT))
25887 +               goto out;
25888 +
25889 +       state = 2;
25890 +       /* moved here from the individual commands */
25891 +       ret = -EPERM;
25892 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
25893 +               goto out;
25894 +
25895 +       state = 3;
25896 +       /* vcmd involves resource management  */
25897 +       ret = -EPERM;
25898 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
25899 +               goto out;
25900 +
25901 +       state = 4;
25902 +       /* various legacy exceptions */
25903 +       switch (cmd) {
25904 +       /* will go away when spectator is a cap */
25905 +       case VCMD_ctx_migrate_v0:
25906 +       case VCMD_ctx_migrate:
25907 +               if (id == 1) {
25908 +                       current->xid = 1;
25909 +                       ret = 1;
25910 +                       goto out;
25911 +               }
25912 +               break;
25913 +
25914 +       /* will go away when spectator is a cap */
25915 +       case VCMD_net_migrate:
25916 +               if (id == 1) {
25917 +                       current->nid = 1;
25918 +                       ret = 1;
25919 +                       goto out;
25920 +               }
25921 +               break;
25922 +       }
25923 +
25924 +       /* vcmds are fine by default */
25925 +       permit = 1;
25926 +
25927 +       /* admin type vcmds require admin ... */
25928 +       if (flags & VCF_ADMIN)
25929 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
25930 +
25931 +       /* ... but setup type vcmds override that */
25932 +       if (!permit && (flags & VCF_SETUP))
25933 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
25934 +
25935 +       state = 5;
25936 +       ret = -EPERM;
25937 +       if (!permit)
25938 +               goto out;
25939 +
25940 +       state = 6;
25941 +       if (!id && (flags & VCF_ZIDOK))
25942 +               goto skip_id;
25943 +
25944 +       ret = -ESRCH;
25945 +       if (args & VCA_VXI) {
25946 +               vxi = lookup_vx_info(id);
25947 +               if (!vxi)
25948 +                       goto out;
25949 +
25950 +               if ((flags & VCF_ADMIN) &&
25951 +                       /* special case kill for shutdown */
25952 +                       (cmd != VCMD_ctx_kill) &&
25953 +                       /* can context be administrated? */
25954 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
25955 +                       ret = -EACCES;
25956 +                       goto out_vxi;
25957 +               }
25958 +       }
25959 +       state = 7;
25960 +       if (args & VCA_NXI) {
25961 +               nxi = lookup_nx_info(id);
25962 +               if (!nxi)
25963 +                       goto out_vxi;
25964 +
25965 +               if ((flags & VCF_ADMIN) &&
25966 +                       /* can context be administrated? */
25967 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
25968 +                       ret = -EACCES;
25969 +                       goto out_nxi;
25970 +               }
25971 +       }
25972 +skip_id:
25973 +       state = 8;
25974 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
25975 +
25976 +out_nxi:
25977 +       if ((args & VCA_NXI) && nxi)
25978 +               put_nx_info(nxi);
25979 +out_vxi:
25980 +       if ((args & VCA_VXI) && vxi)
25981 +               put_vx_info(vxi);
25982 +out:
25983 +       vxdprintk(VXD_CBIT(switch, 1),
25984 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
25985 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25986 +               VC_VERSION(cmd), ret, ret, state, permit);
25987 +       return ret;
25988 +}
25989 +
25990 +asmlinkage long
25991 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
25992 +{
25993 +       return do_vserver(cmd, id, data, 0);
25994 +}
25995 +
25996 +#ifdef CONFIG_COMPAT
25997 +
25998 +asmlinkage long
25999 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
26000 +{
26001 +       return do_vserver(cmd, id, data, 1);
26002 +}
26003 +
26004 +#endif /* CONFIG_COMPAT */
26005 diff -NurpP --minimal linux-2.6.25/kernel/vserver/sysctl.c linux-2.6.25-vs2.3.0.34.9/kernel/vserver/sysctl.c
26006 --- linux-2.6.25/kernel/vserver/sysctl.c        1969-12-31 19:00:00.000000000 -0500
26007 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/sysctl.c   2008-04-19 15:14:52.000000000 -0400
26008 @@ -0,0 +1,244 @@
26009 +/*
26010 + *  kernel/vserver/sysctl.c
26011 + *
26012 + *  Virtual Context Support
26013 + *
26014 + *  Copyright (C) 2004-2007  Herbert Pötzl
26015 + *
26016 + *  V0.01  basic structure
26017 + *
26018 + */
26019 +
26020 +#include <linux/module.h>
26021 +#include <linux/ctype.h>
26022 +#include <linux/sysctl.h>
26023 +#include <linux/parser.h>
26024 +#include <asm/uaccess.h>
26025 +
26026 +
26027 +enum {
26028 +       CTL_DEBUG_ERROR         = 0,
26029 +       CTL_DEBUG_SWITCH        = 1,
26030 +       CTL_DEBUG_XID,
26031 +       CTL_DEBUG_NID,
26032 +       CTL_DEBUG_TAG,
26033 +       CTL_DEBUG_NET,
26034 +       CTL_DEBUG_LIMIT,
26035 +       CTL_DEBUG_CRES,
26036 +       CTL_DEBUG_DLIM,
26037 +       CTL_DEBUG_QUOTA,
26038 +       CTL_DEBUG_CVIRT,
26039 +       CTL_DEBUG_SPACE,
26040 +       CTL_DEBUG_MISC,
26041 +};
26042 +
26043 +
26044 +unsigned int vx_debug_switch   = 0;
26045 +unsigned int vx_debug_xid      = 0;
26046 +unsigned int vx_debug_nid      = 0;
26047 +unsigned int vx_debug_tag      = 0;
26048 +unsigned int vx_debug_net      = 0;
26049 +unsigned int vx_debug_limit    = 0;
26050 +unsigned int vx_debug_cres     = 0;
26051 +unsigned int vx_debug_dlim     = 0;
26052 +unsigned int vx_debug_quota    = 0;
26053 +unsigned int vx_debug_cvirt    = 0;
26054 +unsigned int vx_debug_space    = 0;
26055 +unsigned int vx_debug_misc     = 0;
26056 +
26057 +
26058 +static struct ctl_table_header *vserver_table_header;
26059 +static ctl_table vserver_root_table[];
26060 +
26061 +
26062 +void vserver_register_sysctl(void)
26063 +{
26064 +       if (!vserver_table_header) {
26065 +               vserver_table_header = register_sysctl_table(vserver_root_table);
26066 +       }
26067 +
26068 +}
26069 +
26070 +void vserver_unregister_sysctl(void)
26071 +{
26072 +       if (vserver_table_header) {
26073 +               unregister_sysctl_table(vserver_table_header);
26074 +               vserver_table_header = NULL;
26075 +       }
26076 +}
26077 +
26078 +
26079 +static int proc_dodebug(ctl_table *table, int write,
26080 +       struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
26081 +{
26082 +       char            tmpbuf[20], *p, c;
26083 +       unsigned int    value;
26084 +       size_t          left, len;
26085 +
26086 +       if ((*ppos && !write) || !*lenp) {
26087 +               *lenp = 0;
26088 +               return 0;
26089 +       }
26090 +
26091 +       left = *lenp;
26092 +
26093 +       if (write) {
26094 +               if (!access_ok(VERIFY_READ, buffer, left))
26095 +                       return -EFAULT;
26096 +               p = (char *)buffer;
26097 +               while (left && __get_user(c, p) >= 0 && isspace(c))
26098 +                       left--, p++;
26099 +               if (!left)
26100 +                       goto done;
26101 +
26102 +               if (left > sizeof(tmpbuf) - 1)
26103 +                       return -EINVAL;
26104 +               if (copy_from_user(tmpbuf, p, left))
26105 +                       return -EFAULT;
26106 +               tmpbuf[left] = '\0';
26107 +
26108 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
26109 +                       value = 10 * value + (*p - '0');
26110 +               if (*p && !isspace(*p))
26111 +                       return -EINVAL;
26112 +               while (left && isspace(*p))
26113 +                       left--, p++;
26114 +               *(unsigned int *)table->data = value;
26115 +       } else {
26116 +               if (!access_ok(VERIFY_WRITE, buffer, left))
26117 +                       return -EFAULT;
26118 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
26119 +               if (len > left)
26120 +                       len = left;
26121 +               if (__copy_to_user(buffer, tmpbuf, len))
26122 +                       return -EFAULT;
26123 +               if ((left -= len) > 0) {
26124 +                       if (put_user('\n', (char *)buffer + len))
26125 +                               return -EFAULT;
26126 +                       left--;
26127 +               }
26128 +       }
26129 +
26130 +done:
26131 +       *lenp -= left;
26132 +       *ppos += *lenp;
26133 +       return 0;
26134 +}
26135 +
26136 +static int zero;
26137 +
26138 +#define        CTL_ENTRY(ctl, name)                            \
26139 +       {                                               \
26140 +               .ctl_name       = ctl,                  \
26141 +               .procname       = #name,                \
26142 +               .data           = &vx_ ## name,         \
26143 +               .maxlen         = sizeof(int),          \
26144 +               .mode           = 0644,                 \
26145 +               .proc_handler   = &proc_dodebug,        \
26146 +               .strategy       = &sysctl_intvec,       \
26147 +               .extra1         = &zero,                \
26148 +       }
26149 +
26150 +static ctl_table vserver_debug_table[] = {
26151 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
26152 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
26153 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
26154 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
26155 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
26156 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
26157 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
26158 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
26159 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
26160 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
26161 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
26162 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
26163 +       { .ctl_name = 0 }
26164 +};
26165 +
26166 +static ctl_table vserver_root_table[] = {
26167 +       {
26168 +               .ctl_name       = CTL_VSERVER,
26169 +               .procname       = "vserver",
26170 +               .mode           = 0555,
26171 +               .child          = vserver_debug_table
26172 +       },
26173 +       { .ctl_name = 0 }
26174 +};
26175 +
26176 +
26177 +static match_table_t tokens = {
26178 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
26179 +       { CTL_DEBUG_XID,        "xid=%x"        },
26180 +       { CTL_DEBUG_NID,        "nid=%x"        },
26181 +       { CTL_DEBUG_TAG,        "tag=%x"        },
26182 +       { CTL_DEBUG_NET,        "net=%x"        },
26183 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
26184 +       { CTL_DEBUG_CRES,       "cres=%x"       },
26185 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
26186 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
26187 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
26188 +       { CTL_DEBUG_SPACE,      "space=%x"      },
26189 +       { CTL_DEBUG_MISC,       "misc=%x"       },
26190 +       { CTL_DEBUG_ERROR,      NULL            }
26191 +};
26192 +
26193 +#define        HANDLE_CASE(id, name, val)                              \
26194 +       case CTL_DEBUG_ ## id:                                  \
26195 +               vx_debug_ ## name = val;                        \
26196 +               printk("vs_debug_" #name "=0x%x\n", val);       \
26197 +               break
26198 +
26199 +
26200 +static int __init vs_debug_setup(char *str)
26201 +{
26202 +       char *p;
26203 +       int token;
26204 +
26205 +       printk("vs_debug_setup(%s)\n", str);
26206 +       while ((p = strsep(&str, ",")) != NULL) {
26207 +               substring_t args[MAX_OPT_ARGS];
26208 +               unsigned int value;
26209 +
26210 +               if (!*p)
26211 +                       continue;
26212 +
26213 +               token = match_token(p, tokens, args);
26214 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
26215 +
26216 +               switch (token) {
26217 +               HANDLE_CASE(SWITCH, switch, value);
26218 +               HANDLE_CASE(XID,    xid,    value);
26219 +               HANDLE_CASE(NID,    nid,    value);
26220 +               HANDLE_CASE(TAG,    tag,    value);
26221 +               HANDLE_CASE(NET,    net,    value);
26222 +               HANDLE_CASE(LIMIT,  limit,  value);
26223 +               HANDLE_CASE(CRES,   cres,   value);
26224 +               HANDLE_CASE(DLIM,   dlim,   value);
26225 +               HANDLE_CASE(QUOTA,  quota,  value);
26226 +               HANDLE_CASE(CVIRT,  cvirt,  value);
26227 +               HANDLE_CASE(SPACE,  space,  value);
26228 +               HANDLE_CASE(MISC,   misc,   value);
26229 +               default:
26230 +                       return -EINVAL;
26231 +                       break;
26232 +               }
26233 +       }
26234 +       return 1;
26235 +}
26236 +
26237 +__setup("vsdebug=", vs_debug_setup);
26238 +
26239 +
26240 +
26241 +EXPORT_SYMBOL_GPL(vx_debug_switch);
26242 +EXPORT_SYMBOL_GPL(vx_debug_xid);
26243 +EXPORT_SYMBOL_GPL(vx_debug_nid);
26244 +EXPORT_SYMBOL_GPL(vx_debug_net);
26245 +EXPORT_SYMBOL_GPL(vx_debug_limit);
26246 +EXPORT_SYMBOL_GPL(vx_debug_cres);
26247 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
26248 +EXPORT_SYMBOL_GPL(vx_debug_quota);
26249 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
26250 +EXPORT_SYMBOL_GPL(vx_debug_space);
26251 +EXPORT_SYMBOL_GPL(vx_debug_misc);
26252 +
26253 diff -NurpP --minimal linux-2.6.25/kernel/vserver/tag.c linux-2.6.25-vs2.3.0.34.9/kernel/vserver/tag.c
26254 --- linux-2.6.25/kernel/vserver/tag.c   1969-12-31 19:00:00.000000000 -0500
26255 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/tag.c      2008-04-19 15:14:52.000000000 -0400
26256 @@ -0,0 +1,63 @@
26257 +/*
26258 + *  linux/kernel/vserver/tag.c
26259 + *
26260 + *  Virtual Server: Shallow Tag Space
26261 + *
26262 + *  Copyright (C) 2007  Herbert Pötzl
26263 + *
26264 + *  V0.01  basic implementation
26265 + *
26266 + */
26267 +
26268 +#include <linux/sched.h>
26269 +#include <linux/vserver/debug.h>
26270 +#include <linux/vs_pid.h>
26271 +#include <linux/vs_tag.h>
26272 +
26273 +#include <linux/vserver/tag_cmd.h>
26274 +
26275 +
26276 +int dx_migrate_task(struct task_struct *p, tag_t tag)
26277 +{
26278 +       if (!p)
26279 +               BUG();
26280 +
26281 +       vxdprintk(VXD_CBIT(tag, 5),
26282 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
26283 +
26284 +       task_lock(p);
26285 +       p->tag = tag;
26286 +       task_unlock(p);
26287 +
26288 +       vxdprintk(VXD_CBIT(tag, 5),
26289 +               "moved task %p into [#%d]", p, tag);
26290 +       return 0;
26291 +}
26292 +
26293 +/* vserver syscall commands below here */
26294 +
26295 +/* taks xid and vx_info functions */
26296 +
26297 +
26298 +int vc_task_tag(uint32_t id)
26299 +{
26300 +       tag_t tag;
26301 +
26302 +       if (id) {
26303 +               struct task_struct *tsk;
26304 +               read_lock(&tasklist_lock);
26305 +               tsk = find_task_by_real_pid(id);
26306 +               tag = (tsk) ? tsk->tag : -ESRCH;
26307 +               read_unlock(&tasklist_lock);
26308 +       } else
26309 +               tag = dx_current_tag();
26310 +       return tag;
26311 +}
26312 +
26313 +
26314 +int vc_tag_migrate(uint32_t tag)
26315 +{
26316 +       return dx_migrate_task(current, tag & 0xFFFF);
26317 +}
26318 +
26319 +
26320 diff -NurpP --minimal linux-2.6.25/kernel/vserver/vci_config.h linux-2.6.25-vs2.3.0.34.9/kernel/vserver/vci_config.h
26321 --- linux-2.6.25/kernel/vserver/vci_config.h    1969-12-31 19:00:00.000000000 -0500
26322 +++ linux-2.6.25-vs2.3.0.34.9/kernel/vserver/vci_config.h       2008-04-19 15:14:52.000000000 -0400
26323 @@ -0,0 +1,81 @@
26324 +
26325 +/*  interface version */
26326 +
26327 +#define VCI_VERSION            0x00020302
26328 +
26329 +
26330 +enum {
26331 +       VCI_KCBIT_NO_DYNAMIC = 0,
26332 +
26333 +       VCI_KCBIT_PROC_SECURE = 4,
26334 +       VCI_KCBIT_HARDCPU = 5,
26335 +       VCI_KCBIT_IDLELIMIT = 6,
26336 +       VCI_KCBIT_IDLETIME = 7,
26337 +
26338 +       VCI_KCBIT_COWBL = 8,
26339 +       VCI_KCBIT_FULLCOWBL = 9,
26340 +       VCI_KCBIT_SPACES = 10,
26341 +       VCI_KCBIT_NETV2 = 11,
26342 +
26343 +       VCI_KCBIT_DEBUG = 16,
26344 +       VCI_KCBIT_HISTORY = 20,
26345 +       VCI_KCBIT_TAGGED = 24,
26346 +       VCI_KCBIT_PPTAG = 28,
26347 +
26348 +       VCI_KCBIT_MORE = 31,
26349 +};
26350 +
26351 +
26352 +static inline uint32_t vci_kernel_config(void)
26353 +{
26354 +       return
26355 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
26356 +
26357 +       /* configured features */
26358 +#ifdef CONFIG_VSERVER_PROC_SECURE
26359 +       (1 << VCI_KCBIT_PROC_SECURE) |
26360 +#endif
26361 +#ifdef CONFIG_VSERVER_HARDCPU
26362 +       (1 << VCI_KCBIT_HARDCPU) |
26363 +#endif
26364 +#ifdef CONFIG_VSERVER_IDLELIMIT
26365 +       (1 << VCI_KCBIT_IDLELIMIT) |
26366 +#endif
26367 +#ifdef CONFIG_VSERVER_IDLETIME
26368 +       (1 << VCI_KCBIT_IDLETIME) |
26369 +#endif
26370 +#ifdef CONFIG_VSERVER_COWBL
26371 +       (1 << VCI_KCBIT_COWBL) |
26372 +       (1 << VCI_KCBIT_FULLCOWBL) |
26373 +#endif
26374 +       (1 << VCI_KCBIT_SPACES) |
26375 +       (1 << VCI_KCBIT_NETV2) |
26376 +
26377 +       /* debug options */
26378 +#ifdef CONFIG_VSERVER_DEBUG
26379 +       (1 << VCI_KCBIT_DEBUG) |
26380 +#endif
26381 +#ifdef CONFIG_VSERVER_HISTORY
26382 +       (1 << VCI_KCBIT_HISTORY) |
26383 +#endif
26384 +
26385 +       /* inode context tagging */
26386 +#if    defined(CONFIG_TAGGING_NONE)
26387 +       (0 << VCI_KCBIT_TAGGED) |
26388 +#elif  defined(CONFIG_TAGGING_UID16)
26389 +       (1 << VCI_KCBIT_TAGGED) |
26390 +#elif  defined(CONFIG_TAGGING_GID16)
26391 +       (2 << VCI_KCBIT_TAGGED) |
26392 +#elif  defined(CONFIG_TAGGING_ID24)
26393 +       (3 << VCI_KCBIT_TAGGED) |
26394 +#elif  defined(CONFIG_TAGGING_INTERN)
26395 +       (4 << VCI_KCBIT_TAGGED) |
26396 +#elif  defined(CONFIG_TAGGING_RUNTIME)
26397 +       (5 << VCI_KCBIT_TAGGED) |
26398 +#else
26399 +       (7 << VCI_KCBIT_TAGGED) |
26400 +#endif
26401 +       (1 << VCI_KCBIT_PPTAG) |
26402 +       0;
26403 +}
26404 +
26405 diff -NurpP --minimal linux-2.6.25/Makefile linux-2.6.25-vs2.3.0.34.9/Makefile
26406 --- linux-2.6.25/Makefile       2008-04-17 12:05:26.000000000 -0400
26407 +++ linux-2.6.25-vs2.3.0.34.9/Makefile  2008-04-29 20:29:51.000000000 -0400
26408 @@ -1,7 +1,7 @@
26409  VERSION = 2
26410  PATCHLEVEL = 6
26411  SUBLEVEL = 25
26412 -EXTRAVERSION = .4
26413 +EXTRAVERSION = .4-vs2.3.x-vs2.3.0.34.9
26414  NAME = Funky Weasel is Jiggy wit it
26415  
26416  # *DOCUMENTATION*
26417 diff -NurpP --minimal linux-2.6.25/mm/filemap_xip.c linux-2.6.25-vs2.3.0.34.9/mm/filemap_xip.c
26418 --- linux-2.6.25/mm/filemap_xip.c       2008-04-17 12:05:44.000000000 -0400
26419 +++ linux-2.6.25-vs2.3.0.34.9/mm/filemap_xip.c  2008-04-19 15:14:52.000000000 -0400
26420 @@ -14,6 +14,7 @@
26421  #include <linux/uio.h>
26422  #include <linux/rmap.h>
26423  #include <linux/sched.h>
26424 +#include <linux/vs_memory.h>
26425  #include <asm/tlbflush.h>
26426  
26427  /*
26428 diff -NurpP --minimal linux-2.6.25/mm/fremap.c linux-2.6.25-vs2.3.0.34.9/mm/fremap.c
26429 --- linux-2.6.25/mm/fremap.c    2008-04-17 12:05:44.000000000 -0400
26430 +++ linux-2.6.25-vs2.3.0.34.9/mm/fremap.c       2008-04-19 15:14:52.000000000 -0400
26431 @@ -15,6 +15,7 @@
26432  #include <linux/rmap.h>
26433  #include <linux/module.h>
26434  #include <linux/syscalls.h>
26435 +#include <linux/vs_memory.h>
26436  
26437  #include <asm/mmu_context.h>
26438  #include <asm/cacheflush.h>
26439 diff -NurpP --minimal linux-2.6.25/mm/hugetlb.c linux-2.6.25-vs2.3.0.34.9/mm/hugetlb.c
26440 --- linux-2.6.25/mm/hugetlb.c   2008-04-17 12:05:44.000000000 -0400
26441 +++ linux-2.6.25-vs2.3.0.34.9/mm/hugetlb.c      2008-04-19 15:14:52.000000000 -0400
26442 @@ -19,6 +19,7 @@
26443  #include <asm/pgtable.h>
26444  
26445  #include <linux/hugetlb.h>
26446 +#include <linux/vs_memory.h>
26447  #include "internal.h"
26448  
26449  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
26450 diff -NurpP --minimal linux-2.6.25/mm/memory.c linux-2.6.25-vs2.3.0.34.9/mm/memory.c
26451 --- linux-2.6.25/mm/memory.c    2008-04-17 12:05:44.000000000 -0400
26452 +++ linux-2.6.25-vs2.3.0.34.9/mm/memory.c       2008-04-19 15:14:52.000000000 -0400
26453 @@ -505,6 +505,9 @@ static int copy_pte_range(struct mm_stru
26454         int progress = 0;
26455         int rss[2];
26456  
26457 +       if (!vx_rss_avail(dst_mm, ((end - addr)/PAGE_SIZE + 1)))
26458 +               return -ENOMEM;
26459 +
26460  again:
26461         rss[1] = rss[0] = 0;
26462         dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
26463 @@ -2058,6 +2061,11 @@ static int do_swap_page(struct mm_struct
26464                 goto out;
26465         }
26466  
26467 +       if (!vx_rss_avail(mm, 1)) {
26468 +               ret = VM_FAULT_OOM;
26469 +               goto out;
26470 +       }
26471 +
26472         mark_page_accessed(page);
26473         lock_page(page);
26474         delayacct_clear_flag(DELAYACCT_PF_SWAPIN);
26475 @@ -2129,6 +2137,8 @@ static int do_anonymous_page(struct mm_s
26476         /* Allocate our own private page. */
26477         pte_unmap(page_table);
26478  
26479 +       if (!vx_rss_avail(mm, 1))
26480 +               goto oom;
26481         if (unlikely(anon_vma_prepare(vma)))
26482                 goto oom;
26483         page = alloc_zeroed_user_highpage_movable(vma, address);
26484 @@ -2453,6 +2463,7 @@ static inline int handle_pte_fault(struc
26485  {
26486         pte_t entry;
26487         spinlock_t *ptl;
26488 +       int ret = 0, type = VXPT_UNKNOWN;
26489  
26490         entry = *pte;
26491         if (!pte_present(entry)) {
26492 @@ -2480,9 +2491,12 @@ static inline int handle_pte_fault(struc
26493         if (unlikely(!pte_same(*pte, entry)))
26494                 goto unlock;
26495         if (write_access) {
26496 -               if (!pte_write(entry))
26497 -                       return do_wp_page(mm, vma, address,
26498 +               if (!pte_write(entry)) {
26499 +                       ret = do_wp_page(mm, vma, address,
26500                                         pte, pmd, ptl, entry);
26501 +                       type = VXPT_WRITE;
26502 +                       goto out;
26503 +               }
26504                 entry = pte_mkdirty(entry);
26505         }
26506         entry = pte_mkyoung(entry);
26507 @@ -2500,7 +2514,10 @@ static inline int handle_pte_fault(struc
26508         }
26509  unlock:
26510         pte_unmap_unlock(pte, ptl);
26511 -       return 0;
26512 +       ret = 0;
26513 +out:
26514 +       vx_page_fault(mm, vma, type, ret);
26515 +       return ret;
26516  }
26517  
26518  /*
26519 diff -NurpP --minimal linux-2.6.25/mm/mlock.c linux-2.6.25-vs2.3.0.34.9/mm/mlock.c
26520 --- linux-2.6.25/mm/mlock.c     2008-04-17 10:37:25.000000000 -0400
26521 +++ linux-2.6.25-vs2.3.0.34.9/mm/mlock.c        2008-04-19 15:14:52.000000000 -0400
26522 @@ -12,6 +12,7 @@
26523  #include <linux/syscalls.h>
26524  #include <linux/sched.h>
26525  #include <linux/module.h>
26526 +#include <linux/vs_memory.h>
26527  
26528  int can_do_mlock(void)
26529  {
26530 @@ -76,7 +77,7 @@ success:
26531                         ret = make_pages_present(start, end);
26532         }
26533  
26534 -       mm->locked_vm -= pages;
26535 +       vx_vmlocked_sub(mm, pages);
26536  out:
26537         if (ret == -ENOMEM)
26538                 ret = -EAGAIN;
26539 @@ -134,7 +135,7 @@ static int do_mlock(unsigned long start,
26540  
26541  asmlinkage long sys_mlock(unsigned long start, size_t len)
26542  {
26543 -       unsigned long locked;
26544 +       unsigned long locked, grow;
26545         unsigned long lock_limit;
26546         int error = -ENOMEM;
26547  
26548 @@ -145,8 +146,10 @@ asmlinkage long sys_mlock(unsigned long 
26549         len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
26550         start &= PAGE_MASK;
26551  
26552 -       locked = len >> PAGE_SHIFT;
26553 -       locked += current->mm->locked_vm;
26554 +       grow = len >> PAGE_SHIFT;
26555 +       if (!vx_vmlocked_avail(current->mm, grow))
26556 +               goto out;
26557 +       locked = current->mm->locked_vm + grow;
26558  
26559         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
26560         lock_limit >>= PAGE_SHIFT;
26561 @@ -154,6 +157,7 @@ asmlinkage long sys_mlock(unsigned long 
26562         /* check against resource limits */
26563         if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
26564                 error = do_mlock(start, len, 1);
26565 +out:
26566         up_write(&current->mm->mmap_sem);
26567         return error;
26568  }
26569 @@ -213,6 +217,8 @@ asmlinkage long sys_mlockall(int flags)
26570         lock_limit >>= PAGE_SHIFT;
26571  
26572         ret = -ENOMEM;
26573 +       if (!vx_vmlocked_avail(current->mm, current->mm->total_vm))
26574 +               goto out;
26575         if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
26576             capable(CAP_IPC_LOCK))
26577                 ret = do_mlockall(flags);
26578 diff -NurpP --minimal linux-2.6.25/mm/mmap.c linux-2.6.25-vs2.3.0.34.9/mm/mmap.c
26579 --- linux-2.6.25/mm/mmap.c      2008-04-17 12:05:44.000000000 -0400
26580 +++ linux-2.6.25-vs2.3.0.34.9/mm/mmap.c 2008-04-19 15:14:52.000000000 -0400
26581 @@ -1197,10 +1197,10 @@ munmap_back:
26582                 kmem_cache_free(vm_area_cachep, vma);
26583         }
26584  out:   
26585 -       mm->total_vm += len >> PAGE_SHIFT;
26586 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26587         vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
26588         if (vm_flags & VM_LOCKED) {
26589 -               mm->locked_vm += len >> PAGE_SHIFT;
26590 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
26591                 make_pages_present(addr, addr + len);
26592         }
26593         if ((flags & MAP_POPULATE) && !(flags & MAP_NONBLOCK))
26594 @@ -1549,9 +1549,9 @@ static int acct_stack_growth(struct vm_a
26595                 return -ENOMEM;
26596  
26597         /* Ok, everything looks good - let it rip */
26598 -       mm->total_vm += grow;
26599 +       vx_vmpages_add(mm, grow);
26600         if (vma->vm_flags & VM_LOCKED)
26601 -               mm->locked_vm += grow;
26602 +               vx_vmlocked_add(mm, grow);
26603         vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
26604         return 0;
26605  }
26606 @@ -1722,9 +1722,9 @@ static void remove_vma_list(struct mm_st
26607         do {
26608                 long nrpages = vma_pages(vma);
26609  
26610 -               mm->total_vm -= nrpages;
26611 +               vx_vmpages_sub(mm, nrpages);
26612                 if (vma->vm_flags & VM_LOCKED)
26613 -                       mm->locked_vm -= nrpages;
26614 +                       vx_vmlocked_sub(mm, nrpages);
26615                 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
26616                 vma = remove_vma(vma);
26617         } while (vma);
26618 @@ -1967,6 +1967,8 @@ unsigned long do_brk(unsigned long addr,
26619                 lock_limit >>= PAGE_SHIFT;
26620                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
26621                         return -EAGAIN;
26622 +               if (!vx_vmlocked_avail(mm, len >> PAGE_SHIFT))
26623 +                       return -ENOMEM;
26624         }
26625  
26626         /*
26627 @@ -1993,7 +1995,8 @@ unsigned long do_brk(unsigned long addr,
26628         if (mm->map_count > sysctl_max_map_count)
26629                 return -ENOMEM;
26630  
26631 -       if (security_vm_enough_memory(len >> PAGE_SHIFT))
26632 +       if (security_vm_enough_memory(len >> PAGE_SHIFT) ||
26633 +               !vx_vmpages_avail(mm, len >> PAGE_SHIFT))
26634                 return -ENOMEM;
26635  
26636         /* Can we just expand an old private anonymous mapping? */
26637 @@ -2018,9 +2021,9 @@ unsigned long do_brk(unsigned long addr,
26638         vma->vm_page_prot = vm_get_page_prot(flags);
26639         vma_link(mm, vma, prev, rb_link, rb_parent);
26640  out:
26641 -       mm->total_vm += len >> PAGE_SHIFT;
26642 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26643         if (flags & VM_LOCKED) {
26644 -               mm->locked_vm += len >> PAGE_SHIFT;
26645 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
26646                 make_pages_present(addr, addr + len);
26647         }
26648         return addr;
26649 @@ -2049,6 +2052,11 @@ void exit_mmap(struct mm_struct *mm)
26650         free_pgtables(&tlb, vma, FIRST_USER_ADDRESS, 0);
26651         tlb_finish_mmu(tlb, 0, end);
26652  
26653 +       set_mm_counter(mm, file_rss, 0);
26654 +       set_mm_counter(mm, anon_rss, 0);
26655 +       vx_vmpages_sub(mm, mm->total_vm);
26656 +       vx_vmlocked_sub(mm, mm->locked_vm);
26657 +
26658         /*
26659          * Walk the list again, actually closing and freeing it,
26660          * with preemption enabled, without holding any MM locks.
26661 @@ -2088,7 +2096,8 @@ int insert_vm_struct(struct mm_struct * 
26662         if (__vma && __vma->vm_start < vma->vm_end)
26663                 return -ENOMEM;
26664         if ((vma->vm_flags & VM_ACCOUNT) &&
26665 -            security_vm_enough_memory_mm(mm, vma_pages(vma)))
26666 +               (security_vm_enough_memory_mm(mm, vma_pages(vma)) ||
26667 +               !vx_vmpages_avail(mm, vma_pages(vma))))
26668                 return -ENOMEM;
26669         vma_link(mm, vma, prev, rb_link, rb_parent);
26670         return 0;
26671 @@ -2161,6 +2170,8 @@ int may_expand_vm(struct mm_struct *mm, 
26672  
26673         if (cur + npages > lim)
26674                 return 0;
26675 +       if (!vx_vmpages_avail(mm, npages))
26676 +               return 0;
26677         return 1;
26678  }
26679  
26680 @@ -2238,7 +2249,6 @@ int install_special_mapping(struct mm_st
26681                 return -ENOMEM;
26682         }
26683  
26684 -       mm->total_vm += len >> PAGE_SHIFT;
26685 -
26686 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26687         return 0;
26688  }
26689 diff -NurpP --minimal linux-2.6.25/mm/mremap.c linux-2.6.25-vs2.3.0.34.9/mm/mremap.c
26690 --- linux-2.6.25/mm/mremap.c    2008-04-17 11:31:40.000000000 -0400
26691 +++ linux-2.6.25-vs2.3.0.34.9/mm/mremap.c       2008-04-19 15:14:52.000000000 -0400
26692 @@ -18,6 +18,7 @@
26693  #include <linux/highmem.h>
26694  #include <linux/security.h>
26695  #include <linux/syscalls.h>
26696 +#include <linux/vs_memory.h>
26697  
26698  #include <asm/uaccess.h>
26699  #include <asm/cacheflush.h>
26700 @@ -212,7 +213,7 @@ static unsigned long move_vma(struct vm_
26701          * If this were a serious issue, we'd add a flag to do_munmap().
26702          */
26703         hiwater_vm = mm->hiwater_vm;
26704 -       mm->total_vm += new_len >> PAGE_SHIFT;
26705 +       vx_vmpages_add(mm, new_len >> PAGE_SHIFT);
26706         vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
26707  
26708         if (do_munmap(mm, old_addr, old_len) < 0) {
26709 @@ -230,7 +231,7 @@ static unsigned long move_vma(struct vm_
26710         }
26711  
26712         if (vm_flags & VM_LOCKED) {
26713 -               mm->locked_vm += new_len >> PAGE_SHIFT;
26714 +               vx_vmlocked_add(mm, new_len >> PAGE_SHIFT);
26715                 if (new_len > old_len)
26716                         make_pages_present(new_addr + old_len,
26717                                            new_addr + new_len);
26718 @@ -341,6 +342,9 @@ unsigned long do_mremap(unsigned long ad
26719                 ret = -EAGAIN;
26720                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
26721                         goto out;
26722 +               if (!vx_vmlocked_avail(current->mm,
26723 +                       (new_len - old_len) >> PAGE_SHIFT))
26724 +                       goto out;
26725         }
26726         if (!may_expand_vm(mm, (new_len - old_len) >> PAGE_SHIFT)) {
26727                 ret = -ENOMEM;
26728 @@ -369,10 +373,10 @@ unsigned long do_mremap(unsigned long ad
26729                         vma_adjust(vma, vma->vm_start,
26730                                 addr + new_len, vma->vm_pgoff, NULL);
26731  
26732 -                       mm->total_vm += pages;
26733 +                       vx_vmpages_add(mm, pages);
26734                         vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages);
26735                         if (vma->vm_flags & VM_LOCKED) {
26736 -                               mm->locked_vm += pages;
26737 +                               vx_vmlocked_add(mm, pages);
26738                                 make_pages_present(addr + old_len,
26739                                                    addr + new_len);
26740                         }
26741 diff -NurpP --minimal linux-2.6.25/mm/nommu.c linux-2.6.25-vs2.3.0.34.9/mm/nommu.c
26742 --- linux-2.6.25/mm/nommu.c     2008-04-17 12:05:44.000000000 -0400
26743 +++ linux-2.6.25-vs2.3.0.34.9/mm/nommu.c        2008-04-19 15:14:52.000000000 -0400
26744 @@ -991,7 +991,7 @@ unsigned long do_mmap_pgoff(struct file 
26745         realalloc += kobjsize(vma);
26746         askedalloc += sizeof(*vma);
26747  
26748 -       current->mm->total_vm += len >> PAGE_SHIFT;
26749 +       vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
26750  
26751         add_nommu_vma(vma);
26752  
26753 @@ -1117,7 +1117,7 @@ int do_munmap(struct mm_struct *mm, unsi
26754         kfree(vml);
26755  
26756         update_hiwater_vm(mm);
26757 -       mm->total_vm -= len >> PAGE_SHIFT;
26758 +       vx_vmpages_sub(mm, len >> PAGE_SHIFT);
26759  
26760  #ifdef DEBUG
26761         show_process_blocks();
26762 @@ -1150,7 +1150,7 @@ void exit_mmap(struct mm_struct * mm)
26763                 printk("Exit_mmap:\n");
26764  #endif
26765  
26766 -               mm->total_vm = 0;
26767 +               vx_vmpages_sub(mm, mm->total_vm);
26768  
26769                 while ((tmp = mm->context.vmlist)) {
26770                         mm->context.vmlist = tmp->next;
26771 diff -NurpP --minimal linux-2.6.25/mm/oom_kill.c linux-2.6.25-vs2.3.0.34.9/mm/oom_kill.c
26772 --- linux-2.6.25/mm/oom_kill.c  2008-04-17 12:05:44.000000000 -0400
26773 +++ linux-2.6.25-vs2.3.0.34.9/mm/oom_kill.c     2008-04-19 16:55:20.000000000 -0400
26774 @@ -26,6 +26,7 @@
26775  #include <linux/module.h>
26776  #include <linux/notifier.h>
26777  #include <linux/memcontrol.h>
26778 +#include <linux/vs_memory.h>
26779  
26780  int sysctl_panic_on_oom;
26781  int sysctl_oom_kill_allocating_task;
26782 @@ -73,6 +74,12 @@ unsigned long badness(struct task_struct
26783         points = mm->total_vm;
26784  
26785         /*
26786 +        * add points for context badness
26787 +        */
26788 +
26789 +       points += vx_badness(p, mm);
26790 +
26791 +       /*
26792          * After this unlock we can no longer dereference local variable `mm'
26793          */
26794         task_unlock(p);
26795 @@ -162,8 +169,8 @@ unsigned long badness(struct task_struct
26796         }
26797  
26798  #ifdef DEBUG
26799 -       printk(KERN_DEBUG "OOMkill: task %d (%s) got %lu points\n",
26800 -       p->pid, p->comm, points);
26801 +       printk(KERN_DEBUG "OOMkill: task %d:#%u (%s) got %d points\n",
26802 +               task_pid_nr(p), p->xid, p->comm, points);
26803  #endif
26804         return points;
26805  }
26806 @@ -322,8 +329,8 @@ static void __oom_kill_task(struct task_
26807         }
26808  
26809         if (verbose)
26810 -               printk(KERN_ERR "Killed process %d (%s)\n",
26811 -                               task_pid_nr(p), p->comm);
26812 +               printk(KERN_ERR "Killed process %d:#%u (%s)\n",
26813 +                               task_pid_nr(p), p->xid, p->comm);
26814  
26815         /*
26816          * We give our sacrificial lamb high priority and access to
26817 @@ -403,8 +410,8 @@ static int oom_kill_process(struct task_
26818                 return 0;
26819         }
26820  
26821 -       printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n",
26822 -                                       message, task_pid_nr(p), p->comm, points);
26823 +       printk(KERN_ERR "%s: kill process %d:#%u (%s) score %li or a child\n",
26824 +                               message, task_pid_nr(p), p->xid, p->comm, points);
26825  
26826         /* Try to kill a child first */
26827         list_for_each_entry(c, &p->children, sibling) {
26828 diff -NurpP --minimal linux-2.6.25/mm/page_alloc.c linux-2.6.25-vs2.3.0.34.9/mm/page_alloc.c
26829 --- linux-2.6.25/mm/page_alloc.c        2008-04-17 12:05:44.000000000 -0400
26830 +++ linux-2.6.25-vs2.3.0.34.9/mm/page_alloc.c   2008-04-19 16:53:55.000000000 -0400
26831 @@ -45,6 +45,8 @@
26832  #include <linux/fault-inject.h>
26833  #include <linux/page-isolation.h>
26834  #include <linux/memcontrol.h>
26835 +#include <linux/vs_base.h>
26836 +#include <linux/vs_limit.h>
26837  
26838  #include <asm/tlbflush.h>
26839  #include <asm/div64.h>
26840 @@ -1762,6 +1764,9 @@ void si_meminfo(struct sysinfo *val)
26841         val->totalhigh = totalhigh_pages;
26842         val->freehigh = nr_free_highpages();
26843         val->mem_unit = PAGE_SIZE;
26844 +
26845 +       if (vx_flags(VXF_VIRT_MEM, 0))
26846 +               vx_vsi_meminfo(val);
26847  }
26848  
26849  EXPORT_SYMBOL(si_meminfo);
26850 @@ -1782,6 +1787,9 @@ void si_meminfo_node(struct sysinfo *val
26851         val->freehigh = 0;
26852  #endif
26853         val->mem_unit = PAGE_SIZE;
26854 +
26855 +       if (vx_flags(VXF_VIRT_MEM, 0))
26856 +               vx_vsi_meminfo(val);
26857  }
26858  #endif
26859  
26860 diff -NurpP --minimal linux-2.6.25/mm/rmap.c linux-2.6.25-vs2.3.0.34.9/mm/rmap.c
26861 --- linux-2.6.25/mm/rmap.c      2008-04-17 12:05:44.000000000 -0400
26862 +++ linux-2.6.25-vs2.3.0.34.9/mm/rmap.c 2008-04-19 16:53:36.000000000 -0400
26863 @@ -49,6 +49,7 @@
26864  #include <linux/module.h>
26865  #include <linux/kallsyms.h>
26866  #include <linux/memcontrol.h>
26867 +#include <linux/vs_memory.h>
26868  
26869  #include <asm/tlbflush.h>
26870  
26871 diff -NurpP --minimal linux-2.6.25/mm/shmem.c linux-2.6.25-vs2.3.0.34.9/mm/shmem.c
26872 --- linux-2.6.25/mm/shmem.c     2008-04-17 12:05:44.000000000 -0400
26873 +++ linux-2.6.25-vs2.3.0.34.9/mm/shmem.c        2008-04-19 15:14:52.000000000 -0400
26874 @@ -56,7 +56,6 @@
26875  #include <asm/pgtable.h>
26876  
26877  /* This magic number is used in glibc for posix shared memory */
26878 -#define TMPFS_MAGIC    0x01021994
26879  
26880  #define ENTRIES_PER_PAGE (PAGE_CACHE_SIZE/sizeof(unsigned long))
26881  #define ENTRIES_PER_PAGEPAGE (ENTRIES_PER_PAGE*ENTRIES_PER_PAGE)
26882 @@ -1773,7 +1772,7 @@ static int shmem_statfs(struct dentry *d
26883  {
26884         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
26885  
26886 -       buf->f_type = TMPFS_MAGIC;
26887 +       buf->f_type = TMPFS_SUPER_MAGIC;
26888         buf->f_bsize = PAGE_CACHE_SIZE;
26889         buf->f_namelen = NAME_MAX;
26890         spin_lock(&sbinfo->stat_lock);
26891 @@ -2341,7 +2340,7 @@ static int shmem_fill_super(struct super
26892         sb->s_maxbytes = SHMEM_MAX_BYTES;
26893         sb->s_blocksize = PAGE_CACHE_SIZE;
26894         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
26895 -       sb->s_magic = TMPFS_MAGIC;
26896 +       sb->s_magic = TMPFS_SUPER_MAGIC;
26897         sb->s_op = &shmem_ops;
26898         sb->s_time_gran = 1;
26899  #ifdef CONFIG_TMPFS_POSIX_ACL
26900 diff -NurpP --minimal linux-2.6.25/mm/slab.c linux-2.6.25-vs2.3.0.34.9/mm/slab.c
26901 --- linux-2.6.25/mm/slab.c      2008-04-17 12:05:44.000000000 -0400
26902 +++ linux-2.6.25-vs2.3.0.34.9/mm/slab.c 2008-04-19 15:14:52.000000000 -0400
26903 @@ -509,6 +509,8 @@ struct kmem_cache {
26904  #define STATS_INC_FREEMISS(x)  do { } while (0)
26905  #endif
26906  
26907 +#include "slab_vs.h"
26908 +
26909  #if DEBUG
26910  
26911  /*
26912 @@ -3344,6 +3346,7 @@ retry:
26913  
26914         obj = slab_get_obj(cachep, slabp, nodeid);
26915         check_slabp(cachep, slabp);
26916 +       vx_slab_alloc(cachep, flags);
26917         l3->free_objects--;
26918         /* move slabp to correct slabp list: */
26919         list_del(&slabp->list);
26920 @@ -3416,6 +3419,7 @@ __cache_alloc_node(struct kmem_cache *ca
26921         /* ___cache_alloc_node can fall back to other nodes */
26922         ptr = ____cache_alloc_node(cachep, flags, nodeid);
26923    out:
26924 +       vx_slab_alloc(cachep, flags);
26925         local_irq_restore(save_flags);
26926         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
26927  
26928 @@ -3587,6 +3591,7 @@ static inline void __cache_free(struct k
26929  
26930         check_irq_off();
26931         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
26932 +       vx_slab_free(cachep);
26933  
26934         /*
26935          * Skip calling cache_free_alien() when the platform is not numa.
26936 diff -NurpP --minimal linux-2.6.25/mm/slab_vs.h linux-2.6.25-vs2.3.0.34.9/mm/slab_vs.h
26937 --- linux-2.6.25/mm/slab_vs.h   1969-12-31 19:00:00.000000000 -0500
26938 +++ linux-2.6.25-vs2.3.0.34.9/mm/slab_vs.h      2008-04-19 15:14:52.000000000 -0400
26939 @@ -0,0 +1,27 @@
26940 +
26941 +#include <linux/vserver/context.h>
26942 +
26943 +#include <linux/vs_context.h>
26944 +
26945 +static inline
26946 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
26947 +{
26948 +       int what = gfp_zone(cachep->gfpflags);
26949 +
26950 +       if (!current->vx_info)
26951 +               return;
26952 +
26953 +       atomic_add(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
26954 +}
26955 +
26956 +static inline
26957 +void vx_slab_free(struct kmem_cache *cachep)
26958 +{
26959 +       int what = gfp_zone(cachep->gfpflags);
26960 +
26961 +       if (!current->vx_info)
26962 +               return;
26963 +
26964 +       atomic_sub(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
26965 +}
26966 +
26967 diff -NurpP --minimal linux-2.6.25/mm/swapfile.c linux-2.6.25-vs2.3.0.34.9/mm/swapfile.c
26968 --- linux-2.6.25/mm/swapfile.c  2008-04-17 12:05:44.000000000 -0400
26969 +++ linux-2.6.25-vs2.3.0.34.9/mm/swapfile.c     2008-04-19 15:14:52.000000000 -0400
26970 @@ -32,6 +32,8 @@
26971  #include <asm/pgtable.h>
26972  #include <asm/tlbflush.h>
26973  #include <linux/swapops.h>
26974 +#include <linux/vs_base.h>
26975 +#include <linux/vs_memory.h>
26976  
26977  DEFINE_SPINLOCK(swap_lock);
26978  unsigned int nr_swapfiles;
26979 @@ -1743,6 +1745,8 @@ void si_swapinfo(struct sysinfo *val)
26980         val->freeswap = nr_swap_pages + nr_to_be_unused;
26981         val->totalswap = total_swap_pages + nr_to_be_unused;
26982         spin_unlock(&swap_lock);
26983 +       if (vx_flags(VXF_VIRT_MEM, 0))
26984 +               vx_vsi_swapinfo(val);
26985  }
26986  
26987  /*
26988 diff -NurpP --minimal linux-2.6.25/net/core/dev.c linux-2.6.25-vs2.3.0.34.9/net/core/dev.c
26989 --- linux-2.6.25/net/core/dev.c 2008-04-17 12:05:44.000000000 -0400
26990 +++ linux-2.6.25-vs2.3.0.34.9/net/core/dev.c    2008-04-19 15:14:52.000000000 -0400
26991 @@ -119,6 +119,7 @@
26992  #include <linux/err.h>
26993  #include <linux/ctype.h>
26994  #include <linux/if_arp.h>
26995 +#include <linux/vs_inet.h>
26996  
26997  #include "net-sysfs.h"
26998  
26999 @@ -2336,6 +2337,8 @@ static int dev_ifconf(struct net *net, c
27000  
27001         total = 0;
27002         for_each_netdev(net, dev) {
27003 +               if (!nx_dev_visible(current->nx_info, dev))
27004 +                       continue;
27005                 for (i = 0; i < NPROTO; i++) {
27006                         if (gifconf_list[i]) {
27007                                 int done;
27008 @@ -2404,6 +2407,9 @@ static void dev_seq_printf_stats(struct 
27009  {
27010         struct net_device_stats *stats = dev->get_stats(dev);
27011  
27012 +       if (!nx_dev_visible(current->nx_info, dev))
27013 +               return;
27014 +
27015         seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
27016                    "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
27017                    dev->name, stats->rx_bytes, stats->rx_packets,
27018 diff -NurpP --minimal linux-2.6.25/net/core/rtnetlink.c linux-2.6.25-vs2.3.0.34.9/net/core/rtnetlink.c
27019 --- linux-2.6.25/net/core/rtnetlink.c   2008-04-17 12:05:44.000000000 -0400
27020 +++ linux-2.6.25-vs2.3.0.34.9/net/core/rtnetlink.c      2008-04-23 14:29:56.000000000 -0400
27021 @@ -669,6 +669,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
27022  
27023         idx = 0;
27024         for_each_netdev(net, dev) {
27025 +               if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
27026 +                       continue;
27027                 if (idx < s_idx)
27028                         goto cont;
27029                 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
27030 @@ -1202,6 +1204,9 @@ void rtmsg_ifinfo(int type, struct net_d
27031         struct sk_buff *skb;
27032         int err = -ENOBUFS;
27033  
27034 +       if (!nx_dev_visible(current->nx_info, dev))
27035 +               return;
27036 +
27037         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
27038         if (skb == NULL)
27039                 goto errout;
27040 diff -NurpP --minimal linux-2.6.25/net/core/sock.c linux-2.6.25-vs2.3.0.34.9/net/core/sock.c
27041 --- linux-2.6.25/net/core/sock.c        2008-04-17 12:05:44.000000000 -0400
27042 +++ linux-2.6.25-vs2.3.0.34.9/net/core/sock.c   2008-04-23 14:31:31.000000000 -0400
27043 @@ -126,6 +126,10 @@
27044  #include <linux/ipsec.h>
27045  
27046  #include <linux/filter.h>
27047 +#include <linux/vs_socket.h>
27048 +#include <linux/vs_limit.h>
27049 +#include <linux/vs_context.h>
27050 +#include <linux/vs_network.h>
27051  
27052  #ifdef CONFIG_INET
27053  #include <net/tcp.h>
27054 @@ -907,6 +911,8 @@ static struct sock *sk_prot_alloc(struct
27055                 if (!try_module_get(prot->owner))
27056                         goto out_free_sec;
27057         }
27058 +               sock_vx_init(sk);
27059 +               sock_nx_init(sk);
27060  
27061         return sk;
27062  
27063 @@ -984,6 +990,11 @@ void sk_free(struct sock *sk)
27064                        __FUNCTION__, atomic_read(&sk->sk_omem_alloc));
27065  
27066         put_net(sk->sk_net);
27067 +       vx_sock_dec(sk);
27068 +       clr_vx_info(&sk->sk_vx_info);
27069 +       sk->sk_xid = -1;
27070 +       clr_nx_info(&sk->sk_nx_info);
27071 +       sk->sk_nid = -1;
27072         sk_prot_free(sk->sk_prot_creator, sk);
27073  }
27074  
27075 @@ -999,6 +1010,8 @@ struct sock *sk_clone(const struct sock 
27076  
27077                 /* SANITY */
27078                 get_net(newsk->sk_net);
27079 +               sock_vx_init(newsk);
27080 +               sock_nx_init(newsk);
27081                 sk_node_init(&newsk->sk_node);
27082                 sock_lock_init(newsk);
27083                 bh_lock_sock(newsk);
27084 @@ -1045,6 +1058,12 @@ struct sock *sk_clone(const struct sock 
27085                 newsk->sk_priority = 0;
27086                 atomic_set(&newsk->sk_refcnt, 2);
27087  
27088 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
27089 +               newsk->sk_xid = sk->sk_xid;
27090 +               vx_sock_inc(newsk);
27091 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
27092 +               newsk->sk_nid = sk->sk_nid;
27093 +
27094                 /*
27095                  * Increment the counter in the same struct proto as the master
27096                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
27097 @@ -1727,6 +1746,11 @@ void sock_init_data(struct socket *sock,
27098  
27099         sk->sk_stamp = ktime_set(-1L, 0);
27100  
27101 +       set_vx_info(&sk->sk_vx_info, current->vx_info);
27102 +       sk->sk_xid = vx_current_xid();
27103 +       vx_sock_inc(sk);
27104 +       set_nx_info(&sk->sk_nx_info, current->nx_info);
27105 +       sk->sk_nid = nx_current_nid();
27106         atomic_set(&sk->sk_refcnt, 1);
27107         atomic_set(&sk->sk_drops, 0);
27108  }
27109 diff -NurpP --minimal linux-2.6.25/net/ipv4/af_inet.c linux-2.6.25-vs2.3.0.34.9/net/ipv4/af_inet.c
27110 --- linux-2.6.25/net/ipv4/af_inet.c     2008-04-17 12:05:44.000000000 -0400
27111 +++ linux-2.6.25-vs2.3.0.34.9/net/ipv4/af_inet.c        2008-04-19 16:08:42.000000000 -0400
27112 @@ -115,6 +115,7 @@
27113  #ifdef CONFIG_IP_MROUTE
27114  #include <linux/mroute.h>
27115  #endif
27116 +#include <linux/vs_limit.h>
27117  
27118  DEFINE_SNMP_STAT(struct linux_mib, net_statistics) __read_mostly;
27119  
27120 @@ -317,9 +318,12 @@ lookup_protocol:
27121         }
27122  
27123         err = -EPERM;
27124 +       if ((protocol == IPPROTO_ICMP) &&
27125 +               nx_capable(answer->capability, NXC_RAW_ICMP))
27126 +               goto override;
27127         if (answer->capability > 0 && !capable(answer->capability))
27128                 goto out_rcu_unlock;
27129 -
27130 +override:
27131         sock->ops = answer->ops;
27132         answer_prot = answer->prot;
27133         answer_no_check = answer->no_check;
27134 @@ -433,6 +437,7 @@ int inet_bind(struct socket *sock, struc
27135         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
27136         struct sock *sk = sock->sk;
27137         struct inet_sock *inet = inet_sk(sk);
27138 +       struct nx_v4_sock_addr nsa;
27139         unsigned short snum;
27140         int chk_addr_ret;
27141         int err;
27142 @@ -446,7 +451,11 @@ int inet_bind(struct socket *sock, struc
27143         if (addr_len < sizeof(struct sockaddr_in))
27144                 goto out;
27145  
27146 -       chk_addr_ret = inet_addr_type(&init_net, addr->sin_addr.s_addr);
27147 +       err = v4_map_sock_addr(inet, addr, &nsa);
27148 +       if (err)
27149 +               goto out;
27150 +
27151 +       chk_addr_ret = inet_addr_type(&init_net, nsa.saddr);
27152  
27153         /* Not specified by any standard per-se, however it breaks too
27154          * many applications when removed.  It is unfortunate since
27155 @@ -458,7 +467,7 @@ int inet_bind(struct socket *sock, struc
27156         err = -EADDRNOTAVAIL;
27157         if (!sysctl_ip_nonlocal_bind &&
27158             !inet->freebind &&
27159 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
27160 +           nsa.saddr != htonl(INADDR_ANY) &&
27161             chk_addr_ret != RTN_LOCAL &&
27162             chk_addr_ret != RTN_MULTICAST &&
27163             chk_addr_ret != RTN_BROADCAST)
27164 @@ -483,7 +492,7 @@ int inet_bind(struct socket *sock, struc
27165         if (sk->sk_state != TCP_CLOSE || inet->num)
27166                 goto out_release_sock;
27167  
27168 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
27169 +       v4_set_sock_addr(inet, &nsa);
27170         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
27171                 inet->saddr = 0;  /* Use device */
27172  
27173 @@ -676,11 +685,13 @@ int inet_getname(struct socket *sock, st
27174                      peer == 1))
27175                         return -ENOTCONN;
27176                 sin->sin_port = inet->dport;
27177 -               sin->sin_addr.s_addr = inet->daddr;
27178 +               sin->sin_addr.s_addr =
27179 +                       nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
27180         } else {
27181                 __be32 addr = inet->rcv_saddr;
27182                 if (!addr)
27183                         addr = inet->saddr;
27184 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
27185                 sin->sin_port = inet->sport;
27186                 sin->sin_addr.s_addr = addr;
27187         }
27188 diff -NurpP --minimal linux-2.6.25/net/ipv4/devinet.c linux-2.6.25-vs2.3.0.34.9/net/ipv4/devinet.c
27189 --- linux-2.6.25/net/ipv4/devinet.c     2008-04-17 12:05:44.000000000 -0400
27190 +++ linux-2.6.25-vs2.3.0.34.9/net/ipv4/devinet.c        2008-04-19 15:14:52.000000000 -0400
27191 @@ -421,6 +421,7 @@ struct in_device *inetdev_by_index(struc
27192         return in_dev;
27193  }
27194  
27195 +
27196  /* Called only from RTNL semaphored context. No locks. */
27197  
27198  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
27199 @@ -672,6 +673,8 @@ int devinet_ioctl(unsigned int cmd, void
27200                 *colon = ':';
27201  
27202         if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) {
27203 +               struct nx_info *nxi = current->nx_info;
27204 +
27205                 if (tryaddrmatch) {
27206                         /* Matthias Andree */
27207                         /* compare label and address (4.4BSD style) */
27208 @@ -680,6 +683,8 @@ int devinet_ioctl(unsigned int cmd, void
27209                            This is checked above. */
27210                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
27211                              ifap = &ifa->ifa_next) {
27212 +                               if (!nx_v4_ifa_visible(nxi, ifa))
27213 +                                       continue;
27214                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
27215                                     sin_orig.sin_addr.s_addr ==
27216                                                         ifa->ifa_address) {
27217 @@ -692,9 +697,12 @@ int devinet_ioctl(unsigned int cmd, void
27218                    comparing just the label */
27219                 if (!ifa) {
27220                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
27221 -                            ifap = &ifa->ifa_next)
27222 +                            ifap = &ifa->ifa_next) {
27223 +                               if (!nx_v4_ifa_visible(nxi, ifa))
27224 +                                       continue;
27225                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
27226                                         break;
27227 +                       }
27228                 }
27229         }
27230  
27231 @@ -846,6 +854,8 @@ static int inet_gifconf(struct net_devic
27232                 goto out;
27233  
27234         for (; ifa; ifa = ifa->ifa_next) {
27235 +               if (!nx_v4_ifa_visible(current->nx_info, ifa))
27236 +                       continue;
27237                 if (!buf) {
27238                         done += sizeof(ifr);
27239                         continue;
27240 @@ -1171,6 +1181,7 @@ static int inet_dump_ifaddr(struct sk_bu
27241         struct net_device *dev;
27242         struct in_device *in_dev;
27243         struct in_ifaddr *ifa;
27244 +       struct sock *sk = skb->sk;
27245         int s_ip_idx, s_idx = cb->args[0];
27246  
27247         if (net != &init_net)
27248 @@ -1188,6 +1199,8 @@ static int inet_dump_ifaddr(struct sk_bu
27249  
27250                 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
27251                      ifa = ifa->ifa_next, ip_idx++) {
27252 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
27253 +                               continue;
27254                         if (ip_idx < s_ip_idx)
27255                                 continue;
27256                         if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
27257 diff -NurpP --minimal linux-2.6.25/net/ipv4/fib_hash.c linux-2.6.25-vs2.3.0.34.9/net/ipv4/fib_hash.c
27258 --- linux-2.6.25/net/ipv4/fib_hash.c    2008-04-17 12:05:44.000000000 -0400
27259 +++ linux-2.6.25-vs2.3.0.34.9/net/ipv4/fib_hash.c       2008-04-19 15:14:52.000000000 -0400
27260 @@ -1025,7 +1025,7 @@ static int fib_seq_show(struct seq_file 
27261         prefix  = f->fn_key;
27262         mask    = FZ_MASK(iter->zone);
27263         flags   = fib_flag_trans(fa->fa_type, mask, fi);
27264 -       if (fi)
27265 +       if (fi && nx_dev_visible(current->nx_info, fi->fib_dev))
27266                 snprintf(bf, sizeof(bf),
27267                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u",
27268                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
27269 diff -NurpP --minimal linux-2.6.25/net/ipv4/inet_connection_sock.c linux-2.6.25-vs2.3.0.34.9/net/ipv4/inet_connection_sock.c
27270 --- linux-2.6.25/net/ipv4/inet_connection_sock.c        2008-04-17 12:05:44.000000000 -0400
27271 +++ linux-2.6.25-vs2.3.0.34.9/net/ipv4/inet_connection_sock.c   2008-04-19 15:14:52.000000000 -0400
27272 @@ -47,10 +47,40 @@ void inet_get_local_port_range(int *low,
27273  }
27274  EXPORT_SYMBOL(inet_get_local_port_range);
27275  
27276 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
27277 +{
27278 +       __be32  sk1_rcv_saddr = inet_rcv_saddr(sk1),
27279 +               sk2_rcv_saddr = inet_rcv_saddr(sk2);
27280 +
27281 +       if (inet_v6_ipv6only(sk2))
27282 +               return 0;
27283 +
27284 +       if (sk1_rcv_saddr &&
27285 +           sk2_rcv_saddr &&
27286 +           sk1_rcv_saddr == sk2_rcv_saddr)
27287 +               return 1;
27288 +
27289 +       if (sk1_rcv_saddr &&
27290 +           !sk2_rcv_saddr &&
27291 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
27292 +               return 1;
27293 +
27294 +       if (sk2_rcv_saddr &&
27295 +           !sk1_rcv_saddr &&
27296 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
27297 +               return 1;
27298 +
27299 +       if (!sk1_rcv_saddr &&
27300 +           !sk2_rcv_saddr &&
27301 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
27302 +               return 1;
27303 +
27304 +       return 0;
27305 +}
27306 +
27307  int inet_csk_bind_conflict(const struct sock *sk,
27308                            const struct inet_bind_bucket *tb)
27309  {
27310 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
27311         struct sock *sk2;
27312         struct hlist_node *node;
27313         int reuse = sk->sk_reuse;
27314 @@ -63,9 +93,7 @@ int inet_csk_bind_conflict(const struct 
27315                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
27316                         if (!reuse || !sk2->sk_reuse ||
27317                             sk2->sk_state == TCP_LISTEN) {
27318 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
27319 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
27320 -                                   sk2_rcv_saddr == sk_rcv_saddr)
27321 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
27322                                         break;
27323                         }
27324                 }
27325 diff -NurpP --minimal linux-2.6.25/net/ipv4/inet_diag.c linux-2.6.25-vs2.3.0.34.9/net/ipv4/inet_diag.c
27326 --- linux-2.6.25/net/ipv4/inet_diag.c   2008-04-17 12:05:44.000000000 -0400
27327 +++ linux-2.6.25-vs2.3.0.34.9/net/ipv4/inet_diag.c      2008-04-19 16:05:51.000000000 -0400
27328 @@ -34,6 +34,8 @@
27329  #include <linux/stddef.h>
27330  
27331  #include <linux/inet_diag.h>
27332 +#include <linux/vs_network.h>
27333 +#include <linux/vs_inet.h>
27334  
27335  static const struct inet_diag_handler **inet_diag_table;
27336  
27337 @@ -122,8 +124,8 @@ static int inet_csk_diag_fill(struct soc
27338  
27339         r->id.idiag_sport = inet->sport;
27340         r->id.idiag_dport = inet->dport;
27341 -       r->id.idiag_src[0] = inet->rcv_saddr;
27342 -       r->id.idiag_dst[0] = inet->daddr;
27343 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, inet->rcv_saddr);
27344 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
27345  
27346  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
27347         if (r->idiag_family == AF_INET6) {
27348 @@ -210,8 +212,8 @@ static int inet_twsk_diag_fill(struct in
27349         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
27350         r->id.idiag_sport     = tw->tw_sport;
27351         r->id.idiag_dport     = tw->tw_dport;
27352 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
27353 -       r->id.idiag_dst[0]    = tw->tw_daddr;
27354 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
27355 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
27356         r->idiag_state        = tw->tw_substate;
27357         r->idiag_timer        = 3;
27358         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
27359 @@ -268,6 +270,7 @@ static int inet_diag_get_exact(struct sk
27360         err = -EINVAL;
27361  
27362         if (req->idiag_family == AF_INET) {
27363 +               /* TODO: lback */
27364                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
27365                                  req->id.idiag_dport, req->id.idiag_src[0],
27366                                  req->id.idiag_sport, req->id.idiag_if);
27367 @@ -510,6 +513,7 @@ static int inet_csk_diag_dump(struct soc
27368                 } else
27369  #endif
27370                 {
27371 +                       /* TODO: lback */
27372                         entry.saddr = &inet->rcv_saddr;
27373                         entry.daddr = &inet->daddr;
27374                 }
27375 @@ -546,6 +550,7 @@ static int inet_twsk_diag_dump(struct in
27376                 } else
27377  #endif
27378                 {
27379 +                       /* TODO: lback */
27380                         entry.saddr = &tw->tw_rcv_saddr;
27381                         entry.daddr = &tw->tw_daddr;
27382                 }
27383 @@ -592,8 +597,8 @@ static int inet_diag_fill_req(struct sk_
27384  
27385         r->id.idiag_sport = inet->sport;
27386         r->id.idiag_dport = ireq->rmt_port;
27387 -       r->id.idiag_src[0] = ireq->loc_addr;
27388 -       r->id.idiag_dst[0] = ireq->rmt_addr;
27389 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
27390 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
27391         r->idiag_expires = jiffies_to_msecs(tmo);
27392         r->idiag_rqueue = 0;
27393         r->idiag_wqueue = 0;
27394 @@ -663,6 +668,7 @@ static int inet_diag_dump_reqs(struct sk
27395                                 continue;
27396  
27397                         if (bc) {
27398 +                               /* TODO: lback */
27399                                 entry.saddr =
27400  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
27401                                         (entry.family == AF_INET6) ?
27402 @@ -731,6 +737,8 @@ static int inet_diag_dump(struct sk_buff
27403                         sk_for_each(sk, node, &hashinfo->listening_hash[i]) {
27404                                 struct inet_sock *inet = inet_sk(sk);
27405  
27406 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27407 +                                       continue;
27408                                 if (num < s_num) {
27409                                         num++;
27410                                         continue;
27411 @@ -792,6 +800,8 @@ skip_listen_ht:
27412                 sk_for_each(sk, node, &head->chain) {
27413                         struct inet_sock *inet = inet_sk(sk);
27414  
27415 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27416 +                               continue;
27417                         if (num < s_num)
27418                                 goto next_normal;
27419                         if (!(r->idiag_states & (1 << sk->sk_state)))
27420 @@ -816,6 +826,8 @@ next_normal:
27421                         inet_twsk_for_each(tw, node,
27422                                     &head->twchain) {
27423  
27424 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
27425 +                                       continue;
27426                                 if (num < s_num)
27427                                         goto next_dying;
27428                                 if (r->id.idiag_sport != tw->tw_sport &&
27429 diff -NurpP --minimal linux-2.6.25/net/ipv4/inet_hashtables.c linux-2.6.25-vs2.3.0.34.9/net/ipv4/inet_hashtables.c
27430 --- linux-2.6.25/net/ipv4/inet_hashtables.c     2008-04-17 12:05:44.000000000 -0400
27431 +++ linux-2.6.25-vs2.3.0.34.9/net/ipv4/inet_hashtables.c        2008-04-19 15:14:52.000000000 -0400
27432 @@ -21,6 +21,7 @@
27433  
27434  #include <net/inet_connection_sock.h>
27435  #include <net/inet_hashtables.h>
27436 +#include <net/route.h>
27437  #include <net/ip.h>
27438  
27439  /*
27440 @@ -144,11 +145,10 @@ static struct sock *inet_lookup_listener
27441                         const __be32 rcv_saddr = inet->rcv_saddr;
27442                         int score = sk->sk_family == PF_INET ? 1 : 0;
27443  
27444 -                       if (rcv_saddr) {
27445 -                               if (rcv_saddr != daddr)
27446 -                                       continue;
27447 +                       if (v4_inet_addr_match(sk->sk_nx_info, daddr, rcv_saddr))
27448                                 score += 2;
27449 -                       }
27450 +                       else
27451 +                               continue;
27452                         if (sk->sk_bound_dev_if) {
27453                                 if (sk->sk_bound_dev_if != dif)
27454                                         continue;
27455 @@ -180,7 +180,7 @@ struct sock *__inet_lookup_listener(stru
27456                 const struct inet_sock *inet = inet_sk((sk = __sk_head(head)));
27457  
27458                 if (inet->num == hnum && !sk->sk_node.next &&
27459 -                   (!inet->rcv_saddr || inet->rcv_saddr == daddr) &&
27460 +                   v4_inet_addr_match(sk->sk_nx_info, daddr, inet->rcv_saddr) &&
27461                     (sk->sk_family == PF_INET || !ipv6_only_sock(sk)) &&
27462                     !sk->sk_bound_dev_if && sk->sk_net == net)
27463                         goto sherry_cache;
27464 diff -NurpP --minimal linux-2.6.25/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.25-vs2.3.0.34.9/net/ipv4/netfilter/nf_nat_helper.c
27465 --- linux-2.6.25/net/ipv4/netfilter/nf_nat_helper.c     2008-04-17 12:05:45.000000000 -0400
27466 +++ linux-2.6.25-vs2.3.0.34.9/net/ipv4/netfilter/nf_nat_helper.c        2008-04-19 15:14:52.000000000 -0400
27467 @@ -18,6 +18,7 @@
27468  #include <net/tcp.h>
27469  
27470  #include <linux/netfilter_ipv4.h>
27471 +#include <net/route.h>
27472  #include <net/netfilter/nf_conntrack.h>
27473  #include <net/netfilter/nf_conntrack_helper.h>
27474  #include <net/netfilter/nf_conntrack_ecache.h>
27475 diff -NurpP --minimal linux-2.6.25/net/ipv4/netfilter.c linux-2.6.25-vs2.3.0.34.9/net/ipv4/netfilter.c
27476 --- linux-2.6.25/net/ipv4/netfilter.c   2008-04-17 12:05:45.000000000 -0400
27477 +++ linux-2.6.25-vs2.3.0.34.9/net/ipv4/netfilter.c      2008-04-19 15:14:52.000000000 -0400
27478 @@ -4,7 +4,7 @@
27479  #include <linux/netfilter_ipv4.h>
27480  #include <linux/ip.h>
27481  #include <linux/skbuff.h>
27482 -#include <net/route.h>
27483 +// #include <net/route.h>
27484  #include <net/xfrm.h>
27485  #include <net/ip.h>
27486  #include <net/netfilter/nf_queue.h>
27487 diff -NurpP --minimal linux-2.6.25/net/ipv4/raw.c linux-2.6.25-vs2.3.0.34.9/net/ipv4/raw.c
27488 --- linux-2.6.25/net/ipv4/raw.c 2008-04-17 12:05:45.000000000 -0400
27489 +++ linux-2.6.25-vs2.3.0.34.9/net/ipv4/raw.c    2008-04-29 20:28:52.000000000 -0400
27490 @@ -126,7 +126,7 @@ static struct sock *__raw_v4_lookup(stru
27491  
27492                 if (sk->sk_net == net && inet->num == num               &&
27493                     !(inet->daddr && inet->daddr != raddr)              &&
27494 -                   !(inet->rcv_saddr && inet->rcv_saddr != laddr)      &&
27495 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
27496                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
27497                         goto found; /* gotcha */
27498         }
27499 @@ -382,6 +382,12 @@ static int raw_send_hdrinc(struct sock *
27500                 icmp_out_count(((struct icmphdr *)
27501                         skb_transport_header(skb))->type);
27502  
27503 +       err = -EPERM;
27504 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
27505 +               sk->sk_nx_info &&
27506 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
27507 +               goto error_free;
27508 +
27509         err = NF_HOOK(PF_INET, NF_INET_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
27510                       dst_output);
27511         if (err > 0)
27512 @@ -393,6 +399,7 @@ out:
27513  
27514  error_fault:
27515         err = -EFAULT;
27516 +error_free:
27517         kfree_skb(skb);
27518  error:
27519         IP_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
27520 @@ -560,6 +567,13 @@ static int raw_sendmsg(struct kiocb *ioc
27521                 }
27522  
27523                 security_sk_classify_flow(sk, &fl);
27524 +               if (sk->sk_nx_info) {
27525 +                       err = ip_v4_find_src(sk->sk_net,
27526 +                               sk->sk_nx_info, &rt, &fl);
27527 +
27528 +                       if (err)
27529 +                               goto done;
27530 +               }
27531                 err = ip_route_output_flow(&init_net, &rt, &fl, sk, 1);
27532         }
27533         if (err)
27534 @@ -622,17 +636,19 @@ static int raw_bind(struct sock *sk, str
27535  {
27536         struct inet_sock *inet = inet_sk(sk);
27537         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
27538 +       struct nx_v4_sock_addr nsa = { 0 };
27539         int ret = -EINVAL;
27540         int chk_addr_ret;
27541  
27542         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
27543                 goto out;
27544 -       chk_addr_ret = inet_addr_type(sk->sk_net, addr->sin_addr.s_addr);
27545 +       v4_map_sock_addr(inet, addr, &nsa);
27546 +       chk_addr_ret = inet_addr_type(sk->sk_net, nsa.saddr);
27547         ret = -EADDRNOTAVAIL;
27548 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
27549 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
27550             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
27551                 goto out;
27552 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
27553 +       v4_set_sock_addr(inet, &nsa);
27554         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
27555                 inet->saddr = 0;  /* Use device */
27556         sk_dst_reset(sk);
27557 @@ -684,7 +700,8 @@ static int raw_recvmsg(struct kiocb *ioc
27558         /* Copy the address. */
27559         if (sin) {
27560                 sin->sin_family = AF_INET;
27561 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27562 +               sin->sin_addr.s_addr =
27563 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
27564                 sin->sin_port = 0;
27565                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
27566         }
27567 @@ -862,7 +879,8 @@ static struct sock *raw_get_first(struct
27568                 struct hlist_node *node;
27569  
27570                 sk_for_each(sk, node, &state->h->ht[state->bucket])
27571 -                       if (sk->sk_net == state->p.net)
27572 +                       if ((sk->sk_net == state->p.net) &&
27573 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27574                                 goto found;
27575         }
27576         sk = NULL;
27577 @@ -878,7 +896,8 @@ static struct sock *raw_get_next(struct 
27578                 sk = sk_next(sk);
27579  try_again:
27580                 ;
27581 -       } while (sk && sk->sk_net != state->p.net);
27582 +       } while (sk && ((sk->sk_net != state->p.net) ||
27583 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27584  
27585         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
27586                 sk = sk_head(&state->h->ht[state->bucket]);
27587 @@ -937,7 +956,10 @@ static void raw_sock_seq_show(struct seq
27588  
27589         seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
27590                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d",
27591 -               i, src, srcp, dest, destp, sp->sk_state,
27592 +               i,
27593 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27594 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27595 +               sp->sk_state,
27596                 atomic_read(&sp->sk_wmem_alloc),
27597                 atomic_read(&sp->sk_rmem_alloc),
27598                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
27599 diff -NurpP --minimal linux-2.6.25/net/ipv4/syncookies.c linux-2.6.25-vs2.3.0.34.9/net/ipv4/syncookies.c
27600 --- linux-2.6.25/net/ipv4/syncookies.c  2008-04-17 12:05:45.000000000 -0400
27601 +++ linux-2.6.25-vs2.3.0.34.9/net/ipv4/syncookies.c     2008-04-19 15:14:52.000000000 -0400
27602 @@ -20,6 +20,7 @@
27603  #include <linux/cryptohash.h>
27604  #include <linux/kernel.h>
27605  #include <net/tcp.h>
27606 +#include <net/route.h>
27607  
27608  extern int sysctl_tcp_syncookies;
27609  
27610 diff -NurpP --minimal linux-2.6.25/net/ipv4/tcp.c linux-2.6.25-vs2.3.0.34.9/net/ipv4/tcp.c
27611 --- linux-2.6.25/net/ipv4/tcp.c 2008-04-17 12:05:45.000000000 -0400
27612 +++ linux-2.6.25-vs2.3.0.34.9/net/ipv4/tcp.c    2008-04-19 15:14:52.000000000 -0400
27613 @@ -263,6 +263,7 @@
27614  #include <linux/cache.h>
27615  #include <linux/err.h>
27616  #include <linux/crypto.h>
27617 +#include <linux/in.h>
27618  
27619  #include <net/icmp.h>
27620  #include <net/tcp.h>
27621 diff -NurpP --minimal linux-2.6.25/net/ipv4/tcp_ipv4.c linux-2.6.25-vs2.3.0.34.9/net/ipv4/tcp_ipv4.c
27622 --- linux-2.6.25/net/ipv4/tcp_ipv4.c    2008-04-17 12:05:45.000000000 -0400
27623 +++ linux-2.6.25-vs2.3.0.34.9/net/ipv4/tcp_ipv4.c       2008-04-19 15:14:52.000000000 -0400
27624 @@ -1965,6 +1965,12 @@ static void *listening_get_next(struct s
27625                 req = req->dl_next;
27626                 while (1) {
27627                         while (req) {
27628 +                               vxdprintk(VXD_CBIT(net, 6),
27629 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
27630 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
27631 +                               if (req->sk &&
27632 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
27633 +                                       continue;
27634                                 if (req->rsk_ops->family == st->family) {
27635                                         cur = req;
27636                                         goto out;
27637 @@ -1989,6 +1995,10 @@ get_req:
27638         }
27639  get_sk:
27640         sk_for_each_from(sk, node) {
27641 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
27642 +                       sk, sk->sk_nid, nx_current_nid());
27643 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27644 +                       continue;
27645                 if (sk->sk_family == st->family) {
27646                         cur = sk;
27647                         goto out;
27648 @@ -2038,18 +2048,26 @@ static void *established_get_first(struc
27649  
27650                 read_lock_bh(lock);
27651                 sk_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
27652 -                       if (sk->sk_family != st->family) {
27653 +                       vxdprintk(VXD_CBIT(net, 6),
27654 +                               "sk,egf: %p [#%d] (from %d)",
27655 +                               sk, sk->sk_nid, nx_current_nid());
27656 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27657 +                               continue;
27658 +                       if (sk->sk_family != st->family)
27659                                 continue;
27660 -                       }
27661                         rc = sk;
27662                         goto out;
27663                 }
27664                 st->state = TCP_SEQ_STATE_TIME_WAIT;
27665                 inet_twsk_for_each(tw, node,
27666                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
27667 -                       if (tw->tw_family != st->family) {
27668 +                       vxdprintk(VXD_CBIT(net, 6),
27669 +                               "tw: %p [#%d] (from %d)",
27670 +                               tw, tw->tw_nid, nx_current_nid());
27671 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
27672 +                               continue;
27673 +                       if (tw->tw_family != st->family)
27674                                 continue;
27675 -                       }
27676                         rc = tw;
27677                         goto out;
27678                 }
27679 @@ -2073,7 +2091,8 @@ static void *established_get_next(struct
27680                 tw = cur;
27681                 tw = tw_next(tw);
27682  get_tw:
27683 -               while (tw && tw->tw_family != st->family) {
27684 +               while (tw && (tw->tw_family != st->family ||
27685 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
27686                         tw = tw_next(tw);
27687                 }
27688                 if (tw) {
27689 @@ -2094,6 +2113,11 @@ get_tw:
27690                 sk = sk_next(sk);
27691  
27692         sk_for_each_from(sk, node) {
27693 +               vxdprintk(VXD_CBIT(net, 6),
27694 +                       "sk,egn: %p [#%d] (from %d)",
27695 +                       sk, sk->sk_nid, nx_current_nid());
27696 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27697 +                       continue;
27698                 if (sk->sk_family == st->family)
27699                         goto found;
27700         }
27701 @@ -2266,9 +2290,9 @@ static void get_openreq4(struct sock *sk
27702         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
27703                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p",
27704                 i,
27705 -               ireq->loc_addr,
27706 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
27707                 ntohs(inet_sk(sk)->sport),
27708 -               ireq->rmt_addr,
27709 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
27710                 ntohs(ireq->rmt_port),
27711                 TCP_SYN_RECV,
27712                 0, 0, /* could print option size, but that is af dependent. */
27713 @@ -2310,7 +2334,10 @@ static void get_tcp4_sock(struct sock *s
27714  
27715         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
27716                         "%08X %5d %8d %lu %d %p %u %u %u %u %d",
27717 -               i, src, srcp, dest, destp, sk->sk_state,
27718 +               i,
27719 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27720 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27721 +               sk->sk_state,
27722                 tp->write_seq - tp->snd_una,
27723                 sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog :
27724                                              (tp->rcv_nxt - tp->copied_seq),
27725 @@ -2345,7 +2372,10 @@ static void get_timewait4_sock(struct in
27726  
27727         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
27728                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p",
27729 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
27730 +               i,
27731 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27732 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27733 +               tw->tw_substate, 0, 0,
27734                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
27735                 atomic_read(&tw->tw_refcnt), tw);
27736  }
27737 diff -NurpP --minimal linux-2.6.25/net/ipv4/tcp_minisocks.c linux-2.6.25-vs2.3.0.34.9/net/ipv4/tcp_minisocks.c
27738 --- linux-2.6.25/net/ipv4/tcp_minisocks.c       2008-04-17 11:31:40.000000000 -0400
27739 +++ linux-2.6.25-vs2.3.0.34.9/net/ipv4/tcp_minisocks.c  2008-04-19 15:14:52.000000000 -0400
27740 @@ -28,6 +28,10 @@
27741  #include <net/inet_common.h>
27742  #include <net/xfrm.h>
27743  
27744 +#include <linux/vs_limit.h>
27745 +#include <linux/vs_socket.h>
27746 +#include <linux/vs_context.h>
27747 +
27748  #ifdef CONFIG_SYSCTL
27749  #define SYNC_INIT 0 /* let the user enable it */
27750  #else
27751 @@ -293,6 +297,11 @@ void tcp_time_wait(struct sock *sk, int 
27752                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
27753                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
27754  
27755 +               tw->tw_xid              = sk->sk_xid;
27756 +               tw->tw_vx_info          = NULL;
27757 +               tw->tw_nid              = sk->sk_nid;
27758 +               tw->tw_nx_info          = NULL;
27759 +
27760  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
27761                 if (tw->tw_family == PF_INET6) {
27762                         struct ipv6_pinfo *np = inet6_sk(sk);
27763 diff -NurpP --minimal linux-2.6.25/net/ipv4/udp.c linux-2.6.25-vs2.3.0.34.9/net/ipv4/udp.c
27764 --- linux-2.6.25/net/ipv4/udp.c 2008-04-17 12:05:45.000000000 -0400
27765 +++ linux-2.6.25-vs2.3.0.34.9/net/ipv4/udp.c    2008-04-21 12:41:01.000000000 -0400
27766 @@ -246,14 +246,7 @@ int udp_get_port(struct sock *sk, unsign
27767         return  __udp_lib_get_port(sk, snum, udp_hash, scmp);
27768  }
27769  
27770 -int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
27771 -{
27772 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
27773 -
27774 -       return  ( !ipv6_only_sock(sk2)  &&
27775 -                 (!inet1->rcv_saddr || !inet2->rcv_saddr ||
27776 -                  inet1->rcv_saddr == inet2->rcv_saddr      ));
27777 -}
27778 +extern int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2);
27779  
27780  static inline int udp_v4_get_port(struct sock *sk, unsigned short snum)
27781  {
27782 @@ -273,16 +266,23 @@ static struct sock *__udp4_lib_lookup(st
27783         int badness = -1;
27784  
27785         read_lock(&udp_hash_lock);
27786 +
27787         sk_for_each(sk, node, &udptable[hnum & (UDP_HTABLE_SIZE - 1)]) {
27788                 struct inet_sock *inet = inet_sk(sk);
27789  
27790                 if (sk->sk_net == net && sk->sk_hash == hnum &&
27791                                 !ipv6_only_sock(sk)) {
27792                         int score = (sk->sk_family == PF_INET ? 1 : 0);
27793 +
27794                         if (inet->rcv_saddr) {
27795                                 if (inet->rcv_saddr != daddr)
27796                                         continue;
27797                                 score+=2;
27798 +                       } else {
27799 +                               /* block non nx_info ips */
27800 +                               if (!v4_addr_in_nx_info(sk->sk_nx_info,
27801 +                                       daddr, NXA_MASK_BIND))
27802 +                                       continue;
27803                         }
27804                         if (inet->daddr) {
27805                                 if (inet->daddr != saddr)
27806 @@ -308,6 +308,7 @@ static struct sock *__udp4_lib_lookup(st
27807                         }
27808                 }
27809         }
27810 +
27811         if (result)
27812                 sock_hold(result);
27813         read_unlock(&udp_hash_lock);
27814 @@ -329,7 +330,7 @@ static inline struct sock *udp_v4_mcast_
27815                 if (s->sk_hash != hnum                                  ||
27816                     (inet->daddr && inet->daddr != rmt_addr)            ||
27817                     (inet->dport != rmt_port && inet->dport)            ||
27818 -                   (inet->rcv_saddr && inet->rcv_saddr != loc_addr)    ||
27819 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
27820                     ipv6_only_sock(s)                                   ||
27821                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
27822                         continue;
27823 @@ -662,7 +663,15 @@ int udp_sendmsg(struct kiocb *iocb, stru
27824                                     .uli_u = { .ports =
27825                                                { .sport = inet->sport,
27826                                                  .dport = dport } } };
27827 +               struct nx_info *nxi = sk->sk_nx_info;
27828 +               struct net *net = sk->sk_net;
27829 +
27830                 security_sk_classify_flow(sk, &fl);
27831 +
27832 +               err = ip_v4_find_src(net, nxi, &rt, &fl);
27833 +               if (err)
27834 +                       goto out;
27835 +
27836                 err = ip_route_output_flow(&init_net, &rt, &fl, sk, 1);
27837                 if (err) {
27838                         if (err == -ENETUNREACH)
27839 @@ -905,7 +914,8 @@ try_again:
27840         {
27841                 sin->sin_family = AF_INET;
27842                 sin->sin_port = udp_hdr(skb)->source;
27843 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27844 +               sin->sin_addr.s_addr = nx_map_sock_lback(
27845 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
27846                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
27847         }
27848         if (inet->cmsg_flags)
27849 @@ -1516,7 +1526,8 @@ static struct sock *udp_get_first(struct
27850         for (state->bucket = 0; state->bucket < UDP_HTABLE_SIZE; ++state->bucket) {
27851                 struct hlist_node *node;
27852                 sk_for_each(sk, node, state->hashtable + state->bucket) {
27853 -                       if (sk->sk_family == state->family)
27854 +                       if (sk->sk_family == state->family &&
27855 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27856                                 goto found;
27857                 }
27858         }
27859 @@ -1533,7 +1544,8 @@ static struct sock *udp_get_next(struct 
27860                 sk = sk_next(sk);
27861  try_again:
27862                 ;
27863 -       } while (sk && sk->sk_family != state->family);
27864 +       } while (sk && (sk->sk_family != state->family ||
27865 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27866  
27867         if (!sk && ++state->bucket < UDP_HTABLE_SIZE) {
27868                 sk = sk_head(state->hashtable + state->bucket);
27869 @@ -1648,7 +1660,10 @@ static void udp4_format_sock(struct sock
27870  
27871         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
27872                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p",
27873 -               bucket, src, srcp, dest, destp, sp->sk_state,
27874 +               bucket,
27875 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27876 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27877 +               sp->sk_state,
27878                 atomic_read(&sp->sk_wmem_alloc),
27879                 atomic_read(&sp->sk_rmem_alloc),
27880                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
27881 diff -NurpP --minimal linux-2.6.25/net/ipv6/addrconf.c linux-2.6.25-vs2.3.0.34.9/net/ipv6/addrconf.c
27882 --- linux-2.6.25/net/ipv6/addrconf.c    2008-04-17 12:05:45.000000000 -0400
27883 +++ linux-2.6.25-vs2.3.0.34.9/net/ipv6/addrconf.c       2008-04-19 16:44:23.000000000 -0400
27884 @@ -87,6 +87,8 @@
27885  
27886  #include <linux/proc_fs.h>
27887  #include <linux/seq_file.h>
27888 +#include <linux/vs_network.h>
27889 +#include <linux/vs_inet6.h>
27890  
27891  /* Set to 3 to get tracing... */
27892  #define ACONF_DEBUG 2
27893 @@ -918,7 +920,8 @@ static inline int ipv6_saddr_preferred(i
27894  }
27895  
27896  int ipv6_dev_get_saddr(struct net_device *daddr_dev,
27897 -                      struct in6_addr *daddr, struct in6_addr *saddr)
27898 +                      struct in6_addr *daddr, struct in6_addr *saddr,
27899 +                      struct nx_info *nxi)
27900  {
27901         struct ipv6_saddr_score hiscore;
27902         struct inet6_ifaddr *ifa_result = NULL;
27903 @@ -964,6 +967,10 @@ int ipv6_dev_get_saddr(struct net_device
27904  
27905                         score.addr_type = __ipv6_addr_type(&ifa->addr);
27906  
27907 +                       /* Use only addresses assigned to the context */
27908 +                       if (!v6_ifa_in_nx_info(ifa, nxi))
27909 +                               continue;
27910 +
27911                         /* Rule 0:
27912                          * - Tentative Address (RFC2462 section 5.4)
27913                          *  - A tentative address is not considered
27914 @@ -1181,9 +1188,10 @@ record_it:
27915  
27916  
27917  int ipv6_get_saddr(struct dst_entry *dst,
27918 -                  struct in6_addr *daddr, struct in6_addr *saddr)
27919 +                  struct in6_addr *daddr, struct in6_addr *saddr,
27920 +                  struct nx_info *nxi)
27921  {
27922 -       return ipv6_dev_get_saddr(dst ? ip6_dst_idev(dst)->dev : NULL, daddr, saddr);
27923 +       return ipv6_dev_get_saddr(dst ? ip6_dst_idev(dst)->dev : NULL, daddr, saddr, nxi);
27924  }
27925  
27926  EXPORT_SYMBOL(ipv6_get_saddr);
27927 @@ -1287,35 +1295,46 @@ struct inet6_ifaddr *ipv6_get_ifaddr(str
27928         return ifp;
27929  }
27930  
27931 +extern int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2);
27932 +
27933  int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
27934  {
27935         const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
27936         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
27937 -       __be32 sk_rcv_saddr = inet_sk(sk)->rcv_saddr;
27938         __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
27939         int sk_ipv6only = ipv6_only_sock(sk);
27940         int sk2_ipv6only = inet_v6_ipv6only(sk2);
27941         int addr_type = ipv6_addr_type(sk_rcv_saddr6);
27942         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
27943  
27944 -       if (!sk2_rcv_saddr && !sk_ipv6only)
27945 +       /* FIXME: needs handling for v4 ANY */
27946 +       if (!sk2_rcv_saddr && !sk_ipv6only && !sk2->sk_nx_info)
27947                 return 1;
27948  
27949         if (addr_type2 == IPV6_ADDR_ANY &&
27950 -           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
27951 +           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED) &&
27952 +           v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1))
27953                 return 1;
27954  
27955         if (addr_type == IPV6_ADDR_ANY &&
27956 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
27957 +           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED) &&
27958 +           (sk2_rcv_saddr6 && v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1)))
27959 +               return 1;
27960 +
27961 +       if (addr_type == IPV6_ADDR_ANY &&
27962 +           addr_type2 == IPV6_ADDR_ANY &&
27963 +           nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info))
27964                 return 1;
27965  
27966         if (sk2_rcv_saddr6 &&
27967 +           addr_type != IPV6_ADDR_ANY &&
27968 +           addr_type != IPV6_ADDR_ANY &&
27969             ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
27970                 return 1;
27971  
27972         if (addr_type == IPV6_ADDR_MAPPED &&
27973             !sk2_ipv6only &&
27974 -           (!sk2_rcv_saddr || !sk_rcv_saddr || sk_rcv_saddr == sk2_rcv_saddr))
27975 +           ipv4_rcv_saddr_equal(sk, sk2))
27976                 return 1;
27977  
27978         return 0;
27979 @@ -2846,7 +2865,10 @@ static void if6_seq_stop(struct seq_file
27980  static int if6_seq_show(struct seq_file *seq, void *v)
27981  {
27982         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
27983 -       seq_printf(seq,
27984 +
27985 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
27986 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
27987 +               seq_printf(seq,
27988                    NIP6_SEQFMT " %02x %02x %02x %02x %8s\n",
27989                    NIP6(ifp->addr),
27990                    ifp->idev->dev->ifindex,
27991 @@ -3337,6 +3359,11 @@ static int inet6_dump_addr(struct sk_buf
27992         struct inet6_ifaddr *ifa;
27993         struct ifmcaddr6 *ifmca;
27994         struct ifacaddr6 *ifaca;
27995 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27996 +
27997 +       /* disable ipv6 on non v6 guests */
27998 +       if (nxi && !nx_info_has_v6(nxi))
27999 +               return skb->len;
28000  
28001         s_idx = cb->args[0];
28002         s_ip_idx = ip_idx = cb->args[1];
28003 @@ -3358,6 +3385,8 @@ static int inet6_dump_addr(struct sk_buf
28004                              ifa = ifa->if_next, ip_idx++) {
28005                                 if (ip_idx < s_ip_idx)
28006                                         continue;
28007 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
28008 +                                       continue;
28009                                 err = inet6_fill_ifaddr(skb, ifa,
28010                                                         NETLINK_CB(cb->skb).pid,
28011                                                         cb->nlh->nlmsg_seq,
28012 @@ -3371,6 +3400,8 @@ static int inet6_dump_addr(struct sk_buf
28013                              ifmca = ifmca->next, ip_idx++) {
28014                                 if (ip_idx < s_ip_idx)
28015                                         continue;
28016 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
28017 +                                       continue;
28018                                 err = inet6_fill_ifmcaddr(skb, ifmca,
28019                                                           NETLINK_CB(cb->skb).pid,
28020                                                           cb->nlh->nlmsg_seq,
28021 @@ -3384,6 +3415,8 @@ static int inet6_dump_addr(struct sk_buf
28022                              ifaca = ifaca->aca_next, ip_idx++) {
28023                                 if (ip_idx < s_ip_idx)
28024                                         continue;
28025 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
28026 +                                       continue;
28027                                 err = inet6_fill_ifacaddr(skb, ifaca,
28028                                                           NETLINK_CB(cb->skb).pid,
28029                                                           cb->nlh->nlmsg_seq,
28030 @@ -3678,6 +3711,11 @@ static int inet6_dump_ifinfo(struct sk_b
28031         int s_idx = cb->args[0];
28032         struct net_device *dev;
28033         struct inet6_dev *idev;
28034 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
28035 +
28036 +       /* FIXME: maybe disable ipv6 on non v6 guests?
28037 +       if (skb->sk && skb->sk->sk_vx_info)
28038 +               return skb->len; */
28039  
28040         if (net != &init_net)
28041                 return 0;
28042 @@ -3687,6 +3725,8 @@ static int inet6_dump_ifinfo(struct sk_b
28043         for_each_netdev(&init_net, dev) {
28044                 if (idx < s_idx)
28045                         goto cont;
28046 +               if (!v6_dev_in_nx_info(dev, nxi))
28047 +                       goto cont;
28048                 if ((idev = in6_dev_get(dev)) == NULL)
28049                         goto cont;
28050                 err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
28051 diff -NurpP --minimal linux-2.6.25/net/ipv6/af_inet6.c linux-2.6.25-vs2.3.0.34.9/net/ipv6/af_inet6.c
28052 --- linux-2.6.25/net/ipv6/af_inet6.c    2008-04-17 12:05:45.000000000 -0400
28053 +++ linux-2.6.25-vs2.3.0.34.9/net/ipv6/af_inet6.c       2008-04-19 15:14:52.000000000 -0400
28054 @@ -43,6 +43,8 @@
28055  #include <linux/netdevice.h>
28056  #include <linux/icmpv6.h>
28057  #include <linux/netfilter_ipv6.h>
28058 +#include <linux/vs_inet.h>
28059 +#include <linux/vs_inet6.h>
28060  
28061  #include <net/ip.h>
28062  #include <net/ipv6.h>
28063 @@ -51,6 +53,7 @@
28064  #include <net/tcp.h>
28065  #include <net/ipip.h>
28066  #include <net/protocol.h>
28067 +#include <net/route.h>
28068  #include <net/inet_common.h>
28069  #include <net/transp_v6.h>
28070  #include <net/ip6_route.h>
28071 @@ -148,9 +151,12 @@ lookup_protocol:
28072         }
28073  
28074         err = -EPERM;
28075 +       if ((protocol == IPPROTO_ICMPV6) &&
28076 +               nx_capable(answer->capability, NXC_RAW_ICMP))
28077 +               goto override;
28078         if (answer->capability > 0 && !capable(answer->capability))
28079                 goto out_rcu_unlock;
28080 -
28081 +override:
28082         sock->ops = answer->ops;
28083         answer_prot = answer->prot;
28084         answer_no_check = answer->no_check;
28085 @@ -248,6 +254,7 @@ int inet6_bind(struct socket *sock, stru
28086         struct sock *sk = sock->sk;
28087         struct inet_sock *inet = inet_sk(sk);
28088         struct ipv6_pinfo *np = inet6_sk(sk);
28089 +       struct nx_v6_sock_addr nsa;
28090         __be32 v4addr = 0;
28091         unsigned short snum;
28092         int addr_type = 0;
28093 @@ -259,6 +266,11 @@ int inet6_bind(struct socket *sock, stru
28094  
28095         if (addr_len < SIN6_LEN_RFC2133)
28096                 return -EINVAL;
28097 +
28098 +       err = v6_map_sock_addr(inet, addr, &nsa);
28099 +       if (err)
28100 +               return err;
28101 +
28102         addr_type = ipv6_addr_type(&addr->sin6_addr);
28103         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
28104                 return -EINVAL;
28105 @@ -282,6 +294,10 @@ int inet6_bind(struct socket *sock, stru
28106                         err = -EADDRNOTAVAIL;
28107                         goto out;
28108                 }
28109 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
28110 +                       err = -EADDRNOTAVAIL;
28111 +                       goto out;
28112 +               }
28113         } else {
28114                 if (addr_type != IPV6_ADDR_ANY) {
28115                         struct net_device *dev = NULL;
28116 @@ -307,6 +323,11 @@ int inet6_bind(struct socket *sock, stru
28117                                 }
28118                         }
28119  
28120 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
28121 +                               err = -EADDRNOTAVAIL;
28122 +                               goto out;
28123 +                       }
28124 +
28125                         /* ipv4 addr of the socket is invalid.  Only the
28126                          * unspecified and mapped address have a v4 equivalent.
28127                          */
28128 @@ -325,6 +346,8 @@ int inet6_bind(struct socket *sock, stru
28129                 }
28130         }
28131  
28132 +       v6_set_sock_addr(inet, &nsa);
28133 +
28134         inet->rcv_saddr = v4addr;
28135         inet->saddr = v4addr;
28136  
28137 @@ -419,9 +442,11 @@ int inet6_getname(struct socket *sock, s
28138                         return -ENOTCONN;
28139                 sin->sin6_port = inet->dport;
28140                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
28141 +               /* FIXME: remap lback? */
28142                 if (np->sndflow)
28143                         sin->sin6_flowinfo = np->flow_label;
28144         } else {
28145 +               /* FIXME: remap lback? */
28146                 if (ipv6_addr_any(&np->rcv_saddr))
28147                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
28148                 else
28149 diff -NurpP --minimal linux-2.6.25/net/ipv6/fib6_rules.c linux-2.6.25-vs2.3.0.34.9/net/ipv6/fib6_rules.c
28150 --- linux-2.6.25/net/ipv6/fib6_rules.c  2008-04-17 12:05:45.000000000 -0400
28151 +++ linux-2.6.25-vs2.3.0.34.9/net/ipv6/fib6_rules.c     2008-04-19 15:14:52.000000000 -0400
28152 @@ -86,7 +86,7 @@ static int fib6_rule_action(struct fib_r
28153                     r->src.plen && !(flags & RT6_LOOKUP_F_HAS_SADDR)) {
28154                         struct in6_addr saddr;
28155                         if (ipv6_get_saddr(&rt->u.dst, &flp->fl6_dst,
28156 -                                          &saddr))
28157 +                                          &saddr, NULL))
28158                                 goto again;
28159                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
28160                                                r->src.plen))
28161 diff -NurpP --minimal linux-2.6.25/net/ipv6/inet6_hashtables.c linux-2.6.25-vs2.3.0.34.9/net/ipv6/inet6_hashtables.c
28162 --- linux-2.6.25/net/ipv6/inet6_hashtables.c    2008-04-17 12:05:45.000000000 -0400
28163 +++ linux-2.6.25-vs2.3.0.34.9/net/ipv6/inet6_hashtables.c       2008-04-19 15:14:52.000000000 -0400
28164 @@ -16,6 +16,7 @@
28165  
28166  #include <linux/module.h>
28167  #include <linux/random.h>
28168 +#include <linux/vs_inet6.h>
28169  
28170  #include <net/inet_connection_sock.h>
28171  #include <net/inet_hashtables.h>
28172 @@ -114,6 +115,9 @@ struct sock *inet6_lookup_listener(struc
28173                                 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
28174                                         continue;
28175                                 score++;
28176 +                       } else {
28177 +                               if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
28178 +                                       continue;
28179                         }
28180                         if (sk->sk_bound_dev_if) {
28181                                 if (sk->sk_bound_dev_if != dif)
28182 diff -NurpP --minimal linux-2.6.25/net/ipv6/ip6_output.c linux-2.6.25-vs2.3.0.34.9/net/ipv6/ip6_output.c
28183 --- linux-2.6.25/net/ipv6/ip6_output.c  2008-04-17 12:05:45.000000000 -0400
28184 +++ linux-2.6.25-vs2.3.0.34.9/net/ipv6/ip6_output.c     2008-04-19 15:14:52.000000000 -0400
28185 @@ -920,7 +920,7 @@ static int ip6_dst_lookup_tail(struct so
28186                 goto out_err_release;
28187  
28188         if (ipv6_addr_any(&fl->fl6_src)) {
28189 -               err = ipv6_get_saddr(*dst, &fl->fl6_dst, &fl->fl6_src);
28190 +               err = ipv6_get_saddr(*dst, &fl->fl6_dst, &fl->fl6_src, sk->sk_nx_info);
28191                 if (err)
28192                         goto out_err_release;
28193         }
28194 diff -NurpP --minimal linux-2.6.25/net/ipv6/Kconfig linux-2.6.25-vs2.3.0.34.9/net/ipv6/Kconfig
28195 --- linux-2.6.25/net/ipv6/Kconfig       2008-04-17 12:05:45.000000000 -0400
28196 +++ linux-2.6.25-vs2.3.0.34.9/net/ipv6/Kconfig  2008-04-19 15:14:52.000000000 -0400
28197 @@ -4,8 +4,8 @@
28198  
28199  #   IPv6 as module will cause a CRASH if you try to unload it
28200  config IPV6
28201 -       tristate "The IPv6 protocol"
28202 -       default m
28203 +       bool "The IPv6 protocol"
28204 +       default n
28205         ---help---
28206           This is complemental support for the IP version 6.
28207           You will still be able to do traditional IPv4 networking as well.
28208 diff -NurpP --minimal linux-2.6.25/net/ipv6/ndisc.c linux-2.6.25-vs2.3.0.34.9/net/ipv6/ndisc.c
28209 --- linux-2.6.25/net/ipv6/ndisc.c       2008-04-17 12:05:45.000000000 -0400
28210 +++ linux-2.6.25-vs2.3.0.34.9/net/ipv6/ndisc.c  2008-04-19 15:14:52.000000000 -0400
28211 @@ -563,7 +563,7 @@ static void ndisc_send_na(struct net_dev
28212                         override = 0;
28213                 in6_ifa_put(ifp);
28214         } else {
28215 -               if (ipv6_dev_get_saddr(dev, daddr, &tmpaddr))
28216 +               if (ipv6_dev_get_saddr(dev, daddr, &tmpaddr, NULL))
28217                         return;
28218                 src_addr = &tmpaddr;
28219         }
28220 diff -NurpP --minimal linux-2.6.25/net/ipv6/route.c linux-2.6.25-vs2.3.0.34.9/net/ipv6/route.c
28221 --- linux-2.6.25/net/ipv6/route.c       2008-04-17 12:05:45.000000000 -0400
28222 +++ linux-2.6.25-vs2.3.0.34.9/net/ipv6/route.c  2008-04-19 15:14:52.000000000 -0400
28223 @@ -2122,7 +2122,7 @@ static int rt6_fill_node(struct sk_buff 
28224                 NLA_PUT_U32(skb, RTA_IIF, iif);
28225         else if (dst) {
28226                 struct in6_addr saddr_buf;
28227 -               if (ipv6_get_saddr(&rt->u.dst, dst, &saddr_buf) == 0)
28228 +               if (ipv6_get_saddr(&rt->u.dst, dst, &saddr_buf, (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
28229                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
28230         }
28231  
28232 diff -NurpP --minimal linux-2.6.25/net/ipv6/tcp_ipv6.c linux-2.6.25-vs2.3.0.34.9/net/ipv6/tcp_ipv6.c
28233 --- linux-2.6.25/net/ipv6/tcp_ipv6.c    2008-04-17 12:05:45.000000000 -0400
28234 +++ linux-2.6.25-vs2.3.0.34.9/net/ipv6/tcp_ipv6.c       2008-04-19 15:14:52.000000000 -0400
28235 @@ -68,6 +68,7 @@
28236  
28237  #include <linux/crypto.h>
28238  #include <linux/scatterlist.h>
28239 +#include <linux/vs_inet6.h>
28240  
28241  /* Socket used for sending RSTs and ACKs */
28242  static struct socket *tcp6_socket;
28243 @@ -154,8 +155,15 @@ static int tcp_v6_connect(struct sock *s
28244          *      connect() to INADDR_ANY means loopback (BSD'ism).
28245          */
28246  
28247 -       if(ipv6_addr_any(&usin->sin6_addr))
28248 -               usin->sin6_addr.s6_addr[15] = 0x1;
28249 +       if(ipv6_addr_any(&usin->sin6_addr)) {
28250 +               struct nx_info *nxi =  sk->sk_nx_info;
28251 +
28252 +               if (nxi && nx_info_has_v6(nxi))
28253 +                       /* FIXME: remap lback? */
28254 +                       usin->sin6_addr = nxi->v6.ip;
28255 +               else
28256 +                       usin->sin6_addr.s6_addr[15] = 0x1;
28257 +       }
28258  
28259         addr_type = ipv6_addr_type(&usin->sin6_addr);
28260  
28261 diff -NurpP --minimal linux-2.6.25/net/ipv6/udp.c linux-2.6.25-vs2.3.0.34.9/net/ipv6/udp.c
28262 --- linux-2.6.25/net/ipv6/udp.c 2008-04-17 12:05:45.000000000 -0400
28263 +++ linux-2.6.25-vs2.3.0.34.9/net/ipv6/udp.c    2008-04-19 15:14:52.000000000 -0400
28264 @@ -49,6 +49,7 @@
28265  
28266  #include <linux/proc_fs.h>
28267  #include <linux/seq_file.h>
28268 +#include <linux/vs_inet6.h>
28269  #include "udp_impl.h"
28270  
28271  static inline int udp_v6_get_port(struct sock *sk, unsigned short snum)
28272 @@ -83,6 +84,10 @@ static struct sock *__udp6_lib_lookup(st
28273                                 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
28274                                         continue;
28275                                 score++;
28276 +                       } else {
28277 +                               /* block non nx_info ips */
28278 +                               if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
28279 +                                       continue;
28280                         }
28281                         if (!ipv6_addr_any(&np->daddr)) {
28282                                 if (!ipv6_addr_equal(&np->daddr, saddr))
28283 diff -NurpP --minimal linux-2.6.25/net/ipv6/xfrm6_policy.c linux-2.6.25-vs2.3.0.34.9/net/ipv6/xfrm6_policy.c
28284 --- linux-2.6.25/net/ipv6/xfrm6_policy.c        2008-04-17 12:05:45.000000000 -0400
28285 +++ linux-2.6.25-vs2.3.0.34.9/net/ipv6/xfrm6_policy.c   2008-04-19 16:13:21.000000000 -0400
28286 @@ -58,7 +58,7 @@ static int xfrm6_get_saddr(xfrm_address_
28287                 return -EHOSTUNREACH;
28288  
28289         ipv6_get_saddr(dst, (struct in6_addr *)&daddr->a6,
28290 -                      (struct in6_addr *)&saddr->a6);
28291 +                      (struct in6_addr *)&saddr->a6, NULL);
28292         dst_release(dst);
28293         return 0;
28294  }
28295 diff -NurpP --minimal linux-2.6.25/net/netlink/af_netlink.c linux-2.6.25-vs2.3.0.34.9/net/netlink/af_netlink.c
28296 --- linux-2.6.25/net/netlink/af_netlink.c       2008-04-17 12:05:45.000000000 -0400
28297 +++ linux-2.6.25-vs2.3.0.34.9/net/netlink/af_netlink.c  2008-04-19 15:14:52.000000000 -0400
28298 @@ -56,6 +56,9 @@
28299  #include <linux/audit.h>
28300  #include <linux/selinux.h>
28301  #include <linux/mutex.h>
28302 +#include <linux/vs_context.h>
28303 +#include <linux/vs_network.h>
28304 +#include <linux/vs_limit.h>
28305  
28306  #include <net/net_namespace.h>
28307  #include <net/sock.h>
28308 diff -NurpP --minimal linux-2.6.25/net/sctp/ipv6.c linux-2.6.25-vs2.3.0.34.9/net/sctp/ipv6.c
28309 --- linux-2.6.25/net/sctp/ipv6.c        2008-04-17 12:05:45.000000000 -0400
28310 +++ linux-2.6.25-vs2.3.0.34.9/net/sctp/ipv6.c   2008-04-19 15:14:52.000000000 -0400
28311 @@ -316,7 +316,7 @@ static void sctp_v6_get_saddr(struct sct
28312                           __FUNCTION__, asoc, dst, NIP6(daddr->v6.sin6_addr));
28313  
28314         if (!asoc) {
28315 -               ipv6_get_saddr(dst, &daddr->v6.sin6_addr,&saddr->v6.sin6_addr);
28316 +               ipv6_get_saddr(dst, &daddr->v6.sin6_addr,&saddr->v6.sin6_addr, asoc->base.sk->sk_nx_info);
28317                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: " NIP6_FMT "\n",
28318                                   NIP6(saddr->v6.sin6_addr));
28319                 return;
28320 diff -NurpP --minimal linux-2.6.25/net/socket.c linux-2.6.25-vs2.3.0.34.9/net/socket.c
28321 --- linux-2.6.25/net/socket.c   2008-04-17 12:05:45.000000000 -0400
28322 +++ linux-2.6.25-vs2.3.0.34.9/net/socket.c      2008-04-19 15:14:52.000000000 -0400
28323 @@ -93,6 +93,10 @@
28324  
28325  #include <net/sock.h>
28326  #include <linux/netfilter.h>
28327 +#include <linux/vs_base.h>
28328 +#include <linux/vs_socket.h>
28329 +#include <linux/vs_inet.h>
28330 +#include <linux/vs_inet6.h>
28331  
28332  static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
28333  static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
28334 @@ -547,7 +551,7 @@ static inline int __sock_sendmsg(struct 
28335                                  struct msghdr *msg, size_t size)
28336  {
28337         struct sock_iocb *si = kiocb_to_siocb(iocb);
28338 -       int err;
28339 +       int err, len;
28340  
28341         si->sock = sock;
28342         si->scm = NULL;
28343 @@ -558,7 +562,22 @@ static inline int __sock_sendmsg(struct 
28344         if (err)
28345                 return err;
28346  
28347 -       return sock->ops->sendmsg(iocb, sock, msg, size);
28348 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
28349 +       if (sock->sk) {
28350 +               if (len == size)
28351 +                       vx_sock_send(sock->sk, size);
28352 +               else
28353 +                       vx_sock_fail(sock->sk, size);
28354 +       }
28355 +       vxdprintk(VXD_CBIT(net, 7),
28356 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
28357 +               sock, sock->sk,
28358 +               (sock->sk)?sock->sk->sk_nx_info:0,
28359 +               (sock->sk)?sock->sk->sk_vx_info:0,
28360 +               (sock->sk)?sock->sk->sk_xid:0,
28361 +               (sock->sk)?sock->sk->sk_nid:0,
28362 +               (unsigned int)size, len);
28363 +       return len;
28364  }
28365  
28366  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
28367 @@ -627,7 +646,7 @@ EXPORT_SYMBOL_GPL(__sock_recv_timestamp)
28368  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
28369                                  struct msghdr *msg, size_t size, int flags)
28370  {
28371 -       int err;
28372 +       int err, len;
28373         struct sock_iocb *si = kiocb_to_siocb(iocb);
28374  
28375         si->sock = sock;
28376 @@ -640,7 +659,18 @@ static inline int __sock_recvmsg(struct 
28377         if (err)
28378                 return err;
28379  
28380 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
28381 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
28382 +       if ((len >= 0) && sock->sk)
28383 +               vx_sock_recv(sock->sk, len);
28384 +       vxdprintk(VXD_CBIT(net, 7),
28385 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
28386 +               sock, sock->sk,
28387 +               (sock->sk)?sock->sk->sk_nx_info:0,
28388 +               (sock->sk)?sock->sk->sk_vx_info:0,
28389 +               (sock->sk)?sock->sk->sk_xid:0,
28390 +               (sock->sk)?sock->sk->sk_nid:0,
28391 +               (unsigned int)size, len);
28392 +       return len;
28393  }
28394  
28395  int sock_recvmsg(struct socket *sock, struct msghdr *msg,
28396 @@ -1105,6 +1135,13 @@ static int __sock_create(struct net *net
28397         if (type < 0 || type >= SOCK_MAX)
28398                 return -EINVAL;
28399  
28400 +       if (!nx_check(0, VS_ADMIN)) {
28401 +               if (family == PF_INET && !current_nx_info_has_v4())
28402 +                       return -EAFNOSUPPORT;
28403 +               if (family == PF_INET6 && !current_nx_info_has_v6())
28404 +                       return -EAFNOSUPPORT;
28405 +       }
28406 +
28407         /* Compatibility.
28408  
28409            This uglymoron is moved from INET layer to here to avoid
28410 @@ -1222,6 +1259,7 @@ asmlinkage long sys_socket(int family, i
28411         if (retval < 0)
28412                 goto out;
28413  
28414 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
28415         retval = sock_map_fd(sock);
28416         if (retval < 0)
28417                 goto out_release;
28418 @@ -1254,10 +1292,12 @@ asmlinkage long sys_socketpair(int famil
28419         err = sock_create(family, type, protocol, &sock1);
28420         if (err < 0)
28421                 goto out;
28422 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
28423  
28424         err = sock_create(family, type, protocol, &sock2);
28425         if (err < 0)
28426                 goto out_release_1;
28427 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
28428  
28429         err = sock1->ops->socketpair(sock1, sock2);
28430         if (err < 0)
28431 diff -NurpP --minimal linux-2.6.25/net/sunrpc/auth.c linux-2.6.25-vs2.3.0.34.9/net/sunrpc/auth.c
28432 --- linux-2.6.25/net/sunrpc/auth.c      2008-04-17 12:05:45.000000000 -0400
28433 +++ linux-2.6.25-vs2.3.0.34.9/net/sunrpc/auth.c 2008-04-19 15:14:52.000000000 -0400
28434 @@ -13,6 +13,7 @@
28435  #include <linux/errno.h>
28436  #include <linux/sunrpc/clnt.h>
28437  #include <linux/spinlock.h>
28438 +#include <linux/vs_tag.h>
28439  
28440  #ifdef RPC_DEBUG
28441  # define RPCDBG_FACILITY       RPCDBG_AUTH
28442 @@ -345,6 +346,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
28443         struct auth_cred acred = {
28444                 .uid = current->fsuid,
28445                 .gid = current->fsgid,
28446 +               .tag = dx_current_tag(),
28447                 .group_info = current->group_info,
28448         };
28449         struct rpc_cred *ret;
28450 @@ -382,6 +384,7 @@ rpcauth_bindcred(struct rpc_task *task)
28451         struct auth_cred acred = {
28452                 .uid = current->fsuid,
28453                 .gid = current->fsgid,
28454 +               .tag = dx_current_tag(),
28455                 .group_info = current->group_info,
28456         };
28457         struct rpc_cred *ret;
28458 diff -NurpP --minimal linux-2.6.25/net/sunrpc/auth_unix.c linux-2.6.25-vs2.3.0.34.9/net/sunrpc/auth_unix.c
28459 --- linux-2.6.25/net/sunrpc/auth_unix.c 2008-04-17 10:37:27.000000000 -0400
28460 +++ linux-2.6.25-vs2.3.0.34.9/net/sunrpc/auth_unix.c    2008-04-19 15:14:52.000000000 -0400
28461 @@ -11,12 +11,14 @@
28462  #include <linux/module.h>
28463  #include <linux/sunrpc/clnt.h>
28464  #include <linux/sunrpc/auth.h>
28465 +#include <linux/vs_tag.h>
28466  
28467  #define NFS_NGROUPS    16
28468  
28469  struct unx_cred {
28470         struct rpc_cred         uc_base;
28471         gid_t                   uc_gid;
28472 +       tag_t                   uc_tag;
28473         gid_t                   uc_gids[NFS_NGROUPS];
28474  };
28475  #define uc_uid                 uc_base.cr_uid
28476 @@ -73,6 +75,7 @@ unx_create_cred(struct rpc_auth *auth, s
28477         if (flags & RPCAUTH_LOOKUP_ROOTCREDS) {
28478                 cred->uc_uid = 0;
28479                 cred->uc_gid = 0;
28480 +               cred->uc_tag = dx_current_tag();
28481                 cred->uc_gids[0] = NOGROUP;
28482         } else {
28483                 int groups = acred->group_info->ngroups;
28484 @@ -80,6 +83,7 @@ unx_create_cred(struct rpc_auth *auth, s
28485                         groups = NFS_NGROUPS;
28486  
28487                 cred->uc_gid = acred->gid;
28488 +               cred->uc_tag = acred->tag;
28489                 for (i = 0; i < groups; i++)
28490                         cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
28491                 if (i < NFS_NGROUPS)
28492 @@ -124,7 +128,8 @@ unx_match(struct auth_cred *acred, struc
28493                 int groups;
28494  
28495                 if (cred->uc_uid != acred->uid
28496 -                || cred->uc_gid != acred->gid)
28497 +                || cred->uc_gid != acred->gid
28498 +                || cred->uc_tag != acred->tag)
28499                         return 0;
28500  
28501                 groups = acred->group_info->ngroups;
28502 @@ -150,7 +155,7 @@ unx_marshal(struct rpc_task *task, __be3
28503         struct rpc_clnt *clnt = task->tk_client;
28504         struct unx_cred *cred = container_of(task->tk_msg.rpc_cred, struct unx_cred, uc_base);
28505         __be32          *base, *hold;
28506 -       int             i;
28507 +       int             i, tag;
28508  
28509         *p++ = htonl(RPC_AUTH_UNIX);
28510         base = p++;
28511 @@ -160,9 +165,12 @@ unx_marshal(struct rpc_task *task, __be3
28512          * Copy the UTS nodename captured when the client was created.
28513          */
28514         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
28515 +       tag = task->tk_client->cl_tag;
28516  
28517 -       *p++ = htonl((u32) cred->uc_uid);
28518 -       *p++ = htonl((u32) cred->uc_gid);
28519 +       *p++ = htonl((u32) TAGINO_UID(tag,
28520 +               cred->uc_uid, cred->uc_tag));
28521 +       *p++ = htonl((u32) TAGINO_GID(tag,
28522 +               cred->uc_gid, cred->uc_tag));
28523         hold = p++;
28524         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
28525                 *p++ = htonl((u32) cred->uc_gids[i]);
28526 diff -NurpP --minimal linux-2.6.25/net/sunrpc/clnt.c linux-2.6.25-vs2.3.0.34.9/net/sunrpc/clnt.c
28527 --- linux-2.6.25/net/sunrpc/clnt.c      2008-04-17 12:05:45.000000000 -0400
28528 +++ linux-2.6.25-vs2.3.0.34.9/net/sunrpc/clnt.c 2008-04-19 16:09:36.000000000 -0400
28529 @@ -31,6 +31,7 @@
28530  #include <linux/utsname.h>
28531  #include <linux/workqueue.h>
28532  #include <linux/in6.h>
28533 +#include <linux/vs_cvirt.h>
28534  
28535  #include <linux/sunrpc/clnt.h>
28536  #include <linux/sunrpc/rpc_pipe_fs.h>
28537 @@ -324,7 +325,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
28538                 clnt->cl_autobind = 1;
28539         if (args->flags & RPC_CLNT_CREATE_DISCRTRY)
28540                 clnt->cl_discrtry = 1;
28541 -
28542 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
28543 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
28544 +               clnt->cl_tag = 1; */
28545         return clnt;
28546  }
28547  EXPORT_SYMBOL_GPL(rpc_create);
28548 diff -NurpP --minimal linux-2.6.25/net/unix/af_unix.c linux-2.6.25-vs2.3.0.34.9/net/unix/af_unix.c
28549 --- linux-2.6.25/net/unix/af_unix.c     2008-04-17 12:05:45.000000000 -0400
28550 +++ linux-2.6.25-vs2.3.0.34.9/net/unix/af_unix.c        2008-04-19 15:55:39.000000000 -0400
28551 @@ -116,6 +116,8 @@
28552  #include <linux/mount.h>
28553  #include <net/checksum.h>
28554  #include <linux/security.h>
28555 +#include <linux/vs_context.h>
28556 +#include <linux/vs_limit.h>
28557  
28558  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
28559  static DEFINE_SPINLOCK(unix_table_lock);
28560 @@ -255,6 +257,8 @@ static struct sock *__unix_find_socket_b
28561                 if (s->sk_net != net)
28562                         continue;
28563  
28564 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28565 +                       continue;
28566                 if (u->addr->len == len &&
28567                     !memcmp(u->addr->name, sunname, len))
28568                         goto found;
28569 @@ -819,7 +823,7 @@ static int unix_bind(struct socket *sock
28570                  */
28571                 mode = S_IFSOCK |
28572                        (SOCK_INODE(sock)->i_mode & ~current->fs->umask);
28573 -               err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0);
28574 +               err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0, NULL);
28575                 if (err)
28576                         goto out_mknod_dput;
28577                 mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
28578 diff -NurpP --minimal linux-2.6.25/net/x25/af_x25.c linux-2.6.25-vs2.3.0.34.9/net/x25/af_x25.c
28579 --- linux-2.6.25/net/x25/af_x25.c       2008-04-17 12:05:45.000000000 -0400
28580 +++ linux-2.6.25-vs2.3.0.34.9/net/x25/af_x25.c  2008-04-19 15:14:52.000000000 -0400
28581 @@ -506,7 +506,10 @@ static int x25_create(struct net *net, s
28582  
28583         x25 = x25_sk(sk);
28584  
28585 -       sock_init_data(sock, sk);
28586 +       sk->sk_socket = sock;
28587 +       sk->sk_type = sock->type;
28588 +       sk->sk_sleep = &sock->wait;
28589 +       sock->sk = sk;
28590  
28591         x25_init_timers(sk);
28592  
28593 diff -NurpP --minimal linux-2.6.25/scripts/checksyscalls.sh linux-2.6.25-vs2.3.0.34.9/scripts/checksyscalls.sh
28594 --- linux-2.6.25/scripts/checksyscalls.sh       2008-04-17 11:31:42.000000000 -0400
28595 +++ linux-2.6.25-vs2.3.0.34.9/scripts/checksyscalls.sh  2008-04-19 15:14:52.000000000 -0400
28596 @@ -108,7 +108,6 @@ cat << EOF
28597  #define __IGNORE_afs_syscall
28598  #define __IGNORE_getpmsg
28599  #define __IGNORE_putpmsg
28600 -#define __IGNORE_vserver
28601  EOF
28602  }
28603  
28604 diff -NurpP --minimal linux-2.6.25/security/commoncap.c linux-2.6.25-vs2.3.0.34.9/security/commoncap.c
28605 --- linux-2.6.25/security/commoncap.c   2008-04-17 12:05:46.000000000 -0400
28606 +++ linux-2.6.25-vs2.3.0.34.9/security/commoncap.c      2008-04-23 22:22:54.000000000 -0400
28607 @@ -24,6 +24,7 @@
28608  #include <linux/hugetlb.h>
28609  #include <linux/mount.h>
28610  #include <linux/sched.h>
28611 +#include <linux/vs_context.h>
28612  
28613  /* Global security state */
28614  
28615 @@ -32,7 +33,7 @@ EXPORT_SYMBOL(securebits);
28616  
28617  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
28618  {
28619 -       NETLINK_CB(skb).eff_cap = current->cap_effective;
28620 +       NETLINK_CB(skb).eff_cap = vx_mbcaps(current->cap_effective);
28621         return 0;
28622  }
28623  
28624 @@ -53,9 +54,24 @@ EXPORT_SYMBOL(cap_netlink_recv);
28625   */
28626  int cap_capable (struct task_struct *tsk, int cap)
28627  {
28628 +       struct vx_info *vxi = tsk->vx_info;
28629 +
28630 +#if 0
28631 +       printk("cap_capable() VXF_STATE_SETUP = %llx, raised = %x, eff = %08x:%08x\n",
28632 +               vx_info_flags(vxi, VXF_STATE_SETUP, 0),
28633 +               cap_raised(tsk->cap_effective, cap),
28634 +               tsk->cap_effective.cap[1], tsk->cap_effective.cap[0]);
28635 +#endif
28636 +
28637 +       /* special case SETUP */
28638 +       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
28639 +               cap_raised(tsk->cap_effective, cap))
28640 +               return 0;
28641 +
28642         /* Derived from include/linux/sched.h:capable. */
28643 -       if (cap_raised(tsk->cap_effective, cap))
28644 +       if (vx_cap_raised(vxi, tsk->cap_effective, cap))
28645                 return 0;
28646 +
28647         return -EPERM;
28648  }
28649  
28650 @@ -583,7 +599,8 @@ void cap_task_reparent_to_init (struct t
28651  
28652  int cap_syslog (int type)
28653  {
28654 -       if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
28655 +       if ((type != 3 && type != 10) &&
28656 +               !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
28657                 return -EPERM;
28658         return 0;
28659  }
28660 diff -NurpP --minimal linux-2.6.25/security/dummy.c linux-2.6.25-vs2.3.0.34.9/security/dummy.c
28661 --- linux-2.6.25/security/dummy.c       2008-04-17 12:05:46.000000000 -0400
28662 +++ linux-2.6.25-vs2.3.0.34.9/security/dummy.c  2008-04-23 20:28:54.000000000 -0400
28663 @@ -27,6 +27,7 @@
28664  #include <linux/hugetlb.h>
28665  #include <linux/ptrace.h>
28666  #include <linux/file.h>
28667 +#include <linux/vs_context.h>
28668  
28669  static int dummy_ptrace (struct task_struct *parent, struct task_struct *child)
28670  {
28671 @@ -714,7 +715,7 @@ static int dummy_sem_semop (struct sem_a
28672  
28673  static int dummy_netlink_send (struct sock *sk, struct sk_buff *skb)
28674  {
28675 -       NETLINK_CB(skb).eff_cap = current->cap_effective;
28676 +       NETLINK_CB(skb).eff_cap = vx_mbcaps(current->cap_effective);
28677         return 0;
28678  }
28679  
28680 diff -NurpP --minimal linux-2.6.25/security/selinux/hooks.c linux-2.6.25-vs2.3.0.34.9/security/selinux/hooks.c
28681 --- linux-2.6.25/security/selinux/hooks.c       2008-04-17 12:05:46.000000000 -0400
28682 +++ linux-2.6.25-vs2.3.0.34.9/security/selinux/hooks.c  2008-04-19 15:14:52.000000000 -0400
28683 @@ -64,7 +64,6 @@
28684  #include <linux/dccp.h>
28685  #include <linux/quota.h>
28686  #include <linux/un.h>          /* for Unix socket types */
28687 -#include <net/af_unix.h>       /* for Unix socket types */
28688  #include <linux/parser.h>
28689  #include <linux/nfs_mount.h>
28690  #include <net/ipv6.h>
This page took 2.36889 seconds and 3 git commands to generate.