]> git.pld-linux.org Git - packages/kernel.git/blob - linux-2.6-vs2.2.patch
- mention apparmor in release
[packages/kernel.git] / linux-2.6-vs2.2.patch
1 diff -NurpP --minimal linux-2.6.24-rc7/Documentation/vserver/debug.txt linux-2.6.24-rc7-vs2.2.0.5.0.7/Documentation/vserver/debug.txt
2 --- linux-2.6.24-rc7/Documentation/vserver/debug.txt    1970-01-01 01:00:00 +0100
3 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/Documentation/vserver/debug.txt      2007-12-13 13:25:42 +0100
4 @@ -0,0 +1,154 @@
5 +
6 +debug_cvirt:
7 +
8 + 2   4 "vx_map_tgid: %p/%llx: %d -> %d"
9 +       "vx_rmap_tgid: %p/%llx: %d -> %d"
10 +
11 +debug_dlim:
12 +
13 + 0   1 "ALLOC (%p,#%d)%c inode (%d)"
14 +       "FREE  (%p,#%d)%c inode"
15 + 1   2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
16 +       "FREE  (%p,#%d)%c %lld bytes"
17 + 2   4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
18 + 3   8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
19 +       "ext3_has_free_blocks(%p): free=%lu, root=%lu"
20 +       "rcu_free_dl_info(%p)"
21 + 4  10 "alloc_dl_info(%p,%d) = %p"
22 +       "dealloc_dl_info(%p)"
23 +       "get_dl_info(%p[#%d.%d])"
24 +       "put_dl_info(%p[#%d.%d])"
25 + 5  20 "alloc_dl_info(%p,%d)*"
26 + 6  40 "__hash_dl_info: %p[#%d]"
27 +       "__unhash_dl_info: %p[#%d]"
28 + 7  80 "locate_dl_info(%p,#%d) = %p"
29 +
30 +debug_misc:
31 +
32 + 0   1 "destroy_dqhash: %p [#0x%08x] c=%d"
33 +       "new_dqhash: %p [#0x%08x]"
34 +       "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
35 +       "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
36 +       "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
37 +       "vroot_get_real_bdev not set"
38 + 1   2 "cow_break_link(»%s«)"
39 +       "temp copy »%s«"
40 + 2   4 "dentry_open(new): %p"
41 +       "dentry_open(old): %p"
42 +       "lookup_create(new): %p"
43 +       "old path »%s«"
44 +       "path_lookup(old): %d"
45 +       "vfs_create(new): %d"
46 +       "vfs_rename: %d"
47 +       "vfs_sendfile: %d"
48 + 3   8 "fput(new_file=%p[#%d])"
49 +       "fput(old_file=%p[#%d])"
50 + 4  10 "vx_info_kill(%p[#%d],%d,%d) = %d"
51 +       "vx_info_kill(%p[#%d],%d,%d)*"
52 + 5  20 "vs_reboot(%p[#%d],%d)"
53 + 6  40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
54 +
55 +debug_net:
56 +
57 + 2   4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
58 + 3   8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
59 +       "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
60 + 4  10 "ip_route_connect(%p) %p,%p;%lx"
61 + 5  20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
62 + 6  40 "sk,egf: %p [#%d] (from %d)"
63 +       "sk,egn: %p [#%d] (from %d)"
64 +       "sk,req: %p [#%d] (from %d)"
65 +       "sk: %p [#%d] (from %d)"
66 +       "tw: %p [#%d] (from %d)"
67 + 7  80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
68 +       "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
69 +
70 +debug_nid:
71 +
72 + 0   1 "__lookup_nx_info(#%u): %p[#%u]"
73 +       "alloc_nx_info(%d) = %p"
74 +       "create_nx_info(%d) (dynamic rejected)"
75 +       "create_nx_info(%d) = %p (already there)"
76 +       "create_nx_info(%d) = %p (new)"
77 +       "dealloc_nx_info(%p)"
78 + 1   2 "alloc_nx_info(%d)*"
79 +       "create_nx_info(%d)*"
80 + 2   4 "get_nx_info(%p[#%d.%d])"
81 +       "put_nx_info(%p[#%d.%d])"
82 + 3   8 "claim_nx_info(%p[#%d.%d.%d]) %p"
83 +       "clr_nx_info(%p[#%d.%d])"
84 +       "init_nx_info(%p[#%d.%d])"
85 +       "release_nx_info(%p[#%d.%d.%d]) %p"
86 +       "set_nx_info(%p[#%d.%d])"
87 + 4  10 "__hash_nx_info: %p[#%d]"
88 +       "__nx_dynamic_id: [#%d]"
89 +       "__unhash_nx_info: %p[#%d.%d.%d]"
90 + 5  20 "moved task %p into nxi:%p[#%d]"
91 +       "nx_migrate_task(%p,%p[#%d.%d.%d])"
92 +       "task_get_nx_info(%p)"
93 + 6  40 "nx_clear_persistent(%p[#%d])"
94 +
95 +debug_quota:
96 +
97 + 0   1 "quota_sync_dqh(%p,%d) discard inode %p"
98 + 1   2 "quota_sync_dqh(%p,%d)"
99 +       "sync_dquots(%p,%d)"
100 +       "sync_dquots_dqh(%p,%d)"
101 + 3   8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
102 +
103 +debug_switch:
104 +
105 + 0   1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
106 + 1   2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
107 + 4  10 "%s: (%s %s) returned %s with %d"
108 +
109 +debug_tag:
110 +
111 + 7  80 "dx_parse_tag(»%s«): %d:#%d"
112 +       "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
113 +
114 +debug_xid:
115 +
116 + 0   1 "__lookup_vx_info(#%u): %p[#%u]"
117 +       "alloc_vx_info(%d) = %p"
118 +       "alloc_vx_info(%d)*"
119 +       "create_vx_info(%d) (dynamic rejected)"
120 +       "create_vx_info(%d) = %p (already there)"
121 +       "create_vx_info(%d) = %p (new)"
122 +       "dealloc_vx_info(%p)"
123 +       "loc_vx_info(%d) = %p (found)"
124 +       "loc_vx_info(%d) = %p (new)"
125 +       "loc_vx_info(%d) = %p (not available)"
126 + 1   2 "create_vx_info(%d)*"
127 +       "loc_vx_info(%d)*"
128 + 2   4 "get_vx_info(%p[#%d.%d])"
129 +       "put_vx_info(%p[#%d.%d])"
130 + 3   8 "claim_vx_info(%p[#%d.%d.%d]) %p"
131 +       "clr_vx_info(%p[#%d.%d])"
132 +       "init_vx_info(%p[#%d.%d])"
133 +       "release_vx_info(%p[#%d.%d.%d]) %p"
134 +       "set_vx_info(%p[#%d.%d])"
135 + 4  10 "__hash_vx_info: %p[#%d]"
136 +       "__unhash_vx_info: %p[#%d.%d.%d]"
137 +       "__vx_dynamic_id: [#%d]"
138 + 5  20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
139 +       "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
140 +       "moved task %p into vxi:%p[#%d]"
141 +       "task_get_vx_info(%p)"
142 +       "vx_migrate_task(%p,%p[#%d.%d])"
143 + 6  40 "vx_clear_persistent(%p[#%d])"
144 +       "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
145 +       "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
146 +       "vx_set_persistent(%p[#%d])"
147 +       "vx_set_reaper(%p[#%d],%p[#%d,%d])"
148 + 7  80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
149 +
150 +
151 +debug_limit:
152 +
153 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
154 +       "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
155 +
156 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
157 +       "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
158 +       "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
159 diff -NurpP --minimal linux-2.6.24-rc7/arch/alpha/Kconfig linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/alpha/Kconfig
160 --- linux-2.6.24-rc7/arch/alpha/Kconfig 2007-11-29 01:09:49 +0100
161 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/alpha/Kconfig   2007-12-13 13:25:26 +0100
162 @@ -665,6 +665,8 @@ config DUMMY_CONSOLE
163         depends on VGA_HOSE
164         default y
165  
166 +source "kernel/vserver/Kconfig"
167 +
168  source "security/Kconfig"
169  
170  source "crypto/Kconfig"
171 diff -NurpP --minimal linux-2.6.24-rc7/arch/alpha/kernel/asm-offsets.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/alpha/kernel/asm-offsets.c
172 --- linux-2.6.24-rc7/arch/alpha/kernel/asm-offsets.c    2006-02-15 13:54:10 +0100
173 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/alpha/kernel/asm-offsets.c      2007-12-13 13:25:44 +0100
174 @@ -36,6 +36,7 @@ void foo(void)
175         DEFINE(PT_PTRACED, PT_PTRACED);
176         DEFINE(CLONE_VM, CLONE_VM);
177         DEFINE(CLONE_UNTRACED, CLONE_UNTRACED);
178 +       DEFINE(CLONE_KTHREAD, CLONE_KTHREAD);
179         DEFINE(SIGCHLD, SIGCHLD);
180         BLANK();
181  
182 diff -NurpP --minimal linux-2.6.24-rc7/arch/alpha/kernel/entry.S linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/alpha/kernel/entry.S
183 --- linux-2.6.24-rc7/arch/alpha/kernel/entry.S  2007-11-29 01:09:50 +0100
184 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/alpha/kernel/entry.S    2007-12-13 13:25:48 +0100
185 @@ -643,7 +643,7 @@ kernel_thread:
186         stq     $2, 152($sp)            /* HAE */
187  
188         /* Shuffle FLAGS to the front; add CLONE_VM.  */
189 -       ldi     $1, CLONE_VM|CLONE_UNTRACED
190 +       ldi     $1, CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD;
191         or      $18, $1, $16
192         bsr     $26, sys_clone
193  
194 @@ -872,24 +872,15 @@ sys_getxgid:
195         .globl  sys_getxpid
196         .ent    sys_getxpid
197  sys_getxpid:
198 +       lda     $sp, -16($sp)
199 +       stq     $26, 0($sp)
200         .prologue 0
201 -       ldq     $2, TI_TASK($8)
202  
203 -       /* See linux/kernel/timer.c sys_getppid for discussion
204 -          about this loop.  */
205 -       ldq     $3, TASK_GROUP_LEADER($2)
206 -       ldq     $4, TASK_REAL_PARENT($3)
207 -       ldl     $0, TASK_TGID($2)
208 -1:     ldl     $1, TASK_TGID($4)
209 -#ifdef CONFIG_SMP
210 -       mov     $4, $5
211 -       mb
212 -       ldq     $3, TASK_GROUP_LEADER($2)
213 -       ldq     $4, TASK_REAL_PARENT($3)
214 -       cmpeq   $4, $5, $5
215 -       beq     $5, 1b
216 -#endif
217 -       stq     $1, 80($sp)
218 +       lda     $16, 96($sp)
219 +       jsr     $26, do_getxpid
220 +       ldq     $26, 0($sp)
221 +
222 +       lda     $sp, 16($sp)
223         ret
224  .end sys_getxpid
225  
226 diff -NurpP --minimal linux-2.6.24-rc7/arch/alpha/kernel/osf_sys.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/alpha/kernel/osf_sys.c
227 --- linux-2.6.24-rc7/arch/alpha/kernel/osf_sys.c        2007-11-29 01:09:50 +0100
228 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/alpha/kernel/osf_sys.c  2007-12-13 13:25:31 +0100
229 @@ -883,7 +883,7 @@ osf_gettimeofday(struct timeval32 __user
230  {
231         if (tv) {
232                 struct timeval ktv;
233 -               do_gettimeofday(&ktv);
234 +               vx_gettimeofday(&ktv);
235                 if (put_tv32(tv, &ktv))
236                         return -EFAULT;
237         }
238 diff -NurpP --minimal linux-2.6.24-rc7/arch/alpha/kernel/ptrace.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/alpha/kernel/ptrace.c
239 --- linux-2.6.24-rc7/arch/alpha/kernel/ptrace.c 2007-11-29 01:09:50 +0100
240 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/alpha/kernel/ptrace.c   2007-12-13 13:25:11 +0100
241 @@ -15,6 +15,7 @@
242  #include <linux/slab.h>
243  #include <linux/security.h>
244  #include <linux/signal.h>
245 +#include <linux/vs_base.h>
246  
247  #include <asm/uaccess.h>
248  #include <asm/pgtable.h>
249 diff -NurpP --minimal linux-2.6.24-rc7/arch/alpha/kernel/semaphore.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/alpha/kernel/semaphore.c
250 --- linux-2.6.24-rc7/arch/alpha/kernel/semaphore.c      2007-11-29 01:09:50 +0100
251 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/alpha/kernel/semaphore.c        2007-12-13 13:25:29 +0100
252 @@ -68,8 +68,8 @@ __down_failed(struct semaphore *sem)
253         DECLARE_WAITQUEUE(wait, tsk);
254  
255  #ifdef CONFIG_DEBUG_SEMAPHORE
256 -       printk("%s(%d): down failed(%p)\n",
257 -              tsk->comm, task_pid_nr(tsk), sem);
258 +       printk("%s(%d:#%u): down failed(%p)\n",
259 +              tsk->comm, task_pid_nr(tsk), tsk->xid, sem);
260  #endif
261  
262         tsk->state = TASK_UNINTERRUPTIBLE;
263 @@ -97,8 +97,8 @@ __down_failed(struct semaphore *sem)
264         wake_up(&sem->wait);
265  
266  #ifdef CONFIG_DEBUG_SEMAPHORE
267 -       printk("%s(%d): down acquired(%p)\n",
268 -              tsk->comm, task_pid_nr(tsk), sem);
269 +       printk("%s(%d:#%u): down acquired(%p)\n",
270 +              tsk->comm, task_pid_nr(tsk), tsk->xid, sem);
271  #endif
272  }
273  
274 @@ -110,8 +110,8 @@ __down_failed_interruptible(struct semap
275         long ret = 0;
276  
277  #ifdef CONFIG_DEBUG_SEMAPHORE
278 -       printk("%s(%d): down failed(%p)\n",
279 -              tsk->comm, task_pid_nr(tsk), sem);
280 +       printk("%s(%d:#%u): down failed(%p)\n",
281 +              tsk->comm, task_pid_nr(tsk), tsk->xid, sem);
282  #endif
283  
284         tsk->state = TASK_INTERRUPTIBLE;
285 diff -NurpP --minimal linux-2.6.24-rc7/arch/alpha/kernel/systbls.S linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/alpha/kernel/systbls.S
286 --- linux-2.6.24-rc7/arch/alpha/kernel/systbls.S        2007-07-09 13:17:31 +0200
287 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/alpha/kernel/systbls.S  2007-12-13 13:25:27 +0100
288 @@ -446,7 +446,7 @@ sys_call_table:
289         .quad sys_stat64                        /* 425 */
290         .quad sys_lstat64
291         .quad sys_fstat64
292 -       .quad sys_ni_syscall                    /* sys_vserver */
293 +       .quad sys_vserver                       /* sys_vserver */
294         .quad sys_ni_syscall                    /* sys_mbind */
295         .quad sys_ni_syscall                    /* sys_get_mempolicy */
296         .quad sys_ni_syscall                    /* sys_set_mempolicy */
297 diff -NurpP --minimal linux-2.6.24-rc7/arch/alpha/kernel/traps.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/alpha/kernel/traps.c
298 --- linux-2.6.24-rc7/arch/alpha/kernel/traps.c  2007-11-29 01:09:50 +0100
299 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/alpha/kernel/traps.c    2007-12-13 13:25:29 +0100
300 @@ -182,7 +182,8 @@ die_if_kernel(char * str, struct pt_regs
301  #ifdef CONFIG_SMP
302         printk("CPU %d ", hard_smp_processor_id());
303  #endif
304 -       printk("%s(%d): %s %ld\n", current->comm, task_pid_nr(current), str, err);
305 +       printk("%s(%d[#%u]): %s %ld\n", current->comm,
306 +               task_pid_nr(current), current->xid, str, err);
307         dik_show_regs(regs, r9_15);
308         add_taint(TAINT_DIE);
309         dik_show_trace((unsigned long *)(regs+1));
310 diff -NurpP --minimal linux-2.6.24-rc7/arch/alpha/mm/fault.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/alpha/mm/fault.c
311 --- linux-2.6.24-rc7/arch/alpha/mm/fault.c      2007-11-29 01:09:50 +0100
312 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/alpha/mm/fault.c        2007-12-13 13:25:29 +0100
313 @@ -193,8 +193,8 @@ do_page_fault(unsigned long address, uns
314                 down_read(&mm->mmap_sem);
315                 goto survive;
316         }
317 -       printk(KERN_ALERT "VM: killing process %s(%d)\n",
318 -              current->comm, task_pid_nr(current));
319 +       printk(KERN_ALERT "VM: killing process %s(%d:#%u)\n",
320 +              current->comm, task_pid_nr(current), current->xid);
321         if (!user_mode(regs))
322                 goto no_context;
323         do_group_exit(SIGKILL);
324 diff -NurpP --minimal linux-2.6.24-rc7/arch/arm/Kconfig linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/arm/Kconfig
325 --- linux-2.6.24-rc7/arch/arm/Kconfig   2007-12-31 17:58:08 +0100
326 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/arm/Kconfig     2007-12-31 12:34:02 +0100
327 @@ -1080,6 +1080,8 @@ source "kernel/Kconfig.instrumentation"
328  
329  source "arch/arm/Kconfig.debug"
330  
331 +source "kernel/vserver/Kconfig"
332 +
333  source "security/Kconfig"
334  
335  source "crypto/Kconfig"
336 diff -NurpP --minimal linux-2.6.24-rc7/arch/arm/kernel/calls.S linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/arm/kernel/calls.S
337 --- linux-2.6.24-rc7/arch/arm/kernel/calls.S    2007-11-29 01:09:50 +0100
338 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/arm/kernel/calls.S      2007-12-13 13:25:28 +0100
339 @@ -322,7 +322,7 @@
340  /* 310 */      CALL(sys_request_key)
341                 CALL(sys_keyctl)
342                 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
343 -/* vserver */  CALL(sys_ni_syscall)
344 +               CALL(sys_vserver)
345                 CALL(sys_ioprio_set)
346  /* 315 */      CALL(sys_ioprio_get)
347                 CALL(sys_inotify_init)
348 diff -NurpP --minimal linux-2.6.24-rc7/arch/arm/kernel/process.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/arm/kernel/process.c
349 --- linux-2.6.24-rc7/arch/arm/kernel/process.c  2007-11-29 01:09:50 +0100
350 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/arm/kernel/process.c    2007-12-13 13:25:44 +0100
351 @@ -265,7 +265,8 @@ void __show_regs(struct pt_regs *regs)
352  void show_regs(struct pt_regs * regs)
353  {
354         printk("\n");
355 -       printk("Pid: %d, comm: %20s\n", task_pid_nr(current), current->comm);
356 +       printk("Pid: %d[#%u], comm: %20s\n",
357 +               task_pid_nr(current), current->xid, current->comm);
358         __show_regs(regs);
359         __backtrace();
360  }
361 @@ -427,7 +428,8 @@ pid_t kernel_thread(int (*fn)(void *), v
362         regs.ARM_pc = (unsigned long)kernel_thread_helper;
363         regs.ARM_cpsr = SVC_MODE;
364  
365 -       return do_fork(flags|CLONE_VM|CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
366 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
367 +               0, &regs, 0, NULL, NULL);
368  }
369  EXPORT_SYMBOL(kernel_thread);
370  
371 diff -NurpP --minimal linux-2.6.24-rc7/arch/arm/kernel/traps.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/arm/kernel/traps.c
372 --- linux-2.6.24-rc7/arch/arm/kernel/traps.c    2007-12-31 17:58:08 +0100
373 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/arm/kernel/traps.c      2007-12-31 12:34:02 +0100
374 @@ -222,8 +222,8 @@ static void __die(const char *str, int e
375                str, err, ++die_counter);
376         print_modules();
377         __show_regs(regs);
378 -       printk("Process %s (pid: %d, stack limit = 0x%p)\n",
379 -               tsk->comm, task_pid_nr(tsk), thread + 1);
380 +       printk("Process %s (pid: %d:#%u, stack limit = 0x%p)\n",
381 +               tsk->comm, task_pid_nr(tsk), tsk->xid, thread + 1);
382  
383         if (!user_mode(regs) || in_interrupt()) {
384                 dump_mem("Stack: ", regs->ARM_sp,
385 diff -NurpP --minimal linux-2.6.24-rc7/arch/arm/mm/fault.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/arm/mm/fault.c
386 --- linux-2.6.24-rc7/arch/arm/mm/fault.c        2007-11-29 01:09:52 +0100
387 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/arm/mm/fault.c  2007-12-13 13:25:29 +0100
388 @@ -265,7 +265,8 @@ do_page_fault(unsigned long addr, unsign
389                  * happened to us that made us unable to handle
390                  * the page fault gracefully.
391                  */
392 -               printk("VM: killing process %s\n", tsk->comm);
393 +               printk("VM: killing process %s(%d:#%u)\n",
394 +                       tsk->comm, task_pid_nr(tsk), tsk->xid);
395                 do_group_exit(SIGKILL);
396                 return 0;
397         }
398 diff -NurpP --minimal linux-2.6.24-rc7/arch/cris/Kconfig linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/cris/Kconfig
399 --- linux-2.6.24-rc7/arch/cris/Kconfig  2007-11-29 01:09:56 +0100
400 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/cris/Kconfig    2007-12-13 13:25:26 +0100
401 @@ -217,6 +217,8 @@ source "kernel/Kconfig.instrumentation"
402  
403  source "arch/cris/Kconfig.debug"
404  
405 +source "kernel/vserver/Kconfig"
406 +
407  source "security/Kconfig"
408  
409  source "crypto/Kconfig"
410 diff -NurpP --minimal linux-2.6.24-rc7/arch/cris/arch-v10/kernel/process.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/cris/arch-v10/kernel/process.c
411 --- linux-2.6.24-rc7/arch/cris/arch-v10/kernel/process.c        2007-11-29 01:09:57 +0100
412 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/cris/arch-v10/kernel/process.c  2007-12-13 13:25:44 +0100
413 @@ -103,7 +103,8 @@ int kernel_thread(int (*fn)(void *), voi
414         regs.dccr = 1 << I_DCCR_BITNR;
415  
416         /* Ok, create the new process.. */
417 -        return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
418 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
419 +               0, &regs, 0, NULL, NULL);
420  }
421  
422  /* setup the child's kernel stack with a pt_regs and switch_stack on it.
423 diff -NurpP --minimal linux-2.6.24-rc7/arch/cris/arch-v32/kernel/process.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/cris/arch-v32/kernel/process.c
424 --- linux-2.6.24-rc7/arch/cris/arch-v32/kernel/process.c        2007-11-29 01:09:57 +0100
425 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/cris/arch-v32/kernel/process.c  2007-12-13 13:25:44 +0100
426 @@ -120,7 +120,8 @@ kernel_thread(int (*fn)(void *), void * 
427         regs.ccs = 1 << (I_CCS_BITNR + CCS_SHIFT);
428  
429         /* Create the new process. */
430 -        return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
431 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
432 +               0, &regs, 0, NULL, NULL);
433  }
434  
435  /*
436 diff -NurpP --minimal linux-2.6.24-rc7/arch/frv/kernel/kernel_thread.S linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/frv/kernel/kernel_thread.S
437 --- linux-2.6.24-rc7/arch/frv/kernel/kernel_thread.S    2005-03-02 12:38:20 +0100
438 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/frv/kernel/kernel_thread.S      2007-12-13 13:25:44 +0100
439 @@ -13,6 +13,8 @@
440  #include <asm/unistd.h>
441  
442  #define CLONE_VM       0x00000100      /* set if VM shared between processes */
443 +#define CLONE_KTHREAD  0x10000000      /* kernel thread */
444 +#define CLONE_KT       (CLONE_VM | CLONE_KTHREAD)      /* kernel thread flags */
445  #define        KERN_ERR        "<3>"
446  
447         .section .rodata
448 @@ -37,7 +39,7 @@ kernel_thread:
449  
450         # start by forking the current process, but with shared VM
451         setlos.p        #__NR_clone,gr7         ; syscall number
452 -       ori             gr10,#CLONE_VM,gr8      ; first syscall arg     [clone_flags]
453 +       ori             gr10,#CLONE_KT,gr8      ; first syscall arg     [clone_flags]
454         sethi.p         #0xe4e4,gr9             ; second syscall arg    [newsp]
455         setlo           #0xe4e4,gr9
456         setlos.p        #0,gr10                 ; third syscall arg     [parent_tidptr]
457 diff -NurpP --minimal linux-2.6.24-rc7/arch/h8300/Kconfig linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/h8300/Kconfig
458 --- linux-2.6.24-rc7/arch/h8300/Kconfig 2007-11-29 01:09:58 +0100
459 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/h8300/Kconfig   2007-12-13 13:25:26 +0100
460 @@ -227,6 +227,8 @@ source "kernel/Kconfig.instrumentation"
461  
462  source "arch/h8300/Kconfig.debug"
463  
464 +source "kernel/vserver/Kconfig"
465 +
466  source "security/Kconfig"
467  
468  source "crypto/Kconfig"
469 diff -NurpP --minimal linux-2.6.24-rc7/arch/h8300/kernel/process.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/h8300/kernel/process.c
470 --- linux-2.6.24-rc7/arch/h8300/kernel/process.c        2007-11-29 01:00:10 +0100
471 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/h8300/kernel/process.c  2007-12-13 13:25:44 +0100
472 @@ -135,7 +135,7 @@ int kernel_thread(int (*fn)(void *), voi
473  
474         fs = get_fs();
475         set_fs (KERNEL_DS);
476 -       clone_arg = flags | CLONE_VM;
477 +       clone_arg = flags | CLONE_VM | CLONE_KTHREAD;
478         __asm__("mov.l sp,er3\n\t"
479                 "sub.l er2,er2\n\t"
480                 "mov.l %2,er1\n\t"
481 diff -NurpP --minimal linux-2.6.24-rc7/arch/ia64/Kconfig linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ia64/Kconfig
482 --- linux-2.6.24-rc7/arch/ia64/Kconfig  2007-11-29 01:10:02 +0100
483 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ia64/Kconfig    2007-12-13 13:25:26 +0100
484 @@ -596,6 +596,8 @@ source "kernel/Kconfig.instrumentation"
485  
486  source "arch/ia64/Kconfig.debug"
487  
488 +source "kernel/vserver/Kconfig"
489 +
490  source "security/Kconfig"
491  
492  source "crypto/Kconfig"
493 diff -NurpP --minimal linux-2.6.24-rc7/arch/ia64/ia32/ia32_entry.S linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ia64/ia32/ia32_entry.S
494 --- linux-2.6.24-rc7/arch/ia64/ia32/ia32_entry.S        2007-11-29 01:00:17 +0100
495 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ia64/ia32/ia32_entry.S  2007-12-13 13:25:28 +0100
496 @@ -446,7 +446,7 @@ ia32_syscall_table:
497         data8 sys_tgkill        /* 270 */
498         data8 compat_sys_utimes
499         data8 sys32_fadvise64_64
500 -       data8 sys_ni_syscall
501 +       data8 sys32_vserver
502         data8 sys_ni_syscall
503         data8 sys_ni_syscall    /* 275 */
504         data8 sys_ni_syscall
505 diff -NurpP --minimal linux-2.6.24-rc7/arch/ia64/ia32/sys_ia32.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ia64/ia32/sys_ia32.c
506 --- linux-2.6.24-rc7/arch/ia64/ia32/sys_ia32.c  2007-11-29 01:10:03 +0100
507 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ia64/ia32/sys_ia32.c    2007-12-13 13:25:31 +0100
508 @@ -1182,7 +1182,7 @@ sys32_gettimeofday (struct compat_timeva
509  {
510         if (tv) {
511                 struct timeval ktv;
512 -               do_gettimeofday(&ktv);
513 +               vx_gettimeofday(&ktv);
514                 if (put_tv32(tv, &ktv))
515                         return -EFAULT;
516         }
517 diff -NurpP --minimal linux-2.6.24-rc7/arch/ia64/kernel/asm-offsets.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ia64/kernel/asm-offsets.c
518 --- linux-2.6.24-rc7/arch/ia64/kernel/asm-offsets.c     2007-11-29 01:00:17 +0100
519 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ia64/kernel/asm-offsets.c       2007-12-13 13:25:44 +0100
520 @@ -194,6 +194,7 @@ void foo(void)
521      /* for assembly files which can't include sched.h: */
522         DEFINE(IA64_CLONE_VFORK, CLONE_VFORK);
523         DEFINE(IA64_CLONE_VM, CLONE_VM);
524 +       DEFINE(IA64_CLONE_KTHREAD, CLONE_KTHREAD);
525  
526         BLANK();
527         DEFINE(IA64_CPUINFO_NSEC_PER_CYC_OFFSET,
528 diff -NurpP --minimal linux-2.6.24-rc7/arch/ia64/kernel/entry.S linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ia64/kernel/entry.S
529 --- linux-2.6.24-rc7/arch/ia64/kernel/entry.S   2007-11-29 01:00:17 +0100
530 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ia64/kernel/entry.S     2007-12-13 13:25:28 +0100
531 @@ -1547,7 +1547,7 @@ sys_call_table:
532         data8 sys_mq_notify
533         data8 sys_mq_getsetattr
534         data8 sys_kexec_load
535 -       data8 sys_ni_syscall                    // reserved for vserver
536 +       data8 sys_vserver
537         data8 sys_waitid                        // 1270
538         data8 sys_add_key
539         data8 sys_request_key
540 diff -NurpP --minimal linux-2.6.24-rc7/arch/ia64/kernel/perfmon.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ia64/kernel/perfmon.c
541 --- linux-2.6.24-rc7/arch/ia64/kernel/perfmon.c 2007-11-29 01:10:03 +0100
542 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ia64/kernel/perfmon.c   2007-12-13 13:25:41 +0100
543 @@ -40,6 +40,7 @@
544  #include <linux/capability.h>
545  #include <linux/rcupdate.h>
546  #include <linux/completion.h>
547 +#include <linux/vs_memory.h>
548  
549  #include <asm/errno.h>
550  #include <asm/intrinsics.h>
551 @@ -2389,7 +2390,7 @@ pfm_smpl_buffer_alloc(struct task_struct
552          */
553         insert_vm_struct(mm, vma);
554  
555 -       mm->total_vm  += size >> PAGE_SHIFT;
556 +       vx_vmpages_add(mm, size >> PAGE_SHIFT);
557         vm_stat_account(vma->vm_mm, vma->vm_flags, vma->vm_file,
558                                                         vma_pages(vma));
559         up_write(&task->mm->mmap_sem);
560 diff -NurpP --minimal linux-2.6.24-rc7/arch/ia64/kernel/process.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ia64/kernel/process.c
561 --- linux-2.6.24-rc7/arch/ia64/kernel/process.c 2007-12-31 17:58:10 +0100
562 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ia64/kernel/process.c   2007-12-31 12:36:36 +0100
563 @@ -106,8 +106,8 @@ show_regs (struct pt_regs *regs)
564         unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
565  
566         print_modules();
567 -       printk("\nPid: %d, CPU %d, comm: %20s\n", task_pid_nr(current),
568 -                       smp_processor_id(), current->comm);
569 +       printk("\nPid: %d[#%u], CPU %d, comm: %20s\n", task_pid_nr(current),
570 +                       current->xid, smp_processor_id(), current->comm);
571         printk("psr : %016lx ifs : %016lx ip  : [<%016lx>]    %s (%s)\n",
572                regs->cr_ipsr, regs->cr_ifs, ip, print_tainted(),
573                init_utsname()->release);
574 @@ -705,7 +705,8 @@ kernel_thread (int (*fn)(void *), void *
575         regs.sw.ar_fpsr = regs.pt.ar_fpsr = ia64_getreg(_IA64_REG_AR_FPSR);
576         regs.sw.ar_bspstore = (unsigned long) current + IA64_RBS_OFFSET;
577         regs.sw.pr = (1 << PRED_KERNEL_STACK);
578 -       return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs.pt, 0, NULL, NULL);
579 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
580 +               0, &regs.pt, 0, NULL, NULL);
581  }
582  EXPORT_SYMBOL(kernel_thread);
583  
584 diff -NurpP --minimal linux-2.6.24-rc7/arch/ia64/kernel/ptrace.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ia64/kernel/ptrace.c
585 --- linux-2.6.24-rc7/arch/ia64/kernel/ptrace.c  2007-11-29 01:00:17 +0100
586 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ia64/kernel/ptrace.c    2007-12-13 13:25:28 +0100
587 @@ -17,6 +17,7 @@
588  #include <linux/security.h>
589  #include <linux/audit.h>
590  #include <linux/signal.h>
591 +#include <linux/vs_base.h>
592  
593  #include <asm/pgtable.h>
594  #include <asm/processor.h>
595 @@ -1447,6 +1448,9 @@ sys_ptrace (long request, pid_t pid, uns
596         read_unlock(&tasklist_lock);
597         if (!child)
598                 goto out;
599 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
600 +               goto out_tsk;
601 +
602         ret = -EPERM;
603         if (pid == 1)           /* no messing around with init! */
604                 goto out_tsk;
605 diff -NurpP --minimal linux-2.6.24-rc7/arch/ia64/kernel/traps.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ia64/kernel/traps.c
606 --- linux-2.6.24-rc7/arch/ia64/kernel/traps.c   2007-11-29 01:10:03 +0100
607 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ia64/kernel/traps.c     2007-12-13 13:25:29 +0100
608 @@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
609         put_cpu();
610  
611         if (++die.lock_owner_depth < 3) {
612 -               printk("%s[%d]: %s %ld [%d]\n",
613 -               current->comm, task_pid_nr(current), str, err, ++die_counter);
614 +               printk("%s[%d[#%u]]: %s %ld [%d]\n",
615 +                       current->comm, task_pid_nr(current), current->xid,
616 +                       str, err, ++die_counter);
617                 (void) notify_die(DIE_OOPS, (char *)str, regs, err, 255, SIGSEGV);
618                 show_regs(regs);
619         } else
620 @@ -314,8 +315,9 @@ handle_fpu_swa (int fp_fault, struct pt_
621                         if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
622                                 last.time = current_jiffies + 5 * HZ;
623                                 printk(KERN_WARNING
624 -                                       "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
625 -                                       current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
626 +                                       "%s(%d[#%u]): floating-point assist fault at ip %016lx, isr %016lx\n",
627 +                                       current->comm, task_pid_nr(current), current->xid,
628 +                                       regs->cr_iip + ia64_psr(regs)->ri, isr);
629                         }
630                 }
631         }
632 diff -NurpP --minimal linux-2.6.24-rc7/arch/ia64/mm/fault.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ia64/mm/fault.c
633 --- linux-2.6.24-rc7/arch/ia64/mm/fault.c       2007-11-29 01:10:03 +0100
634 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ia64/mm/fault.c 2007-12-13 13:25:11 +0100
635 @@ -10,6 +10,7 @@
636  #include <linux/interrupt.h>
637  #include <linux/kprobes.h>
638  #include <linux/kdebug.h>
639 +#include <linux/vs_memory.h>
640  
641  #include <asm/pgtable.h>
642  #include <asm/processor.h>
643 diff -NurpP --minimal linux-2.6.24-rc7/arch/m32r/kernel/process.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/m32r/kernel/process.c
644 --- linux-2.6.24-rc7/arch/m32r/kernel/process.c 2007-05-02 19:24:21 +0200
645 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/m32r/kernel/process.c   2007-12-13 13:25:44 +0100
646 @@ -211,8 +211,8 @@ int kernel_thread(int (*fn)(void *), voi
647         regs.psw = M32R_PSW_BIE;
648  
649         /* Ok, create the new process. */
650 -       return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL,
651 -               NULL);
652 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
653 +               0, &regs, 0, NULL, NULL);
654  }
655  
656  /*
657 diff -NurpP --minimal linux-2.6.24-rc7/arch/m32r/kernel/traps.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/m32r/kernel/traps.c
658 --- linux-2.6.24-rc7/arch/m32r/kernel/traps.c   2007-11-29 01:10:04 +0100
659 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/m32r/kernel/traps.c     2007-12-13 13:25:29 +0100
660 @@ -195,8 +195,9 @@ static void show_registers(struct pt_reg
661         } else {
662                 printk("SPI: %08lx\n", sp);
663         }
664 -       printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
665 -               current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
666 +       printk("Process %s (pid: %d[#%u], process nr: %d, stackpage=%08lx)",
667 +               current->comm, task_pid_nr(current), current->xid,
668 +               0xffff & i, 4096+(unsigned long)current);
669  
670         /*
671          * When in-kernel, we also print out the stack and code at the
672 diff -NurpP --minimal linux-2.6.24-rc7/arch/m68k/Kconfig linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/m68k/Kconfig
673 --- linux-2.6.24-rc7/arch/m68k/Kconfig  2007-11-29 01:10:04 +0100
674 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/m68k/Kconfig    2007-12-13 13:25:26 +0100
675 @@ -687,6 +687,8 @@ source "kernel/Kconfig.instrumentation"
676  
677  source "arch/m68k/Kconfig.debug"
678  
679 +source "kernel/vserver/Kconfig"
680 +
681  source "security/Kconfig"
682  
683  source "crypto/Kconfig"
684 diff -NurpP --minimal linux-2.6.24-rc7/arch/m68k/kernel/process.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/m68k/kernel/process.c
685 --- linux-2.6.24-rc7/arch/m68k/kernel/process.c 2007-11-29 01:00:20 +0100
686 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/m68k/kernel/process.c   2007-12-13 13:25:44 +0100
687 @@ -160,7 +160,8 @@ int kernel_thread(int (*fn)(void *), voi
688  
689         {
690         register long retval __asm__ ("d0");
691 -       register long clone_arg __asm__ ("d1") = flags | CLONE_VM | CLONE_UNTRACED;
692 +       register long clone_arg __asm__ ("d1") =
693 +               flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD;
694  
695         retval = __NR_clone;
696         __asm__ __volatile__
697 diff -NurpP --minimal linux-2.6.24-rc7/arch/m68k/kernel/ptrace.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/m68k/kernel/ptrace.c
698 --- linux-2.6.24-rc7/arch/m68k/kernel/ptrace.c  2007-11-29 01:10:05 +0100
699 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/m68k/kernel/ptrace.c    2007-12-13 13:25:28 +0100
700 @@ -18,6 +18,7 @@
701  #include <linux/ptrace.h>
702  #include <linux/user.h>
703  #include <linux/signal.h>
704 +#include <linux/vs_base.h>
705  
706  #include <asm/uaccess.h>
707  #include <asm/page.h>
708 @@ -269,6 +270,8 @@ long arch_ptrace(struct task_struct *chi
709                 ret = ptrace_request(child, request, addr, data);
710                 break;
711         }
712 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
713 +               goto out_tsk;
714  
715         return ret;
716  out_eio:
717 diff -NurpP --minimal linux-2.6.24-rc7/arch/m68k/kernel/traps.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/m68k/kernel/traps.c
718 --- linux-2.6.24-rc7/arch/m68k/kernel/traps.c   2007-11-29 01:10:05 +0100
719 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/m68k/kernel/traps.c     2007-12-13 13:25:29 +0100
720 @@ -899,8 +899,8 @@ void show_registers(struct pt_regs *regs
721         printk("d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
722                regs->d4, regs->d5, regs->a0, regs->a1);
723  
724 -       printk("Process %s (pid: %d, task=%p)\n",
725 -               current->comm, task_pid_nr(current), current);
726 +       printk("Process %s (pid: %d[#%u], task=%p)\n",
727 +               current->comm, task_pid_nr(current), current->xid, current);
728         addr = (unsigned long)&fp->un;
729         printk("Frame format=%X ", regs->format);
730         switch (regs->format) {
731 diff -NurpP --minimal linux-2.6.24-rc7/arch/m68knommu/Kconfig linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/m68knommu/Kconfig
732 --- linux-2.6.24-rc7/arch/m68knommu/Kconfig     2007-11-29 01:10:05 +0100
733 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/m68knommu/Kconfig       2007-12-13 13:25:26 +0100
734 @@ -711,6 +711,8 @@ source "kernel/Kconfig.instrumentation"
735  
736  source "arch/m68knommu/Kconfig.debug"
737  
738 +source "kernel/vserver/Kconfig"
739 +
740  source "security/Kconfig"
741  
742  source "crypto/Kconfig"
743 diff -NurpP --minimal linux-2.6.24-rc7/arch/m68knommu/kernel/process.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/m68knommu/kernel/process.c
744 --- linux-2.6.24-rc7/arch/m68knommu/kernel/process.c    2007-11-29 01:00:20 +0100
745 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/m68knommu/kernel/process.c      2007-12-13 13:25:44 +0100
746 @@ -123,7 +123,7 @@ void show_regs(struct pt_regs * regs)
747  int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
748  {
749         int retval;
750 -       long clone_arg = flags | CLONE_VM;
751 +       long clone_arg = flags | CLONE_VM | CLONE_KTHREAD;
752         mm_segment_t fs;
753  
754         fs = get_fs();
755 diff -NurpP --minimal linux-2.6.24-rc7/arch/m68knommu/kernel/traps.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/m68knommu/kernel/traps.c
756 --- linux-2.6.24-rc7/arch/m68knommu/kernel/traps.c      2007-11-29 01:00:20 +0100
757 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/m68knommu/kernel/traps.c        2007-12-13 13:25:29 +0100
758 @@ -78,8 +78,9 @@ void die_if_kernel(char *str, struct pt_
759         printk(KERN_EMERG "d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
760                fp->d4, fp->d5, fp->a0, fp->a1);
761  
762 -       printk(KERN_EMERG "Process %s (pid: %d, stackpage=%08lx)\n",
763 -               current->comm, current->pid, PAGE_SIZE+(unsigned long)current);
764 +       printk(KERN_EMERG "Process %s (pid: %d[#%u], stackpage=%08lx)\n",
765 +               current->comm, task_pid_nr(current), current->xid,
766 +               PAGE_SIZE+(unsigned long)current);
767         show_stack(NULL, (unsigned long *)(fp + 1));
768         add_taint(TAINT_DIE);
769         do_exit(SIGSEGV);
770 diff -NurpP --minimal linux-2.6.24-rc7/arch/mips/Kconfig linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/mips/Kconfig
771 --- linux-2.6.24-rc7/arch/mips/Kconfig  2007-12-31 17:58:10 +0100
772 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/mips/Kconfig    2007-12-31 12:34:06 +0100
773 @@ -2060,6 +2060,8 @@ source "kernel/Kconfig.instrumentation"
774  
775  source "arch/mips/Kconfig.debug"
776  
777 +source "kernel/vserver/Kconfig"
778 +
779  source "security/Kconfig"
780  
781  source "crypto/Kconfig"
782 diff -NurpP --minimal linux-2.6.24-rc7/arch/mips/kernel/linux32.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/mips/kernel/linux32.c
783 --- linux-2.6.24-rc7/arch/mips/kernel/linux32.c 2007-11-29 01:10:07 +0100
784 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/mips/kernel/linux32.c   2007-12-13 13:25:35 +0100
785 @@ -229,7 +229,7 @@ sys32_gettimeofday(struct compat_timeval
786  {
787         if (tv) {
788                 struct timeval ktv;
789 -               do_gettimeofday(&ktv);
790 +               vx_gettimeofday(&ktv);
791                 if (put_tv32(tv, &ktv))
792                         return -EFAULT;
793         }
794 diff -NurpP --minimal linux-2.6.24-rc7/arch/mips/kernel/process.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/mips/kernel/process.c
795 --- linux-2.6.24-rc7/arch/mips/kernel/process.c 2007-12-31 17:58:10 +0100
796 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/mips/kernel/process.c   2007-12-31 12:34:06 +0100
797 @@ -240,7 +240,8 @@ long kernel_thread(int (*fn)(void *), vo
798  #endif
799  
800         /* Ok, create the new process.. */
801 -       return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
802 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
803 +               0, &regs, 0, NULL, NULL);
804  }
805  
806  /*
807 diff -NurpP --minimal linux-2.6.24-rc7/arch/mips/kernel/ptrace.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/mips/kernel/ptrace.c
808 --- linux-2.6.24-rc7/arch/mips/kernel/ptrace.c  2007-11-29 01:10:07 +0100
809 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/mips/kernel/ptrace.c    2007-12-13 13:25:28 +0100
810 @@ -25,6 +25,7 @@
811  #include <linux/security.h>
812  #include <linux/audit.h>
813  #include <linux/seccomp.h>
814 +#include <linux/vs_base.h>
815  
816  #include <asm/byteorder.h>
817  #include <asm/cpu.h>
818 @@ -171,6 +172,9 @@ long arch_ptrace(struct task_struct *chi
819  {
820         int ret;
821  
822 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
823 +               goto out;
824 +
825         switch (request) {
826         /* when I and D space are separate, these will need to be fixed. */
827         case PTRACE_PEEKTEXT: /* read word at location addr. */
828 diff -NurpP --minimal linux-2.6.24-rc7/arch/mips/kernel/scall32-o32.S linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/mips/kernel/scall32-o32.S
829 --- linux-2.6.24-rc7/arch/mips/kernel/scall32-o32.S     2007-11-29 01:00:23 +0100
830 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/mips/kernel/scall32-o32.S       2007-12-13 13:25:28 +0100
831 @@ -619,7 +619,7 @@ einval:     li      v0, -EINVAL
832         sys     sys_mq_timedreceive     5
833         sys     sys_mq_notify           2       /* 4275 */
834         sys     sys_mq_getsetattr       3
835 -       sys     sys_ni_syscall          0       /* sys_vserver */
836 +       sys     sys_vserver             3
837         sys     sys_waitid              5
838         sys     sys_ni_syscall          0       /* available, was setaltroot */
839         sys     sys_add_key             5       /* 4280 */
840 diff -NurpP --minimal linux-2.6.24-rc7/arch/mips/kernel/scall64-64.S linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/mips/kernel/scall64-64.S
841 --- linux-2.6.24-rc7/arch/mips/kernel/scall64-64.S      2007-11-29 01:00:23 +0100
842 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/mips/kernel/scall64-64.S        2007-12-13 13:25:28 +0100
843 @@ -434,7 +434,7 @@ sys_call_table:
844         PTR     sys_mq_timedreceive
845         PTR     sys_mq_notify
846         PTR     sys_mq_getsetattr               /* 5235 */
847 -       PTR     sys_ni_syscall                  /* sys_vserver */
848 +       PTR     sys_vserver
849         PTR     sys_waitid
850         PTR     sys_ni_syscall                  /* available, was setaltroot */
851         PTR     sys_add_key
852 diff -NurpP --minimal linux-2.6.24-rc7/arch/mips/kernel/scall64-n32.S linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/mips/kernel/scall64-n32.S
853 --- linux-2.6.24-rc7/arch/mips/kernel/scall64-n32.S     2007-11-29 01:10:07 +0100
854 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/mips/kernel/scall64-n32.S       2007-12-13 13:25:28 +0100
855 @@ -360,7 +360,7 @@ EXPORT(sysn32_call_table)
856         PTR     compat_sys_mq_timedreceive
857         PTR     compat_sys_mq_notify
858         PTR     compat_sys_mq_getsetattr
859 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
860 +       PTR     sys32_vserver                   /* 6240 */
861         PTR     compat_sys_waitid
862         PTR     sys_ni_syscall                  /* available, was setaltroot */
863         PTR     sys_add_key
864 diff -NurpP --minimal linux-2.6.24-rc7/arch/mips/kernel/scall64-o32.S linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/mips/kernel/scall64-o32.S
865 --- linux-2.6.24-rc7/arch/mips/kernel/scall64-o32.S     2007-11-29 01:00:23 +0100
866 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/mips/kernel/scall64-o32.S       2007-12-13 13:25:28 +0100
867 @@ -482,7 +482,7 @@ sys_call_table:
868         PTR     compat_sys_mq_timedreceive
869         PTR     compat_sys_mq_notify            /* 4275 */
870         PTR     compat_sys_mq_getsetattr
871 -       PTR     sys_ni_syscall                  /* sys_vserver */
872 +       PTR     sys32_vserver
873         PTR     sys32_waitid
874         PTR     sys_ni_syscall                  /* available, was setaltroot */
875         PTR     sys_add_key                     /* 4280 */
876 diff -NurpP --minimal linux-2.6.24-rc7/arch/mips/kernel/traps.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/mips/kernel/traps.c
877 --- linux-2.6.24-rc7/arch/mips/kernel/traps.c   2007-12-31 17:58:10 +0100
878 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/mips/kernel/traps.c     2007-12-31 12:34:06 +0100
879 @@ -313,8 +313,9 @@ void show_registers(const struct pt_regs
880  {
881         __show_regs(regs);
882         print_modules();
883 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p)\n",
884 -               current->comm, task_pid_nr(current), current_thread_info(), current);
885 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p)\n",
886 +               current->comm, task_pid_nr(current), current->xid,
887 +               current_thread_info(), current);
888         show_stacktrace(current, regs);
889         show_code((unsigned int __user *) regs->cp0_epc);
890         printk("\n");
891 diff -NurpP --minimal linux-2.6.24-rc7/arch/mips/mm/fault.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/mips/mm/fault.c
892 --- linux-2.6.24-rc7/arch/mips/mm/fault.c       2007-11-29 01:10:14 +0100
893 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/mips/mm/fault.c 2007-12-13 13:25:29 +0100
894 @@ -178,7 +178,8 @@ out_of_memory:
895                 down_read(&mm->mmap_sem);
896                 goto survive;
897         }
898 -       printk("VM: killing process %s\n", tsk->comm);
899 +       printk("VM: killing process %s(%d:#%u)\n",
900 +               tsk->comm, tsk->pid, tsk->xid);
901         if (user_mode(regs))
902                 do_group_exit(SIGKILL);
903         goto no_context;
904 diff -NurpP --minimal linux-2.6.24-rc7/arch/parisc/Kconfig linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/parisc/Kconfig
905 --- linux-2.6.24-rc7/arch/parisc/Kconfig        2007-11-29 01:10:16 +0100
906 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/parisc/Kconfig  2007-12-13 13:25:26 +0100
907 @@ -271,6 +271,8 @@ source "kernel/Kconfig.instrumentation"
908  
909  source "arch/parisc/Kconfig.debug"
910  
911 +source "kernel/vserver/Kconfig"
912 +
913  source "security/Kconfig"
914  
915  source "crypto/Kconfig"
916 diff -NurpP --minimal linux-2.6.24-rc7/arch/parisc/kernel/entry.S linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/parisc/kernel/entry.S
917 --- linux-2.6.24-rc7/arch/parisc/kernel/entry.S 2007-11-29 01:10:16 +0100
918 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/parisc/kernel/entry.S   2007-12-13 13:25:44 +0100
919 @@ -740,6 +740,7 @@ END(fault_vector_11)
920  
921  #define CLONE_VM 0x100 /* Must agree with <linux/sched.h> */
922  #define CLONE_UNTRACED 0x00800000
923 +#define CLONE_KTHREAD 0x10000000
924  
925         .import do_fork
926  ENTRY(__kernel_thread)
927 diff -NurpP --minimal linux-2.6.24-rc7/arch/parisc/kernel/process.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/parisc/kernel/process.c
928 --- linux-2.6.24-rc7/arch/parisc/kernel/process.c       2007-11-29 01:00:27 +0100
929 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/parisc/kernel/process.c 2007-12-13 13:25:44 +0100
930 @@ -174,7 +174,7 @@ pid_t kernel_thread(int (*fn)(void *), v
931          *        kernel_thread can become a #define.
932          */
933  
934 -       return __kernel_thread(fn, arg, flags);
935 +       return __kernel_thread(fn, arg, flags | CLONE_KTHREAD);
936  }
937  EXPORT_SYMBOL(kernel_thread);
938  
939 diff -NurpP --minimal linux-2.6.24-rc7/arch/parisc/kernel/sys_parisc32.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/parisc/kernel/sys_parisc32.c
940 --- linux-2.6.24-rc7/arch/parisc/kernel/sys_parisc32.c  2007-11-29 01:10:16 +0100
941 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/parisc/kernel/sys_parisc32.c    2007-12-13 13:25:35 +0100
942 @@ -204,11 +204,11 @@ static inline long get_ts32(struct times
943  asmlinkage int
944  sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
945  {
946 -    extern void do_gettimeofday(struct timeval *tv);
947 +    extern void vx_gettimeofday(struct timeval *tv);
948  
949      if (tv) {
950             struct timeval ktv;
951 -           do_gettimeofday(&ktv);
952 +           vx_gettimeofday(&ktv);
953             if (put_compat_timeval(tv, &ktv))
954                     return -EFAULT;
955      }
956 diff -NurpP --minimal linux-2.6.24-rc7/arch/parisc/kernel/syscall_table.S linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/parisc/kernel/syscall_table.S
957 --- linux-2.6.24-rc7/arch/parisc/kernel/syscall_table.S 2007-11-29 01:10:17 +0100
958 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/parisc/kernel/syscall_table.S   2007-12-13 13:25:28 +0100
959 @@ -361,7 +361,7 @@
960         ENTRY_COMP(mbind)               /* 260 */
961         ENTRY_COMP(get_mempolicy)
962         ENTRY_COMP(set_mempolicy)
963 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
964 +       ENTRY_DIFF(vserver)
965         ENTRY_SAME(add_key)
966         ENTRY_SAME(request_key)         /* 265 */
967         ENTRY_SAME(keyctl)
968 diff -NurpP --minimal linux-2.6.24-rc7/arch/parisc/kernel/traps.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/parisc/kernel/traps.c
969 --- linux-2.6.24-rc7/arch/parisc/kernel/traps.c 2007-11-29 01:10:17 +0100
970 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/parisc/kernel/traps.c   2007-12-13 13:25:29 +0100
971 @@ -218,8 +218,9 @@ void die_if_kernel(char *str, struct pt_
972                 if (err == 0)
973                         return; /* STFU */
974  
975 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
976 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
977 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
978 +                       current->comm, task_pid_nr(current), current->xid,
979 +                       str, err, regs->iaoq[0]);
980  #ifdef PRINT_USER_FAULTS
981                 /* XXX for debugging only */
982                 show_regs(regs);
983 @@ -251,8 +252,8 @@ KERN_CRIT "                     ||     |
984                 pdc_console_restart();
985         
986         if (err)
987 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
988 -                       current->comm, task_pid_nr(current), str, err);
989 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
990 +                       current->comm, task_pid_nr(current), current->xid, str, err);
991  
992         /* Wot's wrong wif bein' racy? */
993         if (current->thread.flags & PARISC_KERNEL_DEATH) {
994 diff -NurpP --minimal linux-2.6.24-rc7/arch/parisc/mm/fault.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/parisc/mm/fault.c
995 --- linux-2.6.24-rc7/arch/parisc/mm/fault.c     2007-11-29 01:10:17 +0100
996 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/parisc/mm/fault.c       2007-12-13 13:25:29 +0100
997 @@ -210,8 +210,9 @@ bad_area:
998  
999  #ifdef PRINT_USER_FAULTS
1000                 printk(KERN_DEBUG "\n");
1001 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
1002 -                   task_pid_nr(tsk), tsk->comm, code, address);
1003 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
1004 +                   "command='%s' type=%lu address=0x%08lx\n",
1005 +                   task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
1006                 if (vma) {
1007                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
1008                                         vma->vm_start, vma->vm_end);
1009 @@ -261,7 +262,8 @@ no_context:
1010  
1011    out_of_memory:
1012         up_read(&mm->mmap_sem);
1013 -       printk(KERN_CRIT "VM: killing process %s\n", current->comm);
1014 +       printk(KERN_CRIT "VM: killing process %s(%d:#%u)\n",
1015 +               current->comm, current->pid, current->xid);
1016         if (user_mode(regs))
1017                 do_group_exit(SIGKILL);
1018         goto no_context;
1019 diff -NurpP --minimal linux-2.6.24-rc7/arch/powerpc/Kconfig linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/powerpc/Kconfig
1020 --- linux-2.6.24-rc7/arch/powerpc/Kconfig       2007-12-31 17:58:11 +0100
1021 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/powerpc/Kconfig 2007-12-31 12:34:06 +0100
1022 @@ -678,6 +678,8 @@ source "kernel/Kconfig.instrumentation"
1023  
1024  source "arch/powerpc/Kconfig.debug"
1025  
1026 +source "kernel/vserver/Kconfig"
1027 +
1028  source "security/Kconfig"
1029  
1030  config KEYS_COMPAT
1031 diff -NurpP --minimal linux-2.6.24-rc7/arch/powerpc/kernel/asm-offsets.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/powerpc/kernel/asm-offsets.c
1032 --- linux-2.6.24-rc7/arch/powerpc/kernel/asm-offsets.c  2007-12-31 17:58:11 +0100
1033 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/powerpc/kernel/asm-offsets.c    2007-12-31 12:34:07 +0100
1034 @@ -251,6 +251,7 @@ int main(void)
1035  
1036         DEFINE(CLONE_VM, CLONE_VM);
1037         DEFINE(CLONE_UNTRACED, CLONE_UNTRACED);
1038 +       DEFINE(CLONE_KTHREAD, CLONE_KTHREAD);
1039  
1040  #ifndef CONFIG_PPC64
1041         DEFINE(MM_PGD, offsetof(struct mm_struct, pgd));
1042 diff -NurpP --minimal linux-2.6.24-rc7/arch/powerpc/kernel/irq.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/powerpc/kernel/irq.c
1043 --- linux-2.6.24-rc7/arch/powerpc/kernel/irq.c  2007-11-29 01:10:18 +0100
1044 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/powerpc/kernel/irq.c    2007-12-13 13:25:11 +0100
1045 @@ -53,6 +53,7 @@
1046  #include <linux/bootmem.h>
1047  #include <linux/pci.h>
1048  #include <linux/debugfs.h>
1049 +#include <linux/vs_context.h>
1050  
1051  #include <asm/uaccess.h>
1052  #include <asm/system.h>
1053 diff -NurpP --minimal linux-2.6.24-rc7/arch/powerpc/kernel/misc_32.S linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/powerpc/kernel/misc_32.S
1054 --- linux-2.6.24-rc7/arch/powerpc/kernel/misc_32.S      2007-11-29 01:10:18 +0100
1055 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/powerpc/kernel/misc_32.S        2007-12-13 13:25:44 +0100
1056 @@ -773,7 +773,7 @@ _GLOBAL(kernel_thread)
1057         mr      r30,r3          /* function */
1058         mr      r31,r4          /* argument */
1059         ori     r3,r5,CLONE_VM  /* flags */
1060 -       oris    r3,r3,CLONE_UNTRACED>>16
1061 +       oris    r3,r3,(CLONE_UNTRACED|CLONE_KTHREAD)>>16
1062         li      r4,0            /* new sp (unused) */
1063         li      r0,__NR_clone
1064         sc
1065 diff -NurpP --minimal linux-2.6.24-rc7/arch/powerpc/kernel/misc_64.S linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/powerpc/kernel/misc_64.S
1066 --- linux-2.6.24-rc7/arch/powerpc/kernel/misc_64.S      2007-11-29 01:00:28 +0100
1067 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/powerpc/kernel/misc_64.S        2007-12-13 13:25:44 +0100
1068 @@ -434,7 +434,7 @@ _GLOBAL(kernel_thread)
1069         mr      r29,r3
1070         mr      r30,r4
1071         ori     r3,r5,CLONE_VM  /* flags */
1072 -       oris    r3,r3,(CLONE_UNTRACED>>16)
1073 +       oris    r3,r3,(CLONE_UNTRACED|CLONE_KTHREAD)>>16
1074         li      r4,0            /* new sp (unused) */
1075         li      r0,__NR_clone
1076         sc
1077 diff -NurpP --minimal linux-2.6.24-rc7/arch/powerpc/kernel/process.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/powerpc/kernel/process.c
1078 --- linux-2.6.24-rc7/arch/powerpc/kernel/process.c      2007-12-31 17:58:11 +0100
1079 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/powerpc/kernel/process.c        2007-12-31 12:34:07 +0100
1080 @@ -458,8 +458,9 @@ void show_regs(struct pt_regs * regs)
1081  #else
1082                 printk("DAR: "REG", DSISR: "REG"\n", regs->dar, regs->dsisr);
1083  #endif
1084 -       printk("TASK = %p[%d] '%s' THREAD: %p",
1085 -              current, task_pid_nr(current), current->comm, task_thread_info(current));
1086 +       printk("TASK = %p[%d,#%u] '%s' THREAD: %p",
1087 +              current, task_pid_nr(current), current->xid,
1088 +              current->comm, task_thread_info(current));
1089  
1090  #ifdef CONFIG_SMP
1091         printk(" CPU: %d", smp_processor_id());
1092 diff -NurpP --minimal linux-2.6.24-rc7/arch/powerpc/kernel/sys_ppc32.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/powerpc/kernel/sys_ppc32.c
1093 --- linux-2.6.24-rc7/arch/powerpc/kernel/sys_ppc32.c    2007-11-29 01:10:18 +0100
1094 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/powerpc/kernel/sys_ppc32.c      2007-12-13 13:25:35 +0100
1095 @@ -205,7 +205,7 @@ asmlinkage long compat_sys_gettimeofday(
1096  {
1097         if (tv) {
1098                 struct timeval ktv;
1099 -               do_gettimeofday(&ktv);
1100 +               vx_gettimeofday(&ktv);
1101                 if (put_tv32(tv, &ktv))
1102                         return -EFAULT;
1103         }
1104 diff -NurpP --minimal linux-2.6.24-rc7/arch/powerpc/kernel/traps.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/powerpc/kernel/traps.c
1105 --- linux-2.6.24-rc7/arch/powerpc/kernel/traps.c        2007-11-29 01:10:18 +0100
1106 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/powerpc/kernel/traps.c  2007-12-13 13:25:29 +0100
1107 @@ -880,8 +880,9 @@ void nonrecoverable_exception(struct pt_
1108  
1109  void trace_syscall(struct pt_regs *regs)
1110  {
1111 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
1112 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
1113 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
1114 +              current, task_pid_nr(current), current->xid,
1115 +              regs->nip, regs->link, regs->gpr[0],
1116                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
1117  }
1118  
1119 diff -NurpP --minimal linux-2.6.24-rc7/arch/powerpc/kernel/vdso.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/powerpc/kernel/vdso.c
1120 --- linux-2.6.24-rc7/arch/powerpc/kernel/vdso.c 2007-12-31 17:58:11 +0100
1121 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/powerpc/kernel/vdso.c   2007-12-31 12:34:07 +0100
1122 @@ -21,6 +21,7 @@
1123  #include <linux/elf.h>
1124  #include <linux/security.h>
1125  #include <linux/bootmem.h>
1126 +#include <linux/vs_memory.h>
1127  
1128  #include <asm/pgtable.h>
1129  #include <asm/system.h>
1130 diff -NurpP --minimal linux-2.6.24-rc7/arch/powerpc/mm/fault.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/powerpc/mm/fault.c
1131 --- linux-2.6.24-rc7/arch/powerpc/mm/fault.c    2007-11-29 01:10:19 +0100
1132 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/powerpc/mm/fault.c      2007-12-13 13:25:29 +0100
1133 @@ -380,7 +380,8 @@ out_of_memory:
1134                 down_read(&mm->mmap_sem);
1135                 goto survive;
1136         }
1137 -       printk("VM: killing process %s\n", current->comm);
1138 +       printk("VM: killing process %s(%d:#%u)\n",
1139 +               current->comm, current->pid, current->xid);
1140         if (user_mode(regs))
1141                 do_group_exit(SIGKILL);
1142         return SIGKILL;
1143 diff -NurpP --minimal linux-2.6.24-rc7/arch/ppc/Kconfig linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ppc/Kconfig
1144 --- linux-2.6.24-rc7/arch/ppc/Kconfig   2007-11-29 01:10:22 +0100
1145 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ppc/Kconfig     2007-12-13 13:25:26 +0100
1146 @@ -1321,6 +1321,8 @@ source "kernel/Kconfig.instrumentation"
1147  
1148  source "arch/ppc/Kconfig.debug"
1149  
1150 +source "kernel/vserver/Kconfig"
1151 +
1152  source "security/Kconfig"
1153  
1154  source "crypto/Kconfig"
1155 diff -NurpP --minimal linux-2.6.24-rc7/arch/ppc/kernel/asm-offsets.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ppc/kernel/asm-offsets.c
1156 --- linux-2.6.24-rc7/arch/ppc/kernel/asm-offsets.c      2007-07-09 13:18:01 +0200
1157 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ppc/kernel/asm-offsets.c        2007-12-13 13:25:44 +0100
1158 @@ -120,6 +120,7 @@ main(void)
1159         DEFINE(TRAP, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, trap));
1160         DEFINE(CLONE_VM, CLONE_VM);
1161         DEFINE(CLONE_UNTRACED, CLONE_UNTRACED);
1162 +       DEFINE(CLONE_KTHREAD, CLONE_KTHREAD);
1163         DEFINE(MM_PGD, offsetof(struct mm_struct, pgd));
1164  
1165         /* About the CPU features table */
1166 diff -NurpP --minimal linux-2.6.24-rc7/arch/ppc/kernel/misc.S linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ppc/kernel/misc.S
1167 --- linux-2.6.24-rc7/arch/ppc/kernel/misc.S     2007-11-29 01:10:22 +0100
1168 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ppc/kernel/misc.S       2007-12-13 13:25:44 +0100
1169 @@ -875,7 +875,7 @@ _GLOBAL(kernel_thread)
1170         mr      r30,r3          /* function */
1171         mr      r31,r4          /* argument */
1172         ori     r3,r5,CLONE_VM  /* flags */
1173 -       oris    r3,r3,CLONE_UNTRACED>>16
1174 +       oris    r3,r3,(CLONE_UNTRACED|CLONE_KTHREAD)>>16
1175         li      r4,0            /* new sp (unused) */
1176         li      r0,__NR_clone
1177         sc
1178 diff -NurpP --minimal linux-2.6.24-rc7/arch/ppc/kernel/traps.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ppc/kernel/traps.c
1179 --- linux-2.6.24-rc7/arch/ppc/kernel/traps.c    2007-11-29 01:10:22 +0100
1180 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ppc/kernel/traps.c      2007-12-13 13:25:29 +0100
1181 @@ -697,8 +697,9 @@ void nonrecoverable_exception(struct pt_
1182  
1183  void trace_syscall(struct pt_regs *regs)
1184  {
1185 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
1186 -              current, current->pid, regs->nip, regs->link, regs->gpr[0],
1187 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
1188 +              current, current->pid, current->xid,
1189 +              regs->nip, regs->link, regs->gpr[0],
1190                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
1191  }
1192  
1193 diff -NurpP --minimal linux-2.6.24-rc7/arch/ppc/mm/fault.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ppc/mm/fault.c
1194 --- linux-2.6.24-rc7/arch/ppc/mm/fault.c        2007-11-29 01:10:22 +0100
1195 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/ppc/mm/fault.c  2007-12-13 13:25:29 +0100
1196 @@ -295,7 +295,8 @@ out_of_memory:
1197                 down_read(&mm->mmap_sem);
1198                 goto survive;
1199         }
1200 -       printk("VM: killing process %s\n", current->comm);
1201 +       printk("VM: killing process %s(%d:#%u)\n",
1202 +               current->comm, current->pid, current->xid);
1203         if (user_mode(regs))
1204                 do_group_exit(SIGKILL);
1205         return SIGKILL;
1206 diff -NurpP --minimal linux-2.6.24-rc7/arch/s390/Kconfig linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/s390/Kconfig
1207 --- linux-2.6.24-rc7/arch/s390/Kconfig  2007-11-29 01:10:22 +0100
1208 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/s390/Kconfig    2007-12-13 13:25:26 +0100
1209 @@ -533,6 +533,8 @@ source "kernel/Kconfig.instrumentation"
1210  
1211  source "arch/s390/Kconfig.debug"
1212  
1213 +source "kernel/vserver/Kconfig"
1214 +
1215  source "security/Kconfig"
1216  
1217  source "crypto/Kconfig"
1218 diff -NurpP --minimal linux-2.6.24-rc7/arch/s390/kernel/compat_linux.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/s390/kernel/compat_linux.c
1219 --- linux-2.6.24-rc7/arch/s390/kernel/compat_linux.c    2007-11-29 01:10:23 +0100
1220 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/s390/kernel/compat_linux.c      2007-12-13 13:25:35 +0100
1221 @@ -567,7 +567,7 @@ asmlinkage long sys32_gettimeofday(struc
1222  {
1223         if (tv) {
1224                 struct timeval ktv;
1225 -               do_gettimeofday(&ktv);
1226 +               vx_gettimeofday(&ktv);
1227                 if (put_tv32(tv, &ktv))
1228                         return -EFAULT;
1229         }
1230 diff -NurpP --minimal linux-2.6.24-rc7/arch/s390/kernel/process.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/s390/kernel/process.c
1231 --- linux-2.6.24-rc7/arch/s390/kernel/process.c 2007-11-29 01:10:23 +0100
1232 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/s390/kernel/process.c   2007-12-13 13:25:44 +0100
1233 @@ -185,9 +185,9 @@ void show_regs(struct pt_regs *regs)
1234         struct task_struct *tsk = current;
1235  
1236          printk("CPU:    %d    %s\n", task_thread_info(tsk)->cpu, print_tainted());
1237 -        printk("Process %s (pid: %d, task: %p, ksp: %p)\n",
1238 -              current->comm, task_pid_nr(current), (void *) tsk,
1239 -              (void *) tsk->thread.ksp);
1240 +       printk("Process %s (pid: %d[#%u], task: %p, ksp: %p)\n",
1241 +              current->comm, task_pid_nr(current), current->xid,
1242 +              (void *) tsk, (void *) tsk->thread.ksp);
1243  
1244         show_registers(regs);
1245         /* Show stack backtrace if pt_regs is from kernel mode */
1246 @@ -218,7 +218,7 @@ int kernel_thread(int (*fn)(void *), voi
1247         regs.orig_gpr2 = -1;
1248  
1249         /* Ok, create the new process.. */
1250 -       return do_fork(flags | CLONE_VM | CLONE_UNTRACED,
1251 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
1252                        0, &regs, 0, NULL, NULL);
1253  }
1254  
1255 diff -NurpP --minimal linux-2.6.24-rc7/arch/s390/kernel/ptrace.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/s390/kernel/ptrace.c
1256 --- linux-2.6.24-rc7/arch/s390/kernel/ptrace.c  2007-11-29 01:10:23 +0100
1257 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/s390/kernel/ptrace.c    2007-12-13 13:25:28 +0100
1258 @@ -33,6 +33,7 @@
1259  #include <linux/security.h>
1260  #include <linux/audit.h>
1261  #include <linux/signal.h>
1262 +#include <linux/vs_base.h>
1263  
1264  #include <asm/segment.h>
1265  #include <asm/page.h>
1266 @@ -713,7 +714,13 @@ sys_ptrace(long request, long pid, long 
1267                 goto out;
1268         }
1269  
1270 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT)) {
1271 +               ret = -EPERM;
1272 +               goto out_tsk;
1273 +       }
1274 +
1275         ret = do_ptrace(child, request, addr, data);
1276 +out_tsk:
1277         put_task_struct(child);
1278  out:
1279         unlock_kernel();
1280 diff -NurpP --minimal linux-2.6.24-rc7/arch/s390/kernel/syscalls.S linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/s390/kernel/syscalls.S
1281 --- linux-2.6.24-rc7/arch/s390/kernel/syscalls.S        2007-11-29 01:00:32 +0100
1282 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/s390/kernel/syscalls.S  2007-12-13 13:25:28 +0100
1283 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
1284  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
1285  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
1286  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
1287 -NI_SYSCALL                                                     /* reserved for vserver */
1288 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
1289  SYSCALL(s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
1290  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
1291  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
1292 diff -NurpP --minimal linux-2.6.24-rc7/arch/s390/mm/fault.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/s390/mm/fault.c
1293 --- linux-2.6.24-rc7/arch/s390/mm/fault.c       2007-11-29 01:10:23 +0100
1294 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/s390/mm/fault.c 2007-12-13 13:25:29 +0100
1295 @@ -216,7 +216,8 @@ static int do_out_of_memory(struct pt_re
1296                 down_read(&mm->mmap_sem);
1297                 return 1;
1298         }
1299 -       printk("VM: killing process %s\n", tsk->comm);
1300 +       printk("VM: killing process %s(%d:#%u)\n",
1301 +               tsk->comm, tsk->pid, tsk->xid);
1302         if (regs->psw.mask & PSW_MASK_PSTATE)
1303                 do_group_exit(SIGKILL);
1304         do_no_context(regs, error_code, address);
1305 diff -NurpP --minimal linux-2.6.24-rc7/arch/sh/Kconfig linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sh/Kconfig
1306 --- linux-2.6.24-rc7/arch/sh/Kconfig    2007-11-29 01:10:23 +0100
1307 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sh/Kconfig      2007-12-13 13:25:26 +0100
1308 @@ -760,6 +760,8 @@ source "kernel/Kconfig.instrumentation"
1309  
1310  source "arch/sh/Kconfig.debug"
1311  
1312 +source "kernel/vserver/Kconfig"
1313 +
1314  source "security/Kconfig"
1315  
1316  source "crypto/Kconfig"
1317 diff -NurpP --minimal linux-2.6.24-rc7/arch/sh/kernel/irq.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sh/kernel/irq.c
1318 --- linux-2.6.24-rc7/arch/sh/kernel/irq.c       2007-11-29 01:10:25 +0100
1319 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sh/kernel/irq.c 2007-12-13 13:25:11 +0100
1320 @@ -11,6 +11,7 @@
1321  #include <linux/module.h>
1322  #include <linux/kernel_stat.h>
1323  #include <linux/seq_file.h>
1324 +#include <linux/vs_context.h>
1325  #include <asm/processor.h>
1326  #include <asm/machvec.h>
1327  #include <asm/uaccess.h>
1328 diff -NurpP --minimal linux-2.6.24-rc7/arch/sh/kernel/process.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sh/kernel/process.c
1329 --- linux-2.6.24-rc7/arch/sh/kernel/process.c   2007-11-29 01:10:25 +0100
1330 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sh/kernel/process.c     2007-12-13 13:25:44 +0100
1331 @@ -121,7 +121,8 @@ void machine_power_off(void)
1332  void show_regs(struct pt_regs * regs)
1333  {
1334         printk("\n");
1335 -       printk("Pid : %d, Comm: %20s\n", task_pid_nr(current), current->comm);
1336 +       printk("Pid : %d:#%u, Comm: %20s\n",
1337 +               task_pid_nr(current), current->xid, current->comm);
1338         print_symbol("PC is at %s\n", instruction_pointer(regs));
1339         printk("PC  : %08lx SP  : %08lx SR  : %08lx ",
1340                regs->pc, regs->regs[15], regs->sr);
1341 @@ -182,7 +183,7 @@ int kernel_thread(int (*fn)(void *), voi
1342         regs.sr = (1 << 30);
1343  
1344         /* Ok, create the new process.. */
1345 -       return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0,
1346 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD, 0,
1347                        &regs, 0, NULL, NULL);
1348  }
1349  
1350 diff -NurpP --minimal linux-2.6.24-rc7/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sh/kernel/vsyscall/vsyscall.c
1351 --- linux-2.6.24-rc7/arch/sh/kernel/vsyscall/vsyscall.c 2007-11-29 01:00:41 +0100
1352 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sh/kernel/vsyscall/vsyscall.c   2007-12-13 13:25:11 +0100
1353 @@ -19,6 +19,7 @@
1354  #include <linux/elf.h>
1355  #include <linux/sched.h>
1356  #include <linux/err.h>
1357 +#include <linux/vs_memory.h>
1358  
1359  /*
1360   * Should the kernel map a VDSO page into processes and pass its
1361 diff -NurpP --minimal linux-2.6.24-rc7/arch/sh/mm/fault.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sh/mm/fault.c
1362 --- linux-2.6.24-rc7/arch/sh/mm/fault.c 2007-12-31 17:58:12 +0100
1363 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sh/mm/fault.c   2007-12-31 12:34:08 +0100
1364 @@ -212,7 +212,8 @@ out_of_memory:
1365                 down_read(&mm->mmap_sem);
1366                 goto survive;
1367         }
1368 -       printk("VM: killing process %s\n", tsk->comm);
1369 +       printk("VM: killing process %s(%d:#%u)\n",
1370 +               tsk->comm, tsk->pid, tsk->xid);
1371         if (user_mode(regs))
1372                 do_group_exit(SIGKILL);
1373         goto no_context;
1374 diff -NurpP --minimal linux-2.6.24-rc7/arch/sh64/kernel/process.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sh64/kernel/process.c
1375 --- linux-2.6.24-rc7/arch/sh64/kernel/process.c 2007-11-29 01:10:26 +0100
1376 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sh64/kernel/process.c   2007-12-13 13:25:45 +0100
1377 @@ -402,8 +402,8 @@ int kernel_thread(int (*fn)(void *), voi
1378         regs.pc = (unsigned long)kernel_thread_helper;
1379         regs.sr = (1 << 30);
1380  
1381 -       return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0,
1382 -                      &regs, 0, NULL, NULL);
1383 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
1384 +               0, &regs, 0, NULL, NULL);
1385  }
1386  
1387  /*
1388 diff -NurpP --minimal linux-2.6.24-rc7/arch/sh64/mm/fault.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sh64/mm/fault.c
1389 --- linux-2.6.24-rc7/arch/sh64/mm/fault.c       2007-11-29 01:10:26 +0100
1390 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sh64/mm/fault.c 2007-12-13 13:25:29 +0100
1391 @@ -81,7 +81,7 @@ static inline void print_vma(struct vm_a
1392  
1393  static inline void print_task(struct task_struct *tsk)
1394  {
1395 -       printk("Task pid %d\n", task_pid_nr(tsk));
1396 +       printk("Task pid %d:#%u\n", task_pid_nr(tsk), tsk->xid);
1397  }
1398  
1399  static pte_t *lookup_pte(struct mm_struct *mm, unsigned long address)
1400 @@ -332,7 +332,8 @@ out_of_memory:
1401                 down_read(&mm->mmap_sem);
1402                 goto survive;
1403         }
1404 -       printk("VM: killing process %s\n", tsk->comm);
1405 +       printk("VM: killing process %s(%d:#%u)\n",
1406 +               tsk->comm, tsk->pid, tsk->xid);
1407         if (user_mode(regs))
1408                 do_group_exit(SIGKILL);
1409         goto no_context;
1410 diff -NurpP --minimal linux-2.6.24-rc7/arch/sparc/Kconfig linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc/Kconfig
1411 --- linux-2.6.24-rc7/arch/sparc/Kconfig 2007-11-29 01:10:26 +0100
1412 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc/Kconfig   2007-12-13 13:25:26 +0100
1413 @@ -324,6 +324,8 @@ source "kernel/Kconfig.instrumentation"
1414  
1415  source "arch/sparc/Kconfig.debug"
1416  
1417 +source "kernel/vserver/Kconfig"
1418 +
1419  source "security/Kconfig"
1420  
1421  source "crypto/Kconfig"
1422 diff -NurpP --minimal linux-2.6.24-rc7/arch/sparc/kernel/process.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc/kernel/process.c
1423 --- linux-2.6.24-rc7/arch/sparc/kernel/process.c        2007-11-29 01:10:26 +0100
1424 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc/kernel/process.c  2007-12-13 13:25:45 +0100
1425 @@ -706,7 +706,8 @@ pid_t kernel_thread(int (*fn)(void *), v
1426                              /* Notreached by child. */
1427                              "1: mov %%o0, %0\n\t" :
1428                              "=r" (retval) :
1429 -                            "i" (__NR_clone), "r" (flags | CLONE_VM | CLONE_UNTRACED),
1430 +                            "i" (__NR_clone), "r" (flags |
1431 +                                       CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD),
1432                              "i" (__NR_exit),  "r" (fn), "r" (arg) :
1433                              "g1", "g2", "g3", "o0", "o1", "memory", "cc");
1434         return retval;
1435 diff -NurpP --minimal linux-2.6.24-rc7/arch/sparc/kernel/ptrace.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc/kernel/ptrace.c
1436 --- linux-2.6.24-rc7/arch/sparc/kernel/ptrace.c 2008-01-11 12:00:47 +0100
1437 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc/kernel/ptrace.c   2008-01-11 04:30:05 +0100
1438 @@ -19,6 +19,7 @@
1439  #include <linux/smp_lock.h>
1440  #include <linux/security.h>
1441  #include <linux/signal.h>
1442 +#include <linux/vs_base.h>
1443  
1444  #include <asm/pgtable.h>
1445  #include <asm/system.h>
1446 @@ -302,6 +303,10 @@ asmlinkage void do_ptrace(struct pt_regs
1447                 pt_error_return(regs, -ret);
1448                 goto out;
1449         }
1450 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT)) {
1451 +               pt_error_return(regs, ESRCH);
1452 +               goto out_tsk;
1453 +       }
1454  
1455         if ((current->personality == PER_SUNOS && request == PTRACE_SUNATTACH)
1456             || (current->personality != PER_SUNOS && request == PTRACE_ATTACH)) {
1457 diff -NurpP --minimal linux-2.6.24-rc7/arch/sparc/kernel/systbls.S linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc/kernel/systbls.S
1458 --- linux-2.6.24-rc7/arch/sparc/kernel/systbls.S        2007-11-29 01:00:41 +0100
1459 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc/kernel/systbls.S  2007-12-13 13:25:28 +0100
1460 @@ -70,7 +70,7 @@ sys_call_table:
1461  /*250*/        .long sparc_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
1462  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
1463  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
1464 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
1465 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
1466  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
1467  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
1468  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
1469 diff -NurpP --minimal linux-2.6.24-rc7/arch/sparc/kernel/traps.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc/kernel/traps.c
1470 --- linux-2.6.24-rc7/arch/sparc/kernel/traps.c  2007-11-29 01:10:27 +0100
1471 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc/kernel/traps.c    2007-12-13 13:25:29 +0100
1472 @@ -99,7 +99,8 @@ void die_if_kernel(char *str, struct pt_
1473  "              /_| \\__/ |_\\\n"
1474  "                 \\__U_/\n");
1475  
1476 -       printk("%s(%d): %s [#%d]\n", current->comm, task_pid_nr(current), str, ++die_counter);
1477 +       printk("%s(%d[#%u]): %s [#%d]\n", current->comm,
1478 +               task_pid_nr(current), current->xid, str, ++die_counter);
1479         show_regs(regs);
1480         add_taint(TAINT_DIE);
1481  
1482 diff -NurpP --minimal linux-2.6.24-rc7/arch/sparc/mm/fault.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc/mm/fault.c
1483 --- linux-2.6.24-rc7/arch/sparc/mm/fault.c      2007-11-29 01:10:27 +0100
1484 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc/mm/fault.c        2007-12-13 13:25:29 +0100
1485 @@ -367,7 +367,8 @@ no_context:
1486   */
1487  out_of_memory:
1488         up_read(&mm->mmap_sem);
1489 -       printk("VM: killing process %s\n", tsk->comm);
1490 +       printk("VM: killing process %s(%d:#%u)\n",
1491 +               tsk->comm, tsk->pid, tsk->xid);
1492         if (from_user)
1493                 do_group_exit(SIGKILL);
1494         goto no_context;
1495 diff -NurpP --minimal linux-2.6.24-rc7/arch/sparc64/Kconfig linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc64/Kconfig
1496 --- linux-2.6.24-rc7/arch/sparc64/Kconfig       2007-11-29 01:10:27 +0100
1497 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc64/Kconfig 2007-12-13 13:25:26 +0100
1498 @@ -466,6 +466,8 @@ source "kernel/Kconfig.instrumentation"
1499  
1500  source "arch/sparc64/Kconfig.debug"
1501  
1502 +source "kernel/vserver/Kconfig"
1503 +
1504  source "security/Kconfig"
1505  
1506  source "crypto/Kconfig"
1507 diff -NurpP --minimal linux-2.6.24-rc7/arch/sparc64/kernel/binfmt_aout32.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc64/kernel/binfmt_aout32.c
1508 --- linux-2.6.24-rc7/arch/sparc64/kernel/binfmt_aout32.c        2007-11-29 01:10:27 +0100
1509 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc64/kernel/binfmt_aout32.c  2007-12-13 13:25:11 +0100
1510 @@ -27,6 +27,7 @@
1511  #include <linux/binfmts.h>
1512  #include <linux/personality.h>
1513  #include <linux/init.h>
1514 +#include <linux/vs_memory.h>
1515  
1516  #include <asm/system.h>
1517  #include <asm/uaccess.h>
1518 diff -NurpP --minimal linux-2.6.24-rc7/arch/sparc64/kernel/process.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc64/kernel/process.c
1519 --- linux-2.6.24-rc7/arch/sparc64/kernel/process.c      2007-11-29 01:00:42 +0100
1520 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc64/kernel/process.c        2007-12-13 13:25:45 +0100
1521 @@ -719,7 +719,8 @@ pid_t kernel_thread(int (*fn)(void *), v
1522                              /* Notreached by child. */
1523                              "1:" :
1524                              "=r" (retval) :
1525 -                            "i" (__NR_clone), "r" (flags | CLONE_VM | CLONE_UNTRACED),
1526 +                            "i" (__NR_clone), "r" (flags |
1527 +                               CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD),
1528                              "i" (__NR_exit),  "r" (fn), "r" (arg) :
1529                              "g1", "g2", "g3", "o0", "o1", "memory", "cc");
1530         return retval;
1531 diff -NurpP --minimal linux-2.6.24-rc7/arch/sparc64/kernel/ptrace.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc64/kernel/ptrace.c
1532 --- linux-2.6.24-rc7/arch/sparc64/kernel/ptrace.c       2007-02-06 03:00:18 +0100
1533 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc64/kernel/ptrace.c 2007-12-13 13:25:28 +0100
1534 @@ -22,6 +22,7 @@
1535  #include <linux/seccomp.h>
1536  #include <linux/audit.h>
1537  #include <linux/signal.h>
1538 +#include <linux/vs_base.h>
1539  
1540  #include <asm/asi.h>
1541  #include <asm/pgtable.h>
1542 @@ -215,6 +216,10 @@ asmlinkage void do_ptrace(struct pt_regs
1543                 pt_error_return(regs, -ret);
1544                 goto out;
1545         }
1546 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT)) {
1547 +               pt_error_return(regs, ESRCH);
1548 +               goto out_tsk;
1549 +       }
1550  
1551         if ((current->personality == PER_SUNOS && request == PTRACE_SUNATTACH)
1552             || (current->personality != PER_SUNOS && request == PTRACE_ATTACH)) {
1553 diff -NurpP --minimal linux-2.6.24-rc7/arch/sparc64/kernel/sys_sparc32.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc64/kernel/sys_sparc32.c
1554 --- linux-2.6.24-rc7/arch/sparc64/kernel/sys_sparc32.c  2007-11-29 01:10:27 +0100
1555 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc64/kernel/sys_sparc32.c    2007-12-13 13:25:36 +0100
1556 @@ -726,7 +726,7 @@ asmlinkage long sys32_gettimeofday(struc
1557  {
1558         if (tv) {
1559                 struct timeval ktv;
1560 -               do_gettimeofday(&ktv);
1561 +               vx_gettimeofday(&ktv);
1562                 if (put_tv32(tv, &ktv))
1563                         return -EFAULT;
1564         }
1565 diff -NurpP --minimal linux-2.6.24-rc7/arch/sparc64/kernel/systbls.S linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc64/kernel/systbls.S
1566 --- linux-2.6.24-rc7/arch/sparc64/kernel/systbls.S      2007-11-29 01:00:42 +0100
1567 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc64/kernel/systbls.S        2007-12-13 13:25:28 +0100
1568 @@ -71,7 +71,7 @@ sys_call_table32:
1569  /*250*/        .word sys32_mremap, sys32_sysctl, sys32_getsid, sys_fdatasync, sys32_nfsservctl
1570         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
1571  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
1572 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
1573 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
1574  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
1575         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
1576  /*280*/        .word sys32_tee, sys_add_key, sys_request_key, sys_keyctl, compat_sys_openat
1577 @@ -143,7 +143,7 @@ sys_call_table:
1578  /*250*/        .word sys64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
1579         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
1580  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
1581 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
1582 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
1583  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
1584         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
1585  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
1586 diff -NurpP --minimal linux-2.6.24-rc7/arch/sparc64/kernel/traps.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc64/kernel/traps.c
1587 --- linux-2.6.24-rc7/arch/sparc64/kernel/traps.c        2007-11-29 01:10:27 +0100
1588 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc64/kernel/traps.c  2007-12-13 13:25:29 +0100
1589 @@ -2224,7 +2224,8 @@ void die_if_kernel(char *str, struct pt_
1590  "              /_| \\__/ |_\\\n"
1591  "                 \\__U_/\n");
1592  
1593 -       printk("%s(%d): %s [#%d]\n", current->comm, task_pid_nr(current), str, ++die_counter);
1594 +       printk("%s(%d[#%u]): %s [#%d]\n", current->comm,
1595 +               task_pid_nr(current), current->xid, str, ++die_counter);
1596         notify_die(DIE_OOPS, str, regs, 0, 255, SIGSEGV);
1597         __asm__ __volatile__("flushw");
1598         __show_regs(regs);
1599 diff -NurpP --minimal linux-2.6.24-rc7/arch/sparc64/mm/fault.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc64/mm/fault.c
1600 --- linux-2.6.24-rc7/arch/sparc64/mm/fault.c    2007-11-29 01:10:27 +0100
1601 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc64/mm/fault.c      2007-12-13 13:25:29 +0100
1602 @@ -461,7 +461,8 @@ handle_kernel_fault:
1603  out_of_memory:
1604         insn = get_fault_insn(regs, insn);
1605         up_read(&mm->mmap_sem);
1606 -       printk("VM: killing process %s\n", current->comm);
1607 +       printk("VM: killing process %s(%d:#%u)\n",
1608 +               current->comm, current->pid, current->xid);
1609         if (!(regs->tstate & TSTATE_PRIV))
1610                 do_group_exit(SIGKILL);
1611         goto handle_kernel_fault;
1612 diff -NurpP --minimal linux-2.6.24-rc7/arch/sparc64/solaris/fs.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc64/solaris/fs.c
1613 --- linux-2.6.24-rc7/arch/sparc64/solaris/fs.c  2007-02-06 03:00:21 +0100
1614 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/sparc64/solaris/fs.c    2007-12-13 13:25:47 +0100
1615 @@ -368,7 +368,7 @@ static int report_statvfs(struct vfsmoun
1616                 int j = strlen (p);
1617                 
1618                 if (j > 15) j = 15;
1619 -               if (IS_RDONLY(inode)) i = 1;
1620 +               if (IS_RDONLY(inode) || MNT_IS_RDONLY(mnt)) i = 1;
1621                 if (mnt->mnt_flags & MNT_NOSUID) i |= 2;
1622                 if (!sysv_valid_dev(inode->i_sb->s_dev))
1623                         return -EOVERFLOW;
1624 @@ -404,7 +404,7 @@ static int report_statvfs64(struct vfsmo
1625                 int j = strlen (p);
1626                 
1627                 if (j > 15) j = 15;
1628 -               if (IS_RDONLY(inode)) i = 1;
1629 +               if (IS_RDONLY(inode) || MNT_IS_RDONLY(mnt)) i = 1;
1630                 if (mnt->mnt_flags & MNT_NOSUID) i |= 2;
1631                 if (!sysv_valid_dev(inode->i_sb->s_dev))
1632                         return -EOVERFLOW;
1633 diff -NurpP --minimal linux-2.6.24-rc7/arch/um/Kconfig linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/um/Kconfig
1634 --- linux-2.6.24-rc7/arch/um/Kconfig    2007-11-29 01:10:28 +0100
1635 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/um/Kconfig      2007-12-13 13:25:26 +0100
1636 @@ -270,6 +270,8 @@ source "drivers/connector/Kconfig"
1637  
1638  source "fs/Kconfig"
1639  
1640 +source "kernel/vserver/Kconfig"
1641 +
1642  source "security/Kconfig"
1643  
1644  source "crypto/Kconfig"
1645 diff -NurpP --minimal linux-2.6.24-rc7/arch/um/kernel/trap.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/um/kernel/trap.c
1646 --- linux-2.6.24-rc7/arch/um/kernel/trap.c      2007-11-29 01:10:30 +0100
1647 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/um/kernel/trap.c        2007-12-13 13:25:29 +0100
1648 @@ -202,7 +202,8 @@ unsigned long segv(struct faultinfo fi, 
1649                 current->thread.arch.faultinfo = fi;
1650                 force_sig_info(SIGBUS, &si, current);
1651         } else if (err == -ENOMEM) {
1652 -               printk(KERN_INFO "VM: killing process %s\n", current->comm);
1653 +               printk(KERN_INFO "VM: killing process %s(%d:#%u)\n",
1654 +                       current->comm, task_pid_nr(current), current->xid);
1655                 do_exit(SIGKILL);
1656         } else {
1657                 BUG_ON(err != -EFAULT);
1658 diff -NurpP --minimal linux-2.6.24-rc7/arch/v850/Kconfig linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/v850/Kconfig
1659 --- linux-2.6.24-rc7/arch/v850/Kconfig  2007-11-29 01:10:31 +0100
1660 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/v850/Kconfig    2007-12-13 13:25:26 +0100
1661 @@ -335,6 +335,8 @@ source "kernel/Kconfig.instrumentation"
1662  
1663  source "arch/v850/Kconfig.debug"
1664  
1665 +source "kernel/vserver/Kconfig"
1666 +
1667  source "security/Kconfig"
1668  
1669  source "crypto/Kconfig"
1670 diff -NurpP --minimal linux-2.6.24-rc7/arch/v850/kernel/process.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/v850/kernel/process.c
1671 --- linux-2.6.24-rc7/arch/v850/kernel/process.c 2007-07-09 13:18:08 +0200
1672 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/v850/kernel/process.c   2007-12-13 13:25:45 +0100
1673 @@ -82,7 +82,7 @@ int kernel_thread (int (*fn)(void *), vo
1674         /* Clone this thread.  Note that we don't pass the clone syscall's
1675            second argument -- it's ignored for calls from kernel mode (the
1676            child's SP is always set to the top of the kernel stack).  */
1677 -       arg0 = flags | CLONE_VM;
1678 +       arg0 = flags | CLONE_VM | CLONE_KTHREAD;
1679         syscall = __NR_clone;
1680         asm volatile ("trap " SYSCALL_SHORT_TRAP
1681                       : "=r" (ret), "=r" (syscall)
1682 diff -NurpP --minimal linux-2.6.24-rc7/arch/v850/kernel/ptrace.c linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/v850/kernel/ptrace.c
1683 --- linux-2.6.24-rc7/arch/v850/kernel/ptrace.c  2007-11-29 01:00:43 +0100
1684 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/v850/kernel/ptrace.c    2007-12-13 13:25:28 +0100
1685 @@ -23,6 +23,7 @@
1686  #include <linux/sched.h>
1687  #include <linux/ptrace.h>
1688  #include <linux/signal.h>
1689 +#include <linux/vs_base.h>
1690  
1691  #include <asm/errno.h>
1692  #include <asm/ptrace.h>
1693 @@ -116,6 +117,9 @@ long arch_ptrace(struct task_struct *chi
1694  {
1695         int rval;
1696  
1697 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
1698 +               goto out;
1699 +
1700         switch (request) {
1701                 unsigned long val;
1702  
1703 diff -NurpP --minimal linux-2.6.24-rc7/arch/x86/Kconfig linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/x86/Kconfig
1704 --- linux-2.6.24-rc7/arch/x86/Kconfig   2007-12-31 17:58:13 +0100
1705 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/x86/Kconfig     2007-12-31 12:34:15 +0100
1706 @@ -1615,6 +1615,8 @@ source "kernel/Kconfig.instrumentation"
1707  
1708  source "arch/x86/Kconfig.debug"
1709  
1710 +source "kernel/vserver/Kconfig"
1711 +
1712  source "security/Kconfig"
1713  
1714  source "crypto/Kconfig"
1715 diff -NurpP --minimal linux-2.6.24-rc7/arch/x86/kernel/syscall_table_32.S linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/x86/kernel/syscall_table_32.S
1716 --- linux-2.6.24-rc7/arch/x86/kernel/syscall_table_32.S 2007-11-29 01:10:42 +0100
1717 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/arch/x86/kernel/syscall_table_32.S   2007-12-15 02:26:25 +0100
1718 @@ -272,7 +272,7 @@ ENTRY(sys_call_table)
1719         .long sys_tgkill        /* 270 */
1720         .long sys_utimes
1721         .long sys_fadvise64_64
1722 -       .long sys_ni_syscall    /* sys_vserver */
1723 +       .long sys_vserver
1724         .long sys_mbind
1725         .long sys_get_mempolicy
1726         .long sys_set_mempolicy
1727 diff -NurpP --minimal linux-2.6.24-rc7/drivers/block/Kconfig linux-2.6.24-rc7-vs2.2.0.5.0.7/drivers/block/Kconfig
1728 --- linux-2.6.24-rc7/drivers/block/Kconfig      2007-11-29 01:10:50 +0100
1729 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/drivers/block/Kconfig        2007-12-13 13:25:46 +0100
1730 @@ -262,6 +262,13 @@ config BLK_DEV_CRYPTOLOOP
1731           instead, which can be configured to be on-disk compatible with the
1732           cryptoloop device.
1733  
1734 +config BLK_DEV_VROOT
1735 +       tristate "Virtual Root device support"
1736 +       depends on QUOTACTL
1737 +       ---help---
1738 +         Saying Y here will allow you to use quota/fs ioctls on a shared
1739 +         partition within a virtual server without compromising security.
1740 +
1741  config BLK_DEV_NBD
1742         tristate "Network block device support"
1743         depends on NET
1744 diff -NurpP --minimal linux-2.6.24-rc7/drivers/block/Makefile linux-2.6.24-rc7-vs2.2.0.5.0.7/drivers/block/Makefile
1745 --- linux-2.6.24-rc7/drivers/block/Makefile     2007-11-29 01:10:51 +0100
1746 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/drivers/block/Makefile       2007-12-13 13:25:46 +0100
1747 @@ -30,5 +30,6 @@ obj-$(CONFIG_VIRTIO_BLK)      += virtio_blk.o
1748  obj-$(CONFIG_VIODASD)          += viodasd.o
1749  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
1750  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
1751 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
1752  
1753  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
1754 diff -NurpP --minimal linux-2.6.24-rc7/drivers/block/loop.c linux-2.6.24-rc7-vs2.2.0.5.0.7/drivers/block/loop.c
1755 --- linux-2.6.24-rc7/drivers/block/loop.c       2007-11-29 01:10:53 +0100
1756 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/drivers/block/loop.c 2007-12-13 13:25:47 +0100
1757 @@ -76,6 +76,7 @@
1758  #include <linux/gfp.h>
1759  #include <linux/kthread.h>
1760  #include <linux/splice.h>
1761 +#include <linux/vs_context.h>
1762  
1763  #include <asm/uaccess.h>
1764  
1765 @@ -789,6 +790,7 @@ static int loop_set_fd(struct loop_devic
1766         lo->lo_blocksize = lo_blocksize;
1767         lo->lo_device = bdev;
1768         lo->lo_flags = lo_flags;
1769 +       lo->lo_xid = vx_current_xid();
1770         lo->lo_backing_file = file;
1771         lo->transfer = transfer_none;
1772         lo->ioctl = NULL;
1773 @@ -908,6 +910,7 @@ static int loop_clr_fd(struct loop_devic
1774         lo->lo_encrypt_key_size = 0;
1775         lo->lo_flags = 0;
1776         lo->lo_thread = NULL;
1777 +       lo->lo_xid = 0;
1778         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
1779         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
1780         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
1781 @@ -929,7 +932,7 @@ loop_set_status(struct loop_device *lo, 
1782         struct loop_func_table *xfer;
1783  
1784         if (lo->lo_encrypt_key_size && lo->lo_key_owner != current->uid &&
1785 -           !capable(CAP_SYS_ADMIN))
1786 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
1787                 return -EPERM;
1788         if (lo->lo_state != Lo_bound)
1789                 return -ENXIO;
1790 @@ -1009,7 +1012,8 @@ loop_get_status(struct loop_device *lo, 
1791         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
1792         info->lo_encrypt_type =
1793                 lo->lo_encryption ? lo->lo_encryption->number : 0;
1794 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
1795 +       if (lo->lo_encrypt_key_size &&
1796 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
1797                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
1798                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
1799                        lo->lo_encrypt_key_size);
1800 @@ -1318,6 +1322,9 @@ static int lo_open(struct inode *inode, 
1801  {
1802         struct loop_device *lo = inode->i_bdev->bd_disk->private_data;
1803  
1804 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID))
1805 +               return -EACCES;
1806 +
1807         mutex_lock(&lo->lo_ctl_mutex);
1808         lo->lo_refcnt++;
1809         mutex_unlock(&lo->lo_ctl_mutex);
1810 diff -NurpP --minimal linux-2.6.24-rc7/drivers/block/vroot.c linux-2.6.24-rc7-vs2.2.0.5.0.7/drivers/block/vroot.c
1811 --- linux-2.6.24-rc7/drivers/block/vroot.c      1970-01-01 01:00:00 +0100
1812 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/drivers/block/vroot.c        2007-12-31 12:40:51 +0100
1813 @@ -0,0 +1,280 @@
1814 +/*
1815 + *  linux/drivers/block/vroot.c
1816 + *
1817 + *  written by Herbert Pötzl, 9/11/2002
1818 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
1819 + *
1820 + *  based on the loop.c code by Theodore Ts'o.
1821 + *
1822 + * Copyright (C) 2002-2007 by Herbert Pötzl.
1823 + * Redistribution of this file is permitted under the
1824 + * GNU General Public License.
1825 + *
1826 + */
1827 +
1828 +#include <linux/module.h>
1829 +#include <linux/moduleparam.h>
1830 +#include <linux/file.h>
1831 +#include <linux/major.h>
1832 +#include <linux/blkdev.h>
1833 +
1834 +#include <linux/vroot.h>
1835 +#include <linux/vs_context.h>
1836 +
1837 +
1838 +static int max_vroot = 8;
1839 +
1840 +static struct vroot_device *vroot_dev;
1841 +static struct gendisk **disks;
1842 +
1843 +
1844 +static int vroot_set_dev(
1845 +       struct vroot_device *vr,
1846 +       struct file *vr_file,
1847 +       struct block_device *bdev,
1848 +       unsigned int arg)
1849 +{
1850 +       struct block_device *real_bdev;
1851 +       struct file *file;
1852 +       struct inode *inode;
1853 +       int error;
1854 +
1855 +       error = -EBUSY;
1856 +       if (vr->vr_state != Vr_unbound)
1857 +               goto out;
1858 +
1859 +       error = -EBADF;
1860 +       file = fget(arg);
1861 +       if (!file)
1862 +               goto out;
1863 +
1864 +       error = -EINVAL;
1865 +       inode = file->f_dentry->d_inode;
1866 +
1867 +
1868 +       if (S_ISBLK(inode->i_mode)) {
1869 +               real_bdev = inode->i_bdev;
1870 +               vr->vr_device = real_bdev;
1871 +               __iget(real_bdev->bd_inode);
1872 +       } else
1873 +               goto out_fput;
1874 +
1875 +       vxdprintk(VXD_CBIT(misc, 0),
1876 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
1877 +               vr->vr_number, VXD_DEV(real_bdev));
1878 +
1879 +       vr->vr_state = Vr_bound;
1880 +       error = 0;
1881 +
1882 + out_fput:
1883 +       fput(file);
1884 + out:
1885 +       return error;
1886 +}
1887 +
1888 +static int vroot_clr_dev(
1889 +       struct vroot_device *vr,
1890 +       struct file *vr_file,
1891 +       struct block_device *bdev)
1892 +{
1893 +       struct block_device *real_bdev;
1894 +
1895 +       if (vr->vr_state != Vr_bound)
1896 +               return -ENXIO;
1897 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
1898 +               return -EBUSY;
1899 +
1900 +       real_bdev = vr->vr_device;
1901 +
1902 +       vxdprintk(VXD_CBIT(misc, 0),
1903 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1904 +               vr->vr_number, VXD_DEV(real_bdev));
1905 +
1906 +       bdput(real_bdev);
1907 +       vr->vr_state = Vr_unbound;
1908 +       vr->vr_device = NULL;
1909 +       return 0;
1910 +}
1911 +
1912 +
1913 +static int vr_ioctl(struct inode *inode, struct file *file,
1914 +       unsigned int cmd, unsigned long arg)
1915 +{
1916 +       struct vroot_device *vr = inode->i_bdev->bd_disk->private_data;
1917 +       int err;
1918 +
1919 +       down(&vr->vr_ctl_mutex);
1920 +       switch (cmd) {
1921 +       case VROOT_SET_DEV:
1922 +               err = vroot_set_dev(vr, file, inode->i_bdev, arg);
1923 +               break;
1924 +       case VROOT_CLR_DEV:
1925 +               err = vroot_clr_dev(vr, file, inode->i_bdev);
1926 +               break;
1927 +       default:
1928 +               err = -EINVAL;
1929 +               break;
1930 +       }
1931 +       up(&vr->vr_ctl_mutex);
1932 +       return err;
1933 +}
1934 +
1935 +static int vr_open(struct inode *inode, struct file *file)
1936 +{
1937 +       struct vroot_device *vr = inode->i_bdev->bd_disk->private_data;
1938 +
1939 +       down(&vr->vr_ctl_mutex);
1940 +       vr->vr_refcnt++;
1941 +       up(&vr->vr_ctl_mutex);
1942 +       return 0;
1943 +}
1944 +
1945 +static int vr_release(struct inode *inode, struct file *file)
1946 +{
1947 +       struct vroot_device *vr = inode->i_bdev->bd_disk->private_data;
1948 +
1949 +       down(&vr->vr_ctl_mutex);
1950 +       --vr->vr_refcnt;
1951 +       up(&vr->vr_ctl_mutex);
1952 +       return 0;
1953 +}
1954 +
1955 +static struct block_device_operations vr_fops = {
1956 +       .owner =        THIS_MODULE,
1957 +       .open =         vr_open,
1958 +       .release =      vr_release,
1959 +       .ioctl =        vr_ioctl,
1960 +};
1961 +
1962 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1963 +{
1964 +       struct inode *inode = bdev->bd_inode;
1965 +       struct vroot_device *vr;
1966 +       struct block_device *real_bdev;
1967 +       int minor = iminor(inode);
1968 +
1969 +       vr = &vroot_dev[minor];
1970 +       real_bdev = vr->vr_device;
1971 +
1972 +       vxdprintk(VXD_CBIT(misc, 0),
1973 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1974 +               vr->vr_number, VXD_DEV(real_bdev));
1975 +
1976 +       if (vr->vr_state != Vr_bound)
1977 +               return ERR_PTR(-ENXIO);
1978 +
1979 +       __iget(real_bdev->bd_inode);
1980 +       return real_bdev;
1981 +}
1982 +
1983 +/*
1984 + * And now the modules code and kernel interface.
1985 + */
1986 +
1987 +module_param(max_vroot, int, 0);
1988 +
1989 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1990 +MODULE_LICENSE("GPL");
1991 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1992 +
1993 +MODULE_AUTHOR ("Herbert Pötzl");
1994 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1995 +
1996 +
1997 +int __init vroot_init(void)
1998 +{
1999 +       int err, i;
2000 +
2001 +       if (max_vroot < 1 || max_vroot > 256) {
2002 +               max_vroot = MAX_VROOT_DEFAULT;
2003 +               printk(KERN_WARNING "vroot: invalid max_vroot "
2004 +                       "(must be between 1 and 256), "
2005 +                       "using default (%d)\n", max_vroot);
2006 +       }
2007 +
2008 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
2009 +               return -EIO;
2010 +
2011 +       err = -ENOMEM;
2012 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
2013 +       if (!vroot_dev)
2014 +               goto out_mem1;
2015 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
2016 +
2017 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
2018 +       if (!disks)
2019 +               goto out_mem2;
2020 +
2021 +       for (i = 0; i < max_vroot; i++) {
2022 +               disks[i] = alloc_disk(1);
2023 +               if (!disks[i])
2024 +                       goto out_mem3;
2025 +       }
2026 +
2027 +       for (i = 0; i < max_vroot; i++) {
2028 +               struct vroot_device *vr = &vroot_dev[i];
2029 +               struct gendisk *disk = disks[i];
2030 +
2031 +               memset(vr, 0, sizeof(*vr));
2032 +               init_MUTEX(&vr->vr_ctl_mutex);
2033 +               vr->vr_number = i;
2034 +               disk->major = VROOT_MAJOR;
2035 +               disk->first_minor = i;
2036 +               disk->fops = &vr_fops;
2037 +               sprintf(disk->disk_name, "vroot%d", i);
2038 +               disk->private_data = vr;
2039 +       }
2040 +
2041 +       err = register_vroot_grb(&__vroot_get_real_bdev);
2042 +       if (err)
2043 +               goto out_mem3;
2044 +
2045 +       for (i = 0; i < max_vroot; i++)
2046 +               add_disk(disks[i]);
2047 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
2048 +       return 0;
2049 +
2050 +out_mem3:
2051 +       while (i--)
2052 +               put_disk(disks[i]);
2053 +       kfree(disks);
2054 +out_mem2:
2055 +       kfree(vroot_dev);
2056 +out_mem1:
2057 +       unregister_blkdev(VROOT_MAJOR, "vroot");
2058 +       printk(KERN_ERR "vroot: ran out of memory\n");
2059 +       return err;
2060 +}
2061 +
2062 +void vroot_exit(void)
2063 +{
2064 +       int i;
2065 +
2066 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
2067 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
2068 +
2069 +       for (i = 0; i < max_vroot; i++) {
2070 +               del_gendisk(disks[i]);
2071 +               put_disk(disks[i]);
2072 +       }
2073 +       unregister_blkdev(VROOT_MAJOR, "vroot");
2074 +
2075 +       kfree(disks);
2076 +       kfree(vroot_dev);
2077 +}
2078 +
2079 +module_init(vroot_init);
2080 +module_exit(vroot_exit);
2081 +
2082 +#ifndef MODULE
2083 +
2084 +static int __init max_vroot_setup(char *str)
2085 +{
2086 +       max_vroot = simple_strtol(str, NULL, 0);
2087 +       return 1;
2088 +}
2089 +
2090 +__setup("max_vroot=", max_vroot_setup);
2091 +
2092 +#endif
2093 +
2094 diff -NurpP --minimal linux-2.6.24-rc7/drivers/char/sysrq.c linux-2.6.24-rc7-vs2.2.0.5.0.7/drivers/char/sysrq.c
2095 --- linux-2.6.24-rc7/drivers/char/sysrq.c       2007-11-29 01:10:56 +0100
2096 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/drivers/char/sysrq.c 2007-12-13 13:25:42 +0100
2097 @@ -37,6 +37,7 @@
2098  #include <linux/irq.h>
2099  #include <linux/hrtimer.h>
2100  #include <linux/oom.h>
2101 +#include <linux/vserver/debug.h>
2102  
2103  #include <asm/ptrace.h>
2104  #include <asm/irq_regs.h>
2105 @@ -310,6 +311,21 @@ static struct sysrq_key_op sysrq_unrt_op
2106         .enable_mask    = SYSRQ_ENABLE_RTNICE,
2107  };
2108  
2109 +
2110 +#ifdef CONFIG_VSERVER_DEBUG
2111 +static void sysrq_handle_vxinfo(int key, struct tty_struct *tty)
2112 +{
2113 +       dump_vx_info_inactive((key == 'x')?0:1);
2114 +}
2115 +
2116 +static struct sysrq_key_op sysrq_showvxinfo_op = {
2117 +       .handler        = sysrq_handle_vxinfo,
2118 +       .help_msg       = "conteXt",
2119 +       .action_msg     = "Show Context Info",
2120 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
2121 +};
2122 +#endif
2123 +
2124  /* Key Operations table and lock */
2125  static DEFINE_SPINLOCK(sysrq_key_table_lock);
2126  
2127 @@ -358,7 +374,11 @@ static struct sysrq_key_op *sysrq_key_ta
2128         /* x: May be registered on ppc/powerpc for xmon */
2129         NULL,                           /* x */
2130         NULL,                           /* y */
2131 -       NULL                            /* z */
2132 +#ifdef CONFIG_VSERVER_DEBUG
2133 +       &sysrq_showvxinfo_op,           /* z */
2134 +#else
2135 +       NULL,                           /* z */
2136 +#endif
2137  };
2138  
2139  /* key2index calculation, -1 on invalid index */
2140 @@ -370,6 +390,8 @@ static int sysrq_key_table_key2index(int
2141                 retval = key - '0';
2142         else if ((key >= 'a') && (key <= 'z'))
2143                 retval = key + 10 - 'a';
2144 +       else if ((key >= 'A') && (key <= 'Z'))
2145 +               retval = key + 10 - 'A';
2146         else
2147                 retval = -1;
2148         return retval;
2149 diff -NurpP --minimal linux-2.6.24-rc7/drivers/char/tty_io.c linux-2.6.24-rc7-vs2.2.0.5.0.7/drivers/char/tty_io.c
2150 --- linux-2.6.24-rc7/drivers/char/tty_io.c      2007-11-29 01:10:56 +0100
2151 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/drivers/char/tty_io.c        2007-12-13 13:25:48 +0100
2152 @@ -104,6 +104,7 @@
2153  
2154  #include <linux/kmod.h>
2155  #include <linux/nsproxy.h>
2156 +#include <linux/vs_pid.h>
2157  
2158  #undef TTY_DEBUG_HANGUP
2159  
2160 @@ -3139,6 +3140,7 @@ static int tiocspgrp(struct tty_struct *
2161                 return -ENOTTY;
2162         if (get_user(pgrp_nr, p))
2163                 return -EFAULT;
2164 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
2165         if (pgrp_nr < 0)
2166                 return -EINVAL;
2167         rcu_read_lock();
2168 diff -NurpP --minimal linux-2.6.24-rc7/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.24-rc7-vs2.2.0.5.0.7/drivers/infiniband/hw/ipath/ipath_user_pages.c
2169 --- linux-2.6.24-rc7/drivers/infiniband/hw/ipath/ipath_user_pages.c     2007-11-29 01:01:03 +0100
2170 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/drivers/infiniband/hw/ipath/ipath_user_pages.c       2007-12-13 13:25:41 +0100
2171 @@ -33,6 +33,7 @@
2172  
2173  #include <linux/mm.h>
2174  #include <linux/device.h>
2175 +#include <linux/vs_memory.h>
2176  
2177  #include "ipath_kernel.h"
2178  
2179 @@ -61,7 +62,8 @@ static int __get_user_pages(unsigned lon
2180         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur >>
2181                 PAGE_SHIFT;
2182  
2183 -       if (num_pages > lock_limit) {
2184 +       if (num_pages > lock_limit ||
2185 +               !vx_vmlocked_avail(current->mm, num_pages)) {
2186                 ret = -ENOMEM;
2187                 goto bail;
2188         }
2189 @@ -78,7 +80,7 @@ static int __get_user_pages(unsigned lon
2190                         goto bail_release;
2191         }
2192  
2193 -       current->mm->locked_vm += num_pages;
2194 +       vx_vmlocked_add(current->mm, num_pages);
2195  
2196         ret = 0;
2197         goto bail;
2198 @@ -177,7 +179,7 @@ void ipath_release_user_pages(struct pag
2199  
2200         __ipath_release_user_pages(p, num_pages, 1);
2201  
2202 -       current->mm->locked_vm -= num_pages;
2203 +       vx_vmlocked_sub(current->mm, num_pages);
2204  
2205         up_write(&current->mm->mmap_sem);
2206  }
2207 @@ -194,7 +196,7 @@ static void user_pages_account(struct wo
2208                 container_of(_work, struct ipath_user_pages_work, work);
2209  
2210         down_write(&work->mm->mmap_sem);
2211 -       work->mm->locked_vm -= work->num_pages;
2212 +       vx_vmlocked_sub(work->mm, work->num_pages);
2213         up_write(&work->mm->mmap_sem);
2214         mmput(work->mm);
2215         kfree(work);
2216 diff -NurpP --minimal linux-2.6.24-rc7/drivers/md/dm-ioctl.c linux-2.6.24-rc7-vs2.2.0.5.0.7/drivers/md/dm-ioctl.c
2217 --- linux-2.6.24-rc7/drivers/md/dm-ioctl.c      2007-12-31 17:58:18 +0100
2218 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/drivers/md/dm-ioctl.c        2007-12-31 12:34:20 +0100
2219 @@ -15,6 +15,7 @@
2220  #include <linux/slab.h>
2221  #include <linux/dm-ioctl.h>
2222  #include <linux/hdreg.h>
2223 +#include <linux/vs_context.h>
2224  
2225  #include <asm/uaccess.h>
2226  
2227 @@ -100,7 +101,8 @@ static struct hash_cell *__get_name_cell
2228         unsigned int h = hash_str(str);
2229  
2230         list_for_each_entry (hc, _name_buckets + h, name_list)
2231 -               if (!strcmp(hc->name, str)) {
2232 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
2233 +                       !strcmp(hc->name, str)) {
2234                         dm_get(hc->md);
2235                         return hc;
2236                 }
2237 @@ -114,7 +116,8 @@ static struct hash_cell *__get_uuid_cell
2238         unsigned int h = hash_str(str);
2239  
2240         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
2241 -               if (!strcmp(hc->uuid, str)) {
2242 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
2243 +                       !strcmp(hc->uuid, str)) {
2244                         dm_get(hc->md);
2245                         return hc;
2246                 }
2247 @@ -351,6 +354,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
2248  
2249  static int remove_all(struct dm_ioctl *param, size_t param_size)
2250  {
2251 +       if (!vx_check(0, VS_ADMIN))
2252 +               return -EPERM;
2253 +
2254         dm_hash_remove_all(1);
2255         param->data_size = 0;
2256         return 0;
2257 @@ -398,6 +404,8 @@ static int list_devices(struct dm_ioctl 
2258          */
2259         for (i = 0; i < NUM_BUCKETS; i++) {
2260                 list_for_each_entry (hc, _name_buckets + i, name_list) {
2261 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
2262 +                               continue;
2263                         needed += sizeof(struct dm_name_list);
2264                         needed += strlen(hc->name) + 1;
2265                         needed += ALIGN_MASK;
2266 @@ -421,6 +429,8 @@ static int list_devices(struct dm_ioctl 
2267          */
2268         for (i = 0; i < NUM_BUCKETS; i++) {
2269                 list_for_each_entry (hc, _name_buckets + i, name_list) {
2270 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
2271 +                               continue;
2272                         if (old_nl)
2273                                 old_nl->next = (uint32_t) ((void *) nl -
2274                                                            (void *) old_nl);
2275 @@ -611,10 +621,11 @@ static struct hash_cell *__find_device_h
2276         if (!md)
2277                 goto out;
2278  
2279 -       mdptr = dm_get_mdptr(md);
2280 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
2281 +               mdptr = dm_get_mdptr(md);
2282 +
2283         if (!mdptr)
2284                 dm_put(md);
2285 -
2286  out:
2287         return mdptr;
2288  }
2289 @@ -1407,8 +1418,8 @@ static int ctl_ioctl(struct inode *inode
2290         ioctl_fn fn = NULL;
2291         size_t param_size;
2292  
2293 -       /* only root can play with this */
2294 -       if (!capable(CAP_SYS_ADMIN))
2295 +       /* only root and certain contexts can play with this */
2296 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
2297                 return -EACCES;
2298  
2299         if (_IOC_TYPE(command) != DM_IOCTL)
2300 diff -NurpP --minimal linux-2.6.24-rc7/drivers/md/dm.c linux-2.6.24-rc7-vs2.2.0.5.0.7/drivers/md/dm.c
2301 --- linux-2.6.24-rc7/drivers/md/dm.c    2007-12-31 17:58:18 +0100
2302 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/drivers/md/dm.c      2007-12-31 12:34:20 +0100
2303 @@ -22,6 +22,7 @@
2304  #include <linux/hdreg.h>
2305  #include <linux/blktrace_api.h>
2306  #include <linux/smp_lock.h>
2307 +#include <linux/vs_base.h>
2308  
2309  #define DM_MSG_PREFIX "core"
2310  
2311 @@ -78,6 +79,7 @@ struct mapped_device {
2312         rwlock_t map_lock;
2313         atomic_t holders;
2314         atomic_t open_count;
2315 +       xid_t xid;
2316  
2317         unsigned long flags;
2318  
2319 @@ -232,6 +234,7 @@ static void __exit dm_exit(void)
2320  static int dm_blk_open(struct inode *inode, struct file *file)
2321  {
2322         struct mapped_device *md;
2323 +       int ret = -ENXIO;
2324  
2325         spin_lock(&_minor_lock);
2326  
2327 @@ -240,18 +243,19 @@ static int dm_blk_open(struct inode *ino
2328                 goto out;
2329  
2330         if (test_bit(DMF_FREEING, &md->flags) ||
2331 -           test_bit(DMF_DELETING, &md->flags)) {
2332 -               md = NULL;
2333 +           test_bit(DMF_DELETING, &md->flags))
2334 +               goto out;
2335 +
2336 +       ret = -EACCES;
2337 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
2338                 goto out;
2339 -       }
2340  
2341         dm_get(md);
2342         atomic_inc(&md->open_count);
2343 -
2344 +       ret = 0;
2345  out:
2346         spin_unlock(&_minor_lock);
2347 -
2348 -       return md ? 0 : -ENXIO;
2349 +       return ret;
2350  }
2351  
2352  static int dm_blk_close(struct inode *inode, struct file *file)
2353 @@ -447,6 +451,14 @@ int dm_set_geometry(struct mapped_device
2354         return 0;
2355  }
2356  
2357 +/*
2358 + * Get the xid associated with a dm device
2359 + */
2360 +xid_t dm_get_xid(struct mapped_device *md)
2361 +{
2362 +       return md->xid;
2363 +}
2364 +
2365  /*-----------------------------------------------------------------
2366   * CRUD START:
2367   *   A more elegant soln is in the works that uses the queue
2368 @@ -1004,6 +1016,7 @@ static struct mapped_device *alloc_dev(i
2369         INIT_LIST_HEAD(&md->uevent_list);
2370         spin_lock_init(&md->uevent_lock);
2371  
2372 +       md->xid = vx_current_xid();
2373         md->queue = blk_alloc_queue(GFP_KERNEL);
2374         if (!md->queue)
2375                 goto bad1_free_minor;
2376 diff -NurpP --minimal linux-2.6.24-rc7/drivers/md/dm.h linux-2.6.24-rc7-vs2.2.0.5.0.7/drivers/md/dm.h
2377 --- linux-2.6.24-rc7/drivers/md/dm.h    2007-12-31 17:58:18 +0100
2378 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/drivers/md/dm.h      2007-12-31 12:34:20 +0100
2379 @@ -127,6 +127,8 @@ void dm_put_target_type(struct target_ty
2380  int dm_target_iterate(void (*iter_func)(struct target_type *tt,
2381                                         void *param), void *param);
2382  
2383 +xid_t dm_get_xid(struct mapped_device *md);
2384 +
2385  /*-----------------------------------------------------------------
2386   * Useful inlines.
2387   *---------------------------------------------------------------*/
2388 diff -NurpP --minimal linux-2.6.24-rc7/fs/attr.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/attr.c
2389 --- linux-2.6.24-rc7/fs/attr.c  2007-11-29 01:11:47 +0100
2390 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/attr.c    2007-12-13 13:25:40 +0100
2391 @@ -14,6 +14,9 @@
2392  #include <linux/fcntl.h>
2393  #include <linux/quotaops.h>
2394  #include <linux/security.h>
2395 +#include <linux/proc_fs.h>
2396 +#include <linux/devpts_fs.h>
2397 +#include <linux/vs_base.h>
2398  
2399  /* Taken over from the old code... */
2400  
2401 @@ -55,6 +58,27 @@ int inode_change_ok(struct inode *inode,
2402                 if (!is_owner_or_cap(inode))
2403                         goto error;
2404         }
2405 +
2406 +       /* Check for evil vserver activity */
2407 +       if (vx_check(0, VS_ADMIN))
2408 +               goto fine;
2409 +
2410 +       if (IS_BARRIER(inode)) {
2411 +               vxwprintk_task(1, "messing with the barrier.");
2412 +               goto error;
2413 +       }
2414 +       switch (inode->i_sb->s_magic) {
2415 +               case PROC_SUPER_MAGIC:
2416 +                       /* maybe allow that in the future? */
2417 +                       vxwprintk_task(1, "messing with the procfs.");
2418 +                       goto error;
2419 +               case DEVPTS_SUPER_MAGIC:
2420 +                       /* devpts is xid tagged */
2421 +                       if (vx_check((xid_t)inode->i_tag, VS_IDENT))
2422 +                               goto fine;
2423 +                       vxwprintk_task(1, "messing with the devpts.");
2424 +                       goto error;
2425 +       }
2426  fine:
2427         retval = 0;
2428  error:
2429 @@ -78,6 +102,8 @@ int inode_setattr(struct inode * inode, 
2430                 inode->i_uid = attr->ia_uid;
2431         if (ia_valid & ATTR_GID)
2432                 inode->i_gid = attr->ia_gid;
2433 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2434 +               inode->i_tag = attr->ia_tag;
2435         if (ia_valid & ATTR_ATIME)
2436                 inode->i_atime = timespec_trunc(attr->ia_atime,
2437                                                 inode->i_sb->s_time_gran);
2438 @@ -167,7 +193,8 @@ int notify_change(struct dentry * dentry
2439                         error = security_inode_setattr(dentry, attr);
2440                 if (!error) {
2441                         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
2442 -                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
2443 +                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
2444 +                           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag))
2445                                 error = DQUOT_TRANSFER(inode, attr) ? -EDQUOT : 0;
2446                         if (!error)
2447                                 error = inode_setattr(inode, attr);
2448 diff -NurpP --minimal linux-2.6.24-rc7/fs/binfmt_aout.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/binfmt_aout.c
2449 --- linux-2.6.24-rc7/fs/binfmt_aout.c   2007-12-31 17:58:24 +0100
2450 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/binfmt_aout.c     2007-12-31 12:34:39 +0100
2451 @@ -24,6 +24,7 @@
2452  #include <linux/binfmts.h>
2453  #include <linux/personality.h>
2454  #include <linux/init.h>
2455 +#include <linux/vs_memory.h>
2456  
2457  #include <asm/system.h>
2458  #include <asm/uaccess.h>
2459 diff -NurpP --minimal linux-2.6.24-rc7/fs/binfmt_elf.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/binfmt_elf.c
2460 --- linux-2.6.24-rc7/fs/binfmt_elf.c    2007-11-29 01:11:48 +0100
2461 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/binfmt_elf.c      2007-12-13 13:25:11 +0100
2462 @@ -39,6 +39,7 @@
2463  #include <linux/random.h>
2464  #include <linux/elf.h>
2465  #include <linux/utsname.h>
2466 +#include <linux/vs_memory.h>
2467  #include <asm/uaccess.h>
2468  #include <asm/param.h>
2469  #include <asm/page.h>
2470 diff -NurpP --minimal linux-2.6.24-rc7/fs/binfmt_flat.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/binfmt_flat.c
2471 --- linux-2.6.24-rc7/fs/binfmt_flat.c   2007-11-29 01:11:48 +0100
2472 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/binfmt_flat.c     2007-12-13 13:25:11 +0100
2473 @@ -36,6 +36,7 @@
2474  #include <linux/init.h>
2475  #include <linux/flat.h>
2476  #include <linux/syscalls.h>
2477 +#include <linux/vs_memory.h>
2478  
2479  #include <asm/byteorder.h>
2480  #include <asm/system.h>
2481 diff -NurpP --minimal linux-2.6.24-rc7/fs/binfmt_som.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/binfmt_som.c
2482 --- linux-2.6.24-rc7/fs/binfmt_som.c    2007-11-29 01:11:48 +0100
2483 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/binfmt_som.c      2007-12-13 13:25:11 +0100
2484 @@ -28,6 +28,7 @@
2485  #include <linux/shm.h>
2486  #include <linux/personality.h>
2487  #include <linux/init.h>
2488 +#include <linux/vs_memory.h>
2489  
2490  #include <asm/a.out.h>
2491  #include <asm/uaccess.h>
2492 diff -NurpP --minimal linux-2.6.24-rc7/fs/dcache.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/dcache.c
2493 --- linux-2.6.24-rc7/fs/dcache.c        2007-11-29 01:11:48 +0100
2494 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/dcache.c  2007-12-13 13:25:42 +0100
2495 @@ -31,6 +31,7 @@
2496  #include <linux/seqlock.h>
2497  #include <linux/swap.h>
2498  #include <linux/bootmem.h>
2499 +#include <linux/vs_limit.h>
2500  #include "internal.h"
2501  
2502  
2503 @@ -176,6 +177,7 @@ void dput(struct dentry *dentry)
2504         if (!dentry)
2505                 return;
2506  
2507 +       vx_dentry_dec(dentry);
2508  repeat:
2509         if (atomic_read(&dentry->d_count) == 1)
2510                 might_sleep();
2511 @@ -189,6 +191,8 @@ repeat:
2512                 return;
2513         }
2514  
2515 +       vx_dentry_dec(dentry);
2516 +
2517         /*
2518          * AV: ->d_delete() is _NOT_ allowed to block now.
2519          */
2520 @@ -288,6 +292,7 @@ static inline struct dentry * __dget_loc
2521         if (!list_empty(&dentry->d_lru)) {
2522                 dentry_stat.nr_unused--;
2523                 list_del_init(&dentry->d_lru);
2524 +               vx_dentry_inc(dentry);
2525         }
2526         return dentry;
2527  }
2528 @@ -899,6 +904,9 @@ struct dentry *d_alloc(struct dentry * p
2529         struct dentry *dentry;
2530         char *dname;
2531  
2532 +       if (!vx_dentry_avail(1))
2533 +               return NULL;
2534 +
2535         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2536         if (!dentry)
2537                 return NULL;
2538 @@ -947,6 +955,7 @@ struct dentry *d_alloc(struct dentry * p
2539         if (parent)
2540                 list_add(&dentry->d_u.d_child, &parent->d_subdirs);
2541         dentry_stat.nr_dentry++;
2542 +       vx_dentry_inc(dentry);
2543         spin_unlock(&dcache_lock);
2544  
2545         return dentry;
2546 @@ -1296,6 +1305,7 @@ struct dentry * __d_lookup(struct dentry
2547  
2548                 if (!d_unhashed(dentry)) {
2549                         atomic_inc(&dentry->d_count);
2550 +                       vx_dentry_inc(dentry);
2551                         found = dentry;
2552                 }
2553                 spin_unlock(&dentry->d_lock);
2554 diff -NurpP --minimal linux-2.6.24-rc7/fs/devpts/inode.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/devpts/inode.c
2555 --- linux-2.6.24-rc7/fs/devpts/inode.c  2007-07-09 13:19:23 +0200
2556 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/devpts/inode.c    2007-12-13 13:25:30 +0100
2557 @@ -20,8 +20,22 @@
2558  #include <linux/devpts_fs.h>
2559  #include <linux/parser.h>
2560  #include <linux/fsnotify.h>
2561 +#include <linux/vs_base.h>
2562  
2563 -#define DEVPTS_SUPER_MAGIC 0x1cd1
2564 +
2565 +static int devpts_permission(struct inode *inode, int mask, struct nameidata *nd)
2566 +{
2567 +       int ret = -EACCES;
2568 +
2569 +       /* devpts is xid tagged */
2570 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2571 +               ret = generic_permission(inode, mask, NULL);
2572 +       return ret;
2573 +}
2574 +
2575 +static struct inode_operations devpts_file_inode_operations = {
2576 +       .permission     = devpts_permission,
2577 +};
2578  
2579  static struct vfsmount *devpts_mnt;
2580  static struct dentry *devpts_root;
2581 @@ -92,6 +106,25 @@ static int devpts_remount(struct super_b
2582         return 0;
2583  }
2584  
2585 +static int devpts_filter(struct dentry *de)
2586 +{
2587 +       /* devpts is xid tagged */
2588 +       return vx_check((xid_t)de->d_inode->i_tag, VS_WATCH_P | VS_IDENT);
2589 +}
2590 +
2591 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2592 +{
2593 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2594 +}
2595 +
2596 +static struct file_operations devpts_dir_operations = {
2597 +       .open           = dcache_dir_open,
2598 +       .release        = dcache_dir_close,
2599 +       .llseek         = dcache_dir_lseek,
2600 +       .read           = generic_read_dir,
2601 +       .readdir        = devpts_readdir,
2602 +};
2603 +
2604  static const struct super_operations devpts_sops = {
2605         .statfs         = simple_statfs,
2606         .remount_fs     = devpts_remount,
2607 @@ -117,8 +150,10 @@ devpts_fill_super(struct super_block *s,
2608         inode->i_uid = inode->i_gid = 0;
2609         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2610         inode->i_op = &simple_dir_inode_operations;
2611 -       inode->i_fop = &simple_dir_operations;
2612 +       inode->i_fop = &devpts_dir_operations;
2613         inode->i_nlink = 2;
2614 +       /* devpts is xid tagged */
2615 +       inode->i_tag = (tag_t)vx_current_xid();
2616  
2617         devpts_root = s->s_root = d_alloc_root(inode);
2618         if (s->s_root)
2619 @@ -176,6 +211,9 @@ int devpts_pty_new(struct tty_struct *tt
2620         inode->i_gid = config.setgid ? config.gid : current->fsgid;
2621         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2622         init_special_inode(inode, S_IFCHR|config.mode, device);
2623 +       /* devpts is xid tagged */
2624 +       inode->i_tag = (tag_t)vx_current_xid();
2625 +       inode->i_op = &devpts_file_inode_operations;
2626         inode->i_private = tty;
2627  
2628         dentry = get_node(number);
2629 diff -NurpP --minimal linux-2.6.24-rc7/fs/ecryptfs/inode.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ecryptfs/inode.c
2630 --- linux-2.6.24-rc7/fs/ecryptfs/inode.c        2007-11-29 01:11:49 +0100
2631 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ecryptfs/inode.c  2007-12-13 13:25:47 +0100
2632 @@ -414,7 +414,7 @@ static int ecryptfs_link(struct dentry *
2633         dget(lower_new_dentry);
2634         lower_dir_dentry = lock_parent(lower_new_dentry);
2635         rc = vfs_link(lower_old_dentry, lower_dir_dentry->d_inode,
2636 -                     lower_new_dentry);
2637 +                     lower_new_dentry, NULL);
2638         if (rc || !lower_new_dentry->d_inode)
2639                 goto out_lock;
2640         rc = ecryptfs_interpose(lower_new_dentry, new_dentry, dir->i_sb, 0);
2641 @@ -442,7 +442,7 @@ static int ecryptfs_unlink(struct inode 
2642         struct inode *lower_dir_inode = ecryptfs_inode_to_lower(dir);
2643  
2644         lock_parent(lower_dentry);
2645 -       rc = vfs_unlink(lower_dir_inode, lower_dentry);
2646 +       rc = vfs_unlink(lower_dir_inode, lower_dentry, NULL);
2647         if (rc) {
2648                 printk(KERN_ERR "Error in vfs_unlink; rc = [%d]\n", rc);
2649                 goto out_unlock;
2650 @@ -479,7 +479,7 @@ static int ecryptfs_symlink(struct inode
2651                 goto out_lock;
2652         }
2653         rc = vfs_symlink(lower_dir_dentry->d_inode, lower_dentry,
2654 -                        encoded_symname, mode);
2655 +                        encoded_symname, mode, NULL);
2656         kfree(encoded_symname);
2657         if (rc || !lower_dentry->d_inode)
2658                 goto out_lock;
2659 @@ -504,7 +504,7 @@ static int ecryptfs_mkdir(struct inode *
2660  
2661         lower_dentry = ecryptfs_dentry_to_lower(dentry);
2662         lower_dir_dentry = lock_parent(lower_dentry);
2663 -       rc = vfs_mkdir(lower_dir_dentry->d_inode, lower_dentry, mode);
2664 +       rc = vfs_mkdir(lower_dir_dentry->d_inode, lower_dentry, mode, NULL);
2665         if (rc || !lower_dentry->d_inode)
2666                 goto out;
2667         rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0);
2668 @@ -530,7 +530,7 @@ static int ecryptfs_rmdir(struct inode *
2669         dget(dentry);
2670         lower_dir_dentry = lock_parent(lower_dentry);
2671         dget(lower_dentry);
2672 -       rc = vfs_rmdir(lower_dir_dentry->d_inode, lower_dentry);
2673 +       rc = vfs_rmdir(lower_dir_dentry->d_inode, lower_dentry, NULL);
2674         dput(lower_dentry);
2675         if (!rc)
2676                 d_delete(lower_dentry);
2677 @@ -552,7 +552,7 @@ ecryptfs_mknod(struct inode *dir, struct
2678  
2679         lower_dentry = ecryptfs_dentry_to_lower(dentry);
2680         lower_dir_dentry = lock_parent(lower_dentry);
2681 -       rc = vfs_mknod(lower_dir_dentry->d_inode, lower_dentry, mode, dev);
2682 +       rc = vfs_mknod(lower_dir_dentry->d_inode, lower_dentry, mode, dev, NULL);
2683         if (rc || !lower_dentry->d_inode)
2684                 goto out;
2685         rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0);
2686 diff -NurpP --minimal linux-2.6.24-rc7/fs/exec.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/exec.c
2687 --- linux-2.6.24-rc7/fs/exec.c  2007-12-31 17:58:24 +0100
2688 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/exec.c    2007-12-31 12:34:39 +0100
2689 @@ -241,7 +241,9 @@ static int __bprm_mm_init(struct linux_b
2690                 goto err;
2691         }
2692  
2693 -       mm->stack_vm = mm->total_vm = 1;
2694 +       mm->total_vm = 0;
2695 +       vx_vmpages_inc(mm);
2696 +       mm->stack_vm = 1;
2697         up_write(&mm->mmap_sem);
2698  
2699         bprm->p = vma->vm_end - sizeof(void *);
2700 @@ -1465,7 +1467,7 @@ static int format_corename(char *corenam
2701                         /* UNIX time of coredump */
2702                         case 't': {
2703                                 struct timeval tv;
2704 -                               do_gettimeofday(&tv);
2705 +                               vx_gettimeofday(&tv);
2706                                 rc = snprintf(out_ptr, out_end - out_ptr,
2707                                               "%lu", tv.tv_sec);
2708                                 if (rc > out_end - out_ptr)
2709 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext2/balloc.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext2/balloc.c
2710 --- linux-2.6.24-rc7/fs/ext2/balloc.c   2007-11-29 01:11:49 +0100
2711 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext2/balloc.c     2007-12-13 16:31:05 +0100
2712 @@ -16,6 +16,8 @@
2713  #include <linux/sched.h>
2714  #include <linux/buffer_head.h>
2715  #include <linux/capability.h>
2716 +#include <linux/vs_dlimit.h>
2717 +#include <linux/vs_tag.h>
2718  
2719  /*
2720   * balloc.c contains the blocks allocation and deallocation routines
2721 @@ -504,6 +506,7 @@ do_more:
2722         }
2723  error_return:
2724         brelse(bitmap_bh);
2725 +       DLIMIT_FREE_BLOCK(inode, freed);
2726         release_blocks(sb, freed);
2727         DQUOT_FREE_BLOCK(inode, freed);
2728  }
2729 @@ -636,7 +639,6 @@ ext2_try_to_allocate(struct super_block 
2730                         start = 0;
2731                 end = EXT2_BLOCKS_PER_GROUP(sb);
2732         }
2733 -
2734         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2735  
2736  repeat:
2737 @@ -1186,6 +1188,11 @@ ext2_fsblk_t ext2_new_blocks(struct inod
2738                 *errp = -EDQUOT;
2739                 return 0;
2740         }
2741 +       if (DLIMIT_ALLOC_BLOCK(inode, num)) {
2742 +               *errp = -ENOSPC;
2743 +               DQUOT_FREE_BLOCK(inode, num);
2744 +               return 0;
2745 +       }
2746  
2747         sbi = EXT2_SB(sb);
2748         es = EXT2_SB(sb)->s_es;
2749 @@ -1336,6 +1343,7 @@ allocated:
2750  
2751         *errp = 0;
2752         brelse(bitmap_bh);
2753 +       DLIMIT_FREE_BLOCK(inode, *count-num);
2754         DQUOT_FREE_BLOCK(inode, *count-num);
2755         *count = num;
2756         return ret_block;
2757 @@ -1346,8 +1354,10 @@ out:
2758         /*
2759          * Undo the block allocation
2760          */
2761 -       if (!performed_allocation)
2762 +       if (!performed_allocation) {
2763 +               DLIMIT_FREE_BLOCK(inode, *count);
2764                 DQUOT_FREE_BLOCK(inode, *count);
2765 +       }
2766         brelse(bitmap_bh);
2767         return 0;
2768  }
2769 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext2/ext2.h linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext2/ext2.h
2770 --- linux-2.6.24-rc7/fs/ext2/ext2.h     2007-12-31 17:58:24 +0100
2771 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext2/ext2.h       2007-12-31 12:34:39 +0100
2772 @@ -170,6 +170,7 @@ extern const struct file_operations ext2
2773  extern const struct address_space_operations ext2_aops;
2774  extern const struct address_space_operations ext2_aops_xip;
2775  extern const struct address_space_operations ext2_nobh_aops;
2776 +extern int ext2_sync_flags(struct inode *inode);
2777  
2778  /* namei.c */
2779  extern const struct inode_operations ext2_dir_inode_operations;
2780 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext2/file.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext2/file.c
2781 --- linux-2.6.24-rc7/fs/ext2/file.c     2007-11-29 01:11:49 +0100
2782 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext2/file.c       2007-12-13 13:25:39 +0100
2783 @@ -86,4 +86,5 @@ const struct inode_operations ext2_file_
2784  #endif
2785         .setattr        = ext2_setattr,
2786         .permission     = ext2_permission,
2787 +       .sync_flags     = ext2_sync_flags,
2788  };
2789 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext2/ialloc.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext2/ialloc.c
2790 --- linux-2.6.24-rc7/fs/ext2/ialloc.c   2007-11-29 01:11:49 +0100
2791 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext2/ialloc.c     2007-12-13 13:25:46 +0100
2792 @@ -17,6 +17,8 @@
2793  #include <linux/backing-dev.h>
2794  #include <linux/buffer_head.h>
2795  #include <linux/random.h>
2796 +#include <linux/vs_dlimit.h>
2797 +#include <linux/vs_tag.h>
2798  #include "ext2.h"
2799  #include "xattr.h"
2800  #include "acl.h"
2801 @@ -125,6 +127,7 @@ void ext2_free_inode (struct inode * ino
2802                 ext2_xattr_delete_inode(inode);
2803                 DQUOT_FREE_INODE(inode);
2804                 DQUOT_DROP(inode);
2805 +               DLIMIT_FREE_INODE(inode);
2806         }
2807  
2808         es = EXT2_SB(sb)->s_es;
2809 @@ -456,6 +459,11 @@ struct inode *ext2_new_inode(struct inod
2810         if (!inode)
2811                 return ERR_PTR(-ENOMEM);
2812  
2813 +       inode->i_tag = dx_current_fstag(sb);
2814 +       if (DLIMIT_ALLOC_INODE(inode)) {
2815 +               err = -ENOSPC;
2816 +               goto fail_dlim;
2817 +       }
2818         ei = EXT2_I(inode);
2819         sbi = EXT2_SB(sb);
2820         es = sbi->s_es;
2821 @@ -569,7 +577,8 @@ got:
2822         inode->i_blocks = 0;
2823         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
2824         memset(ei->i_data, 0, sizeof(ei->i_data));
2825 -       ei->i_flags = EXT2_I(dir)->i_flags & ~EXT2_BTREE_FL;
2826 +       ei->i_flags = EXT2_I(dir)->i_flags &
2827 +               ~(EXT2_BTREE_FL|EXT2_IUNLINK_FL|EXT2_BARRIER_FL);
2828         if (S_ISLNK(mode))
2829                 ei->i_flags &= ~(EXT2_IMMUTABLE_FL|EXT2_APPEND_FL);
2830         /* dirsync is only applied to directories */
2831 @@ -614,12 +623,15 @@ fail_free_drop:
2832  
2833  fail_drop:
2834         DQUOT_DROP(inode);
2835 +       DLIMIT_FREE_INODE(inode);
2836         inode->i_flags |= S_NOQUOTA;
2837         inode->i_nlink = 0;
2838         iput(inode);
2839         return ERR_PTR(err);
2840  
2841  fail:
2842 +       DLIMIT_FREE_INODE(inode);
2843 +fail_dlim:
2844         make_bad_inode(inode);
2845         iput(inode);
2846         return ERR_PTR(err);
2847 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext2/inode.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext2/inode.c
2848 --- linux-2.6.24-rc7/fs/ext2/inode.c    2007-11-29 01:11:49 +0100
2849 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext2/inode.c      2007-12-13 13:25:40 +0100
2850 @@ -31,6 +31,7 @@
2851  #include <linux/writeback.h>
2852  #include <linux/buffer_head.h>
2853  #include <linux/mpage.h>
2854 +#include <linux/vs_tag.h>
2855  #include "ext2.h"
2856  #include "acl.h"
2857  #include "xip.h"
2858 @@ -1015,7 +1016,7 @@ void ext2_truncate(struct inode *inode)
2859                 return;
2860         if (ext2_inode_is_fast_symlink(inode))
2861                 return;
2862 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2863 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2864                 return;
2865  
2866         blocksize = inode->i_sb->s_blocksize;
2867 @@ -1153,13 +1154,20 @@ void ext2_set_inode_flags(struct inode *
2868  {
2869         unsigned int flags = EXT2_I(inode)->i_flags;
2870  
2871 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2872 +       inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
2873 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2874 +
2875 +       if (flags & EXT2_IMMUTABLE_FL)
2876 +               inode->i_flags |= S_IMMUTABLE;
2877 +       if (flags & EXT2_IUNLINK_FL)
2878 +               inode->i_flags |= S_IUNLINK;
2879 +       if (flags & EXT2_BARRIER_FL)
2880 +               inode->i_flags |= S_BARRIER;
2881 +
2882         if (flags & EXT2_SYNC_FL)
2883                 inode->i_flags |= S_SYNC;
2884         if (flags & EXT2_APPEND_FL)
2885                 inode->i_flags |= S_APPEND;
2886 -       if (flags & EXT2_IMMUTABLE_FL)
2887 -               inode->i_flags |= S_IMMUTABLE;
2888         if (flags & EXT2_NOATIME_FL)
2889                 inode->i_flags |= S_NOATIME;
2890         if (flags & EXT2_DIRSYNC_FL)
2891 @@ -1185,12 +1193,37 @@ void ext2_get_inode_flags(struct ext2_in
2892                 ei->i_flags |= EXT2_DIRSYNC_FL;
2893  }
2894  
2895 +int ext2_sync_flags(struct inode *inode)
2896 +{
2897 +       unsigned int oldflags, newflags;
2898 +
2899 +       oldflags = EXT2_I(inode)->i_flags;
2900 +       newflags = oldflags & ~(EXT2_IMMUTABLE_FL |
2901 +               EXT2_IUNLINK_FL | EXT2_BARRIER_FL);
2902 +
2903 +       if (IS_IMMUTABLE(inode))
2904 +               newflags |= EXT2_IMMUTABLE_FL;
2905 +       if (IS_IUNLINK(inode))
2906 +               newflags |= EXT2_IUNLINK_FL;
2907 +       if (IS_BARRIER(inode))
2908 +               newflags |= EXT2_BARRIER_FL;
2909 +
2910 +       if (oldflags ^ newflags) {
2911 +               EXT2_I(inode)->i_flags = newflags;
2912 +               inode->i_ctime = CURRENT_TIME;
2913 +               mark_inode_dirty(inode);
2914 +       }
2915 +       return 0;
2916 +}
2917 +
2918  void ext2_read_inode (struct inode * inode)
2919  {
2920         struct ext2_inode_info *ei = EXT2_I(inode);
2921         ino_t ino = inode->i_ino;
2922         struct buffer_head * bh;
2923         struct ext2_inode * raw_inode = ext2_get_inode(inode->i_sb, ino, &bh);
2924 +       uid_t uid;
2925 +       gid_t gid;
2926         int n;
2927  
2928  #ifdef CONFIG_EXT2_FS_POSIX_ACL
2929 @@ -1203,12 +1236,17 @@ void ext2_read_inode (struct inode * ino
2930                 goto bad_inode;
2931  
2932         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2933 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2934 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2935 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2936 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2937         if (!(test_opt (inode->i_sb, NO_UID32))) {
2938 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2939 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2940 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2941 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2942         }
2943 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2944 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2945 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2946 +               le16_to_cpu(raw_inode->i_raw_tag));
2947 +
2948         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2949         inode->i_size = le32_to_cpu(raw_inode->i_size);
2950         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2951 @@ -1302,8 +1340,8 @@ static int ext2_update_inode(struct inod
2952         struct ext2_inode_info *ei = EXT2_I(inode);
2953         struct super_block *sb = inode->i_sb;
2954         ino_t ino = inode->i_ino;
2955 -       uid_t uid = inode->i_uid;
2956 -       gid_t gid = inode->i_gid;
2957 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2958 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2959         struct buffer_head * bh;
2960         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2961         int n;
2962 @@ -1339,6 +1377,9 @@ static int ext2_update_inode(struct inod
2963                 raw_inode->i_uid_high = 0;
2964                 raw_inode->i_gid_high = 0;
2965         }
2966 +#ifdef CONFIG_TAGGING_INTERN
2967 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2968 +#endif
2969         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2970         raw_inode->i_size = cpu_to_le32(inode->i_size);
2971         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2972 @@ -1425,7 +1466,8 @@ int ext2_setattr(struct dentry *dentry, 
2973         if (error)
2974                 return error;
2975         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2976 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2977 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2978 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2979                 error = DQUOT_TRANSFER(inode, iattr) ? -EDQUOT : 0;
2980                 if (error)
2981                         return error;
2982 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext2/ioctl.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext2/ioctl.c
2983 --- linux-2.6.24-rc7/fs/ext2/ioctl.c    2007-11-29 01:11:49 +0100
2984 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext2/ioctl.c      2007-12-13 13:25:47 +0100
2985 @@ -13,6 +13,7 @@
2986  #include <linux/sched.h>
2987  #include <linux/compat.h>
2988  #include <linux/smp_lock.h>
2989 +#include <linux/mount.h>
2990  #include <asm/current.h>
2991  #include <asm/uaccess.h>
2992  
2993 @@ -34,7 +35,8 @@ int ext2_ioctl (struct inode * inode, st
2994         case EXT2_IOC_SETFLAGS: {
2995                 unsigned int oldflags;
2996  
2997 -               if (IS_RDONLY(inode))
2998 +               if (IS_RDONLY(inode) ||
2999 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
3000                         return -EROFS;
3001  
3002                 if (!is_owner_or_cap(inode))
3003 @@ -60,7 +62,9 @@ int ext2_ioctl (struct inode * inode, st
3004                  *
3005                  * This test looks nicer. Thanks to Pauline Middelink
3006                  */
3007 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
3008 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
3009 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
3010 +                       EXT2_IMMUTABLE_FL | EXT2_IUNLINK_FL))) {
3011                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3012                                 mutex_unlock(&inode->i_mutex);
3013                                 return -EPERM;
3014 @@ -82,7 +86,8 @@ int ext2_ioctl (struct inode * inode, st
3015         case EXT2_IOC_SETVERSION:
3016                 if (!is_owner_or_cap(inode))
3017                         return -EPERM;
3018 -               if (IS_RDONLY(inode))
3019 +               if (IS_RDONLY(inode) ||
3020 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
3021                         return -EROFS;
3022                 if (get_user(inode->i_generation, (int __user *) arg))
3023                         return -EFAULT; 
3024 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext2/namei.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext2/namei.c
3025 --- linux-2.6.24-rc7/fs/ext2/namei.c    2007-05-02 19:25:17 +0200
3026 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext2/namei.c      2007-12-13 13:25:41 +0100
3027 @@ -31,6 +31,7 @@
3028   */
3029  
3030  #include <linux/pagemap.h>
3031 +#include <linux/vs_tag.h>
3032  #include "ext2.h"
3033  #include "xattr.h"
3034  #include "acl.h"
3035 @@ -66,6 +67,7 @@ static struct dentry *ext2_lookup(struct
3036                 inode = iget(dir->i_sb, ino);
3037                 if (!inode)
3038                         return ERR_PTR(-EACCES);
3039 +               dx_propagate_tag(nd, inode);
3040         }
3041         return d_splice_alias(inode, dentry);
3042  }
3043 @@ -391,6 +393,7 @@ const struct inode_operations ext2_dir_i
3044  #endif
3045         .setattr        = ext2_setattr,
3046         .permission     = ext2_permission,
3047 +       .sync_flags     = ext2_sync_flags,
3048  };
3049  
3050  const struct inode_operations ext2_special_inode_operations = {
3051 @@ -402,4 +405,5 @@ const struct inode_operations ext2_speci
3052  #endif
3053         .setattr        = ext2_setattr,
3054         .permission     = ext2_permission,
3055 +       .sync_flags     = ext2_sync_flags,
3056  };
3057 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext2/super.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext2/super.c
3058 --- linux-2.6.24-rc7/fs/ext2/super.c    2007-11-29 01:11:49 +0100
3059 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext2/super.c      2007-12-13 13:25:38 +0100
3060 @@ -389,7 +389,8 @@ enum {
3061         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
3062         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
3063         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
3064 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
3065 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
3066 +       Opt_tag, Opt_notag, Opt_tagid
3067  };
3068  
3069  static match_table_t tokens = {
3070 @@ -417,6 +418,10 @@ static match_table_t tokens = {
3071         {Opt_acl, "acl"},
3072         {Opt_noacl, "noacl"},
3073         {Opt_xip, "xip"},
3074 +       {Opt_tag, "tag"},
3075 +       {Opt_notag, "notag"},
3076 +       {Opt_tagid, "tagid=%u"},
3077 +       {Opt_tag, "tagxid"},
3078         {Opt_grpquota, "grpquota"},
3079         {Opt_ignore, "noquota"},
3080         {Opt_quota, "quota"},
3081 @@ -487,6 +492,20 @@ static int parse_options (char * options
3082                 case Opt_nouid32:
3083                         set_opt (sbi->s_mount_opt, NO_UID32);
3084                         break;
3085 +#ifndef CONFIG_TAGGING_NONE
3086 +               case Opt_tag:
3087 +                       set_opt (sbi->s_mount_opt, TAGGED);
3088 +                       break;
3089 +               case Opt_notag:
3090 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3091 +                       break;
3092 +#endif
3093 +#ifdef CONFIG_PROPAGATE
3094 +               case Opt_tagid:
3095 +                       /* use args[0] */
3096 +                       set_opt (sbi->s_mount_opt, TAGGED);
3097 +                       break;
3098 +#endif
3099                 case Opt_nocheck:
3100                         clear_opt (sbi->s_mount_opt, CHECK);
3101                         break;
3102 @@ -809,6 +828,8 @@ static int ext2_fill_super(struct super_
3103         if (!parse_options ((char *) data, sbi))
3104                 goto failed_mount;
3105  
3106 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
3107 +               sb->s_flags |= MS_TAGGED;
3108         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3109                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
3110                  MS_POSIXACL : 0);
3111 @@ -1138,6 +1159,13 @@ static int ext2_remount (struct super_bl
3112                 goto restore_opts;
3113         }
3114  
3115 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
3116 +               !(sb->s_flags & MS_TAGGED)) {
3117 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
3118 +                      sb->s_id);
3119 +               return -EINVAL;
3120 +       }
3121 +
3122         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3123                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3124  
3125 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext2/symlink.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext2/symlink.c
3126 --- linux-2.6.24-rc7/fs/ext2/symlink.c  2007-05-02 19:25:17 +0200
3127 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext2/symlink.c    2007-12-13 13:25:39 +0100
3128 @@ -38,6 +38,7 @@ const struct inode_operations ext2_symli
3129         .listxattr      = ext2_listxattr,
3130         .removexattr    = generic_removexattr,
3131  #endif
3132 +       .sync_flags     = ext2_sync_flags,
3133  };
3134   
3135  const struct inode_operations ext2_fast_symlink_inode_operations = {
3136 @@ -49,4 +50,5 @@ const struct inode_operations ext2_fast_
3137         .listxattr      = ext2_listxattr,
3138         .removexattr    = generic_removexattr,
3139  #endif
3140 +       .sync_flags     = ext2_sync_flags,
3141  };
3142 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext2/xattr.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext2/xattr.c
3143 --- linux-2.6.24-rc7/fs/ext2/xattr.c    2007-11-29 01:11:49 +0100
3144 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext2/xattr.c      2007-12-13 13:25:46 +0100
3145 @@ -60,6 +60,7 @@
3146  #include <linux/mbcache.h>
3147  #include <linux/quotaops.h>
3148  #include <linux/rwsem.h>
3149 +#include <linux/vs_dlimit.h>
3150  #include "ext2.h"
3151  #include "xattr.h"
3152  #include "acl.h"
3153 @@ -641,8 +642,12 @@ ext2_xattr_set2(struct inode *inode, str
3154                                    the inode.  */
3155                                 ea_bdebug(new_bh, "reusing block");
3156  
3157 +                               error = -ENOSPC;
3158 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
3159 +                                       goto cleanup;
3160                                 error = -EDQUOT;
3161                                 if (DQUOT_ALLOC_BLOCK(inode, 1)) {
3162 +                                       DLIMIT_FREE_BLOCK(inode, 1);
3163                                         unlock_buffer(new_bh);
3164                                         goto cleanup;
3165                                 }
3166 @@ -735,6 +740,7 @@ ext2_xattr_set2(struct inode *inode, str
3167                                 le32_to_cpu(HDR(old_bh)->h_refcount) - 1);
3168                         if (ce)
3169                                 mb_cache_entry_release(ce);
3170 +                       DLIMIT_FREE_BLOCK(inode, 1);
3171                         DQUOT_FREE_BLOCK(inode, 1);
3172                         mark_buffer_dirty(old_bh);
3173                         ea_bdebug(old_bh, "refcount now=%d",
3174 @@ -799,6 +805,7 @@ ext2_xattr_delete_inode(struct inode *in
3175                 mark_buffer_dirty(bh);
3176                 if (IS_SYNC(inode))
3177                         sync_dirty_buffer(bh);
3178 +               DLIMIT_FREE_BLOCK(inode, 1);
3179                 DQUOT_FREE_BLOCK(inode, 1);
3180         }
3181         EXT2_I(inode)->i_file_acl = 0;
3182 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext3/balloc.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext3/balloc.c
3183 --- linux-2.6.24-rc7/fs/ext3/balloc.c   2007-11-29 01:11:49 +0100
3184 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext3/balloc.c     2007-12-13 13:25:46 +0100
3185 @@ -19,6 +19,8 @@
3186  #include <linux/ext3_jbd.h>
3187  #include <linux/quotaops.h>
3188  #include <linux/buffer_head.h>
3189 +#include <linux/vs_dlimit.h>
3190 +#include <linux/vs_tag.h>
3191  
3192  /*
3193   * balloc.c contains the blocks allocation and deallocation routines
3194 @@ -613,8 +615,10 @@ void ext3_free_blocks(handle_t *handle, 
3195                 return;
3196         }
3197         ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
3198 -       if (dquot_freed_blocks)
3199 +       if (dquot_freed_blocks) {
3200 +               DLIMIT_FREE_BLOCK(inode, dquot_freed_blocks);
3201                 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
3202 +       }
3203         return;
3204  }
3205  
3206 @@ -1353,18 +1357,33 @@ out:
3207   *
3208   * Check if filesystem has at least 1 free block available for allocation.
3209   */
3210 -static int ext3_has_free_blocks(struct ext3_sb_info *sbi)
3211 +static int ext3_has_free_blocks(struct super_block *sb)
3212  {
3213 -       ext3_fsblk_t free_blocks, root_blocks;
3214 +       struct ext3_sb_info *sbi = EXT3_SB(sb);
3215 +       unsigned long long free_blocks, root_blocks;
3216 +       int cond;
3217  
3218         free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
3219         root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
3220 -       if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
3221 +
3222 +       vxdprintk(VXD_CBIT(dlim, 3),
3223 +               "ext3_has_free_blocks(%p): free=%llu, root=%llu",
3224 +               sb, free_blocks, root_blocks);
3225 +
3226 +       DLIMIT_ADJUST_BLOCK(sb, dx_current_tag(), &free_blocks, &root_blocks);
3227 +
3228 +       cond = (free_blocks < root_blocks + 1 &&
3229 +               !capable(CAP_SYS_RESOURCE) &&
3230                 sbi->s_resuid != current->fsuid &&
3231 -               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
3232 -               return 0;
3233 -       }
3234 -       return 1;
3235 +               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)));
3236 +
3237 +       vxdprintk(VXD_CBIT(dlim, 3),
3238 +               "ext3_has_free_blocks(%p): %llu<%llu+1, %c, %u!=%u r=%d",
3239 +               sb, free_blocks, root_blocks,
3240 +               !capable(CAP_SYS_RESOURCE)?'1':'0',
3241 +               sbi->s_resuid, current->fsuid, cond?0:1);
3242 +
3243 +       return (cond ? 0 : 1);
3244  }
3245  
3246  /**
3247 @@ -1381,7 +1400,7 @@ static int ext3_has_free_blocks(struct e
3248   */
3249  int ext3_should_retry_alloc(struct super_block *sb, int *retries)
3250  {
3251 -       if (!ext3_has_free_blocks(EXT3_SB(sb)) || (*retries)++ > 3)
3252 +       if (!ext3_has_free_blocks(sb) || (*retries)++ > 3)
3253                 return 0;
3254  
3255         jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id);
3256 @@ -1444,6 +1463,8 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
3257                 *errp = -EDQUOT;
3258                 return 0;
3259         }
3260 +       if (DLIMIT_ALLOC_BLOCK(inode, num))
3261 +           goto out_dlimit;
3262  
3263         sbi = EXT3_SB(sb);
3264         es = EXT3_SB(sb)->s_es;
3265 @@ -1460,7 +1481,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
3266         if (block_i && ((windowsz = block_i->rsv_window_node.rsv_goal_size) > 0))
3267                 my_rsv = &block_i->rsv_window_node;
3268  
3269 -       if (!ext3_has_free_blocks(sbi)) {
3270 +       if (!ext3_has_free_blocks(sb)) {
3271                 *errp = -ENOSPC;
3272                 goto out;
3273         }
3274 @@ -1647,12 +1668,16 @@ allocated:
3275         *errp = 0;
3276         brelse(bitmap_bh);
3277         DQUOT_FREE_BLOCK(inode, *count-num);
3278 +       DLIMIT_FREE_BLOCK(inode, *count-num);
3279         *count = num;
3280         return ret_block;
3281  
3282  io_error:
3283         *errp = -EIO;
3284  out:
3285 +       if (!performed_allocation)
3286 +               DLIMIT_FREE_BLOCK(inode, *count);
3287 +out_dlimit:
3288         if (fatal) {
3289                 *errp = fatal;
3290                 ext3_std_error(sb, fatal);
3291 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext3/file.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext3/file.c
3292 --- linux-2.6.24-rc7/fs/ext3/file.c     2007-11-29 01:01:52 +0100
3293 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext3/file.c       2007-12-13 13:25:39 +0100
3294 @@ -134,5 +134,6 @@ const struct inode_operations ext3_file_
3295         .removexattr    = generic_removexattr,
3296  #endif
3297         .permission     = ext3_permission,
3298 +       .sync_flags     = ext3_sync_flags,
3299  };
3300  
3301 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext3/ialloc.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext3/ialloc.c
3302 --- linux-2.6.24-rc7/fs/ext3/ialloc.c   2007-11-29 01:11:49 +0100
3303 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext3/ialloc.c     2007-12-13 13:25:46 +0100
3304 @@ -23,6 +23,8 @@
3305  #include <linux/buffer_head.h>
3306  #include <linux/random.h>
3307  #include <linux/bitops.h>
3308 +#include <linux/vs_dlimit.h>
3309 +#include <linux/vs_tag.h>
3310  
3311  #include <asm/byteorder.h>
3312  
3313 @@ -127,6 +129,7 @@ void ext3_free_inode (handle_t *handle, 
3314         ext3_xattr_delete_inode(handle, inode);
3315         DQUOT_FREE_INODE(inode);
3316         DQUOT_DROP(inode);
3317 +       DLIMIT_FREE_INODE(inode);
3318  
3319         is_directory = S_ISDIR(inode->i_mode);
3320  
3321 @@ -442,6 +445,12 @@ struct inode *ext3_new_inode(handle_t *h
3322         inode = new_inode(sb);
3323         if (!inode)
3324                 return ERR_PTR(-ENOMEM);
3325 +
3326 +       inode->i_tag = dx_current_fstag(sb);
3327 +       if (DLIMIT_ALLOC_INODE(inode)) {
3328 +               err = -ENOSPC;
3329 +               goto out_dlimit;
3330 +       }
3331         ei = EXT3_I(inode);
3332  
3333         sbi = EXT3_SB(sb);
3334 @@ -563,7 +572,8 @@ got:
3335         ei->i_dir_start_lookup = 0;
3336         ei->i_disksize = 0;
3337  
3338 -       ei->i_flags = EXT3_I(dir)->i_flags & ~EXT3_INDEX_FL;
3339 +       ei->i_flags = EXT3_I(dir)->i_flags &
3340 +               ~(EXT3_INDEX_FL|EXT3_IUNLINK_FL|EXT3_BARRIER_FL);
3341         if (S_ISLNK(mode))
3342                 ei->i_flags &= ~(EXT3_IMMUTABLE_FL|EXT3_APPEND_FL);
3343         /* dirsync only applies to directories */
3344 @@ -618,6 +628,8 @@ got:
3345  fail:
3346         ext3_std_error(sb, err);
3347  out:
3348 +       DLIMIT_FREE_INODE(inode);
3349 +out_dlimit:
3350         iput(inode);
3351         ret = ERR_PTR(err);
3352  really_out:
3353 @@ -629,6 +641,7 @@ fail_free_drop:
3354  
3355  fail_drop:
3356         DQUOT_DROP(inode);
3357 +       DLIMIT_FREE_INODE(inode);
3358         inode->i_flags |= S_NOQUOTA;
3359         inode->i_nlink = 0;
3360         iput(inode);
3361 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext3/inode.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext3/inode.c
3362 --- linux-2.6.24-rc7/fs/ext3/inode.c    2007-11-29 01:11:49 +0100
3363 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext3/inode.c      2007-12-13 13:25:40 +0100
3364 @@ -36,6 +36,7 @@
3365  #include <linux/mpage.h>
3366  #include <linux/uio.h>
3367  #include <linux/bio.h>
3368 +#include <linux/vs_tag.h>
3369  #include "xattr.h"
3370  #include "acl.h"
3371  
3372 @@ -2304,7 +2305,7 @@ void ext3_truncate(struct inode *inode)
3373                 return;
3374         if (ext3_inode_is_fast_symlink(inode))
3375                 return;
3376 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3377 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3378                 return;
3379  
3380         /*
3381 @@ -2626,13 +2627,20 @@ void ext3_set_inode_flags(struct inode *
3382  {
3383         unsigned int flags = EXT3_I(inode)->i_flags;
3384  
3385 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3386 +       inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
3387 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3388 +
3389 +       if (flags & EXT3_IMMUTABLE_FL)
3390 +               inode->i_flags |= S_IMMUTABLE;
3391 +       if (flags & EXT3_IUNLINK_FL)
3392 +               inode->i_flags |= S_IUNLINK;
3393 +       if (flags & EXT3_BARRIER_FL)
3394 +               inode->i_flags |= S_BARRIER;
3395 +
3396         if (flags & EXT3_SYNC_FL)
3397                 inode->i_flags |= S_SYNC;
3398         if (flags & EXT3_APPEND_FL)
3399                 inode->i_flags |= S_APPEND;
3400 -       if (flags & EXT3_IMMUTABLE_FL)
3401 -               inode->i_flags |= S_IMMUTABLE;
3402         if (flags & EXT3_NOATIME_FL)
3403                 inode->i_flags |= S_NOATIME;
3404         if (flags & EXT3_DIRSYNC_FL)
3405 @@ -2658,6 +2666,45 @@ void ext3_get_inode_flags(struct ext3_in
3406                 ei->i_flags |= EXT3_DIRSYNC_FL;
3407  }
3408  
3409 +int ext3_sync_flags(struct inode *inode)
3410 +{
3411 +       unsigned int oldflags, newflags;
3412 +       int err = 0;
3413 +
3414 +       oldflags = EXT3_I(inode)->i_flags;
3415 +       newflags = oldflags & ~(EXT3_IMMUTABLE_FL |
3416 +               EXT3_IUNLINK_FL | EXT3_BARRIER_FL);
3417 +
3418 +       if (IS_IMMUTABLE(inode))
3419 +               newflags |= EXT3_IMMUTABLE_FL;
3420 +       if (IS_IUNLINK(inode))
3421 +               newflags |= EXT3_IUNLINK_FL;
3422 +       if (IS_BARRIER(inode))
3423 +               newflags |= EXT3_BARRIER_FL;
3424 +
3425 +       if (oldflags ^ newflags) {
3426 +               handle_t *handle;
3427 +               struct ext3_iloc iloc;
3428 +
3429 +               handle = ext3_journal_start(inode, 1);
3430 +               if (IS_ERR(handle))
3431 +                       return PTR_ERR(handle);
3432 +               if (IS_SYNC(inode))
3433 +                       handle->h_sync = 1;
3434 +               err = ext3_reserve_inode_write(handle, inode, &iloc);
3435 +               if (err)
3436 +                       goto flags_err;
3437 +
3438 +               EXT3_I(inode)->i_flags = newflags;
3439 +               inode->i_ctime = CURRENT_TIME;
3440 +
3441 +               err = ext3_mark_iloc_dirty(handle, inode, &iloc);
3442 +       flags_err:
3443 +               ext3_journal_stop(handle);
3444 +       }
3445 +       return err;
3446 +}
3447 +
3448  void ext3_read_inode(struct inode * inode)
3449  {
3450         struct ext3_iloc iloc;
3451 @@ -2665,6 +2712,8 @@ void ext3_read_inode(struct inode * inod
3452         struct ext3_inode_info *ei = EXT3_I(inode);
3453         struct buffer_head *bh;
3454         int block;
3455 +       uid_t uid;
3456 +       gid_t gid;
3457  
3458  #ifdef CONFIG_EXT3_FS_POSIX_ACL
3459         ei->i_acl = EXT3_ACL_NOT_CACHED;
3460 @@ -2677,12 +2726,17 @@ void ext3_read_inode(struct inode * inod
3461         bh = iloc.bh;
3462         raw_inode = ext3_raw_inode(&iloc);
3463         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3464 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3465 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3466 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3467 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3468         if(!(test_opt (inode->i_sb, NO_UID32))) {
3469 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3470 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3471 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3472 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3473         }
3474 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3475 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3476 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3477 +               le16_to_cpu(raw_inode->i_raw_tag));
3478 +
3479         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3480         inode->i_size = le32_to_cpu(raw_inode->i_size);
3481         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3482 @@ -2808,6 +2862,8 @@ static int ext3_do_update_inode(handle_t
3483         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
3484         struct ext3_inode_info *ei = EXT3_I(inode);
3485         struct buffer_head *bh = iloc->bh;
3486 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3487 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3488         int err = 0, rc, block;
3489  
3490         /* For fields not not tracking in the in-memory inode,
3491 @@ -2818,29 +2874,32 @@ static int ext3_do_update_inode(handle_t
3492         ext3_get_inode_flags(ei);
3493         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3494         if(!(test_opt(inode->i_sb, NO_UID32))) {
3495 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3496 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3497 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3498 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3499  /*
3500   * Fix up interoperability with old kernels. Otherwise, old inodes get
3501   * re-used with the upper 16 bits of the uid/gid intact
3502   */
3503                 if(!ei->i_dtime) {
3504                         raw_inode->i_uid_high =
3505 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3506 +                               cpu_to_le16(high_16_bits(uid));
3507                         raw_inode->i_gid_high =
3508 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3509 +                               cpu_to_le16(high_16_bits(gid));
3510                 } else {
3511                         raw_inode->i_uid_high = 0;
3512                         raw_inode->i_gid_high = 0;
3513                 }
3514         } else {
3515                 raw_inode->i_uid_low =
3516 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3517 +                       cpu_to_le16(fs_high2lowuid(uid));
3518                 raw_inode->i_gid_low =
3519 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3520 +                       cpu_to_le16(fs_high2lowgid(gid));
3521                 raw_inode->i_uid_high = 0;
3522                 raw_inode->i_gid_high = 0;
3523         }
3524 +#ifdef CONFIG_TAGGING_INTERN
3525 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3526 +#endif
3527         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3528         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
3529         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3530 @@ -2993,7 +3052,8 @@ int ext3_setattr(struct dentry *dentry, 
3531                 return error;
3532  
3533         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3534 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3535 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3536 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3537                 handle_t *handle;
3538  
3539                 /* (user+group)*(old+new) structure, inode write (sb,
3540 @@ -3015,6 +3075,8 @@ int ext3_setattr(struct dentry *dentry, 
3541                         inode->i_uid = attr->ia_uid;
3542                 if (attr->ia_valid & ATTR_GID)
3543                         inode->i_gid = attr->ia_gid;
3544 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3545 +                       inode->i_tag = attr->ia_tag;
3546                 error = ext3_mark_inode_dirty(handle, inode);
3547                 ext3_journal_stop(handle);
3548         }
3549 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext3/ioctl.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext3/ioctl.c
3550 --- linux-2.6.24-rc7/fs/ext3/ioctl.c    2007-11-29 01:11:49 +0100
3551 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext3/ioctl.c      2007-12-13 13:25:52 +0100
3552 @@ -8,6 +8,7 @@
3553   */
3554  
3555  #include <linux/fs.h>
3556 +#include <linux/mount.h>
3557  #include <linux/jbd.h>
3558  #include <linux/capability.h>
3559  #include <linux/ext3_fs.h>
3560 @@ -15,6 +16,7 @@
3561  #include <linux/time.h>
3562  #include <linux/compat.h>
3563  #include <linux/smp_lock.h>
3564 +#include <linux/vs_tag.h>
3565  #include <asm/uaccess.h>
3566  
3567  int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
3568 @@ -38,7 +40,8 @@ int ext3_ioctl (struct inode * inode, st
3569                 unsigned int oldflags;
3570                 unsigned int jflag;
3571  
3572 -               if (IS_RDONLY(inode))
3573 +               if (IS_RDONLY(inode) ||
3574 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
3575                         return -EROFS;
3576  
3577                 if (!is_owner_or_cap(inode))
3578 @@ -67,7 +70,9 @@ int ext3_ioctl (struct inode * inode, st
3579                  *
3580                  * This test looks nicer. Thanks to Pauline Middelink
3581                  */
3582 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
3583 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
3584 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
3585 +                       EXT3_IMMUTABLE_FL | EXT3_IUNLINK_FL))) {
3586                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3587                                 mutex_unlock(&inode->i_mutex);
3588                                 return -EPERM;
3589 @@ -129,7 +134,8 @@ flags_err:
3590  
3591                 if (!is_owner_or_cap(inode))
3592                         return -EPERM;
3593 -               if (IS_RDONLY(inode))
3594 +               if (IS_RDONLY(inode) ||
3595 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
3596                         return -EROFS;
3597                 if (get_user(generation, (int __user *) arg))
3598                         return -EFAULT;
3599 @@ -183,7 +189,8 @@ flags_err:
3600                 if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode))
3601                         return -ENOTTY;
3602  
3603 -               if (IS_RDONLY(inode))
3604 +               if (IS_RDONLY(inode) ||
3605 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
3606                         return -EROFS;
3607  
3608                 if (!is_owner_or_cap(inode))
3609 @@ -218,7 +225,8 @@ flags_err:
3610                 if (!capable(CAP_SYS_RESOURCE))
3611                         return -EPERM;
3612  
3613 -               if (IS_RDONLY(inode))
3614 +               if (IS_RDONLY(inode) ||
3615 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
3616                         return -EROFS;
3617  
3618                 if (get_user(n_blocks_count, (__u32 __user *)arg))
3619 @@ -239,7 +247,8 @@ flags_err:
3620                 if (!capable(CAP_SYS_RESOURCE))
3621                         return -EPERM;
3622  
3623 -               if (IS_RDONLY(inode))
3624 +               if (IS_RDONLY(inode) ||
3625 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
3626                         return -EROFS;
3627  
3628                 if (copy_from_user(&input, (struct ext3_new_group_input __user *)arg,
3629 @@ -254,6 +263,38 @@ flags_err:
3630                 return err;
3631         }
3632  
3633 +#if defined(CONFIG_VSERVER_LEGACY) && !defined(CONFIG_TAGGING_NONE)
3634 +       case EXT3_IOC_SETTAG: {
3635 +               handle_t *handle;
3636 +               struct ext3_iloc iloc;
3637 +               int tag;
3638 +               int err;
3639 +
3640 +               /* fixme: if stealth, return -ENOTTY */
3641 +               if (!capable(CAP_CONTEXT))
3642 +                       return -EPERM;
3643 +               if (IS_RDONLY(inode))
3644 +                       return -EROFS;
3645 +               if (!(inode->i_sb->s_flags & MS_TAGGED))
3646 +                       return -ENOSYS;
3647 +               if (get_user(tag, (int __user *) arg))
3648 +                       return -EFAULT;
3649 +
3650 +               handle = ext3_journal_start(inode, 1);
3651 +               if (IS_ERR(handle))
3652 +                       return PTR_ERR(handle);
3653 +               err = ext3_reserve_inode_write(handle, inode, &iloc);
3654 +               if (err)
3655 +                       return err;
3656 +
3657 +               inode->i_tag = (tag & 0xFFFF);
3658 +               inode->i_ctime = CURRENT_TIME;
3659 +
3660 +               err = ext3_mark_iloc_dirty(handle, inode, &iloc);
3661 +               ext3_journal_stop(handle);
3662 +               return err;
3663 +       }
3664 +#endif
3665  
3666         default:
3667                 return -ENOTTY;
3668 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext3/namei.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext3/namei.c
3669 --- linux-2.6.24-rc7/fs/ext3/namei.c    2007-11-29 01:11:49 +0100
3670 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext3/namei.c      2007-12-13 13:25:41 +0100
3671 @@ -36,6 +36,7 @@
3672  #include <linux/quotaops.h>
3673  #include <linux/buffer_head.h>
3674  #include <linux/bio.h>
3675 +#include <linux/vs_tag.h>
3676  
3677  #include "namei.h"
3678  #include "xattr.h"
3679 @@ -1052,6 +1053,7 @@ static struct dentry *ext3_lookup(struct
3680                         iput(inode);
3681                         return ERR_PTR(-ENOENT);
3682                 }
3683 +               dx_propagate_tag(nd, inode);
3684         }
3685         return d_splice_alias(inode, dentry);
3686  }
3687 @@ -2432,6 +2434,7 @@ const struct inode_operations ext3_dir_i
3688         .removexattr    = generic_removexattr,
3689  #endif
3690         .permission     = ext3_permission,
3691 +       .sync_flags     = ext3_sync_flags,
3692  };
3693  
3694  const struct inode_operations ext3_special_inode_operations = {
3695 @@ -2443,4 +2446,5 @@ const struct inode_operations ext3_speci
3696         .removexattr    = generic_removexattr,
3697  #endif
3698         .permission     = ext3_permission,
3699 +       .sync_flags     = ext3_sync_flags,
3700  };
3701 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext3/super.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext3/super.c
3702 --- linux-2.6.24-rc7/fs/ext3/super.c    2007-12-31 17:58:24 +0100
3703 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext3/super.c      2007-12-31 12:34:39 +0100
3704 @@ -758,7 +758,7 @@ enum {
3705         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
3706         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
3707         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
3708 -       Opt_grpquota
3709 +       Opt_grpquota, Opt_tag, Opt_notag, Opt_tagid
3710  };
3711  
3712  static match_table_t tokens = {
3713 @@ -808,6 +808,10 @@ static match_table_t tokens = {
3714         {Opt_quota, "quota"},
3715         {Opt_usrquota, "usrquota"},
3716         {Opt_barrier, "barrier=%u"},
3717 +       {Opt_tag, "tag"},
3718 +       {Opt_notag, "notag"},
3719 +       {Opt_tagid, "tagid=%u"},
3720 +       {Opt_tag, "tagxid"},
3721         {Opt_err, NULL},
3722         {Opt_resize, "resize"},
3723  };
3724 @@ -901,6 +905,20 @@ static int parse_options (char *options,
3725                 case Opt_nouid32:
3726                         set_opt (sbi->s_mount_opt, NO_UID32);
3727                         break;
3728 +#ifndef CONFIG_TAGGING_NONE
3729 +               case Opt_tag:
3730 +                       set_opt (sbi->s_mount_opt, TAGGED);
3731 +                       break;
3732 +               case Opt_notag:
3733 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3734 +                       break;
3735 +#endif
3736 +#ifdef CONFIG_PROPAGATE
3737 +               case Opt_tagid:
3738 +                       /* use args[0] */
3739 +                       set_opt (sbi->s_mount_opt, TAGGED);
3740 +                       break;
3741 +#endif
3742                 case Opt_nocheck:
3743                         clear_opt (sbi->s_mount_opt, CHECK);
3744                         break;
3745 @@ -1573,6 +1591,9 @@ static int ext3_fill_super (struct super
3746                             NULL, 0))
3747                 goto failed_mount;
3748  
3749 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
3750 +               sb->s_flags |= MS_TAGGED;
3751 +
3752         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3753                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3754  
3755 @@ -2405,6 +2426,12 @@ static int ext3_remount (struct super_bl
3756  
3757         if (sbi->s_mount_opt & EXT3_MOUNT_ABORT)
3758                 ext3_abort(sb, __FUNCTION__, "Abort forced by user");
3759 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
3760 +               !(sb->s_flags & MS_TAGGED)) {
3761 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
3762 +                       sb->s_id);
3763 +               return -EINVAL;
3764 +       }
3765  
3766         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3767                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3768 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext3/symlink.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext3/symlink.c
3769 --- linux-2.6.24-rc7/fs/ext3/symlink.c  2007-05-02 19:25:17 +0200
3770 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext3/symlink.c    2007-12-13 13:25:39 +0100
3771 @@ -40,6 +40,7 @@ const struct inode_operations ext3_symli
3772         .listxattr      = ext3_listxattr,
3773         .removexattr    = generic_removexattr,
3774  #endif
3775 +       .sync_flags     = ext3_sync_flags,
3776  };
3777  
3778  const struct inode_operations ext3_fast_symlink_inode_operations = {
3779 @@ -51,4 +52,5 @@ const struct inode_operations ext3_fast_
3780         .listxattr      = ext3_listxattr,
3781         .removexattr    = generic_removexattr,
3782  #endif
3783 +       .sync_flags     = ext3_sync_flags,
3784  };
3785 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext3/xattr.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext3/xattr.c
3786 --- linux-2.6.24-rc7/fs/ext3/xattr.c    2007-11-29 01:11:49 +0100
3787 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext3/xattr.c      2007-12-13 13:25:46 +0100
3788 @@ -58,6 +58,7 @@
3789  #include <linux/mbcache.h>
3790  #include <linux/quotaops.h>
3791  #include <linux/rwsem.h>
3792 +#include <linux/vs_dlimit.h>
3793  #include "xattr.h"
3794  #include "acl.h"
3795  
3796 @@ -497,6 +498,7 @@ ext3_xattr_release_block(handle_t *handl
3797                 error = ext3_journal_dirty_metadata(handle, bh);
3798                 if (IS_SYNC(inode))
3799                         handle->h_sync = 1;
3800 +                       DLIMIT_FREE_BLOCK(inode, 1);
3801                 DQUOT_FREE_BLOCK(inode, 1);
3802                 ea_bdebug(bh, "refcount now=%d; releasing",
3803                           le32_to_cpu(BHDR(bh)->h_refcount));
3804 @@ -770,11 +772,14 @@ inserted:
3805                         if (new_bh == bs->bh)
3806                                 ea_bdebug(new_bh, "keeping");
3807                         else {
3808 +                               error = -ENOSPC;
3809 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
3810 +                                       goto cleanup;
3811                                 /* The old block is released after updating
3812                                    the inode. */
3813                                 error = -EDQUOT;
3814                                 if (DQUOT_ALLOC_BLOCK(inode, 1))
3815 -                                       goto cleanup;
3816 +                                       goto cleanup_dlimit;
3817                                 error = ext3_journal_get_write_access(handle,
3818                                                                       new_bh);
3819                                 if (error)
3820 @@ -851,6 +856,8 @@ cleanup:
3821  
3822  cleanup_dquot:
3823         DQUOT_FREE_BLOCK(inode, 1);
3824 +cleanup_dlimit:
3825 +       DLIMIT_FREE_BLOCK(inode, 1);
3826         goto cleanup;
3827  
3828  bad_block:
3829 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext4/balloc.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext4/balloc.c
3830 --- linux-2.6.24-rc7/fs/ext4/balloc.c   2007-11-29 01:11:49 +0100
3831 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext4/balloc.c     2007-12-13 13:25:46 +0100
3832 @@ -19,6 +19,8 @@
3833  #include <linux/ext4_jbd2.h>
3834  #include <linux/quotaops.h>
3835  #include <linux/buffer_head.h>
3836 +#include <linux/vs_dlimit.h>
3837 +#include <linux/vs_tag.h>
3838  
3839  #include "group.h"
3840  /*
3841 @@ -733,8 +735,10 @@ void ext4_free_blocks(handle_t *handle, 
3842                 return;
3843         }
3844         ext4_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
3845 -       if (dquot_freed_blocks)
3846 +       if (dquot_freed_blocks) {
3847 +               DLIMIT_FREE_BLOCK(inode, dquot_freed_blocks);
3848                 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
3849 +       }
3850         return;
3851  }
3852  
3853 @@ -1473,18 +1477,33 @@ out:
3854   *
3855   * Check if filesystem has at least 1 free block available for allocation.
3856   */
3857 -static int ext4_has_free_blocks(struct ext4_sb_info *sbi)
3858 +static int ext4_has_free_blocks(struct super_block *sb)
3859  {
3860 +       struct ext4_sb_info *sbi = EXT4_SB(sb);
3861         ext4_fsblk_t free_blocks, root_blocks;
3862 +       int cond;
3863  
3864         free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
3865         root_blocks = ext4_r_blocks_count(sbi->s_es);
3866 -       if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
3867 +
3868 +       vxdprintk(VXD_CBIT(dlim, 3),
3869 +               "ext4_has_free_blocks(%p): free=%llu, root=%llu",
3870 +               sb, free_blocks, root_blocks);
3871 +
3872 +       DLIMIT_ADJUST_BLOCK(sb, dx_current_tag(), &free_blocks, &root_blocks);
3873 +
3874 +       cond = (free_blocks < root_blocks + 1 &&
3875 +               !capable(CAP_SYS_RESOURCE) &&
3876                 sbi->s_resuid != current->fsuid &&
3877 -               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
3878 -               return 0;
3879 -       }
3880 -       return 1;
3881 +               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)));
3882 +
3883 +       vxdprintk(VXD_CBIT(dlim, 3),
3884 +               "ext4_has_free_blocks(%p): %llu<%llu+1, %c, %u!=%u r=%d",
3885 +               sb, free_blocks, root_blocks,
3886 +               !capable(CAP_SYS_RESOURCE)?'1':'0',
3887 +               sbi->s_resuid, current->fsuid, cond?0:1);
3888 +
3889 +       return (cond ? 0 : 1);
3890  }
3891  
3892  /**
3893 @@ -1501,7 +1520,7 @@ static int ext4_has_free_blocks(struct e
3894   */
3895  int ext4_should_retry_alloc(struct super_block *sb, int *retries)
3896  {
3897 -       if (!ext4_has_free_blocks(EXT4_SB(sb)) || (*retries)++ > 3)
3898 +       if (!ext4_has_free_blocks(sb) || (*retries)++ > 3)
3899                 return 0;
3900  
3901         jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id);
3902 @@ -1564,6 +1583,8 @@ ext4_fsblk_t ext4_new_blocks(handle_t *h
3903                 *errp = -EDQUOT;
3904                 return 0;
3905         }
3906 +       if (DLIMIT_ALLOC_BLOCK(inode, num))
3907 +           goto out_dlimit;
3908  
3909         sbi = EXT4_SB(sb);
3910         es = EXT4_SB(sb)->s_es;
3911 @@ -1580,7 +1601,7 @@ ext4_fsblk_t ext4_new_blocks(handle_t *h
3912         if (block_i && ((windowsz = block_i->rsv_window_node.rsv_goal_size) > 0))
3913                 my_rsv = &block_i->rsv_window_node;
3914  
3915 -       if (!ext4_has_free_blocks(sbi)) {
3916 +       if (!ext4_has_free_blocks(sb)) {
3917                 *errp = -ENOSPC;
3918                 goto out;
3919         }
3920 @@ -1767,12 +1788,16 @@ allocated:
3921         *errp = 0;
3922         brelse(bitmap_bh);
3923         DQUOT_FREE_BLOCK(inode, *count-num);
3924 +       DLIMIT_FREE_BLOCK(inode, *count-num);
3925         *count = num;
3926         return ret_block;
3927  
3928  io_error:
3929         *errp = -EIO;
3930  out:
3931 +       if (!performed_allocation)
3932 +               DLIMIT_FREE_BLOCK(inode, *count);
3933 +out_dlimit:
3934         if (fatal) {
3935                 *errp = fatal;
3936                 ext4_std_error(sb, fatal);
3937 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext4/file.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext4/file.c
3938 --- linux-2.6.24-rc7/fs/ext4/file.c     2007-11-29 01:01:52 +0100
3939 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext4/file.c       2007-12-13 13:25:39 +0100
3940 @@ -135,5 +135,6 @@ const struct inode_operations ext4_file_
3941  #endif
3942         .permission     = ext4_permission,
3943         .fallocate      = ext4_fallocate,
3944 +       .sync_flags     = ext4_sync_flags,
3945  };
3946  
3947 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext4/ialloc.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext4/ialloc.c
3948 --- linux-2.6.24-rc7/fs/ext4/ialloc.c   2007-11-29 01:11:50 +0100
3949 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext4/ialloc.c     2007-12-13 13:25:46 +0100
3950 @@ -24,6 +24,8 @@
3951  #include <linux/random.h>
3952  #include <linux/bitops.h>
3953  #include <linux/blkdev.h>
3954 +#include <linux/vs_dlimit.h>
3955 +#include <linux/vs_tag.h>
3956  #include <asm/byteorder.h>
3957  
3958  #include "xattr.h"
3959 @@ -186,6 +188,7 @@ void ext4_free_inode (handle_t *handle, 
3960         ext4_xattr_delete_inode(handle, inode);
3961         DQUOT_FREE_INODE(inode);
3962         DQUOT_DROP(inode);
3963 +       DLIMIT_FREE_INODE(inode);
3964  
3965         is_directory = S_ISDIR(inode->i_mode);
3966  
3967 @@ -506,6 +509,12 @@ struct inode *ext4_new_inode(handle_t *h
3968         inode = new_inode(sb);
3969         if (!inode)
3970                 return ERR_PTR(-ENOMEM);
3971 +
3972 +       inode->i_tag = dx_current_fstag(sb);
3973 +       if (DLIMIT_ALLOC_INODE(inode)) {
3974 +               err = -ENOSPC;
3975 +               goto out_dlimit;
3976 +       }
3977         ei = EXT4_I(inode);
3978  
3979         sbi = EXT4_SB(sb);
3980 @@ -695,7 +704,8 @@ got:
3981         ei->i_dir_start_lookup = 0;
3982         ei->i_disksize = 0;
3983  
3984 -       ei->i_flags = EXT4_I(dir)->i_flags & ~EXT4_INDEX_FL;
3985 +       ei->i_flags = EXT4_I(dir)->i_flags &
3986 +               ~(EXT4_INDEX_FL|EXT4_IUNLINK_FL|EXT4_BARRIER_FL);
3987         if (S_ISLNK(mode))
3988                 ei->i_flags &= ~(EXT4_IMMUTABLE_FL|EXT4_APPEND_FL);
3989         /* dirsync only applies to directories */
3990 @@ -755,6 +765,8 @@ got:
3991  fail:
3992         ext4_std_error(sb, err);
3993  out:
3994 +       DLIMIT_FREE_INODE(inode);
3995 +out_dlimit:
3996         iput(inode);
3997         ret = ERR_PTR(err);
3998  really_out:
3999 @@ -766,6 +778,7 @@ fail_free_drop:
4000  
4001  fail_drop:
4002         DQUOT_DROP(inode);
4003 +       DLIMIT_FREE_INODE(inode);
4004         inode->i_flags |= S_NOQUOTA;
4005         inode->i_nlink = 0;
4006         iput(inode);
4007 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext4/inode.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext4/inode.c
4008 --- linux-2.6.24-rc7/fs/ext4/inode.c    2007-11-29 01:11:50 +0100
4009 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext4/inode.c      2007-12-13 13:25:40 +0100
4010 @@ -36,6 +36,7 @@
4011  #include <linux/mpage.h>
4012  #include <linux/uio.h>
4013  #include <linux/bio.h>
4014 +#include <linux/vs_tag.h>
4015  #include "xattr.h"
4016  #include "acl.h"
4017  
4018 @@ -2303,7 +2304,7 @@ void ext4_truncate(struct inode *inode)
4019                 return;
4020         if (ext4_inode_is_fast_symlink(inode))
4021                 return;
4022 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4023 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4024                 return;
4025  
4026         /*
4027 @@ -2629,13 +2630,20 @@ void ext4_set_inode_flags(struct inode *
4028  {
4029         unsigned int flags = EXT4_I(inode)->i_flags;
4030  
4031 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
4032 +       inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
4033 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4034 +
4035 +       if (flags & EXT4_IMMUTABLE_FL)
4036 +               inode->i_flags |= S_IMMUTABLE;
4037 +       if (flags & EXT4_IUNLINK_FL)
4038 +               inode->i_flags |= S_IUNLINK;
4039 +       if (flags & EXT4_BARRIER_FL)
4040 +               inode->i_flags |= S_BARRIER;
4041 +
4042         if (flags & EXT4_SYNC_FL)
4043                 inode->i_flags |= S_SYNC;
4044         if (flags & EXT4_APPEND_FL)
4045                 inode->i_flags |= S_APPEND;
4046 -       if (flags & EXT4_IMMUTABLE_FL)
4047 -               inode->i_flags |= S_IMMUTABLE;
4048         if (flags & EXT4_NOATIME_FL)
4049                 inode->i_flags |= S_NOATIME;
4050         if (flags & EXT4_DIRSYNC_FL)
4051 @@ -2661,6 +2669,45 @@ void ext4_get_inode_flags(struct ext4_in
4052                 ei->i_flags |= EXT4_DIRSYNC_FL;
4053  }
4054  
4055 +int ext4_sync_flags(struct inode *inode)
4056 +{
4057 +       unsigned int oldflags, newflags;
4058 +       int err = 0;
4059 +
4060 +       oldflags = EXT4_I(inode)->i_flags;
4061 +       newflags = oldflags & ~(EXT4_IMMUTABLE_FL |
4062 +               EXT4_IUNLINK_FL | EXT4_BARRIER_FL);
4063 +
4064 +       if (IS_IMMUTABLE(inode))
4065 +               newflags |= EXT4_IMMUTABLE_FL;
4066 +       if (IS_IUNLINK(inode))
4067 +               newflags |= EXT4_IUNLINK_FL;
4068 +       if (IS_BARRIER(inode))
4069 +               newflags |= EXT4_BARRIER_FL;
4070 +
4071 +       if (oldflags ^ newflags) {
4072 +               handle_t *handle;
4073 +               struct ext4_iloc iloc;
4074 +
4075 +               handle = ext4_journal_start(inode, 1);
4076 +               if (IS_ERR(handle))
4077 +                       return PTR_ERR(handle);
4078 +               if (IS_SYNC(inode))
4079 +                       handle->h_sync = 1;
4080 +               err = ext4_reserve_inode_write(handle, inode, &iloc);
4081 +               if (err)
4082 +                       goto flags_err;
4083 +
4084 +               EXT4_I(inode)->i_flags = newflags;
4085 +               inode->i_ctime = CURRENT_TIME;
4086 +
4087 +               err = ext4_mark_iloc_dirty(handle, inode, &iloc);
4088 +       flags_err:
4089 +               ext4_journal_stop(handle);
4090 +       }
4091 +       return err;
4092 +}
4093 +
4094  void ext4_read_inode(struct inode * inode)
4095  {
4096         struct ext4_iloc iloc;
4097 @@ -2668,6 +2715,8 @@ void ext4_read_inode(struct inode * inod
4098         struct ext4_inode_info *ei = EXT4_I(inode);
4099         struct buffer_head *bh;
4100         int block;
4101 +       uid_t uid;
4102 +       gid_t gid;
4103  
4104  #ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
4105         ei->i_acl = EXT4_ACL_NOT_CACHED;
4106 @@ -2680,12 +2729,17 @@ void ext4_read_inode(struct inode * inod
4107         bh = iloc.bh;
4108         raw_inode = ext4_raw_inode(&iloc);
4109         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
4110 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
4111 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
4112 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
4113 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
4114         if(!(test_opt (inode->i_sb, NO_UID32))) {
4115 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
4116 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
4117 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
4118 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
4119         }
4120 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
4121 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
4122 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
4123 +               le16_to_cpu(raw_inode->i_raw_tag));
4124 +
4125         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
4126         inode->i_size = le32_to_cpu(raw_inode->i_size);
4127  
4128 @@ -2811,6 +2865,8 @@ static int ext4_do_update_inode(handle_t
4129         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
4130         struct ext4_inode_info *ei = EXT4_I(inode);
4131         struct buffer_head *bh = iloc->bh;
4132 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
4133 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
4134         int err = 0, rc, block;
4135  
4136         /* For fields not not tracking in the in-memory inode,
4137 @@ -2821,29 +2877,32 @@ static int ext4_do_update_inode(handle_t
4138         ext4_get_inode_flags(ei);
4139         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
4140         if(!(test_opt(inode->i_sb, NO_UID32))) {
4141 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
4142 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
4143 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
4144 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
4145  /*
4146   * Fix up interoperability with old kernels. Otherwise, old inodes get
4147   * re-used with the upper 16 bits of the uid/gid intact
4148   */
4149                 if(!ei->i_dtime) {
4150                         raw_inode->i_uid_high =
4151 -                               cpu_to_le16(high_16_bits(inode->i_uid));
4152 +                               cpu_to_le16(high_16_bits(uid));
4153                         raw_inode->i_gid_high =
4154 -                               cpu_to_le16(high_16_bits(inode->i_gid));
4155 +                               cpu_to_le16(high_16_bits(gid));
4156                 } else {
4157                         raw_inode->i_uid_high = 0;
4158                         raw_inode->i_gid_high = 0;
4159                 }
4160         } else {
4161                 raw_inode->i_uid_low =
4162 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
4163 +                       cpu_to_le16(fs_high2lowuid(uid));
4164                 raw_inode->i_gid_low =
4165 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
4166 +                       cpu_to_le16(fs_high2lowgid(gid));
4167                 raw_inode->i_uid_high = 0;
4168                 raw_inode->i_gid_high = 0;
4169         }
4170 +#ifdef CONFIG_TAGGING_INTERN
4171 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
4172 +#endif
4173         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
4174         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
4175  
4176 @@ -2998,7 +3057,8 @@ int ext4_setattr(struct dentry *dentry, 
4177                 return error;
4178  
4179         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
4180 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
4181 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
4182 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
4183                 handle_t *handle;
4184  
4185                 /* (user+group)*(old+new) structure, inode write (sb,
4186 @@ -3020,6 +3080,8 @@ int ext4_setattr(struct dentry *dentry, 
4187                         inode->i_uid = attr->ia_uid;
4188                 if (attr->ia_valid & ATTR_GID)
4189                         inode->i_gid = attr->ia_gid;
4190 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
4191 +                       inode->i_tag = attr->ia_tag;
4192                 error = ext4_mark_inode_dirty(handle, inode);
4193                 ext4_journal_stop(handle);
4194         }
4195 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext4/ioctl.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext4/ioctl.c
4196 --- linux-2.6.24-rc7/fs/ext4/ioctl.c    2007-11-29 01:11:50 +0100
4197 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext4/ioctl.c      2007-12-13 13:25:52 +0100
4198 @@ -8,6 +8,7 @@
4199   */
4200  
4201  #include <linux/fs.h>
4202 +#include <linux/mount.h>
4203  #include <linux/jbd2.h>
4204  #include <linux/capability.h>
4205  #include <linux/ext4_fs.h>
4206 @@ -15,6 +16,7 @@
4207  #include <linux/time.h>
4208  #include <linux/compat.h>
4209  #include <linux/smp_lock.h>
4210 +#include <linux/vs_tag.h>
4211  #include <asm/uaccess.h>
4212  
4213  int ext4_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
4214 @@ -38,7 +40,8 @@ int ext4_ioctl (struct inode * inode, st
4215                 unsigned int oldflags;
4216                 unsigned int jflag;
4217  
4218 -               if (IS_RDONLY(inode))
4219 +               if (IS_RDONLY(inode) ||
4220 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4221                         return -EROFS;
4222  
4223                 if (!is_owner_or_cap(inode))
4224 @@ -67,7 +70,9 @@ int ext4_ioctl (struct inode * inode, st
4225                  *
4226                  * This test looks nicer. Thanks to Pauline Middelink
4227                  */
4228 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
4229 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
4230 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
4231 +                       EXT4_IMMUTABLE_FL | EXT4_IUNLINK_FL))) {
4232                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4233                                 mutex_unlock(&inode->i_mutex);
4234                                 return -EPERM;
4235 @@ -129,7 +134,8 @@ flags_err:
4236  
4237                 if (!is_owner_or_cap(inode))
4238                         return -EPERM;
4239 -               if (IS_RDONLY(inode))
4240 +               if (IS_RDONLY(inode) ||
4241 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4242                         return -EROFS;
4243                 if (get_user(generation, (int __user *) arg))
4244                         return -EFAULT;
4245 @@ -183,7 +189,8 @@ flags_err:
4246                 if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode))
4247                         return -ENOTTY;
4248  
4249 -               if (IS_RDONLY(inode))
4250 +               if (IS_RDONLY(inode) ||
4251 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4252                         return -EROFS;
4253  
4254                 if (!is_owner_or_cap(inode))
4255 @@ -218,7 +225,8 @@ flags_err:
4256                 if (!capable(CAP_SYS_RESOURCE))
4257                         return -EPERM;
4258  
4259 -               if (IS_RDONLY(inode))
4260 +               if (IS_RDONLY(inode) ||
4261 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4262                         return -EROFS;
4263  
4264                 if (get_user(n_blocks_count, (__u32 __user *)arg))
4265 @@ -239,7 +247,8 @@ flags_err:
4266                 if (!capable(CAP_SYS_RESOURCE))
4267                         return -EPERM;
4268  
4269 -               if (IS_RDONLY(inode))
4270 +               if (IS_RDONLY(inode) ||
4271 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4272                         return -EROFS;
4273  
4274                 if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg,
4275 @@ -254,6 +263,39 @@ flags_err:
4276                 return err;
4277         }
4278  
4279 +#if defined(CONFIG_VSERVER_LEGACY) && !defined(CONFIG_TAGGING_NONE)
4280 +       case EXT4_IOC_SETTAG: {
4281 +               handle_t *handle;
4282 +               struct ext4_iloc iloc;
4283 +               int tag;
4284 +               int err;
4285 +
4286 +               /* fixme: if stealth, return -ENOTTY */
4287 +               if (!capable(CAP_CONTEXT))
4288 +                       return -EPERM;
4289 +               if (IS_RDONLY(inode))
4290 +                       return -EROFS;
4291 +               if (!(inode->i_sb->s_flags & MS_TAGGED))
4292 +                       return -ENOSYS;
4293 +               if (get_user(tag, (int __user *) arg))
4294 +                       return -EFAULT;
4295 +
4296 +               handle = ext4_journal_start(inode, 1);
4297 +               if (IS_ERR(handle))
4298 +                       return PTR_ERR(handle);
4299 +               err = ext4_reserve_inode_write(handle, inode, &iloc);
4300 +               if (err)
4301 +                       return err;
4302 +
4303 +               inode->i_tag = (tag & 0xFFFF);
4304 +               inode->i_ctime = CURRENT_TIME;
4305 +
4306 +               err = ext4_mark_iloc_dirty(handle, inode, &iloc);
4307 +               ext4_journal_stop(handle);
4308 +               return err;
4309 +       }
4310 +#endif
4311 +
4312         default:
4313                 return -ENOTTY;
4314         }
4315 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext4/namei.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext4/namei.c
4316 --- linux-2.6.24-rc7/fs/ext4/namei.c    2007-11-29 01:11:50 +0100
4317 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext4/namei.c      2007-12-13 13:25:41 +0100
4318 @@ -36,6 +36,7 @@
4319  #include <linux/quotaops.h>
4320  #include <linux/buffer_head.h>
4321  #include <linux/bio.h>
4322 +#include <linux/vs_tag.h>
4323  
4324  #include "namei.h"
4325  #include "xattr.h"
4326 @@ -1048,6 +1049,7 @@ static struct dentry *ext4_lookup(struct
4327                         iput(inode);
4328                         return ERR_PTR(-ENOENT);
4329                 }
4330 +               dx_propagate_tag(nd, inode);
4331         }
4332         return d_splice_alias(inode, dentry);
4333  }
4334 @@ -2463,6 +2465,7 @@ const struct inode_operations ext4_dir_i
4335         .removexattr    = generic_removexattr,
4336  #endif
4337         .permission     = ext4_permission,
4338 +       .sync_flags     = ext4_sync_flags,
4339  };
4340  
4341  const struct inode_operations ext4_special_inode_operations = {
4342 @@ -2474,4 +2477,5 @@ const struct inode_operations ext4_speci
4343         .removexattr    = generic_removexattr,
4344  #endif
4345         .permission     = ext4_permission,
4346 +       .sync_flags     = ext4_sync_flags,
4347  };
4348 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext4/super.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext4/super.c
4349 --- linux-2.6.24-rc7/fs/ext4/super.c    2007-12-31 17:58:24 +0100
4350 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext4/super.c      2007-12-31 12:34:39 +0100
4351 @@ -814,6 +814,7 @@ enum {
4352         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
4353         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
4354         Opt_grpquota, Opt_extents, Opt_noextents,
4355 +       Opt_tag, Opt_notag, Opt_tagid
4356  };
4357  
4358  static match_table_t tokens = {
4359 @@ -865,6 +866,10 @@ static match_table_t tokens = {
4360         {Opt_barrier, "barrier=%u"},
4361         {Opt_extents, "extents"},
4362         {Opt_noextents, "noextents"},
4363 +       {Opt_tag, "tag"},
4364 +       {Opt_notag, "notag"},
4365 +       {Opt_tagid, "tagid=%u"},
4366 +       {Opt_tag, "tagxid"},
4367         {Opt_err, NULL},
4368         {Opt_resize, "resize"},
4369  };
4370 @@ -958,6 +963,20 @@ static int parse_options (char *options,
4371                 case Opt_nouid32:
4372                         set_opt (sbi->s_mount_opt, NO_UID32);
4373                         break;
4374 +#ifndef CONFIG_TAGGING_NONE
4375 +               case Opt_tag:
4376 +                       set_opt (sbi->s_mount_opt, TAGGED);
4377 +                       break;
4378 +               case Opt_notag:
4379 +                       clear_opt (sbi->s_mount_opt, TAGGED);
4380 +                       break;
4381 +#endif
4382 +#ifdef CONFIG_PROPAGATE
4383 +               case Opt_tagid:
4384 +                       /* use args[0] */
4385 +                       set_opt (sbi->s_mount_opt, TAGGED);
4386 +                       break;
4387 +#endif
4388                 case Opt_nocheck:
4389                         clear_opt (sbi->s_mount_opt, CHECK);
4390                         break;
4391 @@ -1694,6 +1713,9 @@ static int ext4_fill_super (struct super
4392                             NULL, 0))
4393                 goto failed_mount;
4394  
4395 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
4396 +               sb->s_flags |= MS_TAGGED;
4397 +
4398         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4399                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
4400  
4401 @@ -2558,6 +2580,12 @@ static int ext4_remount (struct super_bl
4402  
4403         if (sbi->s_mount_opt & EXT4_MOUNT_ABORT)
4404                 ext4_abort(sb, __FUNCTION__, "Abort forced by user");
4405 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
4406 +               !(sb->s_flags & MS_TAGGED)) {
4407 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
4408 +                       sb->s_id);
4409 +               return -EINVAL;
4410 +       }
4411  
4412         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4413                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
4414 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext4/symlink.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext4/symlink.c
4415 --- linux-2.6.24-rc7/fs/ext4/symlink.c  2007-05-02 19:25:17 +0200
4416 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext4/symlink.c    2007-12-13 13:25:39 +0100
4417 @@ -40,6 +40,7 @@ const struct inode_operations ext4_symli
4418         .listxattr      = ext4_listxattr,
4419         .removexattr    = generic_removexattr,
4420  #endif
4421 +       .sync_flags     = ext4_sync_flags,
4422  };
4423  
4424  const struct inode_operations ext4_fast_symlink_inode_operations = {
4425 @@ -51,4 +52,5 @@ const struct inode_operations ext4_fast_
4426         .listxattr      = ext4_listxattr,
4427         .removexattr    = generic_removexattr,
4428  #endif
4429 +       .sync_flags     = ext4_sync_flags,
4430  };
4431 diff -NurpP --minimal linux-2.6.24-rc7/fs/ext4/xattr.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext4/xattr.c
4432 --- linux-2.6.24-rc7/fs/ext4/xattr.c    2007-11-29 01:11:51 +0100
4433 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ext4/xattr.c      2007-12-13 13:25:46 +0100
4434 @@ -58,6 +58,7 @@
4435  #include <linux/mbcache.h>
4436  #include <linux/quotaops.h>
4437  #include <linux/rwsem.h>
4438 +#include <linux/vs_dlimit.h>
4439  #include "xattr.h"
4440  #include "acl.h"
4441  
4442 @@ -489,6 +490,7 @@ ext4_xattr_release_block(handle_t *handl
4443                 error = ext4_journal_dirty_metadata(handle, bh);
4444                 if (IS_SYNC(inode))
4445                         handle->h_sync = 1;
4446 +                       DLIMIT_FREE_BLOCK(inode, 1);
4447                 DQUOT_FREE_BLOCK(inode, 1);
4448                 ea_bdebug(bh, "refcount now=%d; releasing",
4449                           le32_to_cpu(BHDR(bh)->h_refcount));
4450 @@ -779,11 +781,14 @@ inserted:
4451                         if (new_bh == bs->bh)
4452                                 ea_bdebug(new_bh, "keeping");
4453                         else {
4454 +                               error = -ENOSPC;
4455 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
4456 +                                       goto cleanup;
4457                                 /* The old block is released after updating
4458                                    the inode. */
4459                                 error = -EDQUOT;
4460                                 if (DQUOT_ALLOC_BLOCK(inode, 1))
4461 -                                       goto cleanup;
4462 +                                       goto cleanup_dlimit;
4463                                 error = ext4_journal_get_write_access(handle,
4464                                                                       new_bh);
4465                                 if (error)
4466 @@ -860,6 +865,8 @@ cleanup:
4467  
4468  cleanup_dquot:
4469         DQUOT_FREE_BLOCK(inode, 1);
4470 +cleanup_dlimit:
4471 +       DLIMIT_FREE_BLOCK(inode, 1);
4472         goto cleanup;
4473  
4474  bad_block:
4475 diff -NurpP --minimal linux-2.6.24-rc7/fs/fcntl.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/fcntl.c
4476 --- linux-2.6.24-rc7/fs/fcntl.c 2007-11-29 01:11:51 +0100
4477 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/fcntl.c   2007-12-13 13:25:42 +0100
4478 @@ -19,6 +19,7 @@
4479  #include <linux/signal.h>
4480  #include <linux/rcupdate.h>
4481  #include <linux/pid_namespace.h>
4482 +#include <linux/vs_limit.h>
4483  
4484  #include <asm/poll.h>
4485  #include <asm/siginfo.h>
4486 @@ -85,6 +86,8 @@ repeat:
4487         error = -EMFILE;
4488         if (newfd >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
4489                 goto out;
4490 +       if (!vx_files_avail(1))
4491 +               goto out;
4492  
4493         error = expand_files(files, newfd);
4494         if (error < 0)
4495 @@ -128,6 +131,7 @@ static int dupfd(struct file *file, unsi
4496                 else
4497                         FD_CLR(fd, fdt->close_on_exec);
4498                 spin_unlock(&files->file_lock);
4499 +               vx_openfd_inc(fd);
4500                 fd_install(fd, file);
4501         } else {
4502                 spin_unlock(&files->file_lock);
4503 @@ -180,6 +184,9 @@ asmlinkage long sys_dup2(unsigned int ol
4504  
4505         if (tofree)
4506                 filp_close(tofree, files);
4507 +       else
4508 +               vx_openfd_inc(newfd);   /* fd was unused */
4509 +
4510         err = newfd;
4511  out:
4512         return err;
4513 diff -NurpP --minimal linux-2.6.24-rc7/fs/file_table.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/file_table.c
4514 --- linux-2.6.24-rc7/fs/file_table.c    2007-11-29 01:11:51 +0100
4515 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/file_table.c      2007-12-13 13:25:42 +0100
4516 @@ -20,6 +20,8 @@
4517  #include <linux/fsnotify.h>
4518  #include <linux/sysctl.h>
4519  #include <linux/percpu_counter.h>
4520 +#include <linux/vs_limit.h>
4521 +#include <linux/vs_context.h>
4522  
4523  #include <asm/atomic.h>
4524  
4525 @@ -118,6 +120,8 @@ struct file *get_empty_filp(void)
4526         f->f_gid = tsk->fsgid;
4527         eventpoll_init_file(f);
4528         /* f->f_version: 0 */
4529 +       f->f_xid = vx_current_xid();
4530 +       vx_files_inc(f);
4531         return f;
4532  
4533  over:
4534 @@ -233,6 +237,8 @@ void fastcall __fput(struct file *file)
4535         if (file->f_mode & FMODE_WRITE)
4536                 put_write_access(inode);
4537         put_pid(file->f_owner.pid);
4538 +       vx_files_dec(file);
4539 +       file->f_xid = 0;
4540         file_kill(file);
4541         file->f_path.dentry = NULL;
4542         file->f_path.mnt = NULL;
4543 @@ -298,6 +304,8 @@ void put_filp(struct file *file)
4544  {
4545         if (atomic_dec_and_test(&file->f_count)) {
4546                 security_file_free(file);
4547 +               vx_files_dec(file);
4548 +               file->f_xid = 0;
4549                 file_kill(file);
4550                 file_free(file);
4551         }
4552 diff -NurpP --minimal linux-2.6.24-rc7/fs/hfsplus/ioctl.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/hfsplus/ioctl.c
4553 --- linux-2.6.24-rc7/fs/hfsplus/ioctl.c 2007-11-29 01:01:53 +0100
4554 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/hfsplus/ioctl.c   2007-12-13 13:25:47 +0100
4555 @@ -16,6 +16,7 @@
4556  #include <linux/fs.h>
4557  #include <linux/sched.h>
4558  #include <linux/xattr.h>
4559 +#include <linux/mount.h>
4560  #include <asm/uaccess.h>
4561  #include "hfsplus_fs.h"
4562  
4563 @@ -35,7 +36,8 @@ int hfsplus_ioctl(struct inode *inode, s
4564                         flags |= FS_NODUMP_FL; /* EXT2_NODUMP_FL */
4565                 return put_user(flags, (int __user *)arg);
4566         case HFSPLUS_IOC_EXT2_SETFLAGS: {
4567 -               if (IS_RDONLY(inode))
4568 +               if (IS_RDONLY(inode) ||
4569 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4570                         return -EROFS;
4571  
4572                 if (!is_owner_or_cap(inode))
4573 diff -NurpP --minimal linux-2.6.24-rc7/fs/inode.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/inode.c
4574 --- linux-2.6.24-rc7/fs/inode.c 2007-11-29 01:11:52 +0100
4575 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/inode.c   2007-12-13 13:25:52 +0100
4576 @@ -124,6 +124,9 @@ static struct inode *alloc_inode(struct 
4577                 struct address_space * const mapping = &inode->i_data;
4578  
4579                 inode->i_sb = sb;
4580 +
4581 +               /* essential because of inode slab reuse */
4582 +               inode->i_tag = 0;
4583                 inode->i_blkbits = sb->s_blocksize_bits;
4584                 inode->i_flags = 0;
4585                 atomic_set(&inode->i_count, 1);
4586 @@ -246,6 +249,8 @@ void __iget(struct inode * inode)
4587         inodes_stat.nr_unused--;
4588  }
4589  
4590 +EXPORT_SYMBOL_GPL(__iget);
4591 +
4592  /**
4593   * clear_inode - clear an inode
4594   * @inode: inode to clear
4595 diff -NurpP --minimal linux-2.6.24-rc7/fs/ioctl.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ioctl.c
4596 --- linux-2.6.24-rc7/fs/ioctl.c 2007-11-29 01:01:53 +0100
4597 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ioctl.c   2007-12-13 13:25:52 +0100
4598 @@ -12,10 +12,19 @@
4599  #include <linux/fs.h>
4600  #include <linux/security.h>
4601  #include <linux/module.h>
4602 +#include <linux/proc_fs.h>
4603 +#include <linux/vserver/inode.h>
4604 +#include <linux/vs_tag.h>
4605  
4606  #include <asm/uaccess.h>
4607  #include <asm/ioctls.h>
4608  
4609 +
4610 +#ifdef CONFIG_VSERVER_LEGACY
4611 +extern int vx_proc_ioctl(struct inode *, struct file *,
4612 +       unsigned int, unsigned long);
4613 +#endif
4614 +
4615  static long do_ioctl(struct file *filp, unsigned int cmd,
4616                 unsigned long arg)
4617  {
4618 @@ -144,6 +153,48 @@ int vfs_ioctl(struct file *filp, unsigne
4619                         else
4620                                 error = -ENOTTY;
4621                         break;
4622 +#ifdef CONFIG_VSERVER_LEGACY
4623 +#ifndef CONFIG_TAGGING_NONE
4624 +               case FIOC_GETTAG: {
4625 +                       struct inode *inode = filp->f_dentry->d_inode;
4626 +
4627 +                       /* fixme: if stealth, return -ENOTTY */
4628 +                       error = -EPERM;
4629 +                       if (capable(CAP_CONTEXT))
4630 +                               error = put_user(inode->i_tag, (int __user *) arg);
4631 +                       break;
4632 +               }
4633 +               case FIOC_SETTAG: {
4634 +                       struct inode *inode = filp->f_dentry->d_inode;
4635 +                       int tag;
4636 +
4637 +                       /* fixme: if stealth, return -ENOTTY */
4638 +                       error = -EPERM;
4639 +                       if (!capable(CAP_CONTEXT))
4640 +                               break;
4641 +                       error = -EROFS;
4642 +                       if (IS_RDONLY(inode))
4643 +                               break;
4644 +                       error = -ENOSYS;
4645 +                       if (!(inode->i_sb->s_flags & MS_TAGGED))
4646 +                               break;
4647 +                       error = -EFAULT;
4648 +                       if (get_user(tag, (int __user *) arg))
4649 +                               break;
4650 +                       error = 0;
4651 +                       inode->i_tag = (tag & 0xFFFF);
4652 +                       inode->i_ctime = CURRENT_TIME;
4653 +                       mark_inode_dirty(inode);
4654 +                       break;
4655 +               }
4656 +#endif
4657 +               case FIOC_GETXFLG:
4658 +               case FIOC_SETXFLG:
4659 +                       error = -ENOTTY;
4660 +                       if (filp->f_dentry->d_inode->i_sb->s_magic == PROC_SUPER_MAGIC)
4661 +                               error = vx_proc_ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
4662 +                       break;
4663 +#endif
4664                 default:
4665                         if (S_ISREG(filp->f_path.dentry->d_inode->i_mode))
4666                                 error = file_ioctl(filp, cmd, arg);
4667 diff -NurpP --minimal linux-2.6.24-rc7/fs/ioprio.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ioprio.c
4668 --- linux-2.6.24-rc7/fs/ioprio.c        2007-11-29 01:11:52 +0100
4669 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ioprio.c  2007-12-13 16:09:12 +0100
4670 @@ -26,6 +26,7 @@
4671  #include <linux/syscalls.h>
4672  #include <linux/security.h>
4673  #include <linux/pid_namespace.h>
4674 +#include <linux/vs_base.h>
4675  
4676  static int set_task_ioprio(struct task_struct *task, int ioprio)
4677  {
4678 @@ -108,6 +109,8 @@ asmlinkage long sys_ioprio_set(int which
4679                         else
4680                                 pgrp = find_vpid(who);
4681                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
4682 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4683 +                                       continue;
4684                                 ret = set_task_ioprio(p, ioprio);
4685                                 if (ret)
4686                                         break;
4687 @@ -195,6 +198,8 @@ asmlinkage long sys_ioprio_get(int which
4688                         else
4689                                 pgrp = find_vpid(who);
4690                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
4691 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4692 +                                       continue;
4693                                 tmpio = get_task_ioprio(p);
4694                                 if (tmpio < 0)
4695                                         continue;
4696 diff -NurpP --minimal linux-2.6.24-rc7/fs/jfs/acl.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/acl.c
4697 --- linux-2.6.24-rc7/fs/jfs/acl.c       2006-11-30 21:19:25 +0100
4698 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/acl.c 2007-12-13 13:25:40 +0100
4699 @@ -232,7 +232,8 @@ int jfs_setattr(struct dentry *dentry, s
4700                 return rc;
4701  
4702         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
4703 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
4704 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
4705 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
4706                 if (DQUOT_TRANSFER(inode, iattr))
4707                         return -EDQUOT;
4708         }
4709 diff -NurpP --minimal linux-2.6.24-rc7/fs/jfs/file.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/file.c
4710 --- linux-2.6.24-rc7/fs/jfs/file.c      2007-11-29 01:01:54 +0100
4711 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/file.c        2007-12-13 13:25:39 +0100
4712 @@ -98,6 +98,7 @@ const struct inode_operations jfs_file_i
4713         .setattr        = jfs_setattr,
4714         .permission     = jfs_permission,
4715  #endif
4716 +       .sync_flags     = jfs_sync_flags,
4717  };
4718  
4719  const struct file_operations jfs_file_operations = {
4720 diff -NurpP --minimal linux-2.6.24-rc7/fs/jfs/inode.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/inode.c
4721 --- linux-2.6.24-rc7/fs/jfs/inode.c     2007-11-29 01:11:53 +0100
4722 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/inode.c       2007-12-13 13:25:46 +0100
4723 @@ -22,6 +22,7 @@
4724  #include <linux/buffer_head.h>
4725  #include <linux/pagemap.h>
4726  #include <linux/quotaops.h>
4727 +#include <linux/vs_dlimit.h>
4728  #include "jfs_incore.h"
4729  #include "jfs_inode.h"
4730  #include "jfs_filsys.h"
4731 @@ -143,6 +144,7 @@ void jfs_delete_inode(struct inode *inod
4732                 DQUOT_INIT(inode);
4733                 DQUOT_FREE_INODE(inode);
4734                 DQUOT_DROP(inode);
4735 +               DLIMIT_FREE_INODE(inode);
4736         }
4737  
4738         clear_inode(inode);
4739 diff -NurpP --minimal linux-2.6.24-rc7/fs/jfs/ioctl.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/ioctl.c
4740 --- linux-2.6.24-rc7/fs/jfs/ioctl.c     2007-11-29 01:11:53 +0100
4741 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/ioctl.c       2007-12-13 13:25:47 +0100
4742 @@ -10,6 +10,7 @@
4743  #include <linux/capability.h>
4744  #include <linux/time.h>
4745  #include <linux/sched.h>
4746 +#include <linux/mount.h>
4747  #include <asm/current.h>
4748  #include <asm/uaccess.h>
4749  
4750 @@ -66,7 +67,8 @@ int jfs_ioctl(struct inode * inode, stru
4751         case JFS_IOC_SETFLAGS: {
4752                 unsigned int oldflags;
4753  
4754 -               if (IS_RDONLY(inode))
4755 +               if (IS_RDONLY(inode) ||
4756 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4757                         return -EROFS;
4758  
4759                 if (!is_owner_or_cap(inode))
4760 @@ -90,8 +92,8 @@ int jfs_ioctl(struct inode * inode, stru
4761                  * the relevant capability.
4762                  */
4763                 if ((oldflags & JFS_IMMUTABLE_FL) ||
4764 -                       ((flags ^ oldflags) &
4765 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
4766 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
4767 +                       JFS_IMMUTABLE_FL | JFS_IUNLINK_FL))) {
4768                         if (!capable(CAP_LINUX_IMMUTABLE))
4769                                 return -EPERM;
4770                 }
4771 diff -NurpP --minimal linux-2.6.24-rc7/fs/jfs/jfs_dinode.h linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/jfs_dinode.h
4772 --- linux-2.6.24-rc7/fs/jfs/jfs_dinode.h        2007-11-29 01:01:54 +0100
4773 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/jfs_dinode.h  2007-12-13 13:25:39 +0100
4774 @@ -162,9 +162,12 @@ struct dinode {
4775  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
4776  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
4777  
4778 -#define JFS_FL_USER_VISIBLE    0x03F80000
4779 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
4780 +#define JFS_IUNLINK_FL         0x08000000 /* Immutable unlink */
4781 +
4782 +#define JFS_FL_USER_VISIBLE    0x0FF80000
4783  #define JFS_FL_USER_MODIFIABLE 0x03F80000
4784 -#define JFS_FL_INHERIT         0x03C80000
4785 +#define JFS_FL_INHERIT         0x0BC80000
4786  
4787  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
4788  #define JFS_IOC_GETFLAGS       _IOR('f', 1, long)
4789 diff -NurpP --minimal linux-2.6.24-rc7/fs/jfs/jfs_dtree.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/jfs_dtree.c
4790 --- linux-2.6.24-rc7/fs/jfs/jfs_dtree.c 2007-11-29 01:11:53 +0100
4791 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/jfs_dtree.c   2007-12-13 13:25:46 +0100
4792 @@ -102,6 +102,7 @@
4793  
4794  #include <linux/fs.h>
4795  #include <linux/quotaops.h>
4796 +#include <linux/vs_dlimit.h>
4797  #include "jfs_incore.h"
4798  #include "jfs_superblock.h"
4799  #include "jfs_filsys.h"
4800 @@ -383,10 +384,10 @@ static u32 add_index(tid_t tid, struct i
4801                  */
4802                 if (DQUOT_ALLOC_BLOCK(ip, sbi->nbperpage))
4803                         goto clean_up;
4804 -               if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr)) {
4805 -                       DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
4806 -                       goto clean_up;
4807 -               }
4808 +               if (DLIMIT_ALLOC_BLOCK(ip, sbi->nbperpage))
4809 +                       goto clean_up_dquot;
4810 +               if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr))
4811 +                       goto clean_up_dlimit;
4812  
4813                 /*
4814                  * Save the table, we're going to overwrite it with the
4815 @@ -479,6 +480,12 @@ static u32 add_index(tid_t tid, struct i
4816  
4817         return index;
4818  
4819 +      clean_up_dlimit:
4820 +       DLIMIT_FREE_BLOCK(ip, sbi->nbperpage);
4821 +
4822 +      clean_up_dquot:
4823 +       DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
4824 +
4825        clean_up:
4826  
4827         jfs_ip->next_index--;
4828 @@ -952,6 +959,7 @@ static int dtSplitUp(tid_t tid,
4829         struct tlock *tlck;
4830         struct lv *lv;
4831         int quota_allocation = 0;
4832 +       int dlimit_allocation = 0;
4833  
4834         /* get split page */
4835         smp = split->mp;
4836 @@ -1036,6 +1044,12 @@ static int dtSplitUp(tid_t tid,
4837                 }
4838                 quota_allocation += n;
4839  
4840 +               if (DLIMIT_ALLOC_BLOCK(ip, n)) {
4841 +                       rc = -ENOSPC;
4842 +                       goto extendOut;
4843 +               }
4844 +               dlimit_allocation += n;
4845 +
4846                 if ((rc = dbReAlloc(sbi->ipbmap, xaddr, (s64) xlen,
4847                                     (s64) n, &nxaddr)))
4848                         goto extendOut;
4849 @@ -1309,6 +1323,9 @@ static int dtSplitUp(tid_t tid,
4850        freeKeyName:
4851         kfree(key.name);
4852  
4853 +       /* Rollback dlimit allocation */
4854 +       if (rc && dlimit_allocation)
4855 +               DLIMIT_FREE_BLOCK(ip, dlimit_allocation);
4856         /* Rollback quota allocation */
4857         if (rc && quota_allocation)
4858                 DQUOT_FREE_BLOCK(ip, quota_allocation);
4859 @@ -1376,6 +1393,12 @@ static int dtSplitPage(tid_t tid, struct
4860                 release_metapage(rmp);
4861                 return -EDQUOT;
4862         }
4863 +       /* Allocate blocks to dlimit. */
4864 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4865 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
4866 +               release_metapage(rmp);
4867 +               return -ENOSPC;
4868 +       }
4869  
4870         jfs_info("dtSplitPage: ip:0x%p smp:0x%p rmp:0x%p", ip, smp, rmp);
4871  
4872 @@ -1923,6 +1946,12 @@ static int dtSplitRoot(tid_t tid,
4873                 release_metapage(rmp);
4874                 return -EDQUOT;
4875         }
4876 +       /* Allocate blocks to dlimit. */
4877 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4878 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
4879 +               release_metapage(rmp);
4880 +               return -ENOSPC;
4881 +       }
4882  
4883         BT_MARK_DIRTY(rmp, ip);
4884         /*
4885 @@ -2289,6 +2318,8 @@ static int dtDeleteUp(tid_t tid, struct 
4886  
4887         xlen = lengthPXD(&fp->header.self);
4888  
4889 +       /* Free dlimit allocation. */
4890 +       DLIMIT_FREE_BLOCK(ip, xlen);
4891         /* Free quota allocation. */
4892         DQUOT_FREE_BLOCK(ip, xlen);
4893  
4894 @@ -2365,6 +2396,8 @@ static int dtDeleteUp(tid_t tid, struct 
4895  
4896                                 xlen = lengthPXD(&p->header.self);
4897  
4898 +                               /* Free dlimit allocation */
4899 +                               DLIMIT_FREE_BLOCK(ip, xlen);
4900                                 /* Free quota allocation */
4901                                 DQUOT_FREE_BLOCK(ip, xlen);
4902  
4903 diff -NurpP --minimal linux-2.6.24-rc7/fs/jfs/jfs_extent.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/jfs_extent.c
4904 --- linux-2.6.24-rc7/fs/jfs/jfs_extent.c        2007-11-29 01:01:54 +0100
4905 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/jfs_extent.c  2007-12-13 13:25:46 +0100
4906 @@ -18,6 +18,7 @@
4907  
4908  #include <linux/fs.h>
4909  #include <linux/quotaops.h>
4910 +#include <linux/vs_dlimit.h>
4911  #include "jfs_incore.h"
4912  #include "jfs_inode.h"
4913  #include "jfs_superblock.h"
4914 @@ -147,6 +148,14 @@ extAlloc(struct inode *ip, s64 xlen, s64
4915                 return -EDQUOT;
4916         }
4917  
4918 +       /* Allocate blocks to dlimit. */
4919 +       if (DLIMIT_ALLOC_BLOCK(ip, nxlen)) {
4920 +               DQUOT_FREE_BLOCK(ip, nxlen);
4921 +               dbFree(ip, nxaddr, (s64) nxlen);
4922 +               mutex_unlock(&JFS_IP(ip)->commit_mutex);
4923 +               return -ENOSPC;
4924 +       }
4925 +
4926         /* determine the value of the extent flag */
4927         xflag = abnr ? XAD_NOTRECORDED : 0;
4928  
4929 @@ -164,6 +173,7 @@ extAlloc(struct inode *ip, s64 xlen, s64
4930          */
4931         if (rc) {
4932                 dbFree(ip, nxaddr, nxlen);
4933 +               DLIMIT_FREE_BLOCK(ip, nxlen);
4934                 DQUOT_FREE_BLOCK(ip, nxlen);
4935                 mutex_unlock(&JFS_IP(ip)->commit_mutex);
4936                 return (rc);
4937 @@ -261,6 +271,13 @@ int extRealloc(struct inode *ip, s64 nxl
4938                 mutex_unlock(&JFS_IP(ip)->commit_mutex);
4939                 return -EDQUOT;
4940         }
4941 +       /* Allocate blocks to dlimit. */
4942 +       if (DLIMIT_ALLOC_BLOCK(ip, nxlen)) {
4943 +               DQUOT_FREE_BLOCK(ip, nxlen);
4944 +               dbFree(ip, nxaddr, (s64) nxlen);
4945 +               up(&JFS_IP(ip)->commit_sem);
4946 +               return -ENOSPC;
4947 +       }
4948  
4949         delta = nxlen - xlen;
4950  
4951 @@ -297,6 +314,7 @@ int extRealloc(struct inode *ip, s64 nxl
4952                 /* extend the extent */
4953                 if ((rc = xtExtend(0, ip, xoff + xlen, (int) nextend, 0))) {
4954                         dbFree(ip, xaddr + xlen, delta);
4955 +                       DLIMIT_FREE_BLOCK(ip, nxlen);
4956                         DQUOT_FREE_BLOCK(ip, nxlen);
4957                         goto exit;
4958                 }
4959 @@ -308,6 +326,7 @@ int extRealloc(struct inode *ip, s64 nxl
4960                  */
4961                 if ((rc = xtTailgate(0, ip, xoff, (int) ntail, nxaddr, 0))) {
4962                         dbFree(ip, nxaddr, nxlen);
4963 +                       DLIMIT_FREE_BLOCK(ip, nxlen);
4964                         DQUOT_FREE_BLOCK(ip, nxlen);
4965                         goto exit;
4966                 }
4967 diff -NurpP --minimal linux-2.6.24-rc7/fs/jfs/jfs_filsys.h linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/jfs_filsys.h
4968 --- linux-2.6.24-rc7/fs/jfs/jfs_filsys.h        2007-11-29 01:01:54 +0100
4969 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/jfs_filsys.h  2007-12-13 13:25:40 +0100
4970 @@ -263,6 +263,7 @@
4971  #define JFS_NAME_MAX   255
4972  #define JFS_PATH_MAX   BPSIZE
4973  
4974 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
4975  
4976  /*
4977   *     file system state (superblock state)
4978 diff -NurpP --minimal linux-2.6.24-rc7/fs/jfs/jfs_imap.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/jfs_imap.c
4979 --- linux-2.6.24-rc7/fs/jfs/jfs_imap.c  2007-11-29 01:01:54 +0100
4980 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/jfs_imap.c    2007-12-13 13:25:40 +0100
4981 @@ -45,6 +45,7 @@
4982  #include <linux/buffer_head.h>
4983  #include <linux/pagemap.h>
4984  #include <linux/quotaops.h>
4985 +#include <linux/vs_tag.h>
4986  
4987  #include "jfs_incore.h"
4988  #include "jfs_inode.h"
4989 @@ -3061,6 +3062,8 @@ static int copy_from_dinode(struct dinod
4990  {
4991         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
4992         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
4993 +       uid_t uid;
4994 +       gid_t gid;
4995  
4996         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
4997         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
4998 @@ -3081,14 +3084,18 @@ static int copy_from_dinode(struct dinod
4999         }
5000         ip->i_nlink = le32_to_cpu(dip->di_nlink);
5001  
5002 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
5003 +       uid = le32_to_cpu(dip->di_uid);
5004 +       gid = le32_to_cpu(dip->di_gid);
5005 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
5006 +
5007 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
5008         if (sbi->uid == -1)
5009                 ip->i_uid = jfs_ip->saved_uid;
5010         else {
5011                 ip->i_uid = sbi->uid;
5012         }
5013  
5014 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
5015 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
5016         if (sbi->gid == -1)
5017                 ip->i_gid = jfs_ip->saved_gid;
5018         else {
5019 @@ -3153,14 +3160,12 @@ static void copy_to_dinode(struct dinode
5020         dip->di_size = cpu_to_le64(ip->i_size);
5021         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
5022         dip->di_nlink = cpu_to_le32(ip->i_nlink);
5023 -       if (sbi->uid == -1)
5024 -               dip->di_uid = cpu_to_le32(ip->i_uid);
5025 -       else
5026 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
5027 -       if (sbi->gid == -1)
5028 -               dip->di_gid = cpu_to_le32(ip->i_gid);
5029 -       else
5030 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
5031 +
5032 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
5033 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
5034 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
5035 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
5036 +
5037         jfs_get_inode_flags(jfs_ip);
5038         /*
5039          * mode2 is only needed for storing the higher order bits.
5040 diff -NurpP --minimal linux-2.6.24-rc7/fs/jfs/jfs_inode.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/jfs_inode.c
5041 --- linux-2.6.24-rc7/fs/jfs/jfs_inode.c 2007-07-09 13:19:27 +0200
5042 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/jfs_inode.c   2007-12-13 13:25:46 +0100
5043 @@ -18,6 +18,8 @@
5044  
5045  #include <linux/fs.h>
5046  #include <linux/quotaops.h>
5047 +#include <linux/vs_dlimit.h>
5048 +#include <linux/vs_tag.h>
5049  #include "jfs_incore.h"
5050  #include "jfs_inode.h"
5051  #include "jfs_filsys.h"
5052 @@ -30,19 +32,47 @@ void jfs_set_inode_flags(struct inode *i
5053  {
5054         unsigned int flags = JFS_IP(inode)->mode2;
5055  
5056 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
5057 -               S_NOATIME | S_DIRSYNC | S_SYNC);
5058 +       inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
5059 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5060  
5061         if (flags & JFS_IMMUTABLE_FL)
5062                 inode->i_flags |= S_IMMUTABLE;
5063 +       if (flags & JFS_IUNLINK_FL)
5064 +               inode->i_flags |= S_IUNLINK;
5065 +       if (flags & JFS_BARRIER_FL)
5066 +               inode->i_flags |= S_BARRIER;
5067 +
5068 +       if (flags & JFS_SYNC_FL)
5069 +               inode->i_flags |= S_SYNC;
5070         if (flags & JFS_APPEND_FL)
5071                 inode->i_flags |= S_APPEND;
5072         if (flags & JFS_NOATIME_FL)
5073                 inode->i_flags |= S_NOATIME;
5074         if (flags & JFS_DIRSYNC_FL)
5075                 inode->i_flags |= S_DIRSYNC;
5076 -       if (flags & JFS_SYNC_FL)
5077 -               inode->i_flags |= S_SYNC;
5078 +}
5079 +
5080 +int jfs_sync_flags(struct inode *inode)
5081 +{
5082 +       unsigned int oldflags, newflags;
5083 +
5084 +       oldflags = JFS_IP(inode)->mode2;
5085 +       newflags = oldflags & ~(JFS_IMMUTABLE_FL |
5086 +               JFS_IUNLINK_FL | JFS_BARRIER_FL);
5087 +
5088 +       if (IS_IMMUTABLE(inode))
5089 +               newflags |= JFS_IMMUTABLE_FL;
5090 +       if (IS_IUNLINK(inode))
5091 +               newflags |= JFS_IUNLINK_FL;
5092 +       if (IS_BARRIER(inode))
5093 +               newflags |= JFS_BARRIER_FL;
5094 +
5095 +       if (oldflags ^ newflags) {
5096 +               JFS_IP(inode)->mode2 = newflags;
5097 +               inode->i_ctime = CURRENT_TIME;
5098 +               mark_inode_dirty(inode);
5099 +       }
5100 +       return 0;
5101  }
5102  
5103  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
5104 @@ -108,10 +138,17 @@ struct inode *ialloc(struct inode *paren
5105         jfs_inode->saved_uid = inode->i_uid;
5106         jfs_inode->saved_gid = inode->i_gid;
5107  
5108 +       inode->i_tag = dx_current_fstag(sb);
5109 +       if (DLIMIT_ALLOC_INODE(inode)) {
5110 +               iput(inode);
5111 +               return ERR_PTR(-ENOSPC);
5112 +       }
5113 +
5114         /*
5115          * Allocate inode to quota.
5116          */
5117         if (DQUOT_ALLOC_INODE(inode)) {
5118 +               DLIMIT_FREE_INODE(inode);
5119                 DQUOT_DROP(inode);
5120                 inode->i_flags |= S_NOQUOTA;
5121                 inode->i_nlink = 0;
5122 diff -NurpP --minimal linux-2.6.24-rc7/fs/jfs/jfs_inode.h linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/jfs_inode.h
5123 --- linux-2.6.24-rc7/fs/jfs/jfs_inode.h 2007-11-29 01:11:53 +0100
5124 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/jfs_inode.h   2007-12-13 13:25:39 +0100
5125 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
5126  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
5127         int fh_len, int fh_type);
5128  extern void jfs_set_inode_flags(struct inode *);
5129 +extern int jfs_sync_flags(struct inode *);
5130  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
5131  
5132  extern const struct address_space_operations jfs_aops;
5133 diff -NurpP --minimal linux-2.6.24-rc7/fs/jfs/jfs_xtree.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/jfs_xtree.c
5134 --- linux-2.6.24-rc7/fs/jfs/jfs_xtree.c 2007-11-29 01:01:54 +0100
5135 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/jfs_xtree.c   2007-12-13 13:25:46 +0100
5136 @@ -21,6 +21,7 @@
5137  
5138  #include <linux/fs.h>
5139  #include <linux/quotaops.h>
5140 +#include <linux/vs_dlimit.h>
5141  #include "jfs_incore.h"
5142  #include "jfs_filsys.h"
5143  #include "jfs_metapage.h"
5144 @@ -846,7 +847,12 @@ int xtInsert(tid_t tid,            /* transaction 
5145                         hint = 0;
5146                 if ((rc = DQUOT_ALLOC_BLOCK(ip, xlen)))
5147                         goto out;
5148 +               if ((rc = DLIMIT_ALLOC_BLOCK(ip, xlen))) {
5149 +                       DQUOT_FREE_BLOCK(ip, xlen);
5150 +                       goto out;
5151 +               }
5152                 if ((rc = dbAlloc(ip, hint, (s64) xlen, &xaddr))) {
5153 +                       DLIMIT_FREE_BLOCK(ip, xlen);
5154                         DQUOT_FREE_BLOCK(ip, xlen);
5155                         goto out;
5156                 }
5157 @@ -876,6 +882,7 @@ int xtInsert(tid_t tid,             /* transaction 
5158                         /* undo data extent allocation */
5159                         if (*xaddrp == 0) {
5160                                 dbFree(ip, xaddr, (s64) xlen);
5161 +                               DLIMIT_FREE_BLOCK(ip, xlen);
5162                                 DQUOT_FREE_BLOCK(ip, xlen);
5163                         }
5164                         return rc;
5165 @@ -1236,6 +1243,7 @@ xtSplitPage(tid_t tid, struct inode *ip,
5166         struct tlock *tlck;
5167         struct xtlock *sxtlck = NULL, *rxtlck = NULL;
5168         int quota_allocation = 0;
5169 +       int dlimit_allocation = 0;
5170  
5171         smp = split->mp;
5172         sp = XT_PAGE(ip, smp);
5173 @@ -1255,6 +1263,13 @@ xtSplitPage(tid_t tid, struct inode *ip,
5174  
5175         quota_allocation += lengthPXD(pxd);
5176  
5177 +       /* Allocate blocks to dlimit. */
5178 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
5179 +              rc = -ENOSPC;
5180 +              goto clean_up;
5181 +       }
5182 +       dlimit_allocation += lengthPXD(pxd);
5183 +
5184         /*
5185          * allocate the new right page for the split
5186          */
5187 @@ -1456,6 +1471,9 @@ xtSplitPage(tid_t tid, struct inode *ip,
5188  
5189        clean_up:
5190  
5191 +       /* Rollback dlimit allocation. */
5192 +       if (dlimit_allocation)
5193 +               DLIMIT_FREE_BLOCK(ip, dlimit_allocation);
5194         /* Rollback quota allocation. */
5195         if (quota_allocation)
5196                 DQUOT_FREE_BLOCK(ip, quota_allocation);
5197 @@ -1519,6 +1537,12 @@ xtSplitRoot(tid_t tid,
5198                 release_metapage(rmp);
5199                 return -EDQUOT;
5200         }
5201 +       /* Allocate blocks to dlimit. */
5202 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
5203 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
5204 +               release_metapage(rmp);
5205 +               return -ENOSPC;
5206 +       }
5207  
5208         jfs_info("xtSplitRoot: ip:0x%p rmp:0x%p", ip, rmp);
5209  
5210 @@ -3948,6 +3972,8 @@ s64 xtTruncate(tid_t tid, struct inode *
5211         else
5212                 ip->i_size = newsize;
5213  
5214 +       /* update dlimit allocation to reflect freed blocks */
5215 +       DLIMIT_FREE_BLOCK(ip, nfreed);
5216         /* update quota allocation to reflect freed blocks */
5217         DQUOT_FREE_BLOCK(ip, nfreed);
5218  
5219 diff -NurpP --minimal linux-2.6.24-rc7/fs/jfs/namei.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/namei.c
5220 --- linux-2.6.24-rc7/fs/jfs/namei.c     2007-11-29 01:11:53 +0100
5221 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/namei.c       2007-12-13 13:25:41 +0100
5222 @@ -21,6 +21,7 @@
5223  #include <linux/ctype.h>
5224  #include <linux/quotaops.h>
5225  #include <linux/exportfs.h>
5226 +#include <linux/vs_tag.h>
5227  #include "jfs_incore.h"
5228  #include "jfs_superblock.h"
5229  #include "jfs_inode.h"
5230 @@ -1470,6 +1471,7 @@ static struct dentry *jfs_lookup(struct 
5231                 return ERR_PTR(-EACCES);
5232         }
5233  
5234 +       dx_propagate_tag(nd, ip);
5235         dentry = d_splice_alias(ip, dentry);
5236  
5237         if (dentry && (JFS_SBI(dip->i_sb)->mntflag & JFS_OS2))
5238 @@ -1556,6 +1558,7 @@ const struct inode_operations jfs_dir_in
5239         .setattr        = jfs_setattr,
5240         .permission     = jfs_permission,
5241  #endif
5242 +       .sync_flags     = jfs_sync_flags,
5243  };
5244  
5245  const struct file_operations jfs_dir_operations = {
5246 diff -NurpP --minimal linux-2.6.24-rc7/fs/jfs/super.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/super.c
5247 --- linux-2.6.24-rc7/fs/jfs/super.c     2007-11-29 01:11:53 +0100
5248 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/super.c       2007-12-13 13:25:38 +0100
5249 @@ -195,7 +195,8 @@ static void jfs_put_super(struct super_b
5250  enum {
5251         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
5252         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
5253 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
5254 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
5255 +       Opt_tag, Opt_notag, Opt_tagid
5256  };
5257  
5258  static match_table_t tokens = {
5259 @@ -205,6 +206,10 @@ static match_table_t tokens = {
5260         {Opt_resize, "resize=%u"},
5261         {Opt_resize_nosize, "resize"},
5262         {Opt_errors, "errors=%s"},
5263 +       {Opt_tag, "tag"},
5264 +       {Opt_notag, "notag"},
5265 +       {Opt_tagid, "tagid=%u"},
5266 +       {Opt_tag, "tagxid"},
5267         {Opt_ignore, "noquota"},
5268         {Opt_ignore, "quota"},
5269         {Opt_usrquota, "usrquota"},
5270 @@ -339,6 +344,20 @@ static int parse_options(char *options, 
5271                         }
5272                         break;
5273                 }
5274 +#ifndef CONFIG_TAGGING_NONE
5275 +               case Opt_tag:
5276 +                       *flag |= JFS_TAGGED;
5277 +                       break;
5278 +               case Opt_notag:
5279 +                       *flag &= JFS_TAGGED;
5280 +                       break;
5281 +#endif
5282 +#ifdef CONFIG_PROPAGATE
5283 +               case Opt_tagid:
5284 +                       /* use args[0] */
5285 +                       *flag |= JFS_TAGGED;
5286 +                       break;
5287 +#endif
5288                 default:
5289                         printk("jfs: Unrecognized mount option \"%s\" "
5290                                         " or missing value\n", p);
5291 @@ -369,6 +388,13 @@ static int jfs_remount(struct super_bloc
5292         if (!parse_options(data, sb, &newLVSize, &flag)) {
5293                 return -EINVAL;
5294         }
5295 +
5296 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
5297 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
5298 +                       sb->s_id);
5299 +               return -EINVAL;
5300 +       }
5301 +
5302         if (newLVSize) {
5303                 if (sb->s_flags & MS_RDONLY) {
5304                         printk(KERN_ERR
5305 @@ -440,6 +466,9 @@ static int jfs_fill_super(struct super_b
5306  #ifdef CONFIG_JFS_POSIX_ACL
5307         sb->s_flags |= MS_POSIXACL;
5308  #endif
5309 +       /* map mount option tagxid */
5310 +       if (sbi->flag & JFS_TAGGED)
5311 +               sb->s_flags |= MS_TAGGED;
5312  
5313         if (newLVSize) {
5314                 printk(KERN_ERR "resize option for remount only\n");
5315 diff -NurpP --minimal linux-2.6.24-rc7/fs/jfs/xattr.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/xattr.c
5316 --- linux-2.6.24-rc7/fs/jfs/xattr.c     2007-11-29 01:01:54 +0100
5317 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/jfs/xattr.c       2007-12-13 13:25:46 +0100
5318 @@ -23,6 +23,7 @@
5319  #include <linux/posix_acl_xattr.h>
5320  #include <linux/quotaops.h>
5321  #include <linux/security.h>
5322 +#include <linux/vs_dlimit.h>
5323  #include "jfs_incore.h"
5324  #include "jfs_superblock.h"
5325  #include "jfs_dmap.h"
5326 @@ -263,9 +264,16 @@ static int ea_write(struct inode *ip, st
5327         if (DQUOT_ALLOC_BLOCK(ip, nblocks)) {
5328                 return -EDQUOT;
5329         }
5330 +       /* Allocate new blocks to dlimit. */
5331 +       if (DLIMIT_ALLOC_BLOCK(ip, nblocks)) {
5332 +               DQUOT_FREE_BLOCK(ip, nblocks);
5333 +               return -ENOSPC;
5334 +       }
5335  
5336         rc = dbAlloc(ip, INOHINT(ip), nblocks, &blkno);
5337         if (rc) {
5338 +               /*Rollback dlimit allocation. */
5339 +               DLIMIT_FREE_BLOCK(ip, nblocks);
5340                 /*Rollback quota allocation. */
5341                 DQUOT_FREE_BLOCK(ip, nblocks);
5342                 return rc;
5343 @@ -332,6 +340,8 @@ static int ea_write(struct inode *ip, st
5344  
5345        failed:
5346         /* Rollback quota allocation. */
5347 +       DLIMIT_FREE_BLOCK(ip, nblocks);
5348 +       /* Rollback quota allocation. */
5349         DQUOT_FREE_BLOCK(ip, nblocks);
5350  
5351         dbFree(ip, blkno, nblocks);
5352 @@ -468,6 +478,7 @@ static int ea_get(struct inode *inode, s
5353         s64 blkno;
5354         int rc;
5355         int quota_allocation = 0;
5356 +       int dlimit_allocation = 0;
5357  
5358         /* When fsck.jfs clears a bad ea, it doesn't clear the size */
5359         if (ji->ea.flag == 0)
5360 @@ -543,6 +554,12 @@ static int ea_get(struct inode *inode, s
5361  
5362                 quota_allocation = blocks_needed;
5363  
5364 +               /* Allocate new blocks to dlimit. */
5365 +               rc = -ENOSPC;
5366 +               if (DLIMIT_ALLOC_BLOCK(inode, blocks_needed))
5367 +                       goto clean_up;
5368 +               dlimit_allocation = blocks_needed;
5369 +
5370                 rc = dbAlloc(inode, INOHINT(inode), (s64) blocks_needed,
5371                              &blkno);
5372                 if (rc)
5373 @@ -600,6 +617,9 @@ static int ea_get(struct inode *inode, s
5374         return ea_size;
5375  
5376        clean_up:
5377 +       /* Rollback dlimit allocation */
5378 +       if (dlimit_allocation)
5379 +               DLIMIT_FREE_BLOCK(inode, dlimit_allocation);
5380         /* Rollback quota allocation */
5381         if (quota_allocation)
5382                 DQUOT_FREE_BLOCK(inode, quota_allocation);
5383 @@ -676,8 +696,10 @@ static int ea_put(tid_t tid, struct inod
5384         }
5385  
5386         /* If old blocks exist, they must be removed from quota allocation. */
5387 -       if (old_blocks)
5388 +       if (old_blocks) {
5389 +               DLIMIT_FREE_BLOCK(inode, old_blocks);
5390                 DQUOT_FREE_BLOCK(inode, old_blocks);
5391 +       }
5392  
5393         inode->i_ctime = CURRENT_TIME;
5394  
5395 diff -NurpP --minimal linux-2.6.24-rc7/fs/libfs.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/libfs.c
5396 --- linux-2.6.24-rc7/fs/libfs.c 2007-11-29 01:11:53 +0100
5397 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/libfs.c   2007-12-13 13:25:51 +0100
5398 @@ -125,7 +125,8 @@ static inline unsigned char dt_type(stru
5399   * both impossible due to the lock on directory.
5400   */
5401  
5402 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
5403 +static inline int do_dcache_readdir_filter(struct file *filp,
5404 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
5405  {
5406         struct dentry *dentry = filp->f_path.dentry;
5407         struct dentry *cursor = filp->private_data;
5408 @@ -158,6 +159,8 @@ int dcache_readdir(struct file * filp, v
5409                                 next = list_entry(p, struct dentry, d_u.d_child);
5410                                 if (d_unhashed(next) || !next->d_inode)
5411                                         continue;
5412 +                               if (filter && !filter(next))
5413 +                                       continue;
5414  
5415                                 spin_unlock(&dcache_lock);
5416                                 if (filldir(dirent, next->d_name.name, 
5417 @@ -176,6 +179,18 @@ int dcache_readdir(struct file * filp, v
5418         return 0;
5419  }
5420  
5421 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
5422 +{
5423 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
5424 +}
5425 +
5426 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
5427 +       int (*filter)(struct dentry *))
5428 +{
5429 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
5430 +}
5431 +
5432 +
5433  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
5434  {
5435         return -EISDIR;
5436 @@ -770,6 +785,7 @@ EXPORT_SYMBOL(dcache_dir_close);
5437  EXPORT_SYMBOL(dcache_dir_lseek);
5438  EXPORT_SYMBOL(dcache_dir_open);
5439  EXPORT_SYMBOL(dcache_readdir);
5440 +EXPORT_SYMBOL(dcache_readdir_filter);
5441  EXPORT_SYMBOL(generic_read_dir);
5442  EXPORT_SYMBOL(get_sb_pseudo);
5443  EXPORT_SYMBOL(simple_write_begin);
5444 diff -NurpP --minimal linux-2.6.24-rc7/fs/locks.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/locks.c
5445 --- linux-2.6.24-rc7/fs/locks.c 2007-11-29 01:11:53 +0100
5446 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/locks.c   2007-12-13 13:25:49 +0100
5447 @@ -125,6 +125,8 @@
5448  #include <linux/syscalls.h>
5449  #include <linux/time.h>
5450  #include <linux/rcupdate.h>
5451 +#include <linux/vs_base.h>
5452 +#include <linux/vs_limit.h>
5453  
5454  #include <asm/semaphore.h>
5455  #include <asm/uaccess.h>
5456 @@ -147,6 +149,8 @@ static struct kmem_cache *filelock_cache
5457  /* Allocate an empty lock structure. */
5458  static struct file_lock *locks_alloc_lock(void)
5459  {
5460 +       if (!vx_locks_avail(1))
5461 +               return NULL;
5462         return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
5463  }
5464  
5465 @@ -172,6 +176,7 @@ static void locks_free_lock(struct file_
5466         BUG_ON(!list_empty(&fl->fl_block));
5467         BUG_ON(!list_empty(&fl->fl_link));
5468  
5469 +       vx_locks_dec(fl);
5470         locks_release_private(fl);
5471         kmem_cache_free(filelock_cache, fl);
5472  }
5473 @@ -191,6 +196,7 @@ void locks_init_lock(struct file_lock *f
5474         fl->fl_start = fl->fl_end = 0;
5475         fl->fl_ops = NULL;
5476         fl->fl_lmops = NULL;
5477 +       fl->fl_xid = -1;
5478  }
5479  
5480  EXPORT_SYMBOL(locks_init_lock);
5481 @@ -244,6 +250,7 @@ void locks_copy_lock(struct file_lock *n
5482         new->fl_file = fl->fl_file;
5483         new->fl_ops = fl->fl_ops;
5484         new->fl_lmops = fl->fl_lmops;
5485 +       new->fl_xid = fl->fl_xid;
5486  
5487         locks_copy_private(new, fl);
5488  }
5489 @@ -282,6 +289,11 @@ static int flock_make_lock(struct file *
5490         fl->fl_flags = FL_FLOCK;
5491         fl->fl_type = type;
5492         fl->fl_end = OFFSET_MAX;
5493 +
5494 +       vxd_assert(filp->f_xid == vx_current_xid(),
5495 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
5496 +       fl->fl_xid = filp->f_xid;
5497 +       vx_locks_inc(fl);
5498         
5499         *lock = fl;
5500         return 0;
5501 @@ -447,6 +459,7 @@ static int lease_init(struct file *filp,
5502  
5503         fl->fl_owner = current->files;
5504         fl->fl_pid = current->tgid;
5505 +       fl->fl_xid = vx_current_xid();
5506  
5507         fl->fl_file = filp;
5508         fl->fl_flags = FL_LEASE;
5509 @@ -466,6 +479,11 @@ static struct file_lock *lease_alloc(str
5510         if (fl == NULL)
5511                 return ERR_PTR(error);
5512  
5513 +       fl->fl_xid = vx_current_xid();
5514 +       if (filp)
5515 +               vxd_assert(filp->f_xid == fl->fl_xid,
5516 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
5517 +       vx_locks_inc(fl);
5518         error = lease_init(filp, type, fl);
5519         if (error) {
5520                 locks_free_lock(fl);
5521 @@ -781,6 +799,7 @@ static int flock_lock_file(struct file *
5522         if (found)
5523                 cond_resched();
5524  
5525 +       new_fl->fl_xid = -1;
5526  find_conflict:
5527         for_each_lock(inode, before) {
5528                 struct file_lock *fl = *before;
5529 @@ -799,6 +818,7 @@ find_conflict:
5530                 goto out;
5531         locks_copy_lock(new_fl, request);
5532         locks_insert_lock(before, new_fl);
5533 +       vx_locks_inc(new_fl);
5534         new_fl = NULL;
5535         error = 0;
5536  
5537 @@ -809,7 +829,8 @@ out:
5538         return error;
5539  }
5540  
5541 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
5542 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
5543 +       struct file_lock *conflock, xid_t xid)
5544  {
5545         struct file_lock *fl;
5546         struct file_lock *new_fl = NULL;
5547 @@ -819,6 +840,8 @@ static int __posix_lock_file(struct inod
5548         struct file_lock **before;
5549         int error, added = 0;
5550  
5551 +       vxd_assert(xid == vx_current_xid(),
5552 +               "xid(%d) == current(%d)", xid, vx_current_xid());
5553         /*
5554          * We may need two file_lock structures for this operation,
5555          * so we get them in advance to avoid races.
5556 @@ -829,7 +852,11 @@ static int __posix_lock_file(struct inod
5557             (request->fl_type != F_UNLCK ||
5558              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
5559                 new_fl = locks_alloc_lock();
5560 +               new_fl->fl_xid = xid;
5561 +               vx_locks_inc(new_fl);
5562                 new_fl2 = locks_alloc_lock();
5563 +               new_fl2->fl_xid = xid;
5564 +               vx_locks_inc(new_fl2);
5565         }
5566  
5567         lock_kernel();
5568 @@ -1028,7 +1055,8 @@ static int __posix_lock_file(struct inod
5569  int posix_lock_file(struct file *filp, struct file_lock *fl,
5570                         struct file_lock *conflock)
5571  {
5572 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
5573 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
5574 +               fl, conflock, filp->f_xid);
5575  }
5576  EXPORT_SYMBOL(posix_lock_file);
5577  
5578 @@ -1118,7 +1146,7 @@ int locks_mandatory_area(int read_write,
5579         fl.fl_end = offset + count - 1;
5580  
5581         for (;;) {
5582 -               error = __posix_lock_file(inode, &fl, NULL);
5583 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
5584                 if (error != -EAGAIN)
5585                         break;
5586                 if (!(fl.fl_flags & FL_SLEEP))
5587 @@ -1429,6 +1457,7 @@ int generic_setlease(struct file *filp, 
5588  
5589         locks_copy_lock(new_fl, lease);
5590         locks_insert_lock(before, new_fl);
5591 +       vx_locks_inc(fl);
5592  
5593         *flp = new_fl;
5594         return 0;
5595 @@ -1759,6 +1788,11 @@ int fcntl_setlk(unsigned int fd, struct 
5596         if (file_lock == NULL)
5597                 return -ENOLCK;
5598  
5599 +       vxd_assert(filp->f_xid == vx_current_xid(),
5600 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
5601 +       file_lock->fl_xid = filp->f_xid;
5602 +       vx_locks_inc(file_lock);
5603 +
5604         /*
5605          * This might block, so we do it before checking the inode.
5606          */
5607 @@ -1883,6 +1917,11 @@ int fcntl_setlk64(unsigned int fd, struc
5608         if (file_lock == NULL)
5609                 return -ENOLCK;
5610  
5611 +       vxd_assert(filp->f_xid == vx_current_xid(),
5612 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
5613 +       file_lock->fl_xid = filp->f_xid;
5614 +       vx_locks_inc(file_lock);
5615 +
5616         /*
5617          * This might block, so we do it before checking the inode.
5618          */
5619 @@ -2153,8 +2192,11 @@ static int locks_show(struct seq_file *f
5620  
5621         lock_get_status(f, fl, (long)f->private, "");
5622  
5623 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
5624 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
5625 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
5626 +                       continue;
5627                 lock_get_status(f, bfl, (long)f->private, " ->");
5628 +       }
5629  
5630         f->private++;
5631         return 0;
5632 diff -NurpP --minimal linux-2.6.24-rc7/fs/namei.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/namei.c
5633 --- linux-2.6.24-rc7/fs/namei.c 2007-11-29 01:11:53 +0100
5634 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/namei.c   2007-12-13 13:25:49 +0100
5635 @@ -30,6 +30,12 @@
5636  #include <linux/capability.h>
5637  #include <linux/file.h>
5638  #include <linux/fcntl.h>
5639 +#include <linux/proc_fs.h>
5640 +#include <linux/vserver/inode.h>
5641 +#include <linux/vs_base.h>
5642 +#include <linux/vs_tag.h>
5643 +#include <linux/vs_cowbl.h>
5644 +#include <linux/vs_context.h>
5645  #include <asm/namei.h>
5646  #include <asm/uaccess.h>
5647  
5648 @@ -225,6 +231,29 @@ int generic_permission(struct inode *ino
5649         return -EACCES;
5650  }
5651  
5652 +static inline int dx_barrier(struct inode *inode)
5653 +{
5654 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN)) {
5655 +               vxwprintk_task(1, "did hit the barrier.");
5656 +               return 1;
5657 +       }
5658 +       return 0;
5659 +}
5660 +
5661 +static inline int dx_permission(struct inode *inode, int mask, struct nameidata *nd)
5662 +{
5663 +       if (dx_barrier(inode))
5664 +               return -EACCES;
5665 +       if (inode->i_tag == 0)
5666 +               return 0;
5667 +       if (dx_check(inode->i_tag, DX_ADMIN|DX_WATCH|DX_IDENT))
5668 +               return 0;
5669 +
5670 +       vxwprintk_task(1, "denied access to %p[#%d,%lu] »%s«.",
5671 +               inode, inode->i_tag, inode->i_ino, vxd_cond_path(nd));
5672 +       return -EACCES;
5673 +}
5674 +
5675  int permission(struct inode *inode, int mask, struct nameidata *nd)
5676  {
5677         int retval, submask;
5678 @@ -239,14 +268,14 @@ int permission(struct inode *inode, int 
5679                 /*
5680                  * Nobody gets write access to a read-only fs.
5681                  */
5682 -               if (IS_RDONLY(inode) &&
5683 +               if ((IS_RDONLY(inode) || (nd && MNT_IS_RDONLY(nd->mnt))) &&
5684                     (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)))
5685                         return -EROFS;
5686  
5687                 /*
5688                  * Nobody gets write access to an immutable file.
5689                  */
5690 -               if (IS_IMMUTABLE(inode))
5691 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
5692                         return -EACCES;
5693         }
5694  
5695 @@ -261,6 +290,8 @@ int permission(struct inode *inode, int 
5696  
5697         /* Ordinary permission routines do not understand MAY_APPEND. */
5698         submask = mask & ~MAY_APPEND;
5699 +       if ((retval = dx_permission(inode, mask, nd)))
5700 +               return retval;
5701         if (inode->i_op && inode->i_op->permission) {
5702                 retval = inode->i_op->permission(inode, submask, nd);
5703                 if (!retval) {
5704 @@ -449,6 +480,8 @@ static int exec_permission_lite(struct i
5705  {
5706         umode_t mode = inode->i_mode;
5707  
5708 +       if (dx_barrier(inode))
5709 +               return -EACCES;
5710         if (inode->i_op && inode->i_op->permission)
5711                 return -EAGAIN;
5712  
5713 @@ -749,7 +782,8 @@ static __always_inline void follow_dotdo
5714                 if (nd->dentry == fs->root &&
5715                     nd->mnt == fs->rootmnt) {
5716                          read_unlock(&fs->lock);
5717 -                       break;
5718 +                       /* for sane '/' avoid follow_mount() */
5719 +                       return;
5720                 }
5721                  read_unlock(&fs->lock);
5722                 spin_lock(&dcache_lock);
5723 @@ -786,16 +820,33 @@ static int do_lookup(struct nameidata *n
5724  {
5725         struct vfsmount *mnt = nd->mnt;
5726         struct dentry *dentry = __d_lookup(nd->dentry, name);
5727 +       struct inode *inode;
5728  
5729         if (!dentry)
5730                 goto need_lookup;
5731         if (dentry->d_op && dentry->d_op->d_revalidate)
5732                 goto need_revalidate;
5733 +       inode = dentry->d_inode;
5734 +       if (!inode)
5735 +               goto done;
5736 +       if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
5737 +               struct proc_dir_entry *de = PDE(inode);
5738 +
5739 +               if (de && !vx_hide_check(0, de->vx_flags))
5740 +                       goto hidden;
5741 +       }
5742 +       if (!dx_check(inode->i_tag, DX_WATCH|DX_ADMIN|DX_HOSTID|DX_IDENT))
5743 +               goto hidden;
5744  done:
5745         path->mnt = mnt;
5746         path->dentry = dentry;
5747         __follow_mount(path);
5748         return 0;
5749 +hidden:
5750 +       vxwprintk_task(1, "did lookup hidden %p[#%d,%lu] »%s«.",
5751 +               inode, inode->i_tag, inode->i_ino, vxd_path(dentry, mnt));
5752 +       dput(dentry);
5753 +       return -ENOENT;
5754  
5755  need_lookup:
5756         dentry = real_lookup(nd->dentry, name, nd);
5757 @@ -1461,7 +1512,8 @@ static inline int check_sticky(struct in
5758   * 10. We don't allow removal of NFS sillyrenamed files; it's handled by
5759   *     nfs_async_unlink().
5760   */
5761 -static int may_delete(struct inode *dir,struct dentry *victim,int isdir)
5762 +static int may_delete(struct inode *dir, struct dentry *victim,
5763 +       int isdir, struct nameidata *nd)
5764  {
5765         int error;
5766  
5767 @@ -1471,13 +1523,13 @@ static int may_delete(struct inode *dir,
5768         BUG_ON(victim->d_parent->d_inode != dir);
5769         audit_inode_child(victim->d_name.name, victim, dir);
5770  
5771 -       error = permission(dir,MAY_WRITE | MAY_EXEC, NULL);
5772 +       error = permission(dir,MAY_WRITE | MAY_EXEC, nd);
5773         if (error)
5774                 return error;
5775         if (IS_APPEND(dir))
5776                 return -EPERM;
5777         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
5778 -           IS_IMMUTABLE(victim->d_inode))
5779 +               IS_IXORUNLINK(victim->d_inode))
5780                 return -EPERM;
5781         if (isdir) {
5782                 if (!S_ISDIR(victim->d_inode->i_mode))
5783 @@ -1623,6 +1675,14 @@ int may_open(struct nameidata *nd, int a
5784         } else if (IS_RDONLY(inode) && (flag & FMODE_WRITE))
5785                 return -EROFS;
5786  
5787 +#ifdef CONFIG_VSERVER_COWBL
5788 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
5789 +               if (IS_COW_LINK(inode))
5790 +                       return -EMLINK;
5791 +               inode->i_flags &= ~(S_IUNLINK|S_IMMUTABLE);
5792 +               mark_inode_dirty(inode);
5793 +       }
5794 +#endif
5795         error = vfs_permission(nd, acc_mode);
5796         if (error)
5797                 return error;
5798 @@ -1714,6 +1774,11 @@ int open_namei(int dfd, const char *path
5799         struct dentry *dir;
5800         int count = 0;
5801  
5802 +#ifdef CONFIG_VSERVER_COWBL
5803 +       int rflag = flag;
5804 +       int rmode = mode;
5805 +restart:
5806 +#endif
5807         acc_mode = ACC_MODE(flag);
5808  
5809         /* O_TRUNC implies we need access checks for write permissions */
5810 @@ -1807,6 +1872,22 @@ do_last:
5811                 goto exit;
5812  ok:
5813         error = may_open(nd, acc_mode, flag);
5814 +#ifdef CONFIG_VSERVER_COWBL
5815 +       if (error == -EMLINK) {
5816 +               struct dentry *dentry;
5817 +               dentry = cow_break_link(pathname);
5818 +               if (IS_ERR(dentry)) {
5819 +                       error = PTR_ERR(dentry);
5820 +                       goto exit;
5821 +               }
5822 +               dput(dentry);
5823 +               release_open_intent(nd);
5824 +               path_release(nd);
5825 +               flag = rflag;
5826 +               mode = rmode;
5827 +               goto restart;
5828 +       }
5829 +#endif
5830         if (error)
5831                 goto exit;
5832         return 0;
5833 @@ -1918,9 +1999,10 @@ fail:
5834  }
5835  EXPORT_SYMBOL_GPL(lookup_create);
5836  
5837 -int vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
5838 +int vfs_mknod(struct inode *dir, struct dentry *dentry,
5839 +       int mode, dev_t dev, struct nameidata *nd)
5840  {
5841 -       int error = may_create(dir, dentry, NULL);
5842 +       int error = may_create(dir, dentry, nd);
5843  
5844         if (error)
5845                 return error;
5846 @@ -1970,11 +2052,12 @@ asmlinkage long sys_mknodat(int dfd, con
5847                         error = vfs_create(nd.dentry->d_inode,dentry,mode,&nd);
5848                         break;
5849                 case S_IFCHR: case S_IFBLK:
5850 -                       error = vfs_mknod(nd.dentry->d_inode,dentry,mode,
5851 -                                       new_decode_dev(dev));
5852 +                       error = vfs_mknod(nd.dentry->d_inode, dentry, mode,
5853 +                                       new_decode_dev(dev), &nd);
5854                         break;
5855                 case S_IFIFO: case S_IFSOCK:
5856 -                       error = vfs_mknod(nd.dentry->d_inode,dentry,mode,0);
5857 +                       error = vfs_mknod(nd.dentry->d_inode, dentry, mode,
5858 +                                       0, &nd);
5859                         break;
5860                 case S_IFDIR:
5861                         error = -EPERM;
5862 @@ -1997,9 +2080,10 @@ asmlinkage long sys_mknod(const char __u
5863         return sys_mknodat(AT_FDCWD, filename, mode, dev);
5864  }
5865  
5866 -int vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
5867 +int vfs_mkdir(struct inode *dir, struct dentry *dentry,
5868 +       int mode, struct nameidata *nd)
5869  {
5870 -       int error = may_create(dir, dentry, NULL);
5871 +       int error = may_create(dir, dentry, nd);
5872  
5873         if (error)
5874                 return error;
5875 @@ -2041,7 +2125,7 @@ asmlinkage long sys_mkdirat(int dfd, con
5876  
5877         if (!IS_POSIXACL(nd.dentry->d_inode))
5878                 mode &= ~current->fs->umask;
5879 -       error = vfs_mkdir(nd.dentry->d_inode, dentry, mode);
5880 +       error = vfs_mkdir(nd.dentry->d_inode, dentry, mode, &nd);
5881         dput(dentry);
5882  out_unlock:
5883         mutex_unlock(&nd.dentry->d_inode->i_mutex);
5884 @@ -2084,9 +2168,10 @@ void dentry_unhash(struct dentry *dentry
5885         spin_unlock(&dcache_lock);
5886  }
5887  
5888 -int vfs_rmdir(struct inode *dir, struct dentry *dentry)
5889 +int vfs_rmdir(struct inode *dir, struct dentry *dentry,
5890 +       struct nameidata *nd)
5891  {
5892 -       int error = may_delete(dir, dentry, 1);
5893 +       int error = may_delete(dir, dentry, 1, nd);
5894  
5895         if (error)
5896                 return error;
5897 @@ -2148,7 +2233,7 @@ static long do_rmdir(int dfd, const char
5898         error = PTR_ERR(dentry);
5899         if (IS_ERR(dentry))
5900                 goto exit2;
5901 -       error = vfs_rmdir(nd.dentry->d_inode, dentry);
5902 +       error = vfs_rmdir(nd.dentry->d_inode, dentry, &nd);
5903         dput(dentry);
5904  exit2:
5905         mutex_unlock(&nd.dentry->d_inode->i_mutex);
5906 @@ -2164,9 +2249,10 @@ asmlinkage long sys_rmdir(const char __u
5907         return do_rmdir(AT_FDCWD, pathname);
5908  }
5909  
5910 -int vfs_unlink(struct inode *dir, struct dentry *dentry)
5911 +int vfs_unlink(struct inode *dir, struct dentry *dentry,
5912 +       struct nameidata *nd)
5913  {
5914 -       int error = may_delete(dir, dentry, 0);
5915 +       int error = may_delete(dir, dentry, 0, nd);
5916  
5917         if (error)
5918                 return error;
5919 @@ -2228,7 +2314,7 @@ static long do_unlinkat(int dfd, const c
5920                 inode = dentry->d_inode;
5921                 if (inode)
5922                         atomic_inc(&inode->i_count);
5923 -               error = vfs_unlink(nd.dentry->d_inode, dentry);
5924 +               error = vfs_unlink(nd.dentry->d_inode, dentry, &nd);
5925         exit2:
5926                 dput(dentry);
5927         }
5928 @@ -2263,9 +2349,10 @@ asmlinkage long sys_unlink(const char __
5929         return do_unlinkat(AT_FDCWD, pathname);
5930  }
5931  
5932 -int vfs_symlink(struct inode *dir, struct dentry *dentry, const char *oldname, int mode)
5933 +int vfs_symlink(struct inode *dir, struct dentry *dentry,
5934 +       const char *oldname, int mode, struct nameidata *nd)
5935  {
5936 -       int error = may_create(dir, dentry, NULL);
5937 +       int error = may_create(dir, dentry, nd);
5938  
5939         if (error)
5940                 return error;
5941 @@ -2309,7 +2396,7 @@ asmlinkage long sys_symlinkat(const char
5942         if (IS_ERR(dentry))
5943                 goto out_unlock;
5944  
5945 -       error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO);
5946 +       error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO, &nd);
5947         dput(dentry);
5948  out_unlock:
5949         mutex_unlock(&nd.dentry->d_inode->i_mutex);
5950 @@ -2326,7 +2413,8 @@ asmlinkage long sys_symlink(const char _
5951         return sys_symlinkat(oldname, AT_FDCWD, newname);
5952  }
5953  
5954 -int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry)
5955 +int vfs_link(struct dentry *old_dentry, struct inode *dir,
5956 +       struct dentry *new_dentry, struct nameidata *nd)
5957  {
5958         struct inode *inode = old_dentry->d_inode;
5959         int error;
5960 @@ -2334,7 +2422,7 @@ int vfs_link(struct dentry *old_dentry, 
5961         if (!inode)
5962                 return -ENOENT;
5963  
5964 -       error = may_create(dir, new_dentry, NULL);
5965 +       error = may_create(dir, new_dentry, nd);
5966         if (error)
5967                 return error;
5968  
5969 @@ -2344,7 +2432,7 @@ int vfs_link(struct dentry *old_dentry, 
5970         /*
5971          * A link to an append-only or immutable file cannot be created.
5972          */
5973 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
5974 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
5975                 return -EPERM;
5976         if (!dir->i_op || !dir->i_op->link)
5977                 return -EPERM;
5978 @@ -2404,7 +2492,7 @@ asmlinkage long sys_linkat(int olddfd, c
5979         error = PTR_ERR(new_dentry);
5980         if (IS_ERR(new_dentry))
5981                 goto out_unlock;
5982 -       error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry);
5983 +       error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry, &nd);
5984         dput(new_dentry);
5985  out_unlock:
5986         mutex_unlock(&nd.dentry->d_inode->i_mutex);
5987 @@ -2536,14 +2624,14 @@ int vfs_rename(struct inode *old_dir, st
5988         if (old_dentry->d_inode == new_dentry->d_inode)
5989                 return 0;
5990   
5991 -       error = may_delete(old_dir, old_dentry, is_dir);
5992 +       error = may_delete(old_dir, old_dentry, is_dir, NULL);
5993         if (error)
5994                 return error;
5995  
5996         if (!new_dentry->d_inode)
5997                 error = may_create(new_dir, new_dentry, NULL);
5998         else
5999 -               error = may_delete(new_dir, new_dentry, is_dir);
6000 +               error = may_delete(new_dir, new_dentry, is_dir, NULL);
6001         if (error)
6002                 return error;
6003  
6004 @@ -2621,6 +2709,9 @@ static int do_rename(int olddfd, const c
6005         error = -EINVAL;
6006         if (old_dentry == trap)
6007                 goto exit4;
6008 +       error = -EROFS;
6009 +       if (MNT_IS_RDONLY(newnd.mnt))
6010 +               goto exit4;
6011         new_dentry = lookup_hash(&newnd);
6012         error = PTR_ERR(new_dentry);
6013         if (IS_ERR(new_dentry))
6014 @@ -2714,6 +2805,217 @@ int vfs_follow_link(struct nameidata *nd
6015         return __vfs_follow_link(nd, link);
6016  }
6017  
6018 +
6019 +#ifdef CONFIG_VSERVER_COWBL
6020 +
6021 +#include <linux/file.h>
6022 +
6023 +static inline
6024 +long do_cow_splice(struct file *in, struct file *out, size_t len)
6025 +{
6026 +       loff_t ppos = 0;
6027 +
6028 +       return do_splice_direct(in, &ppos, out, len, 0);
6029 +}
6030 +
6031 +struct dentry *cow_break_link(const char *pathname)
6032 +{
6033 +       int ret, mode, pathlen, redo = 0;
6034 +       struct nameidata old_nd, dir_nd;
6035 +       struct dentry *old_dentry, *new_dentry;
6036 +       struct dentry *dir, *res = NULL;
6037 +       struct vfsmount *old_mnt, *new_mnt;
6038 +       struct file *old_file;
6039 +       struct file *new_file;
6040 +       char *to, *path, pad='\251';
6041 +       loff_t ppos, size;
6042 +
6043 +       vxdprintk(VXD_CBIT(misc, 1), "cow_break_link(»%s«)", pathname);
6044 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
6045 +       ret = -ENOMEM;
6046 +       if (!path)
6047 +               goto out;
6048 +
6049 +       /* old_nd will have refs to dentry and mnt */
6050 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
6051 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
6052 +       if (ret < 0)
6053 +               goto out_free_path;
6054 +
6055 +       old_dentry = old_nd.dentry;
6056 +       old_mnt = old_nd.mnt;
6057 +       mode = old_dentry->d_inode->i_mode;
6058 +
6059 +       to = d_path(old_dentry, old_mnt, path, PATH_MAX-2);
6060 +       pathlen = strlen(to);
6061 +       vxdprintk(VXD_CBIT(misc, 2), "old path »%s« [»%.*s«:%d]", to,
6062 +               old_dentry->d_name.len, old_dentry->d_name.name,
6063 +               old_dentry->d_name.len);
6064 +
6065 +       to[pathlen + 1] = 0;
6066 +retry:
6067 +       to[pathlen] = pad--;
6068 +       ret = -EMLINK;
6069 +       if (pad <= '\240')
6070 +               goto out_rel_old;
6071 +
6072 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy »%s«", to);
6073 +       /* dir_nd will have refs to dentry and mnt */
6074 +       ret = path_lookup(to,
6075 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
6076 +       vxdprintk(VXD_CBIT(misc, 2),
6077 +               "path_lookup(new): %d", ret);
6078 +       if (ret < 0)
6079 +               goto retry;
6080 +
6081 +       /* this puppy downs the inode mutex */
6082 +       new_dentry = lookup_create(&dir_nd, 0);
6083 +       vxdprintk(VXD_CBIT(misc, 2),
6084 +               "lookup_create(new): %p [»%.*s«:%d]", new_dentry,
6085 +               new_dentry->d_name.len, new_dentry->d_name.name,
6086 +               new_dentry->d_name.len);
6087 +       if (!new_dentry || IS_ERR(new_dentry)) {
6088 +               path_release(&dir_nd);
6089 +               goto retry;
6090 +       }
6091 +       dir = dir_nd.dentry;
6092 +
6093 +       ret = vfs_create(dir_nd.dentry->d_inode, new_dentry, mode, &dir_nd);
6094 +       vxdprintk(VXD_CBIT(misc, 2),
6095 +               "vfs_create(new): %d", ret);
6096 +       if (ret == -EEXIST) {
6097 +               mutex_unlock(&dir->d_inode->i_mutex);
6098 +               dput(new_dentry);
6099 +               path_release(&dir_nd);
6100 +               goto retry;
6101 +       }
6102 +       else if (ret < 0)
6103 +               goto out_unlock_new;
6104 +
6105 +       /* drop out early, ret passes ENOENT */
6106 +       ret = -ENOENT;
6107 +       if ((redo = d_unhashed(old_dentry)))
6108 +               goto out_unlock_new;
6109 +
6110 +       new_mnt = dir_nd.mnt;
6111 +       dget(old_dentry);
6112 +       mntget(old_mnt);
6113 +       /* this one cleans up the dentry/mnt in case of failure */
6114 +       old_file = dentry_open(old_dentry, old_mnt, O_RDONLY);
6115 +       vxdprintk(VXD_CBIT(misc, 2),
6116 +               "dentry_open(old): %p", old_file);
6117 +       if (!old_file || IS_ERR(old_file)) {
6118 +               res = IS_ERR(old_file) ? (void *) old_file : res;
6119 +               goto out_unlock_new;
6120 +       }
6121 +
6122 +       dget(new_dentry);
6123 +       mntget(new_mnt);
6124 +       /* this one cleans up the dentry/mnt in case of failure */
6125 +       new_file = dentry_open(new_dentry, new_mnt, O_WRONLY);
6126 +       vxdprintk(VXD_CBIT(misc, 2),
6127 +               "dentry_open(new): %p", new_file);
6128 +
6129 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
6130 +       if (!new_file || IS_ERR(new_file))
6131 +               goto out_fput_old;
6132 +
6133 +       size = i_size_read(old_file->f_dentry->d_inode);
6134 +       ppos = 0;
6135 +       ret = do_cow_splice(old_file, new_file, size);
6136 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
6137 +       if (ret < 0) {
6138 +               goto out_fput_both;
6139 +       } else if (ret < size) {
6140 +               ret = -ENOSPC;
6141 +               goto out_fput_both;
6142 +       } else {
6143 +               struct inode *old_inode = old_dentry->d_inode;
6144 +               struct inode *new_inode = new_dentry->d_inode;
6145 +               struct iattr attr = {
6146 +                       .ia_uid = old_inode->i_uid,
6147 +                       .ia_gid = old_inode->i_gid,
6148 +                       .ia_valid = ATTR_UID | ATTR_GID
6149 +                       };
6150 +
6151 +               ret = inode_setattr(new_inode, &attr);
6152 +               if (ret)
6153 +                       goto out_fput_both;
6154 +       }
6155 +
6156 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
6157 +
6158 +       /* drop out late */
6159 +       ret = -ENOENT;
6160 +       if ((redo = d_unhashed(old_dentry)))
6161 +               goto out_unlock;
6162 +
6163 +       vxdprintk(VXD_CBIT(misc, 2),
6164 +               "vfs_rename: [»%*s«:%d] -> [»%*s«:%d]",
6165 +               new_dentry->d_name.len, new_dentry->d_name.name,
6166 +               new_dentry->d_name.len,
6167 +               old_dentry->d_name.len, old_dentry->d_name.name,
6168 +               old_dentry->d_name.len);
6169 +       ret = vfs_rename(dir_nd.dentry->d_inode, new_dentry,
6170 +               old_nd.dentry->d_parent->d_inode, old_dentry);
6171 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
6172 +       res = new_dentry;
6173 +
6174 +out_unlock:
6175 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
6176 +
6177 +out_fput_both:
6178 +       vxdprintk(VXD_CBIT(misc, 3),
6179 +               "fput(new_file=%p[#%d])", new_file,
6180 +               atomic_read(&new_file->f_count));
6181 +       fput(new_file);
6182 +
6183 +out_fput_old:
6184 +       vxdprintk(VXD_CBIT(misc, 3),
6185 +               "fput(old_file=%p[#%d])", old_file,
6186 +               atomic_read(&old_file->f_count));
6187 +       fput(old_file);
6188 +
6189 +out_unlock_new:
6190 +       mutex_unlock(&dir->d_inode->i_mutex);
6191 +       if (!ret)
6192 +               goto out_redo;
6193 +
6194 +       /* error path cleanup */
6195 +       vfs_unlink(dir->d_inode, new_dentry, &dir_nd);
6196 +       dput(new_dentry);
6197 +
6198 +out_redo:
6199 +       if (!redo)
6200 +               goto out_rel_both;
6201 +       /* lookup dentry once again */
6202 +       path_release(&old_nd);
6203 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
6204 +       if (ret)
6205 +               goto out_rel_both;
6206 +
6207 +       new_dentry = old_nd.dentry;
6208 +       vxdprintk(VXD_CBIT(misc, 2),
6209 +               "path_lookup(redo): %p [»%.*s«:%d]", new_dentry,
6210 +               new_dentry->d_name.len, new_dentry->d_name.name,
6211 +               new_dentry->d_name.len);
6212 +       dget(new_dentry);
6213 +       res = new_dentry;
6214 +
6215 +out_rel_both:
6216 +       path_release(&dir_nd);
6217 +out_rel_old:
6218 +       path_release(&old_nd);
6219 +out_free_path:
6220 +       kfree(path);
6221 +out:
6222 +       if (ret)
6223 +               res = ERR_PTR(ret);
6224 +       return res;
6225 +}
6226 +
6227 +#endif
6228 +
6229  /* get the link contents into pagecache */
6230  static char *page_getlink(struct dentry * dentry, struct page **ppage)
6231  {
6232 diff -NurpP --minimal linux-2.6.24-rc7/fs/namespace.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/namespace.c
6233 --- linux-2.6.24-rc7/fs/namespace.c     2007-11-29 01:11:53 +0100
6234 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/namespace.c       2007-12-13 13:25:48 +0100
6235 @@ -25,6 +25,11 @@
6236  #include <linux/security.h>
6237  #include <linux/mount.h>
6238  #include <linux/ramfs.h>
6239 +#include <linux/vs_base.h>
6240 +#include <linux/vs_context.h>
6241 +#include <linux/vs_tag.h>
6242 +#include <linux/vserver/space.h>
6243 +#include <linux/vserver/global.h>
6244  #include <asm/uaccess.h>
6245  #include <asm/unistd.h>
6246  #include "pnode.h"
6247 @@ -241,6 +246,7 @@ static struct vfsmount *clone_mnt(struct
6248                 mnt->mnt_root = dget(root);
6249                 mnt->mnt_mountpoint = mnt->mnt_root;
6250                 mnt->mnt_parent = mnt;
6251 +               mnt->mnt_tag = old->mnt_tag;
6252  
6253                 if (flag & CL_SLAVE) {
6254                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
6255 @@ -343,48 +349,91 @@ static inline void mangle(struct seq_fil
6256         seq_escape(m, s, " \t\n\\");
6257  }
6258  
6259 +static int mnt_is_reachable(struct vfsmount *mnt)
6260 +{
6261 +       struct vfsmount *root_mnt;
6262 +       struct dentry *root, *point;
6263 +       int ret;
6264 +
6265 +       if (mnt == mnt->mnt_ns->root)
6266 +               return 1;
6267 +
6268 +       spin_lock(&vfsmount_lock);
6269 +       root_mnt = current->fs->rootmnt;
6270 +       root = current->fs->root;
6271 +       point = root;
6272 +
6273 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6274 +               point = mnt->mnt_mountpoint;
6275 +               mnt = mnt->mnt_parent;
6276 +       }
6277 +
6278 +       ret = (mnt == root_mnt) && is_subdir(point, root);
6279 +
6280 +       spin_unlock(&vfsmount_lock);
6281 +
6282 +       return ret;
6283 +}
6284 +
6285  static int show_vfsmnt(struct seq_file *m, void *v)
6286  {
6287         struct vfsmount *mnt = list_entry(v, struct vfsmount, mnt_list);
6288         int err = 0;
6289         static struct proc_fs_info {
6290 -               int flag;
6291 -               char *str;
6292 +               int s_flag;
6293 +               int mnt_flag;
6294 +               char *set_str;
6295 +               char *unset_str;
6296         } fs_info[] = {
6297 -               { MS_SYNCHRONOUS, ",sync" },
6298 -               { MS_DIRSYNC, ",dirsync" },
6299 -               { MS_MANDLOCK, ",mand" },
6300 -               { 0, NULL }
6301 -       };
6302 -       static struct proc_fs_info mnt_info[] = {
6303 -               { MNT_NOSUID, ",nosuid" },
6304 -               { MNT_NODEV, ",nodev" },
6305 -               { MNT_NOEXEC, ",noexec" },
6306 -               { MNT_NOATIME, ",noatime" },
6307 -               { MNT_NODIRATIME, ",nodiratime" },
6308 -               { MNT_RELATIME, ",relatime" },
6309 -               { 0, NULL }
6310 +               { MS_RDONLY, MNT_RDONLY, "ro", "rw" },
6311 +               { MS_SYNCHRONOUS, 0, ",sync", NULL },
6312 +               { MS_DIRSYNC, 0, ",dirsync", NULL },
6313 +               { MS_MANDLOCK, 0, ",mand", NULL },
6314 +               { MS_TAGGED, 0, ",tag", NULL },
6315 +               { MS_NOATIME, MNT_NOATIME, ",noatime", NULL },
6316 +               { MS_NODIRATIME, MNT_NODIRATIME, ",nodiratime", NULL },
6317 +               { MS_RELATIME, MNT_RELATIME, ",relatime", NULL },
6318 +               { 0, MNT_NOSUID, ",nosuid", NULL },
6319 +               { 0, MNT_NODEV, ",nodev", NULL },
6320 +               { 0, MNT_NOEXEC, ",noexec", NULL },
6321 +               { 0, 0, NULL, NULL }
6322         };
6323 -       struct proc_fs_info *fs_infop;
6324 +       struct proc_fs_info *p;
6325 +       unsigned long s_flags = mnt->mnt_sb->s_flags;
6326 +       int mnt_flags = mnt->mnt_flags;
6327  
6328 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
6329 -       seq_putc(m, ' ');
6330 -       seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
6331 -       seq_putc(m, ' ');
6332 -       mangle(m, mnt->mnt_sb->s_type->name);
6333 -       if (mnt->mnt_sb->s_subtype && mnt->mnt_sb->s_subtype[0]) {
6334 -               seq_putc(m, '.');
6335 -               mangle(m, mnt->mnt_sb->s_subtype);
6336 -       }
6337 -       seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? " ro" : " rw");
6338 -       for (fs_infop = fs_info; fs_infop->flag; fs_infop++) {
6339 -               if (mnt->mnt_sb->s_flags & fs_infop->flag)
6340 -                       seq_puts(m, fs_infop->str);
6341 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6342 +               return 0;
6343 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6344 +               return 0;
6345 +
6346 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6347 +               mnt == current->fs->rootmnt) {
6348 +               seq_puts(m, "/dev/root / ");
6349 +       } else {
6350 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
6351 +               seq_putc(m, ' ');
6352 +               seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
6353 +               seq_putc(m, ' ');
6354 +
6355 +               if (mnt->mnt_sb->s_subtype && mnt->mnt_sb->s_subtype[0]) {
6356 +                       seq_putc(m, '.');
6357 +                       mangle(m, mnt->mnt_sb->s_subtype);
6358 +               }
6359         }
6360 -       for (fs_infop = mnt_info; fs_infop->flag; fs_infop++) {
6361 -               if (mnt->mnt_flags & fs_infop->flag)
6362 -                       seq_puts(m, fs_infop->str);
6363 +       mangle(m, mnt->mnt_sb->s_type->name);
6364 +       seq_putc(m, ' ');
6365 +       for (p = fs_info; (p->s_flag | p->mnt_flag) ; p++) {
6366 +               if ((s_flags & p->s_flag) || (mnt_flags & p->mnt_flag)) {
6367 +                       if (p->set_str)
6368 +                               seq_puts(m, p->set_str);
6369 +               } else {
6370 +                       if (p->unset_str)
6371 +                               seq_puts(m, p->unset_str);
6372 +               }
6373         }
6374 +       if (mnt->mnt_flags & MNT_TAGID)
6375 +               seq_printf(m, ",tag=%d", mnt->mnt_tag);
6376         if (mnt->mnt_sb->s_op->show_options)
6377                 err = mnt->mnt_sb->s_op->show_options(m, mnt);
6378         seq_puts(m, " 0 0\n");
6379 @@ -403,17 +452,27 @@ static int show_vfsstat(struct seq_file 
6380         struct vfsmount *mnt = list_entry(v, struct vfsmount, mnt_list);
6381         int err = 0;
6382  
6383 -       /* device */
6384 -       if (mnt->mnt_devname) {
6385 -               seq_puts(m, "device ");
6386 -               mangle(m, mnt->mnt_devname);
6387 -       } else
6388 -               seq_puts(m, "no device");
6389 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6390 +               return 0;
6391 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6392 +               return 0;
6393  
6394 -       /* mount point */
6395 -       seq_puts(m, " mounted on ");
6396 -       seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
6397 -       seq_putc(m, ' ');
6398 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6399 +               mnt == current->fs->rootmnt) {
6400 +               seq_puts(m, "device /dev/root mounted on / ");
6401 +       } else {
6402 +               /* device */
6403 +               if (mnt->mnt_devname) {
6404 +                       seq_puts(m, "device ");
6405 +                       mangle(m, mnt->mnt_devname);
6406 +               } else
6407 +                       seq_puts(m, "no device");
6408 +
6409 +               /* mount point */
6410 +               seq_puts(m, " mounted on ");
6411 +               seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
6412 +               seq_putc(m, ' ');
6413 +       }
6414  
6415         /* file system type */
6416         seq_puts(m, "with fstype ");
6417 @@ -643,7 +702,7 @@ asmlinkage long sys_umount(char __user *
6418                 goto dput_and_out;
6419  
6420         retval = -EPERM;
6421 -       if (!capable(CAP_SYS_ADMIN))
6422 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6423                 goto dput_and_out;
6424  
6425         retval = do_umount(nd.mnt, flags);
6426 @@ -667,7 +726,7 @@ asmlinkage long sys_oldumount(char __use
6427  
6428  static int mount_is_safe(struct nameidata *nd)
6429  {
6430 -       if (capable(CAP_SYS_ADMIN))
6431 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6432                 return 0;
6433         return -EPERM;
6434  #ifdef notyet
6435 @@ -919,11 +978,13 @@ static int do_change_type(struct nameida
6436  /*
6437   * do loopback mount.
6438   */
6439 -static int do_loopback(struct nameidata *nd, char *old_name, int recurse)
6440 +static int do_loopback(struct nameidata *nd, char *old_name, tag_t tag,
6441 +       unsigned long flags, int mnt_flags)
6442  {
6443         struct nameidata old_nd;
6444         struct vfsmount *mnt = NULL;
6445         int err = mount_is_safe(nd);
6446 +       int recurse = flags & MS_REC;
6447         if (err)
6448                 return err;
6449         if (!old_name || !*old_name)
6450 @@ -949,6 +1010,12 @@ static int do_loopback(struct nameidata 
6451         if (!mnt)
6452                 goto out;
6453  
6454 +       mnt->mnt_flags = mnt_flags;
6455 +       if (flags & MS_TAGID) {
6456 +               mnt->mnt_tag = tag;
6457 +               mnt->mnt_flags |= MNT_TAGID;
6458 +       }
6459 +
6460         err = graft_tree(mnt, nd);
6461         if (err) {
6462                 LIST_HEAD(umount_list);
6463 @@ -957,6 +1024,7 @@ static int do_loopback(struct nameidata 
6464                 spin_unlock(&vfsmount_lock);
6465                 release_mounts(&umount_list);
6466         }
6467 +       mnt->mnt_flags = mnt_flags;
6468  
6469  out:
6470         up_write(&namespace_sem);
6471 @@ -970,12 +1038,12 @@ out:
6472   * on it - tough luck.
6473   */
6474  static int do_remount(struct nameidata *nd, int flags, int mnt_flags,
6475 -                     void *data)
6476 +                     void *data, xid_t xid)
6477  {
6478         int err;
6479         struct super_block *sb = nd->mnt->mnt_sb;
6480  
6481 -       if (!capable(CAP_SYS_ADMIN))
6482 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
6483                 return -EPERM;
6484  
6485         if (!check_mnt(nd->mnt))
6486 @@ -1009,7 +1077,7 @@ static int do_move_mount(struct nameidat
6487         struct nameidata old_nd, parent_nd;
6488         struct vfsmount *p;
6489         int err = 0;
6490 -       if (!capable(CAP_SYS_ADMIN))
6491 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6492                 return -EPERM;
6493         if (!old_name || !*old_name)
6494                 return -EINVAL;
6495 @@ -1089,7 +1157,7 @@ static int do_new_mount(struct nameidata
6496                 return -EINVAL;
6497  
6498         /* we need capabilities... */
6499 -       if (!capable(CAP_SYS_ADMIN))
6500 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6501                 return -EPERM;
6502  
6503         mnt = do_kern_mount(type, flags, name, data);
6504 @@ -1401,6 +1469,7 @@ long do_mount(char *dev_name, char *dir_
6505         struct nameidata nd;
6506         int retval = 0;
6507         int mnt_flags = 0;
6508 +       tag_t tag = 0;
6509  
6510         /* Discard magic */
6511         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
6512 @@ -1416,7 +1485,19 @@ long do_mount(char *dev_name, char *dir_
6513         if (data_page)
6514                 ((char *)data_page)[PAGE_SIZE - 1] = 0;
6515  
6516 +#ifdef CONFIG_PROPAGATE
6517 +       retval = dx_parse_tag(data_page, &tag, 1);
6518 +       if (retval) {
6519 +               mnt_flags |= MNT_TAGID;
6520 +               /* bind and re-mounts get the tag flag */
6521 +               if (flags & (MS_BIND|MS_REMOUNT))
6522 +                       flags |= MS_TAGID;
6523 +       }
6524 +#endif
6525 +
6526         /* Separate the per-mountpoint flags */
6527 +       if (flags & MS_RDONLY)
6528 +               mnt_flags |= MNT_RDONLY;
6529         if (flags & MS_NOSUID)
6530                 mnt_flags |= MNT_NOSUID;
6531         if (flags & MS_NODEV)
6532 @@ -1430,6 +1511,8 @@ long do_mount(char *dev_name, char *dir_
6533         if (flags & MS_RELATIME)
6534                 mnt_flags |= MNT_RELATIME;
6535  
6536 +       if (!capable(CAP_SYS_ADMIN))
6537 +               mnt_flags |= MNT_NODEV;
6538         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
6539                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT);
6540  
6541 @@ -1444,9 +1527,9 @@ long do_mount(char *dev_name, char *dir_
6542  
6543         if (flags & MS_REMOUNT)
6544                 retval = do_remount(&nd, flags & ~MS_REMOUNT, mnt_flags,
6545 -                                   data_page);
6546 +                                   data_page, tag);
6547         else if (flags & MS_BIND)
6548 -               retval = do_loopback(&nd, dev_name, flags & MS_REC);
6549 +               retval = do_loopback(&nd, dev_name, tag, flags, mnt_flags);
6550         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
6551                 retval = do_change_type(&nd, flags);
6552         else if (flags & MS_MOVE)
6553 @@ -1519,6 +1602,7 @@ static struct mnt_namespace *dup_mnt_ns(
6554                 q = next_mnt(q, new_ns->root);
6555         }
6556         up_write(&namespace_sem);
6557 +       atomic_inc(&vs_global_mnt_ns);
6558  
6559         if (rootmnt)
6560                 mntput(rootmnt);
6561 @@ -1881,5 +1965,6 @@ void __put_mnt_ns(struct mnt_namespace *
6562         spin_unlock(&vfsmount_lock);
6563         up_write(&namespace_sem);
6564         release_mounts(&umount_list);
6565 +       atomic_dec(&vs_global_mnt_ns);
6566         kfree(ns);
6567  }
6568 diff -NurpP --minimal linux-2.6.24-rc7/fs/nfs/client.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/nfs/client.c
6569 --- linux-2.6.24-rc7/fs/nfs/client.c    2007-12-31 17:58:26 +0100
6570 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/nfs/client.c      2007-12-31 12:34:39 +0100
6571 @@ -495,6 +495,9 @@ static int nfs_init_server_rpcclient(str
6572         if (server->flags & NFS4_MOUNT_INTR)
6573                 server->client->cl_intr = 1;
6574  
6575 +       server->client->cl_tag = 0;
6576 +       if (server->flags & NFS_MOUNT_TAGGED)
6577 +               server->client->cl_tag = 1;
6578         return 0;
6579  }
6580  
6581 @@ -645,6 +648,10 @@ static void nfs_server_set_fsinfo(struct
6582                 server->acdirmin = server->acdirmax = 0;
6583         }
6584  
6585 +       /* FIXME: needs fsinfo
6586 +       if (server->flags & NFS_MOUNT_TAGGED)
6587 +               sb->s_flags |= MS_TAGGED;       */
6588 +
6589         server->maxfilesize = fsinfo->maxfilesize;
6590  
6591         /* We're airborne Set socket buffersize */
6592 diff -NurpP --minimal linux-2.6.24-rc7/fs/nfs/dir.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/nfs/dir.c
6593 --- linux-2.6.24-rc7/fs/nfs/dir.c       2007-12-31 17:58:26 +0100
6594 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/nfs/dir.c 2007-12-31 12:34:39 +0100
6595 @@ -34,6 +34,7 @@
6596  #include <linux/namei.h>
6597  #include <linux/mount.h>
6598  #include <linux/sched.h>
6599 +#include <linux/vs_tag.h>
6600  
6601  #include "nfs4_fs.h"
6602  #include "delegation.h"
6603 @@ -913,6 +914,7 @@ static struct dentry *nfs_lookup(struct 
6604         if (IS_ERR(res))
6605                 goto out_unblock_sillyrename;
6606  
6607 +       dx_propagate_tag(nd, inode);
6608  no_entry:
6609         res = d_materialise_unique(dentry, inode);
6610         if (res != NULL) {
6611 @@ -950,7 +952,8 @@ static int is_atomic_open(struct inode *
6612         if (nd->flags & LOOKUP_DIRECTORY)
6613                 return 0;
6614         /* Are we trying to write to a read only partition? */
6615 -       if (IS_RDONLY(dir) && (nd->intent.open.flags & (O_CREAT|O_TRUNC|FMODE_WRITE)))
6616 +       if ((IS_RDONLY(dir) || MNT_IS_RDONLY(nd->mnt)) &&
6617 +               (nd->intent.open.flags & (O_CREAT|O_TRUNC|FMODE_WRITE)))
6618                 return 0;
6619         return 1;
6620  }
6621 diff -NurpP --minimal linux-2.6.24-rc7/fs/nfs/inode.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/nfs/inode.c
6622 --- linux-2.6.24-rc7/fs/nfs/inode.c     2007-11-29 01:11:53 +0100
6623 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/nfs/inode.c       2007-12-13 13:25:51 +0100
6624 @@ -37,6 +37,7 @@
6625  #include <linux/vfs.h>
6626  #include <linux/inet.h>
6627  #include <linux/nfs_xdr.h>
6628 +#include <linux/vs_tag.h>
6629  
6630  #include <asm/system.h>
6631  #include <asm/uaccess.h>
6632 @@ -315,8 +316,10 @@ nfs_fhget(struct super_block *sb, struct
6633                         nfsi->change_attr = fattr->change_attr;
6634                 inode->i_size = nfs_size_to_loff_t(fattr->size);
6635                 inode->i_nlink = fattr->nlink;
6636 -               inode->i_uid = fattr->uid;
6637 -               inode->i_gid = fattr->gid;
6638 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
6639 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
6640 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
6641 +                                        /* maybe fattr->xid someday */
6642                 if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
6643                         /*
6644                          * report the blocks in 512byte units
6645 @@ -409,6 +412,8 @@ void nfs_setattr_update_inode(struct ino
6646                         inode->i_uid = attr->ia_uid;
6647                 if ((attr->ia_valid & ATTR_GID) != 0)
6648                         inode->i_gid = attr->ia_gid;
6649 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
6650 +                       inode->i_tag = attr->ia_tag;
6651                 spin_lock(&inode->i_lock);
6652                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
6653                 spin_unlock(&inode->i_lock);
6654 @@ -833,6 +838,9 @@ static int nfs_check_inode_attributes(st
6655         struct nfs_inode *nfsi = NFS_I(inode);
6656         loff_t cur_size, new_isize;
6657         unsigned long invalid = 0;
6658 +       uid_t uid;
6659 +       gid_t gid;
6660 +       tag_t tag;
6661  
6662  
6663         /* Has the inode gone and changed behind our back? */
6664 @@ -857,10 +865,15 @@ static int nfs_check_inode_attributes(st
6665         if (cur_size != new_isize && nfsi->npages == 0)
6666                 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
6667  
6668 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
6669 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
6670 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
6671 +
6672         /* Have any file permissions changed? */
6673         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)
6674 -                       || inode->i_uid != fattr->uid
6675 -                       || inode->i_gid != fattr->gid)
6676 +                       || inode->i_uid != uid
6677 +                       || inode->i_gid != gid
6678 +                       || inode->i_tag != tag)
6679                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
6680  
6681         /* Has the link count changed? */
6682 @@ -981,6 +994,9 @@ static int nfs_update_inode(struct inode
6683         loff_t cur_isize, new_isize;
6684         unsigned long invalid = 0;
6685         unsigned long now = jiffies;
6686 +       uid_t uid;
6687 +       gid_t gid;
6688 +       tag_t tag;
6689  
6690         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
6691                         __FUNCTION__, inode->i_sb->s_id, inode->i_ino,
6692 @@ -1051,15 +1067,21 @@ static int nfs_update_inode(struct inode
6693         memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
6694         nfsi->change_attr = fattr->change_attr;
6695  
6696 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
6697 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
6698 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
6699 +
6700         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO) ||
6701 -           inode->i_uid != fattr->uid ||
6702 -           inode->i_gid != fattr->gid)
6703 +           inode->i_uid != uid ||
6704 +           inode->i_gid != gid ||
6705 +           inode->i_tag != tag)
6706                 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
6707  
6708         inode->i_mode = fattr->mode;
6709         inode->i_nlink = fattr->nlink;
6710 -       inode->i_uid = fattr->uid;
6711 -       inode->i_gid = fattr->gid;
6712 +       inode->i_uid = uid;
6713 +       inode->i_gid = gid;
6714 +       inode->i_tag = tag;
6715  
6716         if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
6717                 /*
6718 diff -NurpP --minimal linux-2.6.24-rc7/fs/nfs/nfs3xdr.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/nfs/nfs3xdr.c
6719 --- linux-2.6.24-rc7/fs/nfs/nfs3xdr.c   2007-11-29 01:11:53 +0100
6720 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/nfs/nfs3xdr.c     2007-12-13 13:25:51 +0100
6721 @@ -22,6 +22,7 @@
6722  #include <linux/nfs3.h>
6723  #include <linux/nfs_fs.h>
6724  #include <linux/nfsacl.h>
6725 +#include <linux/vs_tag.h>
6726  #include "internal.h"
6727  
6728  #define NFSDBG_FACILITY                NFSDBG_XDR
6729 @@ -180,7 +181,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
6730  }
6731  
6732  static inline __be32 *
6733 -xdr_encode_sattr(__be32 *p, struct iattr *attr)
6734 +xdr_encode_sattr(__be32 *p, struct iattr *attr, int tag)
6735  {
6736         if (attr->ia_valid & ATTR_MODE) {
6737                 *p++ = xdr_one;
6738 @@ -188,15 +189,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
6739         } else {
6740                 *p++ = xdr_zero;
6741         }
6742 -       if (attr->ia_valid & ATTR_UID) {
6743 +       if (attr->ia_valid & ATTR_UID ||
6744 +               (tag && (attr->ia_valid & ATTR_TAG))) {
6745                 *p++ = xdr_one;
6746 -               *p++ = htonl(attr->ia_uid);
6747 +               *p++ = htonl(TAGINO_UID(tag, attr->ia_uid, attr->ia_tag));
6748         } else {
6749                 *p++ = xdr_zero;
6750         }
6751 -       if (attr->ia_valid & ATTR_GID) {
6752 +       if (attr->ia_valid & ATTR_GID ||
6753 +               (tag && (attr->ia_valid & ATTR_TAG))) {
6754                 *p++ = xdr_one;
6755 -               *p++ = htonl(attr->ia_gid);
6756 +               *p++ = htonl(TAGINO_GID(tag, attr->ia_gid, attr->ia_tag));
6757         } else {
6758                 *p++ = xdr_zero;
6759         }
6760 @@ -281,7 +284,8 @@ static int
6761  nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args)
6762  {
6763         p = xdr_encode_fhandle(p, args->fh);
6764 -       p = xdr_encode_sattr(p, args->sattr);
6765 +       p = xdr_encode_sattr(p, args->sattr,
6766 +               req->rq_task->tk_client->cl_tag);
6767         *p++ = htonl(args->guard);
6768         if (args->guard)
6769                 p = xdr_encode_time3(p, &args->guardtime);
6770 @@ -386,7 +390,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
6771                 *p++ = args->verifier[0];
6772                 *p++ = args->verifier[1];
6773         } else
6774 -               p = xdr_encode_sattr(p, args->sattr);
6775 +               p = xdr_encode_sattr(p, args->sattr,
6776 +                       req->rq_task->tk_client->cl_tag);
6777  
6778         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
6779         return 0;
6780 @@ -400,7 +405,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
6781  {
6782         p = xdr_encode_fhandle(p, args->fh);
6783         p = xdr_encode_array(p, args->name, args->len);
6784 -       p = xdr_encode_sattr(p, args->sattr);
6785 +       p = xdr_encode_sattr(p, args->sattr,
6786 +               req->rq_task->tk_client->cl_tag);
6787         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
6788         return 0;
6789  }
6790 @@ -413,7 +419,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
6791  {
6792         p = xdr_encode_fhandle(p, args->fromfh);
6793         p = xdr_encode_array(p, args->fromname, args->fromlen);
6794 -       p = xdr_encode_sattr(p, args->sattr);
6795 +       p = xdr_encode_sattr(p, args->sattr,
6796 +               req->rq_task->tk_client->cl_tag);
6797         *p++ = htonl(args->pathlen);
6798         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
6799  
6800 @@ -431,7 +438,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
6801         p = xdr_encode_fhandle(p, args->fh);
6802         p = xdr_encode_array(p, args->name, args->len);
6803         *p++ = htonl(args->type);
6804 -       p = xdr_encode_sattr(p, args->sattr);
6805 +       p = xdr_encode_sattr(p, args->sattr,
6806 +               req->rq_task->tk_client->cl_tag);
6807         if (args->type == NF3CHR || args->type == NF3BLK) {
6808                 *p++ = htonl(MAJOR(args->rdev));
6809                 *p++ = htonl(MINOR(args->rdev));
6810 diff -NurpP --minimal linux-2.6.24-rc7/fs/nfs/nfsroot.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/nfs/nfsroot.c
6811 --- linux-2.6.24-rc7/fs/nfs/nfsroot.c   2007-11-29 01:11:53 +0100
6812 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/nfs/nfsroot.c     2007-12-13 13:25:51 +0100
6813 @@ -119,12 +119,12 @@ static int mount_port __initdata = 0;             /
6814  enum {
6815         /* Options that take integer arguments */
6816         Opt_port, Opt_rsize, Opt_wsize, Opt_timeo, Opt_retrans, Opt_acregmin,
6817 -       Opt_acregmax, Opt_acdirmin, Opt_acdirmax,
6818 +       Opt_acregmax, Opt_acdirmin, Opt_acdirmax, Opt_tagid,
6819         /* Options that take no arguments */
6820         Opt_soft, Opt_hard, Opt_intr,
6821         Opt_nointr, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac, 
6822         Opt_noac, Opt_lock, Opt_nolock, Opt_v2, Opt_v3, Opt_udp, Opt_tcp,
6823 -       Opt_acl, Opt_noacl,
6824 +       Opt_acl, Opt_noacl, Opt_tag, Opt_notag,
6825         /* Error token */
6826         Opt_err
6827  };
6828 @@ -161,6 +161,10 @@ static match_table_t __initdata tokens =
6829         {Opt_tcp, "tcp"},
6830         {Opt_acl, "acl"},
6831         {Opt_noacl, "noacl"},
6832 +       {Opt_tag, "tag"},
6833 +       {Opt_notag, "notag"},
6834 +       {Opt_tagid, "tagid=%u"},
6835 +       {Opt_tag, "tagxid"},
6836         {Opt_err, NULL}
6837         
6838  };
6839 @@ -275,6 +279,20 @@ static int __init root_nfs_parse(char *n
6840                         case Opt_noacl:
6841                                 nfs_data.flags |= NFS_MOUNT_NOACL;
6842                                 break;
6843 +#ifndef CONFIG_TAGGING_NONE
6844 +                       case Opt_tag:
6845 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
6846 +                               break;
6847 +                       case Opt_notag:
6848 +                               nfs_data.flags &= ~NFS_MOUNT_TAGGED;
6849 +                               break;
6850 +#endif
6851 +#ifdef CONFIG_PROPAGATE
6852 +                       case Opt_tagid:
6853 +                               /* use args[0] */
6854 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
6855 +                               break;
6856 +#endif
6857                         default:
6858                                 printk(KERN_WARNING "Root-NFS: unknown "
6859                                         "option: %s\n", p);
6860 diff -NurpP --minimal linux-2.6.24-rc7/fs/nfs/super.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/nfs/super.c
6861 --- linux-2.6.24-rc7/fs/nfs/super.c     2008-01-11 12:00:49 +0100
6862 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/nfs/super.c       2008-01-11 04:30:09 +0100
6863 @@ -48,6 +48,7 @@
6864  #include <linux/nfs_xdr.h>
6865  #include <linux/magic.h>
6866  #include <linux/parser.h>
6867 +#include <linux/vs_tag.h>
6868  
6869  #include <asm/system.h>
6870  #include <asm/uaccess.h>
6871 @@ -431,6 +432,7 @@ static void nfs_show_mount_options(struc
6872                 { NFS_MOUNT_NOACL, ",noacl", "" },
6873                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
6874                 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
6875 +               { NFS_MOUNT_TAGGED, ",tag", "" },
6876                 { 0, NULL, NULL }
6877         };
6878         const struct proc_nfs_info *nfs_infop;
6879 diff -NurpP --minimal linux-2.6.24-rc7/fs/nfsd/auth.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/nfsd/auth.c
6880 --- linux-2.6.24-rc7/fs/nfsd/auth.c     2007-11-29 01:01:59 +0100
6881 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/nfsd/auth.c       2007-12-13 13:25:51 +0100
6882 @@ -10,6 +10,7 @@
6883  #include <linux/sunrpc/svcauth.h>
6884  #include <linux/nfsd/nfsd.h>
6885  #include <linux/nfsd/export.h>
6886 +#include <linux/vs_tag.h>
6887  
6888  #define        CAP_NFSD_MASK (CAP_FS_MASK|CAP_TO_MASK(CAP_SYS_RESOURCE))
6889  
6890 @@ -56,19 +57,22 @@ int nfsd_setuser(struct svc_rqst *rqstp,
6891                 get_group_info(cred.cr_group_info);
6892  
6893         if (cred.cr_uid != (uid_t) -1)
6894 -               current->fsuid = cred.cr_uid;
6895 +               current->fsuid = INOTAG_UID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid);
6896         else
6897                 current->fsuid = exp->ex_anon_uid;
6898         if (cred.cr_gid != (gid_t) -1)
6899 -               current->fsgid = cred.cr_gid;
6900 +               current->fsgid = INOTAG_GID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid);
6901         else
6902                 current->fsgid = exp->ex_anon_gid;
6903  
6904 +       /* this desperately needs a tag :) */
6905 +       current->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
6906 +
6907         if (!cred.cr_group_info)
6908                 return -ENOMEM;
6909         ret = set_current_groups(cred.cr_group_info);
6910         put_group_info(cred.cr_group_info);
6911 -       if ((cred.cr_uid)) {
6912 +       if (INOTAG_UID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid)) {
6913                 cap_t(current->cap_effective) &= ~CAP_NFSD_MASK;
6914         } else {
6915                 cap_t(current->cap_effective) |= (CAP_NFSD_MASK &
6916 diff -NurpP --minimal linux-2.6.24-rc7/fs/nfsd/nfs3xdr.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/nfsd/nfs3xdr.c
6917 --- linux-2.6.24-rc7/fs/nfsd/nfs3xdr.c  2007-11-29 01:11:53 +0100
6918 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/nfsd/nfs3xdr.c    2007-12-31 13:07:17 +0100
6919 @@ -21,6 +21,7 @@
6920  #include <linux/sunrpc/svc.h>
6921  #include <linux/nfsd/nfsd.h>
6922  #include <linux/nfsd/xdr3.h>
6923 +#include <linux/vs_tag.h>
6924  
6925  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6926  
6927 @@ -107,6 +108,8 @@ static __be32 *
6928  decode_sattr3(__be32 *p, struct iattr *iap)
6929  {
6930         u32     tmp;
6931 +       uid_t   uid = 0;
6932 +       gid_t   gid = 0;
6933  
6934         iap->ia_valid = 0;
6935  
6936 @@ -116,12 +119,15 @@ decode_sattr3(__be32 *p, struct iattr *i
6937         }
6938         if (*p++) {
6939                 iap->ia_valid |= ATTR_UID;
6940 -               iap->ia_uid = ntohl(*p++);
6941 +               uid = ntohl(*p++);
6942         }
6943         if (*p++) {
6944                 iap->ia_valid |= ATTR_GID;
6945 -               iap->ia_gid = ntohl(*p++);
6946 +               gid = ntohl(*p++);
6947         }
6948 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6949 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6950 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6951         if (*p++) {
6952                 u64     newsize;
6953  
6954 @@ -177,8 +183,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
6955         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
6956         *p++ = htonl((u32) stat->mode);
6957         *p++ = htonl((u32) stat->nlink);
6958 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6959 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6960 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6961 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6962 +               stat->uid, stat->tag)));
6963 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6964 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6965 +               stat->gid, stat->tag)));
6966         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
6967                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
6968         } else {
6969 diff -NurpP --minimal linux-2.6.24-rc7/fs/nfsd/nfs4recover.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/nfsd/nfs4recover.c
6970 --- linux-2.6.24-rc7/fs/nfsd/nfs4recover.c      2007-11-29 01:11:54 +0100
6971 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/nfsd/nfs4recover.c        2007-12-13 13:25:47 +0100
6972 @@ -154,7 +154,7 @@ nfsd4_create_clid_dir(struct nfs4_client
6973                 dprintk("NFSD: nfsd4_create_clid_dir: DIRECTORY EXISTS\n");
6974                 goto out_put;
6975         }
6976 -       status = vfs_mkdir(rec_dir.dentry->d_inode, dentry, S_IRWXU);
6977 +       status = vfs_mkdir(rec_dir.dentry->d_inode, dentry, S_IRWXU, NULL);
6978  out_put:
6979         dput(dentry);
6980  out_unlock:
6981 @@ -258,7 +258,7 @@ nfsd4_remove_clid_file(struct dentry *di
6982                 return -EINVAL;
6983         }
6984         mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
6985 -       status = vfs_unlink(dir->d_inode, dentry);
6986 +       status = vfs_unlink(dir->d_inode, dentry, NULL);
6987         mutex_unlock(&dir->d_inode->i_mutex);
6988         return status;
6989  }
6990 @@ -273,7 +273,7 @@ nfsd4_clear_clid_dir(struct dentry *dir,
6991          * a kernel from the future.... */
6992         nfsd4_list_rec_dir(dentry, nfsd4_remove_clid_file);
6993         mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
6994 -       status = vfs_rmdir(dir->d_inode, dentry);
6995 +       status = vfs_rmdir(dir->d_inode, dentry, NULL);
6996         mutex_unlock(&dir->d_inode->i_mutex);
6997         return status;
6998  }
6999 diff -NurpP --minimal linux-2.6.24-rc7/fs/nfsd/nfs4xdr.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/nfsd/nfs4xdr.c
7000 --- linux-2.6.24-rc7/fs/nfsd/nfs4xdr.c  2007-11-29 01:11:54 +0100
7001 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/nfsd/nfs4xdr.c    2007-12-13 13:25:51 +0100
7002 @@ -58,6 +58,7 @@
7003  #include <linux/nfs4_acl.h>
7004  #include <linux/sunrpc/gss_api.h>
7005  #include <linux/sunrpc/svcauth_gss.h>
7006 +#include <linux/vs_tag.h>
7007  
7008  #define NFSDDBG_FACILITY               NFSDDBG_XDR
7009  
7010 @@ -1754,14 +1755,18 @@ out_acl:
7011                 WRITE32(stat.nlink);
7012         }
7013         if (bmval1 & FATTR4_WORD1_OWNER) {
7014 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
7015 +               status = nfsd4_encode_user(rqstp,
7016 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
7017 +                       stat.uid, stat.tag), &p, &buflen);
7018                 if (status == nfserr_resource)
7019                         goto out_resource;
7020                 if (status)
7021                         goto out;
7022         }
7023         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
7024 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
7025 +               status = nfsd4_encode_group(rqstp,
7026 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
7027 +                       stat.gid, stat.tag), &p, &buflen);
7028                 if (status == nfserr_resource)
7029                         goto out_resource;
7030                 if (status)
7031 diff -NurpP --minimal linux-2.6.24-rc7/fs/nfsd/nfsxdr.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/nfsd/nfsxdr.c
7032 --- linux-2.6.24-rc7/fs/nfsd/nfsxdr.c   2007-11-29 01:11:54 +0100
7033 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/nfsd/nfsxdr.c     2007-12-13 13:25:51 +0100
7034 @@ -15,6 +15,7 @@
7035  #include <linux/nfsd/nfsd.h>
7036  #include <linux/nfsd/xdr.h>
7037  #include <linux/mm.h>
7038 +#include <linux/vs_tag.h>
7039  
7040  #define NFSDDBG_FACILITY               NFSDDBG_XDR
7041  
7042 @@ -97,6 +98,8 @@ static __be32 *
7043  decode_sattr(__be32 *p, struct iattr *iap)
7044  {
7045         u32     tmp, tmp1;
7046 +       uid_t   uid = 0;
7047 +       gid_t   gid = 0;
7048  
7049         iap->ia_valid = 0;
7050  
7051 @@ -110,12 +113,15 @@ decode_sattr(__be32 *p, struct iattr *ia
7052         }
7053         if ((tmp = ntohl(*p++)) != (u32)-1) {
7054                 iap->ia_valid |= ATTR_UID;
7055 -               iap->ia_uid = tmp;
7056 +               uid = tmp;
7057         }
7058         if ((tmp = ntohl(*p++)) != (u32)-1) {
7059                 iap->ia_valid |= ATTR_GID;
7060 -               iap->ia_gid = tmp;
7061 +               gid = tmp;
7062         }
7063 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
7064 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
7065 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
7066         if ((tmp = ntohl(*p++)) != (u32)-1) {
7067                 iap->ia_valid |= ATTR_SIZE;
7068                 iap->ia_size = tmp;
7069 @@ -160,8 +166,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
7070         *p++ = htonl(nfs_ftypes[type >> 12]);
7071         *p++ = htonl((u32) stat->mode);
7072         *p++ = htonl((u32) stat->nlink);
7073 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
7074 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
7075 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
7076 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
7077 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
7078 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
7079  
7080         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
7081                 *p++ = htonl(NFS_MAXPATHLEN);
7082 diff -NurpP --minimal linux-2.6.24-rc7/fs/nfsd/vfs.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/nfsd/vfs.c
7083 --- linux-2.6.24-rc7/fs/nfsd/vfs.c      2007-11-29 01:11:54 +0100
7084 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/nfsd/vfs.c        2007-12-13 13:25:47 +0100
7085 @@ -1236,13 +1236,13 @@ nfsd_create(struct svc_rqst *rqstp, stru
7086                 host_err = vfs_create(dirp, dchild, iap->ia_mode, NULL);
7087                 break;
7088         case S_IFDIR:
7089 -               host_err = vfs_mkdir(dirp, dchild, iap->ia_mode);
7090 +               host_err = vfs_mkdir(dirp, dchild, iap->ia_mode, NULL);
7091                 break;
7092         case S_IFCHR:
7093         case S_IFBLK:
7094         case S_IFIFO:
7095         case S_IFSOCK:
7096 -               host_err = vfs_mknod(dirp, dchild, iap->ia_mode, rdev);
7097 +               host_err = vfs_mknod(dirp, dchild, iap->ia_mode, rdev, NULL);
7098                 break;
7099         default:
7100                 printk("nfsd: bad file type %o in nfsd_create\n", type);
7101 @@ -1519,11 +1519,13 @@ nfsd_symlink(struct svc_rqst *rqstp, str
7102                 else {
7103                         strncpy(path_alloced, path, plen);
7104                         path_alloced[plen] = 0;
7105 -                       host_err = vfs_symlink(dentry->d_inode, dnew, path_alloced, mode);
7106 +                       host_err = vfs_symlink(dentry->d_inode, dnew,
7107 +                               path_alloced, mode, NULL);
7108                         kfree(path_alloced);
7109                 }
7110         } else
7111 -               host_err = vfs_symlink(dentry->d_inode, dnew, path, mode);
7112 +               host_err = vfs_symlink(dentry->d_inode, dnew,
7113 +                       path, mode, NULL);
7114  
7115         if (!host_err) {
7116                 if (EX_ISSYNC(fhp->fh_export))
7117 @@ -1582,7 +1584,7 @@ nfsd_link(struct svc_rqst *rqstp, struct
7118         dold = tfhp->fh_dentry;
7119         dest = dold->d_inode;
7120  
7121 -       host_err = vfs_link(dold, dirp, dnew);
7122 +       host_err = vfs_link(dold, dirp, dnew, NULL);
7123         if (!host_err) {
7124                 if (EX_ISSYNC(ffhp->fh_export)) {
7125                         err = nfserrno(nfsd_sync_dir(ddir));
7126 @@ -1747,9 +1749,9 @@ nfsd_unlink(struct svc_rqst *rqstp, stru
7127                         host_err = -EPERM;
7128                 } else
7129  #endif
7130 -               host_err = vfs_unlink(dirp, rdentry);
7131 +               host_err = vfs_unlink(dirp, rdentry, NULL);
7132         } else { /* It's RMDIR */
7133 -               host_err = vfs_rmdir(dirp, rdentry);
7134 +               host_err = vfs_rmdir(dirp, rdentry, NULL);
7135         }
7136  
7137         dput(rdentry);
7138 @@ -1866,7 +1868,8 @@ nfsd_permission(struct svc_rqst *rqstp, 
7139          */
7140         if (!(acc & MAY_LOCAL_ACCESS))
7141                 if (acc & (MAY_WRITE | MAY_SATTR | MAY_TRUNC)) {
7142 -                       if (exp_rdonly(rqstp, exp) || IS_RDONLY(inode))
7143 +                       if (exp_rdonly(rqstp, exp) || IS_RDONLY(inode)
7144 +                               || MNT_IS_RDONLY(exp->ex_mnt))
7145                                 return nfserr_rofs;
7146                         if (/* (acc & MAY_WRITE) && */ IS_IMMUTABLE(inode))
7147                                 return nfserr_perm;
7148 diff -NurpP --minimal linux-2.6.24-rc7/fs/ocfs2/dlm/dlmfs.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ocfs2/dlm/dlmfs.c
7149 --- linux-2.6.24-rc7/fs/ocfs2/dlm/dlmfs.c       2007-11-29 01:11:57 +0100
7150 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ocfs2/dlm/dlmfs.c 2007-12-13 13:25:47 +0100
7151 @@ -43,6 +43,7 @@
7152  #include <linux/init.h>
7153  #include <linux/string.h>
7154  #include <linux/backing-dev.h>
7155 +#include <linux/vs_tag.h>
7156  
7157  #include <asm/uaccess.h>
7158  
7159 @@ -330,6 +331,7 @@ static struct inode *dlmfs_get_root_inod
7160                 inode->i_mode = mode;
7161                 inode->i_uid = current->fsuid;
7162                 inode->i_gid = current->fsgid;
7163 +               inode->i_tag = dx_current_fstag(sb);
7164                 inode->i_blocks = 0;
7165                 inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
7166                 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
7167 @@ -356,6 +358,7 @@ static struct inode *dlmfs_get_inode(str
7168         inode->i_mode = mode;
7169         inode->i_uid = current->fsuid;
7170         inode->i_gid = current->fsgid;
7171 +       inode->i_tag = dx_current_fstag(sb);
7172         inode->i_blocks = 0;
7173         inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
7174         inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
7175 diff -NurpP --minimal linux-2.6.24-rc7/fs/ocfs2/dlmglue.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ocfs2/dlmglue.c
7176 --- linux-2.6.24-rc7/fs/ocfs2/dlmglue.c 2007-11-29 01:11:57 +0100
7177 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ocfs2/dlmglue.c   2007-12-13 13:25:47 +0100
7178 @@ -1468,6 +1468,7 @@ static void __ocfs2_stuff_meta_lvb(struc
7179         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
7180         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
7181         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
7182 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
7183         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
7184         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
7185         lvb->lvb_iatime_packed  =
7186 @@ -1522,6 +1523,7 @@ static void ocfs2_refresh_inode_from_lvb
7187  
7188         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
7189         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
7190 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
7191         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
7192         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
7193         ocfs2_unpack_timespec(&inode->i_atime,
7194 diff -NurpP --minimal linux-2.6.24-rc7/fs/ocfs2/dlmglue.h linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ocfs2/dlmglue.h
7195 --- linux-2.6.24-rc7/fs/ocfs2/dlmglue.h 2007-11-29 01:11:57 +0100
7196 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ocfs2/dlmglue.h   2007-12-13 13:25:47 +0100
7197 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
7198         __be16       lvb_inlink;
7199         __be32       lvb_iattr;
7200         __be32       lvb_igeneration;
7201 -       __be32       lvb_reserved2;
7202 +       __be16       lvb_itag;
7203 +       __be16       lvb_reserved2;
7204  };
7205  
7206  /* ocfs2_meta_lock_full() and ocfs2_data_lock_full() 'arg_flags' flags */
7207 diff -NurpP --minimal linux-2.6.24-rc7/fs/ocfs2/file.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ocfs2/file.c
7208 --- linux-2.6.24-rc7/fs/ocfs2/file.c    2007-12-31 17:58:26 +0100
7209 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ocfs2/file.c      2007-12-31 12:34:40 +0100
7210 @@ -1025,13 +1025,15 @@ int ocfs2_setattr(struct dentry *dentry,
7211                 mlog(0, "uid change: %d\n", attr->ia_uid);
7212         if (attr->ia_valid & ATTR_GID)
7213                 mlog(0, "gid change: %d\n", attr->ia_gid);
7214 +       if (attr->ia_valid & ATTR_TAG)
7215 +               mlog(0, "tag change: %d\n", attr->ia_tag);
7216         if (attr->ia_valid & ATTR_SIZE)
7217                 mlog(0, "size change...\n");
7218         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
7219                 mlog(0, "time change...\n");
7220  
7221  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
7222 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
7223 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
7224         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
7225                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
7226                 return 0;
7227 @@ -2200,6 +2202,7 @@ const struct inode_operations ocfs2_file
7228  const struct inode_operations ocfs2_special_file_iops = {
7229         .setattr        = ocfs2_setattr,
7230         .getattr        = ocfs2_getattr,
7231 +       .sync_flags     = ocfs2_sync_flags,
7232         .permission     = ocfs2_permission,
7233  };
7234  
7235 diff -NurpP --minimal linux-2.6.24-rc7/fs/ocfs2/inode.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ocfs2/inode.c
7236 --- linux-2.6.24-rc7/fs/ocfs2/inode.c   2007-12-31 17:58:26 +0100
7237 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ocfs2/inode.c     2007-12-31 12:34:40 +0100
7238 @@ -28,6 +28,7 @@
7239  #include <linux/slab.h>
7240  #include <linux/highmem.h>
7241  #include <linux/pagemap.h>
7242 +#include <linux/vs_tag.h>
7243  
7244  #include <asm/byteorder.h>
7245  
7246 @@ -42,6 +43,7 @@
7247  #include "file.h"
7248  #include "heartbeat.h"
7249  #include "inode.h"
7250 +#include "ioctl.h"
7251  #include "journal.h"
7252  #include "namei.h"
7253  #include "suballoc.h"
7254 @@ -77,6 +79,10 @@ void ocfs2_set_inode_flags(struct inode 
7255  
7256         if (flags & OCFS2_IMMUTABLE_FL)
7257                 inode->i_flags |= S_IMMUTABLE;
7258 +       if (flags & OCFS2_IUNLINK_FL)
7259 +               inode->i_flags |= S_IUNLINK;
7260 +       if (flags & OCFS2_BARRIER_FL)
7261 +               inode->i_flags |= S_BARRIER;
7262  
7263         if (flags & OCFS2_SYNC_FL)
7264                 inode->i_flags |= S_SYNC;
7265 @@ -107,6 +113,27 @@ void ocfs2_get_inode_flags(struct ocfs2_
7266                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
7267  }
7268  
7269 +int ocfs2_sync_flags(struct inode *inode)
7270 +{
7271 +       unsigned int oldflags, newflags;
7272 +
7273 +       oldflags = OCFS2_I(inode)->ip_flags;
7274 +       newflags = oldflags & ~(OCFS2_IMMUTABLE_FL |
7275 +               OCFS2_IUNLINK_FL | OCFS2_BARRIER_FL);
7276 +
7277 +       if (IS_IMMUTABLE(inode))
7278 +               newflags |= OCFS2_IMMUTABLE_FL;
7279 +       if (IS_IUNLINK(inode))
7280 +               newflags |= OCFS2_IUNLINK_FL;
7281 +       if (IS_BARRIER(inode))
7282 +               newflags |= OCFS2_BARRIER_FL;
7283 +
7284 +       if (oldflags ^ newflags)
7285 +               return ocfs2_set_inode_attr(inode,
7286 +                       newflags, OCFS2_FL_MASK);
7287 +       return 0;
7288 +}
7289 +
7290  struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 blkno, int flags)
7291  {
7292         struct inode *inode = NULL;
7293 @@ -212,6 +239,8 @@ int ocfs2_populate_inode(struct inode *i
7294         struct super_block *sb;
7295         struct ocfs2_super *osb;
7296         int status = -EINVAL;
7297 +       uid_t uid;
7298 +       gid_t gid;
7299  
7300         mlog_entry("(0x%p, size:%llu)\n", inode,
7301                    (unsigned long long)le64_to_cpu(fe->i_size));
7302 @@ -247,8 +276,12 @@ int ocfs2_populate_inode(struct inode *i
7303         inode->i_generation = le32_to_cpu(fe->i_generation);
7304         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
7305         inode->i_mode = le16_to_cpu(fe->i_mode);
7306 -       inode->i_uid = le32_to_cpu(fe->i_uid);
7307 -       inode->i_gid = le32_to_cpu(fe->i_gid);
7308 +       uid = le32_to_cpu(fe->i_uid);
7309 +       gid = le32_to_cpu(fe->i_gid);
7310 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7311 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7312 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
7313 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
7314  
7315         /* Fast symlinks will have i_size but no allocated clusters. */
7316         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
7317 @@ -1230,8 +1263,11 @@ int ocfs2_mark_inode_dirty(handle_t *han
7318  
7319         fe->i_size = cpu_to_le64(i_size_read(inode));
7320         fe->i_links_count = cpu_to_le16(inode->i_nlink);
7321 -       fe->i_uid = cpu_to_le32(inode->i_uid);
7322 -       fe->i_gid = cpu_to_le32(inode->i_gid);
7323 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode),
7324 +               inode->i_uid, inode->i_tag));
7325 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode),
7326 +               inode->i_gid, inode->i_tag));
7327 +       /* i_tag = = cpu_to_le16(inode->i_tag); */
7328         fe->i_mode = cpu_to_le16(inode->i_mode);
7329         fe->i_atime = cpu_to_le64(inode->i_atime.tv_sec);
7330         fe->i_atime_nsec = cpu_to_le32(inode->i_atime.tv_nsec);
7331 @@ -1259,16 +1295,25 @@ leave:
7332  void ocfs2_refresh_inode(struct inode *inode,
7333                          struct ocfs2_dinode *fe)
7334  {
7335 +       uid_t uid;
7336 +       gid_t gid;
7337 +
7338         spin_lock(&OCFS2_I(inode)->ip_lock);
7339  
7340         OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters);
7341         OCFS2_I(inode)->ip_attr = le32_to_cpu(fe->i_attr);
7342 +       /* OCFS2_I(inode)->ip_flags &= ~OCFS2_FL_MASK;
7343 +          OCFS2_I(inode)->ip_flags |= le32_to_cpu(fe->i_flags) & OCFS2_FL_MASK; */
7344         OCFS2_I(inode)->ip_dyn_features = le16_to_cpu(fe->i_dyn_features);
7345         ocfs2_set_inode_flags(inode);
7346         i_size_write(inode, le64_to_cpu(fe->i_size));
7347         inode->i_nlink = le16_to_cpu(fe->i_links_count);
7348 -       inode->i_uid = le32_to_cpu(fe->i_uid);
7349 -       inode->i_gid = le32_to_cpu(fe->i_gid);
7350 +       uid = le32_to_cpu(fe->i_uid);
7351 +       gid = le32_to_cpu(fe->i_gid);
7352 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7353 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7354 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
7355 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
7356         inode->i_mode = le16_to_cpu(fe->i_mode);
7357         if (S_ISLNK(inode->i_mode) && le32_to_cpu(fe->i_clusters) == 0)
7358                 inode->i_blocks = 0;
7359 diff -NurpP --minimal linux-2.6.24-rc7/fs/ocfs2/inode.h linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ocfs2/inode.h
7360 --- linux-2.6.24-rc7/fs/ocfs2/inode.h   2007-11-29 01:11:57 +0100
7361 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ocfs2/inode.h     2007-12-13 13:25:39 +0100
7362 @@ -143,6 +143,7 @@ int ocfs2_aio_write(struct file *file, s
7363  
7364  void ocfs2_set_inode_flags(struct inode *inode);
7365  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
7366 +int ocfs2_sync_flags(struct inode *inode);
7367  
7368  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
7369  {
7370 diff -NurpP --minimal linux-2.6.24-rc7/fs/ocfs2/ioctl.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ocfs2/ioctl.c
7371 --- linux-2.6.24-rc7/fs/ocfs2/ioctl.c   2007-11-29 01:01:59 +0100
7372 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ocfs2/ioctl.c     2007-12-13 13:25:47 +0100
7373 @@ -40,7 +40,7 @@ static int ocfs2_get_inode_attr(struct i
7374         return status;
7375  }
7376  
7377 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
7378 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
7379                                 unsigned mask)
7380  {
7381         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
7382 diff -NurpP --minimal linux-2.6.24-rc7/fs/ocfs2/ioctl.h linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ocfs2/ioctl.h
7383 --- linux-2.6.24-rc7/fs/ocfs2/ioctl.h   2007-07-09 13:19:28 +0200
7384 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ocfs2/ioctl.h     2007-12-13 13:25:47 +0100
7385 @@ -10,6 +10,9 @@
7386  #ifndef OCFS2_IOCTL_H
7387  #define OCFS2_IOCTL_H
7388  
7389 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
7390 +                               unsigned mask);
7391 +
7392  int ocfs2_ioctl(struct inode * inode, struct file * filp,
7393         unsigned int cmd, unsigned long arg);
7394  long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg);
7395 diff -NurpP --minimal linux-2.6.24-rc7/fs/ocfs2/namei.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ocfs2/namei.c
7396 --- linux-2.6.24-rc7/fs/ocfs2/namei.c   2007-11-29 01:11:57 +0100
7397 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ocfs2/namei.c     2007-12-13 13:25:47 +0100
7398 @@ -40,6 +40,7 @@
7399  #include <linux/types.h>
7400  #include <linux/slab.h>
7401  #include <linux/highmem.h>
7402 +#include <linux/vs_tag.h>
7403  
7404  #define MLOG_MASK_PREFIX ML_NAMEI
7405  #include <cluster/masklog.h>
7406 @@ -367,6 +368,9 @@ static int ocfs2_mknod_locked(struct ocf
7407         u64 fe_blkno = 0;
7408         u16 suballoc_bit;
7409         struct inode *inode = NULL;
7410 +       uid_t uid;
7411 +       gid_t gid;
7412 +       tag_t tag;
7413  
7414         mlog_entry("(0x%p, 0x%p, %d, %lu, '%.*s')\n", dir, dentry, mode,
7415                    (unsigned long)dev, dentry->d_name.len,
7416 @@ -426,13 +430,19 @@ static int ocfs2_mknod_locked(struct ocf
7417         fe->i_blkno = cpu_to_le64(fe_blkno);
7418         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
7419         fe->i_suballoc_slot = cpu_to_le16(osb->slot_num);
7420 -       fe->i_uid = cpu_to_le32(current->fsuid);
7421 +
7422 +       tag = dx_current_fstag(osb->sb);
7423 +       uid = current->fsuid;
7424         if (dir->i_mode & S_ISGID) {
7425 -               fe->i_gid = cpu_to_le32(dir->i_gid);
7426 +               gid = dir->i_gid;
7427                 if (S_ISDIR(mode))
7428                         mode |= S_ISGID;
7429         } else
7430 -               fe->i_gid = cpu_to_le32(current->fsgid);
7431 +               gid = current->fsgid;
7432 +
7433 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), uid, tag));
7434 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), gid, tag));
7435 +       inode->i_tag = tag;
7436         fe->i_mode = cpu_to_le16(mode);
7437         if (S_ISCHR(mode) || S_ISBLK(mode))
7438                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
7439 @@ -1917,5 +1927,6 @@ const struct inode_operations ocfs2_dir_
7440         .rename         = ocfs2_rename,
7441         .setattr        = ocfs2_setattr,
7442         .getattr        = ocfs2_getattr,
7443 +       .sync_flags     = ocfs2_sync_flags,
7444         .permission     = ocfs2_permission,
7445  };
7446 diff -NurpP --minimal linux-2.6.24-rc7/fs/ocfs2/ocfs2.h linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ocfs2/ocfs2.h
7447 --- linux-2.6.24-rc7/fs/ocfs2/ocfs2.h   2007-11-29 01:11:57 +0100
7448 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ocfs2/ocfs2.h     2007-12-13 13:25:47 +0100
7449 @@ -170,6 +170,7 @@ enum ocfs2_mount_options
7450         OCFS2_MOUNT_NOINTR  = 1 << 2,   /* Don't catch signals */
7451         OCFS2_MOUNT_ERRORS_PANIC = 1 << 3, /* Panic on errors */
7452         OCFS2_MOUNT_DATA_WRITEBACK = 1 << 4, /* No data ordering */
7453 +       OCFS2_MOUNT_TAGGED = 1 << 8, /* use tagging */
7454  };
7455  
7456  #define OCFS2_OSB_SOFT_RO      0x0001
7457 diff -NurpP --minimal linux-2.6.24-rc7/fs/ocfs2/ocfs2_fs.h linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ocfs2/ocfs2_fs.h
7458 --- linux-2.6.24-rc7/fs/ocfs2/ocfs2_fs.h        2007-11-29 01:11:57 +0100
7459 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ocfs2/ocfs2_fs.h  2007-12-13 13:25:47 +0100
7460 @@ -188,8 +188,12 @@
7461  #define OCFS2_NOATIME_FL       (0x00000080)    /* do not update atime */
7462  #define OCFS2_DIRSYNC_FL       (0x00010000)    /* dirsync behaviour (directories only) */
7463  
7464 +#define OCFS2_BARRIER_FL       (0x04000000)    /* Barrier for chroot() */
7465 +#define OCFS2_IUNLINK_FL       (0x08000000)    /* Immutable unlink */
7466 +
7467  #define OCFS2_FL_VISIBLE       (0x000100FF)    /* User visible flags */
7468  #define OCFS2_FL_MODIFIABLE    (0x000100FF)    /* User modifiable flags */
7469 +#define OCFS2_FL_MASK          (0x0F0100FF)
7470  
7471  /*
7472   * Extent record flags (e_node.leaf.flags)
7473 diff -NurpP --minimal linux-2.6.24-rc7/fs/ocfs2/super.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ocfs2/super.c
7474 --- linux-2.6.24-rc7/fs/ocfs2/super.c   2007-12-31 17:58:26 +0100
7475 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/ocfs2/super.c     2007-12-31 12:34:40 +0100
7476 @@ -150,6 +150,7 @@ enum {
7477         Opt_data_writeback,
7478         Opt_atime_quantum,
7479         Opt_slot,
7480 +       Opt_tag, Opt_notag, Opt_tagid,
7481         Opt_err,
7482  };
7483  
7484 @@ -165,6 +166,10 @@ static match_table_t tokens = {
7485         {Opt_data_writeback, "data=writeback"},
7486         {Opt_atime_quantum, "atime_quantum=%u"},
7487         {Opt_slot, "preferred_slot=%u"},
7488 +       {Opt_tag, "tag"},
7489 +       {Opt_tag, "tagxid"},
7490 +       {Opt_notag, "notag"},
7491 +       {Opt_tagid, "tagid=%u"},
7492         {Opt_err, NULL}
7493  };
7494  
7495 @@ -384,6 +389,14 @@ static int ocfs2_remount(struct super_bl
7496                 goto out;
7497         }
7498  
7499 +       printk("ocfs2_remount: %lx,%lx\n", osb->s_mount_opt, sb->s_flags);
7500 +       if ((parsed_options.mount_opt & OCFS2_MOUNT_TAGGED) &&
7501 +               !(sb->s_flags & MS_TAGGED)) {
7502 +               ret = -EINVAL;
7503 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
7504 +               goto out;
7505 +       }
7506 +
7507         if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
7508             (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
7509                 ret = -EINVAL;
7510 @@ -680,6 +693,9 @@ static int ocfs2_fill_super(struct super
7511  
7512         ocfs2_complete_mount_recovery(osb);
7513  
7514 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
7515 +               sb->s_flags |= MS_TAGGED;
7516 +
7517         if (ocfs2_mount_local(osb))
7518                 snprintf(nodestr, sizeof(nodestr), "local");
7519         else
7520 @@ -816,6 +832,20 @@ static int ocfs2_parse_options(struct su
7521                         if (option)
7522                                 mopt->slot = (s16)option;
7523                         break;
7524 +#ifndef CONFIG_TAGGING_NONE
7525 +               case Opt_tag:
7526 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
7527 +                       break;
7528 +               case Opt_notag:
7529 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
7530 +                       break;
7531 +#endif
7532 +#ifdef CONFIG_PROPAGATE
7533 +               case Opt_tagid:
7534 +                       /* use args[0] */
7535 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
7536 +                       break;
7537 +#endif
7538                 default:
7539                         mlog(ML_ERROR,
7540                              "Unrecognized mount option \"%s\" "
7541 diff -NurpP --minimal linux-2.6.24-rc7/fs/open.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/open.c
7542 --- linux-2.6.24-rc7/fs/open.c  2007-11-29 01:11:57 +0100
7543 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/open.c    2007-12-13 13:25:47 +0100
7544 @@ -27,22 +27,31 @@
7545  #include <linux/rcupdate.h>
7546  #include <linux/audit.h>
7547  #include <linux/falloc.h>
7548 +#include <linux/vs_base.h>
7549 +#include <linux/vs_limit.h>
7550 +#include <linux/vs_dlimit.h>
7551 +#include <linux/vs_tag.h>
7552 +#include <linux/vs_cowbl.h>
7553  
7554  int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
7555  {
7556         int retval = -ENODEV;
7557  
7558         if (dentry) {
7559 +               struct super_block *sb = dentry->d_sb;
7560 +
7561                 retval = -ENOSYS;
7562 -               if (dentry->d_sb->s_op->statfs) {
7563 +               if (sb->s_op->statfs) {
7564                         memset(buf, 0, sizeof(*buf));
7565                         retval = security_sb_statfs(dentry);
7566                         if (retval)
7567                                 return retval;
7568 -                       retval = dentry->d_sb->s_op->statfs(dentry, buf);
7569 +                       retval = sb->s_op->statfs(dentry, buf);
7570                         if (retval == 0 && buf->f_frsize == 0)
7571                                 buf->f_frsize = buf->f_bsize;
7572                 }
7573 +               if (!vx_check(0, VS_ADMIN|VS_WATCH))
7574 +                       vx_vsi_statfs(sb, buf);
7575         }
7576         return retval;
7577  }
7578 @@ -249,7 +258,7 @@ static long do_sys_truncate(const char _
7579                 goto dput_and_out;
7580  
7581         error = -EROFS;
7582 -       if (IS_RDONLY(inode))
7583 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(nd.mnt))
7584                 goto dput_and_out;
7585  
7586         error = -EPERM;
7587 @@ -458,7 +467,7 @@ asmlinkage long sys_faccessat(int dfd, c
7588            special_file(nd.dentry->d_inode->i_mode))
7589                 goto out_path_release;
7590  
7591 -       if(IS_RDONLY(nd.dentry->d_inode))
7592 +       if(IS_RDONLY(nd.dentry->d_inode) || MNT_IS_RDONLY(nd.mnt))
7593                 res = -EROFS;
7594  
7595  out_path_release:
7596 @@ -572,7 +581,7 @@ asmlinkage long sys_fchmod(unsigned int 
7597         audit_inode(NULL, dentry);
7598  
7599         err = -EROFS;
7600 -       if (IS_RDONLY(inode))
7601 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(file->f_vfsmnt))
7602                 goto out_putf;
7603         err = -EPERM;
7604         if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
7605 @@ -602,11 +611,11 @@ asmlinkage long sys_fchmodat(int dfd, co
7606         error = __user_walk_fd(dfd, filename, LOOKUP_FOLLOW, &nd);
7607         if (error)
7608                 goto out;
7609 -       inode = nd.dentry->d_inode;
7610  
7611 -       error = -EROFS;
7612 -       if (IS_RDONLY(inode))
7613 +       error = cow_check_and_break(&nd);
7614 +       if (error)
7615                 goto dput_and_out;
7616 +       inode = nd.dentry->d_inode;
7617  
7618         error = -EPERM;
7619         if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
7620 @@ -631,7 +640,8 @@ asmlinkage long sys_chmod(const char __u
7621         return sys_fchmodat(AT_FDCWD, filename, mode);
7622  }
7623  
7624 -static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
7625 +static int chown_common(struct dentry *dentry, struct vfsmount *mnt,
7626 +       uid_t user, gid_t group)
7627  {
7628         struct inode * inode;
7629         int error;
7630 @@ -643,7 +653,7 @@ static int chown_common(struct dentry * 
7631                 goto out;
7632         }
7633         error = -EROFS;
7634 -       if (IS_RDONLY(inode))
7635 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(mnt))
7636                 goto out;
7637         error = -EPERM;
7638         if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
7639 @@ -651,11 +661,11 @@ static int chown_common(struct dentry * 
7640         newattrs.ia_valid =  ATTR_CTIME;
7641         if (user != (uid_t) -1) {
7642                 newattrs.ia_valid |= ATTR_UID;
7643 -               newattrs.ia_uid = user;
7644 +               newattrs.ia_uid = dx_map_uid(user);
7645         }
7646         if (group != (gid_t) -1) {
7647                 newattrs.ia_valid |= ATTR_GID;
7648 -               newattrs.ia_gid = group;
7649 +               newattrs.ia_gid = dx_map_gid(group);
7650         }
7651         if (!S_ISDIR(inode->i_mode))
7652                 newattrs.ia_valid |=
7653 @@ -675,7 +685,11 @@ asmlinkage long sys_chown(const char __u
7654         error = user_path_walk(filename, &nd);
7655         if (error)
7656                 goto out;
7657 -       error = chown_common(nd.dentry, user, group);
7658 +#ifdef CONFIG_VSERVER_COWBL
7659 +       error = cow_check_and_break(&nd);
7660 +       if (!error)
7661 +#endif
7662 +               error = chown_common(nd.dentry, nd.mnt, user, group);
7663         path_release(&nd);
7664  out:
7665         return error;
7666 @@ -695,7 +709,11 @@ asmlinkage long sys_fchownat(int dfd, co
7667         error = __user_walk_fd(dfd, filename, follow, &nd);
7668         if (error)
7669                 goto out;
7670 -       error = chown_common(nd.dentry, user, group);
7671 +#ifdef CONFIG_VSERVER_COWBL
7672 +       error = cow_check_and_break(&nd);
7673 +       if (!error)
7674 +#endif
7675 +               error = chown_common(nd.dentry, nd.mnt, user, group);
7676         path_release(&nd);
7677  out:
7678         return error;
7679 @@ -709,7 +727,11 @@ asmlinkage long sys_lchown(const char __
7680         error = user_path_walk_link(filename, &nd);
7681         if (error)
7682                 goto out;
7683 -       error = chown_common(nd.dentry, user, group);
7684 +#ifdef CONFIG_VSERVER_COWBL
7685 +       error = cow_check_and_break(&nd);
7686 +       if (!error)
7687 +#endif
7688 +               error = chown_common(nd.dentry, nd.mnt, user, group);
7689         path_release(&nd);
7690  out:
7691         return error;
7692 @@ -728,7 +750,7 @@ asmlinkage long sys_fchown(unsigned int 
7693  
7694         dentry = file->f_path.dentry;
7695         audit_inode(NULL, dentry);
7696 -       error = chown_common(dentry, user, group);
7697 +       error = chown_common(dentry, file->f_vfsmnt, user, group);
7698         fput(file);
7699  out:
7700         return error;
7701 @@ -962,6 +984,7 @@ repeat:
7702         else
7703                 FD_CLR(fd, fdt->close_on_exec);
7704         files->next_fd = fd + 1;
7705 +       vx_openfd_inc(fd);
7706  #if 1
7707         /* Sanity check */
7708         if (fdt->fd[fd] != NULL) {
7709 @@ -989,6 +1012,7 @@ static void __put_unused_fd(struct files
7710         __FD_CLR(fd, fdt->open_fds);
7711         if (fd < files->next_fd)
7712                 files->next_fd = fd;
7713 +       vx_openfd_dec(fd);
7714  }
7715  
7716  void fastcall put_unused_fd(unsigned int fd)
7717 diff -NurpP --minimal linux-2.6.24-rc7/fs/proc/array.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/proc/array.c
7718 --- linux-2.6.24-rc7/fs/proc/array.c    2007-12-31 17:58:26 +0100
7719 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/proc/array.c      2008-01-07 03:06:13 +0100
7720 @@ -78,6 +78,8 @@
7721  #include <linux/rcupdate.h>
7722  #include <linux/delayacct.h>
7723  #include <linux/pid_namespace.h>
7724 +#include <linux/vs_context.h>
7725 +#include <linux/vs_network.h>
7726  
7727  #include <asm/pgtable.h>
7728  #include <asm/processor.h>
7729 @@ -135,8 +137,9 @@ static const char *task_state_array[] = 
7730         "D (disk sleep)",       /*  2 */
7731         "T (stopped)",          /*  4 */
7732         "T (tracing stop)",     /*  8 */
7733 -       "Z (zombie)",           /* 16 */
7734 -       "X (dead)"              /* 32 */
7735 +       "H (on hold)",          /* 16 */
7736 +       "Z (zombie)",           /* 32 */
7737 +       "X (dead)",             /* 64 */
7738  };
7739  
7740  static inline const char *get_task_state(struct task_struct *tsk)
7741 @@ -288,12 +298,15 @@ static inline char *task_sig(struct task
7742  
7743  static inline char *task_cap(struct task_struct *p, char *buffer)
7744  {
7745 -    return buffer + sprintf(buffer, "CapInh:\t%016x\n"
7746 -                           "CapPrm:\t%016x\n"
7747 -                           "CapEff:\t%016x\n",
7748 -                           cap_t(p->cap_inheritable),
7749 -                           cap_t(p->cap_permitted),
7750 -                           cap_t(p->cap_effective));
7751 +       struct vx_info *vxi = p->vx_info;
7752 +
7753 +       return buffer + sprintf(buffer,
7754 +               "CapInh:\t%016x\n"
7755 +               "CapPrm:\t%016x\n"
7756 +               "CapEff:\t%016x\n",
7757 +               (unsigned)vx_info_mbcap(vxi, p->cap_inheritable),
7758 +               (unsigned)vx_info_mbcap(vxi, p->cap_permitted),
7759 +               (unsigned)vx_info_mbcap(vxi, p->cap_effective));
7760  }
7761  
7762  static inline char *task_context_switch_counts(struct task_struct *p,
7763 @@ -305,10 +318,43 @@ static inline char *task_context_switch_
7764                             p->nivcsw);
7765  }
7766  
7767 +int proc_pid_nsproxy(struct task_struct *task, char *buffer)
7768 +{
7769 +       return sprintf(buffer, "Proxy:\t%p(%c)\n"
7770 +                       "Count:\t%u\n"
7771 +                       "uts:\t%p(%c)\n"
7772 +                       "ipc:\t%p(%c)\n"
7773 +                       "mnt:\t%p(%c)\n"
7774 +                       "pid:\t%p(%c)\n"
7775 +                       "user:\t%p(%c)\n"
7776 +                       "net:\t%p(%c)\n",
7777 +                       task->nsproxy,
7778 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
7779 +                       atomic_read(&task->nsproxy->count),
7780 +                       task->nsproxy->uts_ns,
7781 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
7782 +                       task->nsproxy->ipc_ns,
7783 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
7784 +                       task->nsproxy->mnt_ns,
7785 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
7786 +                       task->nsproxy->pid_ns,
7787 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
7788 +                       task->nsproxy->user_ns,
7789 +                       (task->nsproxy->user_ns == init_task.nsproxy->user_ns ? 'I' : '-'),
7790 +                       task->nsproxy->net_ns,
7791 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
7792 +}
7793 +
7794  int proc_pid_status(struct task_struct *task, char *buffer)
7795  {
7796         char *orig = buffer;
7797         struct mm_struct *mm = get_task_mm(task);
7798 +#ifdef CONFIG_VSERVER_LEGACY
7799 +       struct vx_info *vxi;
7800 +#endif
7801 +#ifdef CONFIG_VSERVER_LEGACYNET
7802 +       struct nx_info *nxi;
7803 +#endif
7804  
7805         buffer = task_name(task, buffer);
7806         buffer = task_state(task, buffer);
7807 @@ -320,6 +366,46 @@ int proc_pid_status(struct task_struct *
7808         buffer = task_sig(task, buffer);
7809         buffer = task_cap(task, buffer);
7810         buffer = cpuset_task_status_allowed(task, buffer);
7811 +
7812 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
7813 +               goto skip;
7814 +#ifdef CONFIG_VSERVER_LEGACY
7815 +       buffer += sprintf (buffer,"s_context: %d\n", vx_task_xid(task));
7816 +       vxi = task_get_vx_info(task);
7817 +       if (vxi) {
7818 +               buffer += sprintf (buffer,"ctxflags: %08llx\n"
7819 +                       ,(unsigned long long)vxi->vx_flags);
7820 +               buffer += sprintf (buffer,"initpid: %d\n"
7821 +                       ,vxi->vx_initpid);
7822 +       } else {
7823 +               buffer += sprintf (buffer,"ctxflags: none\n");
7824 +               buffer += sprintf (buffer,"initpid: none\n");
7825 +       }
7826 +       put_vx_info(vxi);
7827 +#else
7828 +       buffer += sprintf (buffer,"VxID: %d\n", vx_task_xid(task));
7829 +#endif
7830 +#ifdef CONFIG_VSERVER_LEGACYNET
7831 +       nxi = task_get_nx_info(task);
7832 +       if (nxi) {
7833 +               int i;
7834 +
7835 +               buffer += sprintf (buffer,"ipv4root:");
7836 +               for (i=0; i<nxi->nbipv4; i++){
7837 +                       buffer += sprintf (buffer," %08x/%08x"
7838 +                               ,nxi->ipv4[i]
7839 +                               ,nxi->mask[i]);
7840 +               }
7841 +               *buffer++ = '\n';
7842 +               buffer += sprintf (buffer,"ipv4root_bcast: %08x\n"
7843 +                       ,nxi->v4_bcast);
7844 +       } else {
7845 +               buffer += sprintf (buffer,"ipv4root: 0\n");
7846 +               buffer += sprintf (buffer,"ipv4root_bcast: 0\n");
7847 +       }
7848 +       put_nx_info(nxi);
7849 +#endif
7850 +skip:
7851  #if defined(CONFIG_S390)
7852         buffer = task_show_regs(task, buffer);
7853  #endif
7854 @@ -494,6 +580,17 @@ static int do_task_stat(struct task_stru
7855         /* convert nsec -> ticks */
7856         start_time = nsec_to_clock_t(start_time);
7857  
7858 +       /* fixup start time for virt uptime */
7859 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
7860 +               unsigned long long bias =
7861 +                       current->vx_info->cvirt.bias_clock;
7862 +
7863 +               if (start_time > bias)
7864 +                       start_time -= bias;
7865 +               else
7866 +                       start_time = 0;
7867 +       }
7868 +
7869         res = sprintf(buffer, "%d (%s) %c %d %d %d %d %d %u %lu \
7870  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
7871  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
7872 diff -NurpP --minimal linux-2.6.24-rc7/fs/proc/base.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/proc/base.c
7873 --- linux-2.6.24-rc7/fs/proc/base.c     2008-01-11 12:00:49 +0100
7874 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/proc/base.c       2008-01-11 04:30:09 +0100
7875 @@ -76,6 +76,8 @@
7876  #include <linux/oom.h>
7877  #include <linux/elf.h>
7878  #include <linux/pid_namespace.h>
7879 +#include <linux/vs_context.h>
7880 +#include <linux/vs_network.h>
7881  #include "internal.h"
7882  
7883  /* NOTE:
7884 @@ -1204,6 +1206,8 @@ static struct inode *proc_pid_make_inode
7885                 inode->i_uid = task->euid;
7886                 inode->i_gid = task->egid;
7887         }
7888 +       /* procfs is xid tagged */
7889 +       inode->i_tag = (tag_t)vx_task_xid(task);
7890         security_task_to_inode(task, inode);
7891  
7892  out:
7893 @@ -1749,6 +1753,13 @@ static struct dentry *proc_pident_lookup
7894         if (!task)
7895                 goto out_no_task;
7896  
7897 +       /* TODO: maybe we can come up with a generic approach? */
7898 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
7899 +               (dentry->d_name.len == 5) &&
7900 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
7901 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
7902 +               goto out;
7903 +
7904         /*
7905          * Yes, it does not scale. And it should not. Don't add
7906          * new entries into /proc/<tgid>/ without very good reasons.
7907 @@ -2128,7 +2139,7 @@ out_iput:
7908  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
7909  {
7910         struct dentry *error;
7911 -       struct task_struct *task = get_proc_task(dir);
7912 +       struct task_struct *task = get_proc_task_real(dir);
7913         const struct pid_entry *p, *last;
7914  
7915         error = ERR_PTR(-ENOENT);
7916 @@ -2193,6 +2204,9 @@ static int proc_pid_io_accounting(struct
7917  static const struct file_operations proc_task_operations;
7918  static const struct inode_operations proc_task_inode_operations;
7919  
7920 +extern int proc_pid_vx_info(struct task_struct *, char *);
7921 +extern int proc_pid_nx_info(struct task_struct *, char *);
7922 +
7923  static const struct pid_entry tgid_base_stuff[] = {
7924         DIR("task",       S_IRUGO|S_IXUGO, task),
7925         DIR("fd",         S_IRUSR|S_IXUSR, fd),
7926 @@ -2236,6 +2250,8 @@ static const struct pid_entry tgid_base_
7927  #ifdef CONFIG_CGROUPS
7928         REG("cgroup",  S_IRUGO, cgroup),
7929  #endif
7930 +       INF("vinfo",      S_IRUGO, pid_vx_info),
7931 +       INF("ninfo",      S_IRUGO, pid_nx_info),
7932         INF("oom_score",  S_IRUGO, oom_score),
7933         REG("oom_adj",    S_IRUGO|S_IWUSR, oom_adjust),
7934  #ifdef CONFIG_AUDITSYSCALL
7935 @@ -2250,6 +2266,7 @@ static const struct pid_entry tgid_base_
7936  #ifdef CONFIG_TASK_IO_ACCOUNTING
7937         INF("io",       S_IRUGO, pid_io_accounting),
7938  #endif
7939 +       INF("nsproxy",  S_IRUGO, pid_nsproxy),
7940  };
7941  
7942  static int proc_tgid_base_readdir(struct file * filp,
7943 @@ -2485,7 +2502,7 @@ static int proc_pid_fill_cache(struct fi
7944  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
7945  {
7946         unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
7947 -       struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
7948 +       struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
7949         struct tgid_iter iter;
7950         struct pid_namespace *ns;
7951  
7952 @@ -2505,6 +2522,8 @@ int proc_pid_readdir(struct file * filp,
7953              iter.task;
7954              iter.tgid += 1, iter = next_tgid(ns, iter)) {
7955                 filp->f_pos = iter.tgid + TGID_OFFSET;
7956 +               if (!vx_proc_task_visible(iter.task))
7957 +                       continue;
7958                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
7959                         put_task_struct(iter.task);
7960                         goto out;
7961 @@ -2636,6 +2655,8 @@ static struct dentry *proc_task_lookup(s
7962         tid = name_to_int(dentry);
7963         if (tid == ~0U)
7964                 goto out;
7965 +       if (vx_current_initpid(tid))
7966 +               goto out;
7967  
7968         ns = dentry->d_sb->s_fs_info;
7969         rcu_read_lock();
7970 diff -NurpP --minimal linux-2.6.24-rc7/fs/proc/generic.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/proc/generic.c
7971 --- linux-2.6.24-rc7/fs/proc/generic.c  2007-12-31 17:58:26 +0100
7972 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/proc/generic.c    2008-01-04 17:52:19 +0100
7973 @@ -21,6 +21,7 @@
7974  #include <linux/bitops.h>
7975  #include <linux/spinlock.h>
7976  #include <linux/completion.h>
7977 +#include <linux/vserver/inode.h>
7978  #include <asm/uaccess.h>
7979  
7980  #include "internal.h"
7981 @@ -401,11 +402,15 @@ struct dentry *proc_lookup(struct inode 
7982  
7983                                 if (de->shadow_proc)
7984                                         de = de->shadow_proc(current, de);
7985 +                               if (!vx_hide_check(0, de->vx_flags))
7986 +                                       continue;
7987                                 ino = de->low_ino;
7988                                 de_get(de);
7989                                 spin_unlock(&proc_subdir_lock);
7990                                 error = -EINVAL;
7991                                 inode = proc_get_inode(dir->i_sb, ino, de);
7992 +                               /* generic proc entries belong to the host */
7993 +                               inode->i_tag = 0;
7994                                 spin_lock(&proc_subdir_lock);
7995                                 break;
7996                         }
7997 @@ -486,6 +491,8 @@ int proc_readdir(struct file * filp,
7998  
7999                                 /* filldir passes info to user space */
8000                                 de_get(de);
8001 +                               if (!vx_hide_check(0, de->vx_flags))
8002 +                                       goto skip;
8003                                 spin_unlock(&proc_subdir_lock);
8004                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
8005                                             de->low_ino, de->mode >> 12) < 0) {
8006 @@ -493,6 +500,7 @@ int proc_readdir(struct file * filp,
8007                                         goto out;
8008                                 }
8009                                 spin_lock(&proc_subdir_lock);
8010 +                       skip:
8011                                 filp->f_pos++;
8012                                 next = de->next;
8013                                 de_put(de);
8014 @@ -590,6 +598,7 @@ static struct proc_dir_entry *proc_creat
8015         ent->nlink = nlink;
8016         atomic_set(&ent->count, 1);
8017         ent->pde_users = 0;
8018 +       ent->vx_flags = IATTR_PROC_DEFAULT;
8019         spin_lock_init(&ent->pde_unload_lock);
8020         ent->pde_unload_completion = NULL;
8021   out:
8022 @@ -612,7 +621,8 @@ struct proc_dir_entry *proc_symlink(cons
8023                                 kfree(ent->data);
8024                                 kfree(ent);
8025                                 ent = NULL;
8026 -                       }
8027 +                       } else
8028 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
8029                 } else {
8030                         kfree(ent);
8031                         ent = NULL;
8032 diff -NurpP --minimal linux-2.6.24-rc7/fs/proc/inode.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/proc/inode.c
8033 --- linux-2.6.24-rc7/fs/proc/inode.c    2007-12-31 17:58:26 +0100
8034 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/proc/inode.c      2007-12-31 12:34:40 +0100
8035 @@ -413,6 +413,8 @@ struct inode *proc_get_inode(struct supe
8036                         inode->i_uid = de->uid;
8037                         inode->i_gid = de->gid;
8038                 }
8039 +               if (de->vx_flags)
8040 +                       PROC_I(inode)->vx_flags = de->vx_flags;
8041                 if (de->size)
8042                         inode->i_size = de->size;
8043                 if (de->nlink)
8044 diff -NurpP --minimal linux-2.6.24-rc7/fs/proc/internal.h linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/proc/internal.h
8045 --- linux-2.6.24-rc7/fs/proc/internal.h 2008-01-11 12:00:49 +0100
8046 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/proc/internal.h   2008-01-11 04:30:09 +0100
8047 @@ -10,6 +10,7 @@
8048   */
8049  
8050  #include <linux/proc_fs.h>
8051 +#include <linux/vs_pid.h>
8052  
8053  #ifdef CONFIG_PROC_SYSCTL
8054  extern int proc_sys_init(void);
8055 @@ -52,6 +53,7 @@ extern int proc_tid_stat(struct task_str
8056  extern int proc_tgid_stat(struct task_struct *, char *);
8057  extern int proc_pid_status(struct task_struct *, char *);
8058  extern int proc_pid_statm(struct task_struct *, char *);
8059 +extern int proc_pid_nsproxy(struct task_struct *, char *);
8060  
8061  extern const struct file_operations proc_maps_operations;
8062  extern const struct file_operations proc_numa_maps_operations;
8063 @@ -71,11 +73,16 @@ static inline struct pid *proc_pid(struc
8064         return PROC_I(inode)->pid;
8065  }
8066  
8067 -static inline struct task_struct *get_proc_task(struct inode *inode)
8068 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
8069  {
8070         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
8071  }
8072  
8073 +static inline struct task_struct *get_proc_task(struct inode *inode)
8074 +{
8075 +       return vx_get_proc_task(inode, proc_pid(inode));
8076 +}
8077 +
8078  static inline int proc_fd(struct inode *inode)
8079  {
8080         return PROC_I(inode)->fd;
8081 diff -NurpP --minimal linux-2.6.24-rc7/fs/proc/proc_misc.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/proc/proc_misc.c
8082 --- linux-2.6.24-rc7/fs/proc/proc_misc.c        2008-01-11 12:00:49 +0100
8083 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/proc/proc_misc.c  2008-01-11 04:30:09 +0100
8084 @@ -53,6 +53,8 @@
8085  #include <asm/div64.h>
8086  #include "internal.h"
8087  
8088 +#include <linux/vs_cvirt.h>
8089 +
8090  #define LOAD_INT(x) ((x) >> FSHIFT)
8091  #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
8092  /*
8093 @@ -81,17 +83,32 @@ static int proc_calc_metrics(char *page,
8094  static int loadavg_read_proc(char *page, char **start, off_t off,
8095                                  int count, int *eof, void *data)
8096  {
8097 +       unsigned int running, threads;
8098         int a, b, c;
8099         int len;
8100  
8101 -       a = avenrun[0] + (FIXED_1/200);
8102 -       b = avenrun[1] + (FIXED_1/200);
8103 -       c = avenrun[2] + (FIXED_1/200);
8104 -       len = sprintf(page,"%d.%02d %d.%02d %d.%02d %ld/%d %d\n",
8105 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
8106 +               struct vx_info *vxi = current->vx_info;
8107 +
8108 +               a = vxi->cvirt.load[0] + (FIXED_1/200);
8109 +               b = vxi->cvirt.load[1] + (FIXED_1/200);
8110 +               c = vxi->cvirt.load[2] + (FIXED_1/200);
8111 +
8112 +               running = atomic_read(&vxi->cvirt.nr_running);
8113 +               threads = atomic_read(&vxi->cvirt.nr_threads);
8114 +       } else {
8115 +               a = avenrun[0] + (FIXED_1/200);
8116 +               b = avenrun[1] + (FIXED_1/200);
8117 +               c = avenrun[2] + (FIXED_1/200);
8118 +
8119 +               running = nr_running();
8120 +               threads = nr_threads;
8121 +       }
8122 +       len = sprintf(page,"%d.%02d %d.%02d %d.%02d %d/%d %d\n",
8123                 LOAD_INT(a), LOAD_FRAC(a),
8124                 LOAD_INT(b), LOAD_FRAC(b),
8125                 LOAD_INT(c), LOAD_FRAC(c),
8126 -               nr_running(), nr_threads,
8127 +               running, threads,
8128                 task_active_pid_ns(current)->last_pid);
8129         return proc_calc_metrics(page, start, off, count, eof, len);
8130  }
8131 @@ -107,6 +124,9 @@ static int uptime_read_proc(char *page, 
8132         do_posix_clock_monotonic_gettime(&uptime);
8133         monotonic_to_bootbased(&uptime);
8134         cputime_to_timespec(idletime, &idle);
8135 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
8136 +               vx_vsi_uptime(&uptime, &idle);
8137 +
8138         len = sprintf(page,"%lu.%02lu %lu.%02lu\n",
8139                         (unsigned long) uptime.tv_sec,
8140                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
8141 @@ -138,7 +158,7 @@ static int meminfo_read_proc(char *page,
8142  
8143         cached = global_page_state(NR_FILE_PAGES) -
8144                         total_swapcache_pages - i.bufferram;
8145 -       if (cached < 0)
8146 +       if (cached < 0 || vx_flags(VXF_VIRT_MEM, 0))
8147                 cached = 0;
8148  
8149         get_vmalloc_info(&vmi);
8150 diff -NurpP --minimal linux-2.6.24-rc7/fs/proc/root.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/proc/root.c
8151 --- linux-2.6.24-rc7/fs/proc/root.c     2007-12-31 17:58:26 +0100
8152 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/proc/root.c       2007-12-31 12:34:40 +0100
8153 @@ -23,6 +23,9 @@
8154  #include "internal.h"
8155  
8156  struct proc_dir_entry *proc_bus, *proc_root_fs, *proc_root_driver;
8157 +struct proc_dir_entry *proc_virtual;
8158 +
8159 +extern void proc_vx_init(void);
8160  
8161  static int proc_test_super(struct super_block *sb, void *data)
8162  {
8163 @@ -138,6 +141,7 @@ void __init proc_root_init(void)
8164         proc_device_tree_init();
8165  #endif
8166         proc_bus = proc_mkdir("bus", NULL);
8167 +       proc_vx_init();
8168         proc_sys_init();
8169  }
8170  
8171 diff -NurpP --minimal linux-2.6.24-rc7/fs/quota.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/quota.c
8172 --- linux-2.6.24-rc7/fs/quota.c 2007-11-29 01:02:00 +0100
8173 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/quota.c   2007-12-13 13:25:46 +0100
8174 @@ -18,6 +18,7 @@
8175  #include <linux/capability.h>
8176  #include <linux/quotaops.h>
8177  #include <linux/types.h>
8178 +#include <linux/vs_context.h>
8179  
8180  /* Check validity of generic quotactl commands */
8181  static int generic_quotactl_valid(struct super_block *sb, int type, int cmd, qid_t id)
8182 @@ -82,11 +83,11 @@ static int generic_quotactl_valid(struct
8183         if (cmd == Q_GETQUOTA) {
8184                 if (((type == USRQUOTA && current->euid != id) ||
8185                      (type == GRPQUOTA && !in_egroup_p(id))) &&
8186 -                   !capable(CAP_SYS_ADMIN))
8187 +                   !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
8188                         return -EPERM;
8189         }
8190         else if (cmd != Q_GETFMT && cmd != Q_SYNC && cmd != Q_GETINFO)
8191 -               if (!capable(CAP_SYS_ADMIN))
8192 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
8193                         return -EPERM;
8194  
8195         return 0;
8196 @@ -133,10 +134,10 @@ static int xqm_quotactl_valid(struct sup
8197         if (cmd == Q_XGETQUOTA) {
8198                 if (((type == XQM_USRQUOTA && current->euid != id) ||
8199                      (type == XQM_GRPQUOTA && !in_egroup_p(id))) &&
8200 -                    !capable(CAP_SYS_ADMIN))
8201 +                    !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
8202                         return -EPERM;
8203         } else if (cmd != Q_XGETQSTAT && cmd != Q_XQUOTASYNC) {
8204 -               if (!capable(CAP_SYS_ADMIN))
8205 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
8206                         return -EPERM;
8207         }
8208  
8209 @@ -329,6 +330,46 @@ static int do_quotactl(struct super_bloc
8210         return 0;
8211  }
8212  
8213 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
8214 +
8215 +#include <linux/vroot.h>
8216 +#include <linux/major.h>
8217 +#include <linux/module.h>
8218 +#include <linux/kallsyms.h>
8219 +#include <linux/vserver/debug.h>
8220 +
8221 +static vroot_grb_func *vroot_get_real_bdev = NULL;
8222 +
8223 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
8224 +
8225 +int register_vroot_grb(vroot_grb_func *func) {
8226 +       int ret = -EBUSY;
8227 +
8228 +       spin_lock(&vroot_grb_lock);
8229 +       if (!vroot_get_real_bdev) {
8230 +               vroot_get_real_bdev = func;
8231 +               ret = 0;
8232 +       }
8233 +       spin_unlock(&vroot_grb_lock);
8234 +       return ret;
8235 +}
8236 +EXPORT_SYMBOL(register_vroot_grb);
8237 +
8238 +int unregister_vroot_grb(vroot_grb_func *func) {
8239 +       int ret = -EINVAL;
8240 +
8241 +       spin_lock(&vroot_grb_lock);
8242 +       if (vroot_get_real_bdev) {
8243 +               vroot_get_real_bdev = NULL;
8244 +               ret = 0;
8245 +       }
8246 +       spin_unlock(&vroot_grb_lock);
8247 +       return ret;
8248 +}
8249 +EXPORT_SYMBOL(unregister_vroot_grb);
8250 +
8251 +#endif
8252 +
8253  /*
8254   * look up a superblock on which quota ops will be performed
8255   * - use the name of a block device to find the superblock thereon
8256 @@ -346,6 +387,22 @@ static inline struct super_block *quotac
8257         putname(tmp);
8258         if (IS_ERR(bdev))
8259                 return ERR_PTR(PTR_ERR(bdev));
8260 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
8261 +       if (bdev && bdev->bd_inode &&
8262 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
8263 +               struct block_device *bdnew = (void *)-EINVAL;
8264 +
8265 +               if (vroot_get_real_bdev)
8266 +                       bdnew = vroot_get_real_bdev(bdev);
8267 +               else
8268 +                       vxdprintk(VXD_CBIT(misc, 0),
8269 +                                       "vroot_get_real_bdev not set");
8270 +               bdput(bdev);
8271 +               if (IS_ERR(bdnew))
8272 +                       return ERR_PTR(PTR_ERR(bdnew));
8273 +               bdev = bdnew;
8274 +       }
8275 +#endif
8276         sb = get_super(bdev);
8277         bdput(bdev);
8278         if (!sb)
8279 diff -NurpP --minimal linux-2.6.24-rc7/fs/reiserfs/bitmap.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/reiserfs/bitmap.c
8280 --- linux-2.6.24-rc7/fs/reiserfs/bitmap.c       2007-11-29 01:11:57 +0100
8281 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/reiserfs/bitmap.c 2007-12-13 13:25:46 +0100
8282 @@ -13,6 +13,7 @@
8283  #include <linux/reiserfs_fs_sb.h>
8284  #include <linux/reiserfs_fs_i.h>
8285  #include <linux/quotaops.h>
8286 +#include <linux/vs_dlimit.h>
8287  
8288  #define PREALLOCATION_SIZE 9
8289  
8290 @@ -429,8 +430,10 @@ static void _reiserfs_free_block(struct 
8291         set_sb_free_blocks(rs, sb_free_blocks(rs) + 1);
8292  
8293         journal_mark_dirty(th, s, sbh);
8294 -       if (for_unformatted)
8295 +       if (for_unformatted) {
8296 +               DLIMIT_FREE_BLOCK(inode, 1);
8297                 DQUOT_FREE_BLOCK_NODIRTY(inode, 1);
8298 +       }
8299  }
8300  
8301  void reiserfs_free_block(struct reiserfs_transaction_handle *th,
8302 @@ -1045,6 +1048,7 @@ static inline int blocknrs_and_prealloc_
8303         b_blocknr_t finish = SB_BLOCK_COUNT(s) - 1;
8304         int passno = 0;
8305         int nr_allocated = 0;
8306 +       int blocks;
8307  
8308         determine_prealloc_size(hint);
8309         if (!hint->formatted_node) {
8310 @@ -1054,19 +1058,30 @@ static inline int blocknrs_and_prealloc_
8311                                "reiserquota: allocating %d blocks id=%u",
8312                                amount_needed, hint->inode->i_uid);
8313  #endif
8314 -               quota_ret =
8315 -                   DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode, amount_needed);
8316 -               if (quota_ret)  /* Quota exceeded? */
8317 +               quota_ret = DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode,
8318 +                       amount_needed);
8319 +               if (quota_ret)
8320                         return QUOTA_EXCEEDED;
8321 +               if (DLIMIT_ALLOC_BLOCK(hint->inode, amount_needed)) {
8322 +                       DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
8323 +                               amount_needed);
8324 +                       return NO_DISK_SPACE;
8325 +               }
8326 +
8327                 if (hint->preallocate && hint->prealloc_size) {
8328  #ifdef REISERQUOTA_DEBUG
8329                         reiserfs_debug(s, REISERFS_DEBUG_CODE,
8330                                        "reiserquota: allocating (prealloc) %d blocks id=%u",
8331                                        hint->prealloc_size, hint->inode->i_uid);
8332  #endif
8333 -                       quota_ret =
8334 -                           DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
8335 -                                                        hint->prealloc_size);
8336 +                       quota_ret = DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
8337 +                               hint->prealloc_size);
8338 +                       if (!quota_ret &&
8339 +                               DLIMIT_ALLOC_BLOCK(hint->inode, hint->prealloc_size)) {
8340 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
8341 +                                       hint->prealloc_size);
8342 +                               quota_ret = 1;
8343 +                       }
8344                         if (quota_ret)
8345                                 hint->preallocate = hint->prealloc_size = 0;
8346                 }
8347 @@ -1098,7 +1113,10 @@ static inline int blocknrs_and_prealloc_
8348                                                nr_allocated,
8349                                                hint->inode->i_uid);
8350  #endif
8351 -                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed + hint->prealloc_size - nr_allocated);      /* Free not allocated blocks */
8352 +                               /* Free not allocated blocks */
8353 +                               blocks = amount_needed + hint->prealloc_size - nr_allocated;
8354 +                               DLIMIT_FREE_BLOCK(hint->inode, blocks);
8355 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
8356                         }
8357                         while (nr_allocated--)
8358                                 reiserfs_free_block(hint->th, hint->inode,
8359 @@ -1129,10 +1147,10 @@ static inline int blocknrs_and_prealloc_
8360                                REISERFS_I(hint->inode)->i_prealloc_count,
8361                                hint->inode->i_uid);
8362  #endif
8363 -               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed +
8364 -                                        hint->prealloc_size - nr_allocated -
8365 -                                        REISERFS_I(hint->inode)->
8366 -                                        i_prealloc_count);
8367 +               blocks = amount_needed + hint->prealloc_size - nr_allocated -
8368 +                       REISERFS_I(hint->inode)->i_prealloc_count;
8369 +               DLIMIT_FREE_BLOCK(hint->inode, blocks);
8370 +               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
8371         }
8372  
8373         return CARRY_ON;
8374 diff -NurpP --minimal linux-2.6.24-rc7/fs/reiserfs/file.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/reiserfs/file.c
8375 --- linux-2.6.24-rc7/fs/reiserfs/file.c 2007-11-29 01:11:58 +0100
8376 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/reiserfs/file.c   2007-12-13 13:25:39 +0100
8377 @@ -306,4 +306,5 @@ const struct inode_operations reiserfs_f
8378         .listxattr = reiserfs_listxattr,
8379         .removexattr = reiserfs_removexattr,
8380         .permission = reiserfs_permission,
8381 +       .sync_flags = reiserfs_sync_flags,
8382  };
8383 diff -NurpP --minimal linux-2.6.24-rc7/fs/reiserfs/inode.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/reiserfs/inode.c
8384 --- linux-2.6.24-rc7/fs/reiserfs/inode.c        2007-11-29 01:11:58 +0100
8385 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/reiserfs/inode.c  2007-12-13 13:25:46 +0100
8386 @@ -18,6 +18,8 @@
8387  #include <linux/writeback.h>
8388  #include <linux/quotaops.h>
8389  #include <linux/swap.h>
8390 +#include <linux/vs_dlimit.h>
8391 +#include <linux/vs_tag.h>
8392  
8393  int reiserfs_commit_write(struct file *f, struct page *page,
8394                           unsigned from, unsigned to);
8395 @@ -52,6 +54,7 @@ void reiserfs_delete_inode(struct inode 
8396                  * stat data deletion */
8397                 if (!err) 
8398                         DQUOT_FREE_INODE(inode);
8399 +               DLIMIT_FREE_INODE(inode);
8400  
8401                 if (journal_end(&th, inode->i_sb, jbegin_count))
8402                         goto out;
8403 @@ -1114,6 +1117,8 @@ static void init_inode(struct inode *ino
8404         struct buffer_head *bh;
8405         struct item_head *ih;
8406         __u32 rdev;
8407 +       uid_t uid;
8408 +       gid_t gid;
8409         //int version = ITEM_VERSION_1;
8410  
8411         bh = PATH_PLAST_BUFFER(path);
8412 @@ -1137,12 +1142,13 @@ static void init_inode(struct inode *ino
8413                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
8414                 unsigned long blocks;
8415  
8416 +               uid = sd_v1_uid(sd);
8417 +               gid = sd_v1_gid(sd);
8418 +
8419                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
8420                 set_inode_sd_version(inode, STAT_DATA_V1);
8421                 inode->i_mode = sd_v1_mode(sd);
8422                 inode->i_nlink = sd_v1_nlink(sd);
8423 -               inode->i_uid = sd_v1_uid(sd);
8424 -               inode->i_gid = sd_v1_gid(sd);
8425                 inode->i_size = sd_v1_size(sd);
8426                 inode->i_atime.tv_sec = sd_v1_atime(sd);
8427                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
8428 @@ -1184,11 +1190,12 @@ static void init_inode(struct inode *ino
8429                 // (directories and symlinks)
8430                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
8431  
8432 +               uid    = sd_v2_uid(sd);
8433 +               gid    = sd_v2_gid(sd);
8434 +
8435                 inode->i_mode = sd_v2_mode(sd);
8436                 inode->i_nlink = sd_v2_nlink(sd);
8437 -               inode->i_uid = sd_v2_uid(sd);
8438                 inode->i_size = sd_v2_size(sd);
8439 -               inode->i_gid = sd_v2_gid(sd);
8440                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
8441                 inode->i_atime.tv_sec = sd_v2_atime(sd);
8442                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
8443 @@ -1218,6 +1225,10 @@ static void init_inode(struct inode *ino
8444                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
8445         }
8446  
8447 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
8448 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
8449 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
8450 +
8451         pathrelse(path);
8452         if (S_ISREG(inode->i_mode)) {
8453                 inode->i_op = &reiserfs_file_inode_operations;
8454 @@ -1240,13 +1251,15 @@ static void init_inode(struct inode *ino
8455  static void inode2sd(void *sd, struct inode *inode, loff_t size)
8456  {
8457         struct stat_data *sd_v2 = (struct stat_data *)sd;
8458 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
8459 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
8460         __u16 flags;
8461  
8462 +       set_sd_v2_uid(sd_v2, uid);
8463 +       set_sd_v2_gid(sd_v2, gid);
8464         set_sd_v2_mode(sd_v2, inode->i_mode);
8465         set_sd_v2_nlink(sd_v2, inode->i_nlink);
8466 -       set_sd_v2_uid(sd_v2, inode->i_uid);
8467         set_sd_v2_size(sd_v2, size);
8468 -       set_sd_v2_gid(sd_v2, inode->i_gid);
8469         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
8470         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
8471         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
8472 @@ -1769,6 +1782,10 @@ int reiserfs_new_inode(struct reiserfs_t
8473  
8474         BUG_ON(!th->t_trans_id);
8475  
8476 +       if (DLIMIT_ALLOC_INODE(inode)) {
8477 +               err = -ENOSPC;
8478 +               goto out_bad_dlimit;
8479 +       }
8480         if (DQUOT_ALLOC_INODE(inode)) {
8481                 err = -EDQUOT;
8482                 goto out_end_trans;
8483 @@ -1954,6 +1971,9 @@ int reiserfs_new_inode(struct reiserfs_t
8484         DQUOT_FREE_INODE(inode);
8485  
8486        out_end_trans:
8487 +       DLIMIT_FREE_INODE(inode);
8488 +
8489 +      out_bad_dlimit:
8490         journal_end(th, th->t_super, th->t_blocks_allocated);
8491         /* Drop can be outside and it needs more credits so it's better to have it outside */
8492         DQUOT_DROP(inode);
8493 @@ -2848,6 +2868,14 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
8494                         inode->i_flags |= S_IMMUTABLE;
8495                 else
8496                         inode->i_flags &= ~S_IMMUTABLE;
8497 +               if (sd_attrs & REISERFS_IUNLINK_FL)
8498 +                       inode->i_flags |= S_IUNLINK;
8499 +               else
8500 +                       inode->i_flags &= ~S_IUNLINK;
8501 +               if (sd_attrs & REISERFS_BARRIER_FL)
8502 +                       inode->i_flags |= S_BARRIER;
8503 +               else
8504 +                       inode->i_flags &= ~S_BARRIER;
8505                 if (sd_attrs & REISERFS_APPEND_FL)
8506                         inode->i_flags |= S_APPEND;
8507                 else
8508 @@ -2870,6 +2898,14 @@ void i_attrs_to_sd_attrs(struct inode *i
8509                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
8510                 else
8511                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
8512 +               if (inode->i_flags & S_IUNLINK)
8513 +                       *sd_attrs |= REISERFS_IUNLINK_FL;
8514 +               else
8515 +                       *sd_attrs &= ~REISERFS_IUNLINK_FL;
8516 +               if (inode->i_flags & S_BARRIER)
8517 +                       *sd_attrs |= REISERFS_BARRIER_FL;
8518 +               else
8519 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
8520                 if (inode->i_flags & S_SYNC)
8521                         *sd_attrs |= REISERFS_SYNC_FL;
8522                 else
8523 @@ -3049,6 +3085,22 @@ static ssize_t reiserfs_direct_IO(int rw
8524                                   reiserfs_get_blocks_direct_io, NULL);
8525  }
8526  
8527 +int reiserfs_sync_flags(struct inode *inode)
8528 +{
8529 +       u16 oldflags, newflags;
8530 +
8531 +       oldflags = REISERFS_I(inode)->i_attrs;
8532 +       newflags = oldflags;
8533 +       i_attrs_to_sd_attrs(inode, &newflags);
8534 +
8535 +       if (oldflags ^ newflags) {
8536 +               REISERFS_I(inode)->i_attrs = newflags;
8537 +               inode->i_ctime = CURRENT_TIME_SEC;
8538 +               mark_inode_dirty(inode);
8539 +       }
8540 +       return 0;
8541 +}
8542 +
8543  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
8544  {
8545         struct inode *inode = dentry->d_inode;
8546 @@ -3102,9 +3154,11 @@ int reiserfs_setattr(struct dentry *dent
8547         }
8548  
8549         error = inode_change_ok(inode, attr);
8550 +
8551         if (!error) {
8552                 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
8553 -                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
8554 +                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
8555 +                   (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
8556                         error = reiserfs_chown_xattrs(inode, attr);
8557  
8558                         if (!error) {
8559 @@ -3134,6 +3188,9 @@ int reiserfs_setattr(struct dentry *dent
8560                                         inode->i_uid = attr->ia_uid;
8561                                 if (attr->ia_valid & ATTR_GID)
8562                                         inode->i_gid = attr->ia_gid;
8563 +                               if ((attr->ia_valid & ATTR_TAG) &&
8564 +                                       IS_TAGGED(inode))
8565 +                                       inode->i_tag = attr->ia_tag;
8566                                 mark_inode_dirty(inode);
8567                                 error =
8568                                     journal_end(&th, inode->i_sb, jbegin_count);
8569 diff -NurpP --minimal linux-2.6.24-rc7/fs/reiserfs/ioctl.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/reiserfs/ioctl.c
8570 --- linux-2.6.24-rc7/fs/reiserfs/ioctl.c        2007-11-29 01:11:58 +0100
8571 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/reiserfs/ioctl.c  2008-01-11 03:51:21 +0100
8572 @@ -4,6 +4,7 @@
8573  
8574  #include <linux/capability.h>
8575  #include <linux/fs.h>
8576 +#include <linux/mount.h>
8577  #include <linux/reiserfs_fs.h>
8578  #include <linux/time.h>
8579  #include <asm/uaccess.h>
8580 @@ -24,7 +25,7 @@ static int reiserfs_unpack(struct inode 
8581  int reiserfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
8582                    unsigned long arg)
8583  {
8584 -       unsigned int flags;
8585 +       unsigned int flags, oldflags;
8586  
8587         switch (cmd) {
8588         case REISERFS_IOC_UNPACK:
8589 @@ -43,12 +44,14 @@ int reiserfs_ioctl(struct inode *inode, 
8590  
8591                 flags = REISERFS_I(inode)->i_attrs;
8592                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
8593 +               flags &= REISERFS_FL_USER_VISIBLE;
8594                 return put_user(flags, (int __user *)arg);
8595         case REISERFS_IOC_SETFLAGS:{
8596                         if (!reiserfs_attrs(inode->i_sb))
8597                                 return -ENOTTY;
8598  
8599 -                       if (IS_RDONLY(inode))
8600 +                       if (IS_RDONLY(inode) ||
8601 +                               (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
8602                                 return -EROFS;
8603  
8604                         if (!is_owner_or_cap(inode))
8605 @@ -74,6 +77,10 @@ int reiserfs_ioctl(struct inode *inode, 
8606                                 if (result)
8607                                         return result;
8608                         }
8609 +
8610 +                       oldflags = REISERFS_I(inode)->i_attrs;
8611 +                       flags = flags & REISERFS_FL_USER_MODIFIABLE;
8612 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
8613                         sd_attrs_to_i_attrs(flags, inode);
8614                         REISERFS_I(inode)->i_attrs = flags;
8615                         inode->i_ctime = CURRENT_TIME_SEC;
8616 @@ -85,7 +92,8 @@ int reiserfs_ioctl(struct inode *inode, 
8617         case REISERFS_IOC_SETVERSION:
8618                 if (!is_owner_or_cap(inode))
8619                         return -EPERM;
8620 -               if (IS_RDONLY(inode))
8621 +               if (IS_RDONLY(inode) ||
8622 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
8623                         return -EROFS;
8624                 if (get_user(inode->i_generation, (int __user *)arg))
8625                         return -EFAULT;
8626 diff -NurpP --minimal linux-2.6.24-rc7/fs/reiserfs/namei.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/reiserfs/namei.c
8627 --- linux-2.6.24-rc7/fs/reiserfs/namei.c        2007-07-09 13:19:28 +0200
8628 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/reiserfs/namei.c  2007-12-13 13:25:48 +0100
8629 @@ -17,6 +17,7 @@
8630  #include <linux/reiserfs_acl.h>
8631  #include <linux/reiserfs_xattr.h>
8632  #include <linux/quotaops.h>
8633 +#include <linux/vs_tag.h>
8634  
8635  #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; }
8636  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
8637 @@ -360,6 +361,7 @@ static struct dentry *reiserfs_lookup(st
8638                         reiserfs_write_unlock(dir->i_sb);
8639                         return ERR_PTR(-EACCES);
8640                 }
8641 +               dx_propagate_tag(nd, inode);
8642  
8643                 /* Propogate the priv_object flag so we know we're in the priv tree */
8644                 if (is_reiserfs_priv_object(dir))
8645 @@ -595,6 +597,7 @@ static int new_inode_init(struct inode *
8646         } else {
8647                 inode->i_gid = current->fsgid;
8648         }
8649 +       inode->i_tag = dx_current_fstag(inode->i_sb);
8650         DQUOT_INIT(inode);
8651         return 0;
8652  }
8653 @@ -1541,6 +1544,7 @@ const struct inode_operations reiserfs_d
8654         .listxattr = reiserfs_listxattr,
8655         .removexattr = reiserfs_removexattr,
8656         .permission = reiserfs_permission,
8657 +       .sync_flags = reiserfs_sync_flags,
8658  };
8659  
8660  /*
8661 @@ -1557,6 +1561,7 @@ const struct inode_operations reiserfs_s
8662         .listxattr = reiserfs_listxattr,
8663         .removexattr = reiserfs_removexattr,
8664         .permission = reiserfs_permission,
8665 +       .sync_flags = reiserfs_sync_flags,
8666  
8667  };
8668  
8669 @@ -1570,5 +1575,6 @@ const struct inode_operations reiserfs_s
8670         .listxattr = reiserfs_listxattr,
8671         .removexattr = reiserfs_removexattr,
8672         .permission = reiserfs_permission,
8673 +       .sync_flags = reiserfs_sync_flags,
8674  
8675  };
8676 diff -NurpP --minimal linux-2.6.24-rc7/fs/reiserfs/stree.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/reiserfs/stree.c
8677 --- linux-2.6.24-rc7/fs/reiserfs/stree.c        2007-11-29 01:11:58 +0100
8678 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/reiserfs/stree.c  2007-12-13 13:25:46 +0100
8679 @@ -55,6 +55,7 @@
8680  #include <linux/reiserfs_fs.h>
8681  #include <linux/buffer_head.h>
8682  #include <linux/quotaops.h>
8683 +#include <linux/vs_dlimit.h>
8684  
8685  /* Does the buffer contain a disk block which is in the tree. */
8686  inline int B_IS_IN_TREE(const struct buffer_head *p_s_bh)
8687 @@ -1297,6 +1298,7 @@ int reiserfs_delete_item(struct reiserfs
8688                        "reiserquota delete_item(): freeing %u, id=%u type=%c",
8689                        quota_cut_bytes, p_s_inode->i_uid, head2type(&s_ih));
8690  #endif
8691 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
8692         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
8693  
8694         /* Return deleted body length */
8695 @@ -1385,6 +1387,7 @@ void reiserfs_delete_solid_item(struct r
8696  #endif
8697                                 DQUOT_FREE_SPACE_NODIRTY(inode,
8698                                                          quota_cut_bytes);
8699 +                               DLIMIT_FREE_SPACE(inode, quota_cut_bytes);
8700                         }
8701                         break;
8702                 }
8703 @@ -1735,6 +1738,7 @@ int reiserfs_cut_from_item(struct reiser
8704                        "reiserquota cut_from_item(): freeing %u id=%u type=%c",
8705                        quota_cut_bytes, p_s_inode->i_uid, '?');
8706  #endif
8707 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
8708         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
8709         return n_ret_value;
8710  }
8711 @@ -1976,6 +1980,11 @@ int reiserfs_paste_into_item(struct reis
8712                 pathrelse(p_s_search_path);
8713                 return -EDQUOT;
8714         }
8715 +       if (DLIMIT_ALLOC_SPACE(inode, n_pasted_size)) {
8716 +               DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
8717 +               pathrelse(p_s_search_path);
8718 +               return -ENOSPC;
8719 +       }
8720         init_tb_struct(th, &s_paste_balance, th->t_super, p_s_search_path,
8721                        n_pasted_size);
8722  #ifdef DISPLACE_NEW_PACKING_LOCALITIES
8723 @@ -2028,6 +2037,7 @@ int reiserfs_paste_into_item(struct reis
8724                        n_pasted_size, inode->i_uid,
8725                        key2type(&(p_s_key->on_disk_key)));
8726  #endif
8727 +       DLIMIT_FREE_SPACE(inode, n_pasted_size);
8728         DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
8729         return retval;
8730  }
8731 @@ -2065,6 +2075,11 @@ int reiserfs_insert_item(struct reiserfs
8732                         pathrelse(p_s_path);
8733                         return -EDQUOT;
8734                 }
8735 +               if (DLIMIT_ALLOC_SPACE(inode, quota_bytes)) {
8736 +                       DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
8737 +                       pathrelse(p_s_path);
8738 +                       return -ENOSPC;
8739 +               }
8740         }
8741         init_tb_struct(th, &s_ins_balance, th->t_super, p_s_path,
8742                        IH_SIZE + ih_item_len(p_s_ih));
8743 @@ -2112,7 +2127,9 @@ int reiserfs_insert_item(struct reiserfs
8744                        "reiserquota insert_item(): freeing %u id=%u type=%c",
8745                        quota_bytes, inode->i_uid, head2type(p_s_ih));
8746  #endif
8747 -       if (inode)
8748 +       if (inode) {
8749 +               DLIMIT_FREE_SPACE(inode, quota_bytes);
8750                 DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
8751 +       }
8752         return retval;
8753  }
8754 diff -NurpP --minimal linux-2.6.24-rc7/fs/reiserfs/super.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/reiserfs/super.c
8755 --- linux-2.6.24-rc7/fs/reiserfs/super.c        2007-11-29 01:11:58 +0100
8756 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/reiserfs/super.c  2007-12-13 13:25:38 +0100
8757 @@ -895,6 +895,14 @@ static int reiserfs_parse_options(struct
8758                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
8759                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
8760  #endif
8761 +#ifndef CONFIG_TAGGING_NONE
8762 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
8763 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
8764 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
8765 +#endif
8766 +#ifdef CONFIG_PROPAGATE
8767 +               {"tag",.arg_required = 'T',.values = NULL},
8768 +#endif
8769  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
8770                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
8771                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
8772 @@ -1156,6 +1164,12 @@ static int reiserfs_remount(struct super
8773                 return -EINVAL;
8774         }
8775  
8776 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
8777 +               !(s->s_flags & MS_TAGGED)) {
8778 +               reiserfs_warning(s, "reiserfs: tagging not permitted on remount.");
8779 +               return -EINVAL;
8780 +       }
8781 +
8782         handle_attrs(s);
8783  
8784         /* Add options that are safe here */
8785 @@ -1604,6 +1618,10 @@ static int reiserfs_fill_super(struct su
8786                 goto error;
8787         }
8788  
8789 +       /* map mount option tagxid */
8790 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
8791 +               s->s_flags |= MS_TAGGED;
8792 +
8793         rs = SB_DISK_SUPER_BLOCK(s);
8794         /* Let's do basic sanity check to verify that underlying device is not
8795            smaller than the filesystem. If the check fails then abort and scream,
8796 diff -NurpP --minimal linux-2.6.24-rc7/fs/reiserfs/xattr.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/reiserfs/xattr.c
8797 --- linux-2.6.24-rc7/fs/reiserfs/xattr.c        2007-11-29 01:11:58 +0100
8798 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/reiserfs/xattr.c  2007-12-13 13:25:47 +0100
8799 @@ -35,6 +35,7 @@
8800  #include <linux/namei.h>
8801  #include <linux/errno.h>
8802  #include <linux/fs.h>
8803 +#include <linux/mount.h>
8804  #include <linux/file.h>
8805  #include <linux/pagemap.h>
8806  #include <linux/xattr.h>
8807 @@ -781,7 +782,7 @@ int reiserfs_delete_xattrs(struct inode 
8808         if (dir->d_inode->i_nlink <= 2) {
8809                 root = get_xa_root(inode->i_sb, XATTR_REPLACE);
8810                 reiserfs_write_lock_xattrs(inode->i_sb);
8811 -               err = vfs_rmdir(root->d_inode, dir);
8812 +               err = vfs_rmdir(root->d_inode, dir, NULL);
8813                 reiserfs_write_unlock_xattrs(inode->i_sb);
8814                 dput(root);
8815         } else {
8816 diff -NurpP --minimal linux-2.6.24-rc7/fs/stat.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/stat.c
8817 --- linux-2.6.24-rc7/fs/stat.c  2007-07-09 13:19:28 +0200
8818 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/stat.c    2007-12-13 13:25:40 +0100
8819 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
8820         stat->nlink = inode->i_nlink;
8821         stat->uid = inode->i_uid;
8822         stat->gid = inode->i_gid;
8823 +       stat->tag = inode->i_tag;
8824         stat->rdev = inode->i_rdev;
8825         stat->atime = inode->i_atime;
8826         stat->mtime = inode->i_mtime;
8827 diff -NurpP --minimal linux-2.6.24-rc7/fs/super.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/super.c
8828 --- linux-2.6.24-rc7/fs/super.c 2007-11-29 01:11:58 +0100
8829 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/super.c   2007-12-13 13:25:38 +0100
8830 @@ -37,6 +37,9 @@
8831  #include <linux/idr.h>
8832  #include <linux/kobject.h>
8833  #include <linux/mutex.h>
8834 +#include <linux/devpts_fs.h>
8835 +#include <linux/proc_fs.h>
8836 +#include <linux/vs_context.h>
8837  #include <asm/uaccess.h>
8838  
8839  
8840 @@ -857,12 +860,18 @@ struct vfsmount *
8841  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
8842  {
8843         struct vfsmount *mnt;
8844 +       struct super_block *sb;
8845         char *secdata = NULL;
8846         int error;
8847  
8848         if (!type)
8849                 return ERR_PTR(-ENODEV);
8850  
8851 +       error = -EPERM;
8852 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
8853 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
8854 +               goto out;
8855 +
8856         error = -ENOMEM;
8857         mnt = alloc_vfsmnt(name);
8858         if (!mnt)
8859 @@ -883,7 +892,14 @@ vfs_kern_mount(struct file_system_type *
8860                 goto out_free_secdata;
8861         BUG_ON(!mnt->mnt_sb);
8862  
8863 -       error = security_sb_kern_mount(mnt->mnt_sb, secdata);
8864 +       sb = mnt->mnt_sb;
8865 +       error = -EPERM;
8866 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
8867 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
8868 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
8869 +               goto out_sb;
8870 +
8871 +       error = security_sb_kern_mount(sb, secdata);
8872         if (error)
8873                 goto out_sb;
8874  
8875 diff -NurpP --minimal linux-2.6.24-rc7/fs/sysfs/mount.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/sysfs/mount.c
8876 --- linux-2.6.24-rc7/fs/sysfs/mount.c   2007-11-29 01:11:58 +0100
8877 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/sysfs/mount.c     2007-12-13 13:25:51 +0100
8878 @@ -19,8 +19,6 @@
8879  
8880  #include "sysfs.h"
8881  
8882 -/* Random magic number */
8883 -#define SYSFS_MAGIC 0x62656572
8884  
8885  static struct vfsmount *sysfs_mount;
8886  struct super_block * sysfs_sb = NULL;
8887 @@ -46,7 +44,7 @@ static int sysfs_fill_super(struct super
8888  
8889         sb->s_blocksize = PAGE_CACHE_SIZE;
8890         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
8891 -       sb->s_magic = SYSFS_MAGIC;
8892 +       sb->s_magic = SYSFS_SUPER_MAGIC;
8893         sb->s_op = &sysfs_ops;
8894         sb->s_time_gran = 1;
8895         sysfs_sb = sb;
8896 diff -NurpP --minimal linux-2.6.24-rc7/fs/utimes.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/utimes.c
8897 --- linux-2.6.24-rc7/fs/utimes.c        2007-11-29 01:11:58 +0100
8898 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/utimes.c  2007-12-13 13:25:46 +0100
8899 @@ -6,6 +6,8 @@
8900  #include <linux/sched.h>
8901  #include <linux/stat.h>
8902  #include <linux/utime.h>
8903 +#include <linux/mount.h>
8904 +#include <linux/vs_cowbl.h>
8905  #include <asm/uaccess.h>
8906  #include <asm/unistd.h>
8907  
8908 @@ -83,11 +85,13 @@ long do_utimes(int dfd, char __user *fil
8909                 if (error)
8910                         goto out;
8911  
8912 +               error = cow_check_and_break(&nd);
8913 +               if (error)
8914 +                       goto dput_and_out;
8915                 dentry = nd.dentry;
8916         }
8917  
8918         inode = dentry->d_inode;
8919 -
8920         error = -EROFS;
8921         if (IS_RDONLY(inode))
8922                 goto dput_and_out;
8923 diff -NurpP --minimal linux-2.6.24-rc7/fs/xattr.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xattr.c
8924 --- linux-2.6.24-rc7/fs/xattr.c 2007-11-29 01:11:58 +0100
8925 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xattr.c   2007-12-13 13:25:47 +0100
8926 @@ -17,6 +17,7 @@
8927  #include <linux/module.h>
8928  #include <linux/fsnotify.h>
8929  #include <linux/audit.h>
8930 +#include <linux/mount.h>
8931  #include <asm/uaccess.h>
8932  
8933  
8934 @@ -193,7 +194,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
8935   */
8936  static long
8937  setxattr(struct dentry *d, char __user *name, void __user *value,
8938 -        size_t size, int flags)
8939 +        size_t size, int flags, struct vfsmount *mnt)
8940  {
8941         int error;
8942         void *kvalue = NULL;
8943 @@ -220,6 +221,9 @@ setxattr(struct dentry *d, char __user *
8944                 }
8945         }
8946  
8947 +       if (MNT_IS_RDONLY(mnt))
8948 +               return -EROFS;
8949 +
8950         error = vfs_setxattr(d, kname, kvalue, size, flags);
8951         kfree(kvalue);
8952         return error;
8953 @@ -235,7 +239,7 @@ sys_setxattr(char __user *path, char __u
8954         error = user_path_walk(path, &nd);
8955         if (error)
8956                 return error;
8957 -       error = setxattr(nd.dentry, name, value, size, flags);
8958 +       error = setxattr(nd.dentry, name, value, size, flags, nd.mnt);
8959         path_release(&nd);
8960         return error;
8961  }
8962 @@ -250,7 +254,7 @@ sys_lsetxattr(char __user *path, char __
8963         error = user_path_walk_link(path, &nd);
8964         if (error)
8965                 return error;
8966 -       error = setxattr(nd.dentry, name, value, size, flags);
8967 +       error = setxattr(nd.dentry, name, value, size, flags, nd.mnt);
8968         path_release(&nd);
8969         return error;
8970  }
8971 @@ -268,7 +272,7 @@ sys_fsetxattr(int fd, char __user *name,
8972                 return error;
8973         dentry = f->f_path.dentry;
8974         audit_inode(NULL, dentry);
8975 -       error = setxattr(dentry, name, value, size, flags);
8976 +       error = setxattr(dentry, name, value, size, flags, f->f_vfsmnt);
8977         fput(f);
8978         return error;
8979  }
8980 @@ -432,7 +436,7 @@ sys_flistxattr(int fd, char __user *list
8981   * Extended attribute REMOVE operations
8982   */
8983  static long
8984 -removexattr(struct dentry *d, char __user *name)
8985 +removexattr(struct dentry *d, char __user *name, struct vfsmount *mnt)
8986  {
8987         int error;
8988         char kname[XATTR_NAME_MAX + 1];
8989 @@ -443,6 +447,9 @@ removexattr(struct dentry *d, char __use
8990         if (error < 0)
8991                 return error;
8992  
8993 +       if (MNT_IS_RDONLY(mnt))
8994 +               return -EROFS;
8995 +
8996         return vfs_removexattr(d, kname);
8997  }
8998  
8999 @@ -455,7 +462,7 @@ sys_removexattr(char __user *path, char 
9000         error = user_path_walk(path, &nd);
9001         if (error)
9002                 return error;
9003 -       error = removexattr(nd.dentry, name);
9004 +       error = removexattr(nd.dentry, name, nd.mnt);
9005         path_release(&nd);
9006         return error;
9007  }
9008 @@ -469,7 +476,7 @@ sys_lremovexattr(char __user *path, char
9009         error = user_path_walk_link(path, &nd);
9010         if (error)
9011                 return error;
9012 -       error = removexattr(nd.dentry, name);
9013 +       error = removexattr(nd.dentry, name, nd.mnt);
9014         path_release(&nd);
9015         return error;
9016  }
9017 @@ -486,7 +493,7 @@ sys_fremovexattr(int fd, char __user *na
9018                 return error;
9019         dentry = f->f_path.dentry;
9020         audit_inode(NULL, dentry);
9021 -       error = removexattr(dentry, name);
9022 +       error = removexattr(dentry, name, f->f_vfsmnt);
9023         fput(f);
9024         return error;
9025  }
9026 diff -NurpP --minimal linux-2.6.24-rc7/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/linux-2.6/xfs_ioctl.c
9027 --- linux-2.6.24-rc7/fs/xfs/linux-2.6/xfs_ioctl.c       2007-12-31 17:58:26 +0100
9028 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/linux-2.6/xfs_ioctl.c 2008-01-04 17:40:24 +0100
9029 @@ -1148,7 +1148,8 @@ xfs_merge_ioc_xflags(
9030  
9031  STATIC unsigned int
9032  xfs_di2lxflags(
9033 -       __uint16_t      di_flags)
9034 +       __uint16_t      di_flags,
9035 +       __uint16_t      di_vflags)
9036  {
9037         unsigned int    flags = 0;
9038  
9039 @@ -1162,6 +1163,11 @@ xfs_di2lxflags(
9040                 flags |= FS_NOATIME_FL;
9041         if (di_flags & XFS_DIFLAG_NODUMP)
9042                 flags |= FS_NODUMP_FL;
9043 +
9044 +       if (di_vflags & XFS_DIVFLAG_IUNLINK)
9045 +               flags |= FS_IUNLINK_FL;
9046 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
9047 +               flags |= FS_BARRIER_FL;
9048         return flags;
9049  }
9050  
9051 @@ -1243,7 +1249,7 @@ xfs_ioc_xattr(
9052         }
9053  
9054         case XFS_IOC_GETXFLAGS: {
9055 -               flags = xfs_di2lxflags(ip->i_d.di_flags);
9056 +               flags = xfs_di2lxflags(ip->i_d.di_flags, ip->i_d.di_vflags);
9057                 if (copy_to_user(arg, &flags, sizeof(flags)))
9058                         error = -EFAULT;
9059                 break;
9060 diff -NurpP --minimal linux-2.6.24-rc7/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/linux-2.6/xfs_iops.c
9061 --- linux-2.6.24-rc7/fs/xfs/linux-2.6/xfs_iops.c        2007-12-31 17:58:26 +0100
9062 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/linux-2.6/xfs_iops.c  2008-01-04 17:50:46 +0100
9063 @@ -52,6 +52,7 @@
9064  #include <linux/xattr.h>
9065  #include <linux/namei.h>
9066  #include <linux/security.h>
9067 +#include <linux/vs_tag.h>
9068  
9069  /*
9070   * Bring the atime in the XFS inode uptodate.
9071 @@ -378,6 +379,7 @@ xfs_vn_lookup(
9072                 d_add(dentry, NULL);
9073                 return NULL;
9074         }
9075 +       dx_propagate_tag(nd, vn_to_inode(cvp));
9076  
9077         return d_splice_alias(vn_to_inode(cvp), dentry);
9078  }
9079 @@ -595,6 +597,10 @@ xfs_vn_setattr(
9080         int             flags = 0;
9081         int             error;
9082  
9083 +       error = inode_change_ok(inode, attr);
9084 +       if (error)
9085 +               return error;
9086 +
9087         if (ia_valid & ATTR_UID) {
9088                 vattr.va_mask |= XFS_AT_UID;
9089                 vattr.va_uid = attr->ia_uid;
9090 @@ -603,6 +609,10 @@ xfs_vn_setattr(
9091                 vattr.va_mask |= XFS_AT_GID;
9092                 vattr.va_gid = attr->ia_gid;
9093         }
9094 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode)) {
9095 +               vattr.va_mask |= XFS_AT_TAG;
9096 +               vattr.va_tag = attr->ia_tag;
9097 +       }
9098         if (ia_valid & ATTR_SIZE) {
9099                 vattr.va_mask |= XFS_AT_SIZE;
9100                 vattr.va_size = attr->ia_size;
9101 @@ -648,6 +658,42 @@ xfs_vn_truncate(
9102  }
9103  
9104  STATIC int
9105 +xfs_vn_sync_flags(struct inode *inode)
9106 +{
9107 +       unsigned int oldflags, newflags;
9108 +       int             flags = 0;
9109 +       int             error;
9110 +       bhv_vattr_t     vattr;
9111 +       bhv_vnode_t     *vp = vn_from_inode(inode);
9112 +
9113 +       memset(&vattr, 0, sizeof vattr);
9114 +
9115 +       vattr.va_mask = XFS_AT_XFLAGS;
9116 +       error = xfs_getattr(XFS_I(inode), &vattr, 0);
9117 +
9118 +       if (error)
9119 +               return error;
9120 +       oldflags = vattr.va_xflags;
9121 +       newflags = oldflags & ~(XFS_XFLAG_IMMUTABLE |
9122 +               XFS_XFLAG_IUNLINK | XFS_XFLAG_BARRIER);
9123 +
9124 +       if (IS_IMMUTABLE(inode))
9125 +               newflags |= XFS_XFLAG_IMMUTABLE;
9126 +       if (IS_IUNLINK(inode))
9127 +               newflags |= XFS_XFLAG_IUNLINK;
9128 +       if (IS_BARRIER(inode))
9129 +               newflags |= XFS_XFLAG_BARRIER;
9130 +
9131 +       if (oldflags ^ newflags) {
9132 +               vattr.va_xflags = newflags;
9133 +               vattr.va_mask |= XFS_AT_XFLAGS;
9134 +               error = xfs_setattr(XFS_I(inode), &vattr, flags, NULL);
9135 +       }
9136 +       vn_revalidate(vp);
9137 +       return error;
9138 +}
9139 +
9140 +STATIC int
9141  xfs_vn_setxattr(
9142         struct dentry   *dentry,
9143         const char      *name,
9144 @@ -760,6 +806,7 @@ const struct inode_operations xfs_inode_
9145         .getxattr               = xfs_vn_getxattr,
9146         .listxattr              = xfs_vn_listxattr,
9147         .removexattr            = xfs_vn_removexattr,
9148 +       .sync_flags             = xfs_vn_sync_flags,
9149  };
9150  
9151  const struct inode_operations xfs_dir_inode_operations = {
9152 @@ -779,6 +826,7 @@ const struct inode_operations xfs_dir_in
9153         .getxattr               = xfs_vn_getxattr,
9154         .listxattr              = xfs_vn_listxattr,
9155         .removexattr            = xfs_vn_removexattr,
9156 +       .sync_flags             = xfs_vn_sync_flags,
9157  };
9158  
9159  const struct inode_operations xfs_symlink_inode_operations = {
9160 @@ -792,4 +840,5 @@ const struct inode_operations xfs_symlin
9161         .getxattr               = xfs_vn_getxattr,
9162         .listxattr              = xfs_vn_listxattr,
9163         .removexattr            = xfs_vn_removexattr,
9164 +       .sync_flags             = xfs_vn_sync_flags,
9165  };
9166 diff -NurpP --minimal linux-2.6.24-rc7/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/linux-2.6/xfs_linux.h
9167 --- linux-2.6.24-rc7/fs/xfs/linux-2.6/xfs_linux.h       2007-11-29 01:11:58 +0100
9168 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/linux-2.6/xfs_linux.h 2007-12-13 13:25:48 +0100
9169 @@ -128,6 +128,7 @@
9170  #define current_pid()          (current->pid)
9171  #define current_fsuid(cred)    (current->fsuid)
9172  #define current_fsgid(cred)    (current->fsgid)
9173 +#define current_fstag(cred,vp) (dx_current_fstag(vn_to_inode(vp)->i_sb))
9174  #define current_test_flags(f)  (current->flags & (f))
9175  #define current_set_flags_nested(sp, f)                \
9176                 (*(sp) = current->flags, current->flags |= (f))
9177 diff -NurpP --minimal linux-2.6.24-rc7/fs/xfs/linux-2.6/xfs_super.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/linux-2.6/xfs_super.c
9178 --- linux-2.6.24-rc7/fs/xfs/linux-2.6/xfs_super.c       2007-11-29 01:11:58 +0100
9179 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/linux-2.6/xfs_super.c 2008-01-04 17:13:44 +0100
9180 @@ -159,6 +159,7 @@ xfs_revalidate_inode(
9181         inode->i_nlink  = ip->i_d.di_nlink;
9182         inode->i_uid    = ip->i_d.di_uid;
9183         inode->i_gid    = ip->i_d.di_gid;
9184 +       inode->i_tag    = ip->i_d.di_tag;
9185  
9186         switch (inode->i_mode & S_IFMT) {
9187         case S_IFBLK:
9188 @@ -182,6 +183,7 @@ xfs_revalidate_inode(
9189         inode->i_mtime.tv_nsec  = ip->i_d.di_mtime.t_nsec;
9190         inode->i_ctime.tv_sec   = ip->i_d.di_ctime.t_sec;
9191         inode->i_ctime.tv_nsec  = ip->i_d.di_ctime.t_nsec;
9192 +
9193         if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE)
9194                 inode->i_flags |= S_IMMUTABLE;
9195         else
9196 @@ -198,6 +200,15 @@ xfs_revalidate_inode(
9197                 inode->i_flags |= S_NOATIME;
9198         else
9199                 inode->i_flags &= ~S_NOATIME;
9200 +
9201 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_IUNLINK)
9202 +               inode->i_flags |= S_IUNLINK;
9203 +       else
9204 +               inode->i_flags &= ~S_IUNLINK;
9205 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
9206 +               inode->i_flags |= S_BARRIER;
9207 +       else
9208 +               inode->i_flags &= ~S_BARRIER;
9209         xfs_iflags_clear(ip, XFS_IMODIFIED);
9210  }
9211  
9212 @@ -698,6 +709,12 @@ xfs_fs_remount(
9213         int                     error;
9214  
9215         error = xfs_parseargs(mp, options, args, 1);
9216 +       if ((args->flags2 & XFSMNT2_TAGGED) &&
9217 +               !(sb->s_flags & MS_TAGGED)) {
9218 +               printk("XFS: %s: tagging not permitted on remount.\n",
9219 +                       sb->s_id);
9220 +               error = EINVAL;
9221 +       }
9222         if (!error)
9223                 error = xfs_mntupdate(mp, flags, args);
9224         kmem_free(args, sizeof(*args));
9225 diff -NurpP --minimal linux-2.6.24-rc7/fs/xfs/linux-2.6/xfs_vnode.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/linux-2.6/xfs_vnode.c
9226 --- linux-2.6.24-rc7/fs/xfs/linux-2.6/xfs_vnode.c       2007-11-29 01:11:58 +0100
9227 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/linux-2.6/xfs_vnode.c 2007-12-13 13:25:40 +0100
9228 @@ -112,6 +112,7 @@ vn_revalidate_core(
9229         inode->i_nlink      = vap->va_nlink;
9230         inode->i_uid        = vap->va_uid;
9231         inode->i_gid        = vap->va_gid;
9232 +       inode->i_tag        = vap->va_tag;
9233         inode->i_blocks     = vap->va_nblocks;
9234         inode->i_mtime      = vap->va_mtime;
9235         inode->i_ctime      = vap->va_ctime;
9236 @@ -119,6 +120,14 @@ vn_revalidate_core(
9237                 inode->i_flags |= S_IMMUTABLE;
9238         else
9239                 inode->i_flags &= ~S_IMMUTABLE;
9240 +       if (vap->va_xflags & XFS_XFLAG_IUNLINK)
9241 +               inode->i_flags |= S_IUNLINK;
9242 +       else
9243 +               inode->i_flags &= ~S_IUNLINK;
9244 +       if (vap->va_xflags & XFS_XFLAG_BARRIER)
9245 +               inode->i_flags |= S_BARRIER;
9246 +       else
9247 +               inode->i_flags &= ~S_BARRIER;
9248         if (vap->va_xflags & XFS_XFLAG_APPEND)
9249                 inode->i_flags |= S_APPEND;
9250         else
9251 diff -NurpP --minimal linux-2.6.24-rc7/fs/xfs/linux-2.6/xfs_vnode.h linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/linux-2.6/xfs_vnode.h
9252 --- linux-2.6.24-rc7/fs/xfs/linux-2.6/xfs_vnode.h       2007-11-29 01:11:58 +0100
9253 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/linux-2.6/xfs_vnode.h 2007-12-13 13:25:40 +0100
9254 @@ -99,6 +99,7 @@ typedef struct bhv_vattr {
9255         xfs_nlink_t     va_nlink;       /* number of references to file */
9256         uid_t           va_uid;         /* owner user id */
9257         gid_t           va_gid;         /* owner group id */
9258 +       tag_t           va_tag;         /* owner group id */
9259         xfs_ino_t       va_nodeid;      /* file id */
9260         xfs_off_t       va_size;        /* file size in bytes */
9261         u_long          va_blocksize;   /* blocksize preferred for i/o */
9262 @@ -147,13 +148,15 @@ typedef struct bhv_vattr {
9263  #define XFS_AT_PROJID          0x04000000
9264  #define XFS_AT_SIZE_NOPERM     0x08000000
9265  #define XFS_AT_GENCOUNT                0x10000000
9266 +#define XFS_AT_TAG             0x20000000
9267  
9268  #define XFS_AT_ALL     (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
9269                 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
9270                 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
9271                 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|XFS_AT_MAC|\
9272                 XFS_AT_ACL|XFS_AT_CAP|XFS_AT_INF|XFS_AT_XFLAGS|XFS_AT_EXTSIZE|\
9273 -               XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_PROJID|XFS_AT_GENCOUNT)
9274 +               XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_PROJID|XFS_AT_GENCOUNT\
9275 +               XFS_AT_TAG)
9276  
9277  #define XFS_AT_STAT    (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
9278                 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
9279 diff -NurpP --minimal linux-2.6.24-rc7/fs/xfs/quota/xfs_qm_syscalls.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/quota/xfs_qm_syscalls.c
9280 --- linux-2.6.24-rc7/fs/xfs/quota/xfs_qm_syscalls.c     2007-11-29 01:11:59 +0100
9281 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/quota/xfs_qm_syscalls.c       2007-12-13 13:25:43 +0100
9282 @@ -17,6 +17,7 @@
9283   */
9284  
9285  #include <linux/capability.h>
9286 +#include <linux/vs_context.h>
9287  
9288  #include "xfs.h"
9289  #include "xfs_fs.h"
9290 @@ -206,7 +207,7 @@ xfs_qm_scall_quotaoff(
9291         xfs_qoff_logitem_t      *qoffstart;
9292         int                     nculprits;
9293  
9294 -       if (!force && !capable(CAP_SYS_ADMIN))
9295 +       if (!force && !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9296                 return XFS_ERROR(EPERM);
9297         /*
9298          * No file system can have quotas enabled on disk but not in core.
9299 @@ -375,7 +376,7 @@ xfs_qm_scall_trunc_qfiles(
9300         int             error;
9301         xfs_inode_t     *qip;
9302  
9303 -       if (!capable(CAP_SYS_ADMIN))
9304 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9305                 return XFS_ERROR(EPERM);
9306         error = 0;
9307         if (!XFS_SB_VERSION_HASQUOTA(&mp->m_sb) || flags == 0) {
9308 @@ -420,7 +421,7 @@ xfs_qm_scall_quotaon(
9309         uint            accflags;
9310         __int64_t       sbflags;
9311  
9312 -       if (!capable(CAP_SYS_ADMIN))
9313 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9314                 return XFS_ERROR(EPERM);
9315  
9316         flags &= (XFS_ALL_QUOTA_ACCT | XFS_ALL_QUOTA_ENFD);
9317 @@ -589,7 +590,7 @@ xfs_qm_scall_setqlim(
9318         int                     error;
9319         xfs_qcnt_t              hard, soft;
9320  
9321 -       if (!capable(CAP_SYS_ADMIN))
9322 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9323                 return XFS_ERROR(EPERM);
9324  
9325         if ((newlim->d_fieldmask &
9326 diff -NurpP --minimal linux-2.6.24-rc7/fs/xfs/xfs_clnt.h linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/xfs_clnt.h
9327 --- linux-2.6.24-rc7/fs/xfs/xfs_clnt.h  2007-11-29 01:11:59 +0100
9328 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/xfs_clnt.h    2007-12-13 13:25:40 +0100
9329 @@ -100,5 +100,6 @@ struct xfs_mount_args {
9330                                                  * I/O size in stat(2) */
9331  #define XFSMNT2_FILESTREAMS    0x00000002      /* enable the filestreams
9332                                                  * allocator */
9333 +#define XFSMNT2_TAGGED         0x80000000      /* context tagging */
9334  
9335  #endif /* __XFS_CLNT_H__ */
9336 diff -NurpP --minimal linux-2.6.24-rc7/fs/xfs/xfs_dinode.h linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/xfs_dinode.h
9337 --- linux-2.6.24-rc7/fs/xfs/xfs_dinode.h        2007-11-29 01:11:59 +0100
9338 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/xfs_dinode.h  2008-01-04 17:20:17 +0100
9339 @@ -53,7 +53,9 @@ typedef struct xfs_dinode_core {
9340         __be32          di_gid;         /* owner's group id */
9341         __be32          di_nlink;       /* number of links to file */
9342         __be16          di_projid;      /* owner's project id */
9343 -       __u8            di_pad[8];      /* unused, zeroed space */
9344 +       __be16          di_tag;         /* context tagging */
9345 +       __be16          di_vflags;      /* vserver specific flags */
9346 +       __u8            di_pad[4];      /* unused, zeroed space */
9347         __be16          di_flushiter;   /* incremented on flush */
9348         xfs_timestamp_t di_atime;       /* time last accessed */
9349         xfs_timestamp_t di_mtime;       /* time last modified */
9350 @@ -257,6 +259,7 @@ typedef enum xfs_dinode_fmt
9351  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
9352  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
9353  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
9354 +
9355  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
9356  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
9357  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
9358 @@ -280,4 +283,7 @@ typedef enum xfs_dinode_fmt
9359          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
9360          XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
9361  
9362 +#define        XFS_DIVFLAG_BARRIER     0x01
9363 +#define        XFS_DIVFLAG_IUNLINK     0x02
9364 +
9365  #endif /* __XFS_DINODE_H__ */
9366 diff -NurpP --minimal linux-2.6.24-rc7/fs/xfs/xfs_fs.h linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/xfs_fs.h
9367 --- linux-2.6.24-rc7/fs/xfs/xfs_fs.h    2007-11-29 01:11:59 +0100
9368 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/xfs_fs.h      2008-01-04 17:19:51 +0100
9369 @@ -67,6 +67,8 @@ struct fsxattr {
9370  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
9371  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
9372  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
9373 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
9374 +#define XFS_XFLAG_IUNLINK      0x20000000      /* immutable unlink */
9375  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
9376  
9377  /*
9378 @@ -296,7 +298,8 @@ typedef struct xfs_bstat {
9379         __s32           bs_extents;     /* number of extents            */
9380         __u32           bs_gen;         /* generation count             */
9381         __u16           bs_projid;      /* project id                   */
9382 -       unsigned char   bs_pad[14];     /* pad space, unused            */
9383 +       __u16           bs_tag;         /* context tagging              */
9384 +       unsigned char   bs_pad[12];     /* pad space, unused            */
9385         __u32           bs_dmevmask;    /* DMIG event mask              */
9386         __u16           bs_dmstate;     /* DMIG state info              */
9387         __u16           bs_aextents;    /* attribute number of extents  */
9388 diff -NurpP --minimal linux-2.6.24-rc7/fs/xfs/xfs_inode.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/xfs_inode.c
9389 --- linux-2.6.24-rc7/fs/xfs/xfs_inode.c 2007-12-31 17:58:27 +0100
9390 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/xfs_inode.c   2008-01-04 17:33:16 +0100
9391 @@ -217,6 +217,7 @@ xfs_inotobp(
9392         return 0;
9393  }
9394  
9395 +#include <linux/vs_tag.h>
9396  
9397  /*
9398   * This routine is called to map an inode to the buffer containing
9399 @@ -781,7 +782,8 @@ xfs_dinode_to_disk(
9400  
9401  STATIC uint
9402  _xfs_dic2xflags(
9403 -       __uint16_t              di_flags)
9404 +       __uint16_t              di_flags,
9405 +       __uint16_t              di_vflags)
9406  {
9407         uint                    flags = 0;
9408  
9409 @@ -815,7 +817,10 @@ _xfs_dic2xflags(
9410                 if (di_flags & XFS_DIFLAG_FILESTREAM)
9411                         flags |= XFS_XFLAG_FILESTREAM;
9412         }
9413 -
9414 +       if (di_vflags & XFS_DIVFLAG_IUNLINK)
9415 +               flags |= XFS_XFLAG_IUNLINK;
9416 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
9417 +               flags |= XFS_XFLAG_BARRIER;
9418         return flags;
9419  }
9420  
9421 @@ -825,7 +830,7 @@ xfs_ip2xflags(
9422  {
9423         xfs_icdinode_t          *dic = &ip->i_d;
9424  
9425 -       return _xfs_dic2xflags(dic->di_flags) |
9426 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
9427                                 (XFS_CFORK_Q(dic) ? XFS_XFLAG_HASATTR : 0);
9428  }
9429  
9430 @@ -833,7 +838,7 @@ uint
9431  xfs_dic2xflags(
9432         xfs_dinode_core_t       *dic)
9433  {
9434 -       return _xfs_dic2xflags(be16_to_cpu(dic->di_flags)) |
9435 +       return _xfs_dic2xflags(be16_to_cpu(dic->di_flags), be16_to_cpu(dic->di_vflags)) |
9436                                 (XFS_CFORK_Q_DISK(dic) ? XFS_XFLAG_HASATTR : 0);
9437  }
9438  
9439 @@ -1134,6 +1139,7 @@ xfs_ialloc(
9440         ASSERT(ip->i_d.di_nlink == nlink);
9441         ip->i_d.di_uid = current_fsuid(cr);
9442         ip->i_d.di_gid = current_fsgid(cr);
9443 +       ip->i_d.di_tag = current_fstag(cr, vp);
9444         ip->i_d.di_projid = prid;
9445         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
9446  
9447 diff -NurpP --minimal linux-2.6.24-rc7/fs/xfs/xfs_inode.h linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/xfs_inode.h
9448 --- linux-2.6.24-rc7/fs/xfs/xfs_inode.h 2007-11-29 01:11:59 +0100
9449 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/xfs_inode.h   2008-01-04 17:27:01 +0100
9450 @@ -226,7 +226,9 @@ typedef struct xfs_icdinode {
9451         __uint32_t      di_gid;         /* owner's group id */
9452         __uint32_t      di_nlink;       /* number of links to file */
9453         __uint16_t      di_projid;      /* owner's project id */
9454 -       __uint8_t       di_pad[8];      /* unused, zeroed space */
9455 +       __uint16_t      di_tag;         /* context tagging */
9456 +       __uint16_t      di_vflags;      /* vserver specific flags */
9457 +       __uint8_t       di_pad[4];      /* unused, zeroed space */
9458         __uint16_t      di_flushiter;   /* incremented on flush */
9459         xfs_ictimestamp_t di_atime;     /* time last accessed */
9460         xfs_ictimestamp_t di_mtime;     /* time last modified */
9461 diff -NurpP --minimal linux-2.6.24-rc7/fs/xfs/xfs_itable.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/xfs_itable.c
9462 --- linux-2.6.24-rc7/fs/xfs/xfs_itable.c        2007-12-31 17:58:27 +0100
9463 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/xfs_itable.c  2007-12-31 12:34:41 +0100
9464 @@ -89,6 +89,7 @@ xfs_bulkstat_one_iget(
9465         buf->bs_mode = dic->di_mode;
9466         buf->bs_uid = dic->di_uid;
9467         buf->bs_gid = dic->di_gid;
9468 +       buf->bs_tag = dic->di_tag;
9469         buf->bs_size = dic->di_size;
9470         vn_atime_to_bstime(vp, &buf->bs_atime);
9471         buf->bs_mtime.tv_sec = dic->di_mtime.t_sec;
9472 diff -NurpP --minimal linux-2.6.24-rc7/fs/xfs/xfs_mount.h linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/xfs_mount.h
9473 --- linux-2.6.24-rc7/fs/xfs/xfs_mount.h 2007-11-29 01:11:59 +0100
9474 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/xfs_mount.h   2007-12-13 13:25:40 +0100
9475 @@ -480,6 +480,7 @@ typedef struct xfs_mount {
9476  #define XFS_MOUNT_FILESTREAMS  (1ULL << 24)    /* enable the filestreams
9477                                                    allocator */
9478  
9479 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
9480  
9481  /*
9482   * Default minimum read and write sizes.
9483 diff -NurpP --minimal linux-2.6.24-rc7/fs/xfs/xfs_vfsops.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/xfs_vfsops.c
9484 --- linux-2.6.24-rc7/fs/xfs/xfs_vfsops.c        2007-11-29 01:11:59 +0100
9485 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/xfs_vfsops.c  2008-01-04 17:39:18 +0100
9486 @@ -301,6 +301,8 @@ xfs_start_flags(
9487  
9488         if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
9489                 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
9490 +       if (ap->flags2 & XFSMNT2_TAGGED)
9491 +               mp->m_flags |= XFS_MOUNT_TAGGED;
9492  
9493         /*
9494          * no recovery flag requires a read-only mount
9495 @@ -415,6 +417,9 @@ xfs_finish_flags(
9496                         mp->m_qflags |= XFS_OQUOTA_ENFD;
9497         }
9498  
9499 +       if (ap->flags2 & XFSMNT2_TAGGED)
9500 +               mp->m_flags |= MS_TAGGED;
9501 +               /* vfs->vfs_super->s_flags |= */
9502         return 0;
9503  }
9504  
9505 @@ -1729,6 +1734,10 @@ xfs_vget(
9506  #define MNTOPT_XDSM    "xdsm"          /* DMI enabled (DMAPI / XDSM) */
9507  #define MNTOPT_DMI     "dmi"           /* DMI enabled (DMAPI / XDSM) */
9508  
9509 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
9510 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
9511 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
9512 +
9513  STATIC unsigned long
9514  suffix_strtoul(char *s, char **endp, unsigned int base)
9515  {
9516 @@ -1936,6 +1945,19 @@ xfs_parseargs(
9517                         args->flags |= XFSMNT_DMAPI;
9518                 } else if (!strcmp(this_char, MNTOPT_DMI)) {
9519                         args->flags |= XFSMNT_DMAPI;
9520 +#ifndef CONFIG_TAGGING_NONE
9521 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
9522 +                       args->flags2 |= XFSMNT2_TAGGED;
9523 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
9524 +                       args->flags2 &= ~XFSMNT2_TAGGED;
9525 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
9526 +                       args->flags2 |= XFSMNT2_TAGGED;
9527 +#endif
9528 +#ifdef CONFIG_PROPAGATE
9529 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
9530 +                       /* use value */
9531 +                       args->flags2 |= XFSMNT2_TAGGED;
9532 +#endif
9533                 } else if (!strcmp(this_char, "ihashsize")) {
9534                         cmn_err(CE_WARN,
9535         "XFS: ihashsize no longer used, option is deprecated.");
9536 diff -NurpP --minimal linux-2.6.24-rc7/fs/xfs/xfs_vnodeops.c linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/xfs_vnodeops.c
9537 --- linux-2.6.24-rc7/fs/xfs/xfs_vnodeops.c      2007-11-29 01:11:59 +0100
9538 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/fs/xfs/xfs_vnodeops.c        2008-01-04 17:17:40 +0100
9539 @@ -122,6 +122,7 @@ xfs_getattr(
9540         vap->va_mode = ip->i_d.di_mode;
9541         vap->va_uid = ip->i_d.di_uid;
9542         vap->va_gid = ip->i_d.di_gid;
9543 +       vap->va_tag = ip->i_d.di_tag;
9544         vap->va_projid = ip->i_d.di_projid;
9545  
9546         /*
9547 @@ -221,6 +222,7 @@ xfs_setattr(
9548         uint                    commit_flags=0;
9549         uid_t                   uid=0, iuid=0;
9550         gid_t                   gid=0, igid=0;
9551 +       tag_t                   tag=0, itag=0;
9552         int                     timeflags = 0;
9553         xfs_prid_t              projid=0, iprojid=0;
9554         int                     mandlock_before, mandlock_after;
9555 @@ -272,6 +274,7 @@ xfs_setattr(
9556             (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_PROJID))) {
9557                 uint    qflags = 0;
9558  
9559 +               /* TODO: handle tagging? */
9560                 if ((mask & XFS_AT_UID) && XFS_IS_UQUOTA_ON(mp)) {
9561                         uid = vap->va_uid;
9562                         qflags |= XFS_QMOPT_UQUOTA;
9563 @@ -351,6 +354,8 @@ xfs_setattr(
9564         if (mask &
9565             (XFS_AT_MODE|XFS_AT_XFLAGS|XFS_AT_EXTSIZE|XFS_AT_UID|
9566              XFS_AT_GID|XFS_AT_PROJID)) {
9567 +               /* TODO: handle tagging? */
9568 +
9569                 /*
9570                  * CAP_FOWNER overrides the following restrictions:
9571                  *
9572 @@ -399,7 +404,7 @@ xfs_setattr(
9573          * and can change the group id only to a group of which he
9574          * or she is a member.
9575          */
9576 -       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_PROJID)) {
9577 +       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_TAG|XFS_AT_PROJID)) {
9578                 /*
9579                  * These IDs could have changed since we last looked at them.
9580                  * But, we're assured that if the ownership did change
9581 @@ -407,10 +412,12 @@ xfs_setattr(
9582                  * would have changed also.
9583                  */
9584                 iuid = ip->i_d.di_uid;
9585 -               iprojid = ip->i_d.di_projid;
9586                 igid = ip->i_d.di_gid;
9587 -               gid = (mask & XFS_AT_GID) ? vap->va_gid : igid;
9588 +               itag = ip->i_d.di_tag;
9589 +               iprojid = ip->i_d.di_projid;
9590                 uid = (mask & XFS_AT_UID) ? vap->va_uid : iuid;
9591 +               gid = (mask & XFS_AT_GID) ? vap->va_gid : igid;
9592 +               tag = (mask & XFS_AT_TAG) ? vap->va_tag : itag;
9593                 projid = (mask & XFS_AT_PROJID) ? (xfs_prid_t)vap->va_projid :
9594                          iprojid;
9595  
9596 @@ -438,6 +445,7 @@ xfs_setattr(
9597                 if ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
9598                     (XFS_IS_PQUOTA_ON(mp) && iprojid != projid) ||
9599                     (XFS_IS_GQUOTA_ON(mp) && igid != gid)) {
9600 +                       /* TODO: handle tagging? */
9601                         ASSERT(tp);
9602                         code = XFS_QM_DQVOPCHOWNRESV(mp, tp, ip, udqp, gdqp,
9603                                                 capable(CAP_FOWNER) ?
9604 @@ -686,7 +694,7 @@ xfs_setattr(
9605          * and can change the group id only to a group of which he
9606          * or she is a member.
9607          */
9608 -       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_PROJID)) {
9609 +       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_TAG|XFS_AT_PROJID)) {
9610                 /*
9611                  * CAP_FSETID overrides the following restrictions:
9612                  *
9613 @@ -702,6 +710,9 @@ xfs_setattr(
9614                  * Change the ownerships and register quota modifications
9615                  * in the transaction.
9616                  */
9617 +               if (itag != tag) {
9618 +                       ip->i_d.di_tag = tag;
9619 +               }
9620                 if (iuid != uid) {
9621                         if (XFS_IS_UQUOTA_ON(mp)) {
9622                                 ASSERT(mask & XFS_AT_UID);
9623 @@ -777,6 +788,7 @@ xfs_setattr(
9624                 }
9625                 if (mask & XFS_AT_XFLAGS) {
9626                         uint    di_flags;
9627 +                       uint    di_vflags = 0;
9628  
9629                         /* can't set PREALLOC this way, just preserve it */
9630                         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
9631 @@ -814,6 +826,11 @@ xfs_setattr(
9632                                         di_flags |= XFS_DIFLAG_EXTSIZE;
9633                         }
9634                         ip->i_d.di_flags = di_flags;
9635 +                       if (vap->va_xflags & XFS_XFLAG_IUNLINK)
9636 +                               di_vflags |= XFS_DIVFLAG_IUNLINK;
9637 +                       if (vap->va_xflags & XFS_XFLAG_BARRIER)
9638 +                               di_vflags |= XFS_DIVFLAG_BARRIER;
9639 +                       ip->i_d.di_vflags = di_vflags;
9640                 }
9641                 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
9642                 timeflags |= XFS_ICHGTIME_CHG;
9643 diff -NurpP --minimal linux-2.6.24-rc7/include/asm-arm/tlb.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/asm-arm/tlb.h
9644 --- linux-2.6.24-rc7/include/asm-arm/tlb.h      2006-06-18 04:54:58 +0200
9645 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/asm-arm/tlb.h        2007-12-13 13:25:12 +0100
9646 @@ -28,6 +28,7 @@
9647  #else /* !CONFIG_MMU */
9648  
9649  #include <asm/pgalloc.h>
9650 +#include <linux/vs_memory.h>
9651  
9652  /*
9653   * TLB handling.  This allows us to remove pages from the page
9654 diff -NurpP --minimal linux-2.6.24-rc7/include/asm-blackfin/unistd.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/asm-blackfin/unistd.h
9655 --- linux-2.6.24-rc7/include/asm-blackfin/unistd.h      2007-11-29 01:02:07 +0100
9656 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/asm-blackfin/unistd.h        2007-12-15 02:23:02 +0100
9657 @@ -278,7 +278,7 @@
9658  #define __NR_tgkill            271
9659  #define __NR_utimes            272
9660  #define __NR_fadvise64_64      273
9661 -                               /* 274 __NR_vserver */
9662 +#define __NR_vserver           274
9663                                 /* 275 __NR_mbind */
9664                                 /* 276 __NR_get_mempolicy */
9665                                 /* 277 __NR_set_mempolicy */
9666 diff -NurpP --minimal linux-2.6.24-rc7/include/asm-generic/tlb.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/asm-generic/tlb.h
9667 --- linux-2.6.24-rc7/include/asm-generic/tlb.h  2008-01-11 12:00:49 +0100
9668 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/asm-generic/tlb.h    2008-01-11 04:30:09 +0100
9669 @@ -15,6 +15,7 @@
9670  
9671  #include <linux/swap.h>
9672  #include <linux/quicklist.h>
9673 +#include <linux/vs_memory.h>
9674  #include <asm/pgalloc.h>
9675  #include <asm/tlbflush.h>
9676  
9677 diff -NurpP --minimal linux-2.6.24-rc7/include/asm-ia64/tlb.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/asm-ia64/tlb.h
9678 --- linux-2.6.24-rc7/include/asm-ia64/tlb.h     2006-09-20 16:58:40 +0200
9679 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/asm-ia64/tlb.h       2007-12-13 13:25:12 +0100
9680 @@ -40,6 +40,7 @@
9681  #include <linux/mm.h>
9682  #include <linux/pagemap.h>
9683  #include <linux/swap.h>
9684 +#include <linux/vs_memory.h>
9685  
9686  #include <asm/pgalloc.h>
9687  #include <asm/processor.h>
9688 diff -NurpP --minimal linux-2.6.24-rc7/include/asm-powerpc/systbl.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/asm-powerpc/systbl.h
9689 --- linux-2.6.24-rc7/include/asm-powerpc/systbl.h       2007-11-29 01:12:13 +0100
9690 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/asm-powerpc/systbl.h 2007-12-13 13:25:28 +0100
9691 @@ -260,7 +260,7 @@ COMPAT_SYS_SPU(fstatfs64)
9692  SYSX(sys_ni_syscall, ppc_fadvise64_64, ppc_fadvise64_64)
9693  PPC_SYS_SPU(rtas)
9694  OLDSYS(debug_setcontext)
9695 -SYSCALL(ni_syscall)
9696 +SYSX(sys_vserver, sys32_vserver, sys_vserver)
9697  COMPAT_SYS(migrate_pages)
9698  COMPAT_SYS(mbind)
9699  COMPAT_SYS(get_mempolicy)
9700 diff -NurpP --minimal linux-2.6.24-rc7/include/asm-powerpc/unistd.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/asm-powerpc/unistd.h
9701 --- linux-2.6.24-rc7/include/asm-powerpc/unistd.h       2007-11-29 01:02:13 +0100
9702 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/asm-powerpc/unistd.h 2007-12-13 13:25:28 +0100
9703 @@ -275,7 +275,7 @@
9704  #endif
9705  #define __NR_rtas              255
9706  #define __NR_sys_debug_setcontext 256
9707 -/* Number 257 is reserved for vserver */
9708 +#define __NR_vserver           257
9709  #define __NR_migrate_pages     258
9710  #define __NR_mbind             259
9711  #define __NR_get_mempolicy     260
9712 diff -NurpP --minimal linux-2.6.24-rc7/include/asm-s390/unistd.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/asm-s390/unistd.h
9713 --- linux-2.6.24-rc7/include/asm-s390/unistd.h  2007-11-29 01:02:13 +0100
9714 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/asm-s390/unistd.h    2007-12-13 13:25:28 +0100
9715 @@ -202,7 +202,7 @@
9716  #define __NR_clock_gettime     (__NR_timer_create+6)
9717  #define __NR_clock_getres      (__NR_timer_create+7)
9718  #define __NR_clock_nanosleep   (__NR_timer_create+8)
9719 -/* Number 263 is reserved for vserver */
9720 +#define __NR_vserver           263
9721  #define __NR_statfs64          265
9722  #define __NR_fstatfs64         266
9723  #define __NR_remap_file_pages  267
9724 diff -NurpP --minimal linux-2.6.24-rc7/include/asm-sparc/unistd.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/asm-sparc/unistd.h
9725 --- linux-2.6.24-rc7/include/asm-sparc/unistd.h 2007-12-31 17:58:28 +0100
9726 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/asm-sparc/unistd.h   2007-12-31 12:34:42 +0100
9727 @@ -282,7 +282,7 @@
9728  #define __NR_timer_getoverrun  264
9729  #define __NR_timer_delete      265
9730  #define __NR_timer_create      266
9731 -/* #define __NR_vserver                267 Reserved for VSERVER */
9732 +#define __NR_vserver           267
9733  #define __NR_io_setup          268
9734  #define __NR_io_destroy                269
9735  #define __NR_io_submit         270
9736 diff -NurpP --minimal linux-2.6.24-rc7/include/asm-sparc64/tlb.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/asm-sparc64/tlb.h
9737 --- linux-2.6.24-rc7/include/asm-sparc64/tlb.h  2007-07-09 13:19:54 +0200
9738 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/asm-sparc64/tlb.h    2007-12-13 13:25:12 +0100
9739 @@ -3,6 +3,7 @@
9740  
9741  #include <linux/swap.h>
9742  #include <linux/pagemap.h>
9743 +#include <linux/vs_memory.h>
9744  #include <asm/pgalloc.h>
9745  #include <asm/tlbflush.h>
9746  #include <asm/mmu_context.h>
9747 diff -NurpP --minimal linux-2.6.24-rc7/include/asm-sparc64/unistd.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/asm-sparc64/unistd.h
9748 --- linux-2.6.24-rc7/include/asm-sparc64/unistd.h       2007-11-29 01:02:14 +0100
9749 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/asm-sparc64/unistd.h 2007-12-13 13:25:28 +0100
9750 @@ -284,7 +284,7 @@
9751  #define __NR_timer_getoverrun  264
9752  #define __NR_timer_delete      265
9753  #define __NR_timer_create      266
9754 -/* #define __NR_vserver                267 Reserved for VSERVER */
9755 +#define __NR_vserver           267
9756  #define __NR_io_setup          268
9757  #define __NR_io_destroy                269
9758  #define __NR_io_submit         270
9759 diff -NurpP --minimal linux-2.6.24-rc7/include/asm-x86/unistd_64.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/asm-x86/unistd_64.h
9760 --- linux-2.6.24-rc7/include/asm-x86/unistd_64.h        2007-11-29 01:12:18 +0100
9761 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/asm-x86/unistd_64.h  2007-12-15 02:12:26 +0100
9762 @@ -535,7 +535,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
9763  #define __NR_utimes                            235
9764  __SYSCALL(__NR_utimes, sys_utimes)
9765  #define __NR_vserver                           236
9766 -__SYSCALL(__NR_vserver, sys_ni_syscall)
9767 +__SYSCALL(__NR_vserver, sys_vserver)
9768  #define __NR_mbind                             237
9769  __SYSCALL(__NR_mbind, sys_mbind)
9770  #define __NR_set_mempolicy                     238
9771 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/Kbuild linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/Kbuild
9772 --- linux-2.6.24-rc7/include/linux/Kbuild       2008-01-11 12:00:49 +0100
9773 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/Kbuild 2008-01-11 04:30:10 +0100
9774 @@ -356,3 +356,6 @@ unifdef-y += xattr.h
9775  unifdef-y += xfrm.h
9776  
9777  objhdr-y += version.h
9778 +
9779 +header-y += vserver/
9780 +
9781 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/capability.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/capability.h
9782 --- linux-2.6.24-rc7/include/linux/capability.h 2007-11-29 01:12:23 +0100
9783 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/capability.h   2007-12-13 13:25:26 +0100
9784 @@ -252,6 +252,7 @@ typedef __u32 kernel_cap_t;
9785     arbitrary SCSI commands */
9786  /* Allow setting encryption key on loopback filesystem */
9787  /* Allow setting zone reclaim policy */
9788 +/* Allow the selection of a security context */
9789  
9790  #define CAP_SYS_ADMIN        21
9791  
9792 @@ -307,6 +308,11 @@ typedef __u32 kernel_cap_t;
9793  
9794  #define CAP_SETFCAP         31
9795  
9796 +/* Allow context manipulations */
9797 +/* Allow changing context info on files */
9798 +
9799 +#define CAP_CONTEXT         31
9800 +
9801  #ifdef __KERNEL__
9802  
9803  /*
9804 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/devpts_fs.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/devpts_fs.h
9805 --- linux-2.6.24-rc7/include/linux/devpts_fs.h  2004-08-14 12:55:59 +0200
9806 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/devpts_fs.h    2007-12-13 13:25:51 +0100
9807 @@ -30,5 +30,7 @@ static inline void devpts_pty_kill(int n
9808  
9809  #endif
9810  
9811 +#define DEVPTS_SUPER_MAGIC     0x00001cd1
9812 +
9813  
9814  #endif /* _LINUX_DEVPTS_FS_H */
9815 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/ext2_fs.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/ext2_fs.h
9816 --- linux-2.6.24-rc7/include/linux/ext2_fs.h    2007-12-31 17:58:28 +0100
9817 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/ext2_fs.h      2007-12-31 12:34:42 +0100
9818 @@ -189,6 +189,8 @@ struct ext2_group_desc
9819  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
9820  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
9821  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
9822 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
9823 +#define EXT2_IUNLINK_FL                        FS_IUNLINK_FL   /* Immutable unlink */
9824  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
9825  
9826  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
9827 @@ -247,7 +249,7 @@ struct ext2_inode {
9828                 struct {
9829                         __u8    l_i_frag;       /* Fragment number */
9830                         __u8    l_i_fsize;      /* Fragment size */
9831 -                       __u16   i_pad1;
9832 +                       __u16   l_i_tag;        /* Context Tag */
9833                         __le16  l_i_uid_high;   /* these 2 fields    */
9834                         __le16  l_i_gid_high;   /* were reserved2[0] */
9835                         __u32   l_i_reserved2;
9836 @@ -279,6 +281,7 @@ struct ext2_inode {
9837  #define i_gid_low      i_gid
9838  #define i_uid_high     osd2.linux2.l_i_uid_high
9839  #define i_gid_high     osd2.linux2.l_i_gid_high
9840 +#define i_raw_tag      osd2.linux2.l_i_tag
9841  #define i_reserved2    osd2.linux2.l_i_reserved2
9842  #endif
9843  
9844 @@ -323,6 +326,7 @@ struct ext2_inode {
9845  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
9846  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
9847  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
9848 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
9849  
9850  
9851  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
9852 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/ext3_fs.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/ext3_fs.h
9853 --- linux-2.6.24-rc7/include/linux/ext3_fs.h    2007-11-29 01:12:23 +0100
9854 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/ext3_fs.h      2007-12-13 13:25:40 +0100
9855 @@ -173,10 +173,20 @@ struct ext3_group_desc
9856  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
9857  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
9858  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
9859 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
9860 +#define EXT3_IUNLINK_FL                        0x08000000 /* Immutable unlink */
9861  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
9862  
9863 +#ifdef CONFIG_VSERVER_LEGACY
9864 +#define EXT3_FL_USER_VISIBLE           0x0803DFFF /* User visible flags */
9865 +#define EXT3_FL_USER_MODIFIABLE                0x080380FF /* User modifiable flags */
9866 +#else
9867  #define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
9868  #define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
9869 +#endif
9870 +#ifdef CONFIG_VSERVER_LEGACY
9871 +#define EXT3_IOC_SETTAG                        FIOC_SETTAGJ
9872 +#endif
9873  
9874  /*
9875   * Inode dynamic state flags
9876 @@ -292,7 +302,7 @@ struct ext3_inode {
9877                 struct {
9878                         __u8    l_i_frag;       /* Fragment number */
9879                         __u8    l_i_fsize;      /* Fragment size */
9880 -                       __u16   i_pad1;
9881 +                       __u16   l_i_tag;        /* Context Tag */
9882                         __le16  l_i_uid_high;   /* these 2 fields    */
9883                         __le16  l_i_gid_high;   /* were reserved2[0] */
9884                         __u32   l_i_reserved2;
9885 @@ -326,6 +336,7 @@ struct ext3_inode {
9886  #define i_gid_low      i_gid
9887  #define i_uid_high     osd2.linux2.l_i_uid_high
9888  #define i_gid_high     osd2.linux2.l_i_gid_high
9889 +#define i_raw_tag      osd2.linux2.l_i_tag
9890  #define i_reserved2    osd2.linux2.l_i_reserved2
9891  
9892  #elif defined(__GNU__)
9893 @@ -380,6 +391,7 @@ struct ext3_inode {
9894  #define EXT3_MOUNT_QUOTA               0x80000 /* Some quota option set */
9895  #define EXT3_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
9896  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
9897 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
9898  
9899  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
9900  #ifndef _LINUX_EXT2_FS_H
9901 @@ -822,6 +834,7 @@ struct buffer_head * ext3_bread (handle_
9902  int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
9903         sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result,
9904         int create, int extend_disksize);
9905 +extern int ext3_sync_flags(struct inode *inode);
9906  
9907  extern void ext3_read_inode (struct inode *);
9908  extern int  ext3_write_inode (struct inode *, int);
9909 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/ext4_fs.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/ext4_fs.h
9910 --- linux-2.6.24-rc7/include/linux/ext4_fs.h    2007-11-29 01:12:23 +0100
9911 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/ext4_fs.h      2007-12-13 13:25:40 +0100
9912 @@ -178,11 +178,21 @@ struct ext4_group_desc
9913  #define EXT4_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
9914  #define EXT4_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
9915  #define EXT4_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
9916 -#define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
9917  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
9918 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
9919 +#define EXT4_IUNLINK_FL                        0x08000000 /* Immutable unlink */
9920 +#define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
9921  
9922 +#ifdef CONFIG_VSERVER_LEGACY
9923 +#define EXT4_FL_USER_VISIBLE           0x080BDFFF /* User visible flags */
9924 +#define EXT4_FL_USER_MODIFIABLE                0x080380FF /* User modifiable flags */
9925 +#else
9926  #define EXT4_FL_USER_VISIBLE           0x000BDFFF /* User visible flags */
9927  #define EXT4_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
9928 +#endif
9929 +#ifdef CONFIG_VSERVER_LEGACY
9930 +#define EXT4_IOC_SETTAG                        FIOC_SETTAGJ
9931 +#endif
9932  
9933  /*
9934   * Inode dynamic state flags
9935 @@ -306,7 +316,8 @@ struct ext4_inode {
9936                         __le16  l_i_file_acl_high;
9937                         __le16  l_i_uid_high;   /* these 2 fields */
9938                         __le16  l_i_gid_high;   /* were reserved2[0] */
9939 -                       __u32   l_i_reserved2;
9940 +                       __u16   l_i_tag;        /* Context Tag */
9941 +                       __u16   l_i_reserved2;
9942                 } linux2;
9943                 struct {
9944                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
9945 @@ -409,6 +420,7 @@ do {                                                                               \
9946  #define i_gid_low      i_gid
9947  #define i_uid_high     osd2.linux2.l_i_uid_high
9948  #define i_gid_high     osd2.linux2.l_i_gid_high
9949 +#define i_raw_tag      osd2.linux2.l_i_tag
9950  #define i_reserved2    osd2.linux2.l_i_reserved2
9951  
9952  #elif defined(__GNU__)
9953 @@ -461,6 +473,7 @@ do {                                                                               \
9954  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
9955  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
9956  #define EXT4_MOUNT_EXTENTS             0x400000 /* Extents support */
9957 +#define EXT4_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
9958  
9959  /* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */
9960  #ifndef _LINUX_EXT2_FS_H
9961 @@ -920,6 +933,7 @@ struct buffer_head * ext4_bread (handle_
9962  int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,
9963         sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result,
9964         int create, int extend_disksize);
9965 +extern int ext4_sync_flags(struct inode *inode);
9966  
9967  extern void ext4_read_inode (struct inode *);
9968  extern int  ext4_write_inode (struct inode *, int);
9969 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/fs.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/fs.h
9970 --- linux-2.6.24-rc7/include/linux/fs.h 2007-11-29 01:12:23 +0100
9971 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/fs.h   2007-12-13 13:25:51 +0100
9972 @@ -124,6 +124,8 @@ extern int dir_notify_enable;
9973  #define MS_SHARED      (1<<20) /* change to shared */
9974  #define MS_RELATIME    (1<<21) /* Update atime relative to mtime/ctime. */
9975  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
9976 +#define MS_TAGGED      (1<<24) /* use generic inode tagging */
9977 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
9978  #define MS_ACTIVE      (1<<30)
9979  #define MS_NOUSER      (1<<31)
9980  
9981 @@ -150,6 +152,8 @@ extern int dir_notify_enable;
9982  #define S_NOCMTIME     128     /* Do not update file c/mtime */
9983  #define S_SWAPFILE     256     /* Do not truncate: swapon got its bmaps */
9984  #define S_PRIVATE      512     /* Inode is fs-internal */
9985 +#define S_BARRIER      1024    /* Barrier for chroot() */
9986 +#define S_IUNLINK      2048    /* Immutable unlink */
9987  
9988  /*
9989   * Note that nosuid etc flags are inode-specific: setting some file-system
9990 @@ -166,24 +170,36 @@ extern int dir_notify_enable;
9991   */
9992  #define __IS_FLG(inode,flg) ((inode)->i_sb->s_flags & (flg))
9993  
9994 -#define IS_RDONLY(inode) ((inode)->i_sb->s_flags & MS_RDONLY)
9995 +#define IS_RDONLY(inode)       __IS_FLG(inode, MS_RDONLY)
9996  #define IS_SYNC(inode)         (__IS_FLG(inode, MS_SYNCHRONOUS) || \
9997                                         ((inode)->i_flags & S_SYNC))
9998  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
9999                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
10000  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
10001 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
10002 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
10003 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
10004  
10005  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
10006  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
10007  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
10008 +#define IS_IUNLINK(inode)      ((inode)->i_flags & S_IUNLINK)
10009 +#define IS_IXORUNLINK(inode)   ((IS_IUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
10010  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
10011  
10012 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_flags & S_BARRIER))
10013  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
10014  #define IS_NOCMTIME(inode)     ((inode)->i_flags & S_NOCMTIME)
10015  #define IS_SWAPFILE(inode)     ((inode)->i_flags & S_SWAPFILE)
10016  #define IS_PRIVATE(inode)      ((inode)->i_flags & S_PRIVATE)
10017  
10018 +#ifdef CONFIG_VSERVER_COWBL
10019 +#  define IS_COW(inode)                (IS_IUNLINK(inode) && IS_IMMUTABLE(inode))
10020 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
10021 +#else
10022 +#  define IS_COW(inode)                (0)
10023 +#  define IS_COW_LINK(inode)   (0)
10024 +#endif
10025 +
10026  /* the read-only stuff doesn't really belong here, but any other place is
10027     probably as bad and I don't want to create yet another include file. */
10028  
10029 @@ -257,11 +273,17 @@ extern int dir_notify_enable;
10030  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
10031  #define FS_EXTENT_FL                   0x00080000 /* Extents */
10032  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
10033 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
10034 +#define FS_IUNLINK_FL                  0x08000000 /* Immutable unlink */
10035  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
10036  
10037 +#ifdef CONFIG_VSERVER_LEGACY
10038 +#define FS_FL_USER_VISIBLE             0x0803DFFF /* User visible flags */
10039 +#define FS_FL_USER_MODIFIABLE          0x080380FF /* User modifiable flags */
10040 +#else
10041  #define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
10042  #define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
10043 -
10044 +#endif
10045  
10046  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
10047  #define SYNC_FILE_RANGE_WRITE          2
10048 @@ -332,6 +354,7 @@ typedef void (dio_iodone_t)(struct kiocb
10049  #define ATTR_FILE      8192
10050  #define ATTR_KILL_PRIV 16384
10051  #define ATTR_OPEN      32768   /* Truncating from open(O_TRUNC) */
10052 +#define ATTR_TAG       65536
10053  
10054  /*
10055   * This is the Inode Attributes structure, used for notify_change().  It
10056 @@ -347,6 +370,7 @@ struct iattr {
10057         umode_t         ia_mode;
10058         uid_t           ia_uid;
10059         gid_t           ia_gid;
10060 +       tag_t           ia_tag;
10061         loff_t          ia_size;
10062         struct timespec ia_atime;
10063         struct timespec ia_mtime;
10064 @@ -360,6 +384,9 @@ struct iattr {
10065         struct file     *ia_file;
10066  };
10067  
10068 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
10069 +#define ATTR_FLAG_IUNLINK      1024    /* Immutable unlink */
10070 +
10071  /*
10072   * Includes for diskquotas.
10073   */
10074 @@ -598,6 +625,7 @@ struct inode {
10075         unsigned int            i_nlink;
10076         uid_t                   i_uid;
10077         gid_t                   i_gid;
10078 +       tag_t                   i_tag;
10079         dev_t                   i_rdev;
10080         unsigned long           i_version;
10081         loff_t                  i_size;
10082 @@ -793,6 +821,7 @@ struct file {
10083         loff_t                  f_pos;
10084         struct fown_struct      f_owner;
10085         unsigned int            f_uid, f_gid;
10086 +       xid_t                   f_xid;
10087         struct file_ra_state    f_ra;
10088  
10089         u64                     f_version;
10090 @@ -876,6 +905,7 @@ struct file_lock {
10091         unsigned char fl_type;
10092         loff_t fl_start;
10093         loff_t fl_end;
10094 +       xid_t fl_xid;
10095  
10096         struct fasync_struct *  fl_fasync; /* for lease break notifications */
10097         unsigned long fl_break_time;    /* for nonblocking lease breaks */
10098 @@ -1068,12 +1098,12 @@ extern void unlock_super(struct super_bl
10099   */
10100  extern int vfs_permission(struct nameidata *, int);
10101  extern int vfs_create(struct inode *, struct dentry *, int, struct nameidata *);
10102 -extern int vfs_mkdir(struct inode *, struct dentry *, int);
10103 -extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t);
10104 -extern int vfs_symlink(struct inode *, struct dentry *, const char *, int);
10105 -extern int vfs_link(struct dentry *, struct inode *, struct dentry *);
10106 -extern int vfs_rmdir(struct inode *, struct dentry *);
10107 -extern int vfs_unlink(struct inode *, struct dentry *);
10108 +extern int vfs_mkdir(struct inode *, struct dentry *, int, struct nameidata *);
10109 +extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t, struct nameidata *);
10110 +extern int vfs_symlink(struct inode *, struct dentry *, const char *, int, struct nameidata *);
10111 +extern int vfs_link(struct dentry *, struct inode *, struct dentry *, struct nameidata *);
10112 +extern int vfs_rmdir(struct inode *, struct dentry *, struct nameidata *);
10113 +extern int vfs_unlink(struct inode *, struct dentry *, struct nameidata *);
10114  extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
10115  
10116  /*
10117 @@ -1215,6 +1245,7 @@ struct inode_operations {
10118         void (*truncate_range)(struct inode *, loff_t, loff_t);
10119         long (*fallocate)(struct inode *inode, int mode, loff_t offset,
10120                           loff_t len);
10121 +       int (*sync_flags) (struct inode *);
10122  };
10123  
10124  struct seq_file;
10125 @@ -1230,6 +1261,7 @@ extern ssize_t vfs_readv(struct file *, 
10126                 unsigned long, loff_t *);
10127  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
10128                 unsigned long, loff_t *);
10129 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
10130  
10131  /*
10132   * NOTE: write_inode, delete_inode, clear_inode, put_inode can be called
10133 @@ -1937,6 +1969,7 @@ extern int dcache_dir_open(struct inode 
10134  extern int dcache_dir_close(struct inode *, struct file *);
10135  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
10136  extern int dcache_readdir(struct file *, void *, filldir_t);
10137 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
10138  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
10139  extern int simple_statfs(struct dentry *, struct kstatfs *);
10140  extern int simple_link(struct dentry *, struct inode *, struct dentry *);
10141 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/init_task.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/init_task.h
10142 --- linux-2.6.24-rc7/include/linux/init_task.h  2007-11-29 01:12:23 +0100
10143 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/init_task.h    2007-12-13 13:25:26 +0100
10144 @@ -173,6 +173,10 @@ extern struct group_info init_groups;
10145         .dirties = INIT_PROP_LOCAL_SINGLE(dirties),                     \
10146         INIT_TRACE_IRQFLAGS                                             \
10147         INIT_LOCKDEP                                                    \
10148 +       .xid            = 0,                                            \
10149 +       .vx_info        = NULL,                                         \
10150 +       .nid            = 0,                                            \
10151 +       .nx_info        = NULL,                                         \
10152  }
10153  
10154  
10155 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/interrupt.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/interrupt.h
10156 --- linux-2.6.24-rc7/include/linux/interrupt.h  2007-11-29 01:12:23 +0100
10157 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/interrupt.h    2007-12-18 00:54:39 +0100
10158 @@ -8,8 +8,8 @@
10159  #include <linux/preempt.h>
10160  #include <linux/cpumask.h>
10161  #include <linux/irqreturn.h>
10162 -#include <linux/hardirq.h>
10163  #include <linux/sched.h>
10164 +#include <linux/hardirq.h>
10165  #include <linux/irqflags.h>
10166  #include <asm/atomic.h>
10167  #include <asm/ptrace.h>
10168 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/ipc.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/ipc.h
10169 --- linux-2.6.24-rc7/include/linux/ipc.h        2007-11-29 01:12:23 +0100
10170 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/ipc.h  2007-12-13 13:25:48 +0100
10171 @@ -93,6 +93,7 @@ struct kern_ipc_perm
10172         key_t           key;
10173         uid_t           uid;
10174         gid_t           gid;
10175 +       xid_t           xid;
10176         uid_t           cuid;
10177         gid_t           cgid;
10178         mode_t          mode; 
10179 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/loop.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/loop.h
10180 --- linux-2.6.24-rc7/include/linux/loop.h       2007-11-29 01:02:17 +0100
10181 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/loop.h 2007-12-13 13:25:47 +0100
10182 @@ -45,6 +45,7 @@ struct loop_device {
10183         struct loop_func_table *lo_encryption;
10184         __u32           lo_init[2];
10185         uid_t           lo_key_owner;   /* Who set the key */
10186 +       xid_t           lo_xid;
10187         int             (*ioctl)(struct loop_device *, int cmd, 
10188                                  unsigned long arg); 
10189  
10190 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/major.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/major.h
10191 --- linux-2.6.24-rc7/include/linux/major.h      2007-11-29 01:02:17 +0100
10192 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/major.h        2007-12-13 13:25:46 +0100
10193 @@ -15,6 +15,7 @@
10194  #define HD_MAJOR               IDE0_MAJOR
10195  #define PTY_SLAVE_MAJOR                3
10196  #define TTY_MAJOR              4
10197 +#define VROOT_MAJOR            4
10198  #define TTYAUX_MAJOR           5
10199  #define LP_MAJOR               6
10200  #define VCS_MAJOR              7
10201 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/mm_types.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/mm_types.h
10202 --- linux-2.6.24-rc7/include/linux/mm_types.h   2007-11-29 01:12:24 +0100
10203 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/mm_types.h     2007-12-13 14:36:57 +0100
10204 @@ -198,6 +198,7 @@ struct mm_struct {
10205  
10206         /* Architecture-specific MM context */
10207         mm_context_t context;
10208 +       struct vx_info *mm_vx_info;
10209  
10210         /* Swap token stuff */
10211         /*
10212 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/mount.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/mount.h
10213 --- linux-2.6.24-rc7/include/linux/mount.h      2007-07-09 13:19:56 +0200
10214 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/mount.h        2007-12-13 13:25:47 +0100
10215 @@ -28,12 +28,16 @@ struct mnt_namespace;
10216  #define MNT_NOATIME    0x08
10217  #define MNT_NODIRATIME 0x10
10218  #define MNT_RELATIME   0x20
10219 +#define MNT_RDONLY     0x40
10220 +
10221 +#define MNT_IS_RDONLY(m)       ((m) && ((m)->mnt_flags & MNT_RDONLY))
10222  
10223  #define MNT_SHRINKABLE 0x100
10224  
10225  #define MNT_SHARED     0x1000  /* if the vfsmount is a shared mount */
10226  #define MNT_UNBINDABLE 0x2000  /* if the vfsmount is a unbindable mount */
10227  #define MNT_PNODE_MASK 0x3000  /* propagation flag mask */
10228 +#define MNT_TAGID      0x8000
10229  
10230  struct vfsmount {
10231         struct list_head mnt_hash;
10232 @@ -61,6 +65,7 @@ struct vfsmount {
10233         atomic_t mnt_count;
10234         int mnt_expiry_mark;            /* true if marked for expiry */
10235         int mnt_pinned;
10236 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
10237  };
10238  
10239  static inline struct vfsmount *mntget(struct vfsmount *mnt)
10240 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/net.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/net.h
10241 --- linux-2.6.24-rc7/include/linux/net.h        2007-11-29 01:12:24 +0100
10242 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/net.h  2007-12-13 13:25:30 +0100
10243 @@ -64,6 +64,7 @@ typedef enum {
10244  #define SOCK_NOSPACE           2
10245  #define SOCK_PASSCRED          3
10246  #define SOCK_PASSSEC           4
10247 +#define SOCK_USER_SOCKET       5
10248  
10249  #ifndef ARCH_HAS_SOCKET_TYPES
10250  /**
10251 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/nfs_mount.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/nfs_mount.h
10252 --- linux-2.6.24-rc7/include/linux/nfs_mount.h  2007-11-29 01:02:18 +0100
10253 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/nfs_mount.h    2007-12-13 13:25:51 +0100
10254 @@ -63,6 +63,7 @@ struct nfs_mount_data {
10255  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
10256  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
10257  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
10258 -#define NFS_MOUNT_FLAGMASK     0xFFFF
10259 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
10260 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
10261  
10262  #endif
10263 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/nsproxy.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/nsproxy.h
10264 --- linux-2.6.24-rc7/include/linux/nsproxy.h    2007-11-29 01:12:25 +0100
10265 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/nsproxy.h      2007-12-31 12:45:36 +0100
10266 @@ -3,6 +3,7 @@
10267  
10268  #include <linux/spinlock.h>
10269  #include <linux/sched.h>
10270 +#include <linux/vserver/debug.h>
10271  
10272  struct mnt_namespace;
10273  struct uts_namespace;
10274 @@ -63,22 +64,33 @@ static inline struct nsproxy *task_nspro
10275  }
10276  
10277  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
10278 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
10279  void exit_task_namespaces(struct task_struct *tsk);
10280  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
10281  void free_nsproxy(struct nsproxy *ns);
10282  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
10283         struct fs_struct *);
10284  
10285 -static inline void put_nsproxy(struct nsproxy *ns)
10286 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
10287 +
10288 +static inline void __get_nsproxy(struct nsproxy *ns,
10289 +       const char *_file, int _line)
10290  {
10291 -       if (atomic_dec_and_test(&ns->count)) {
10292 -               free_nsproxy(ns);
10293 -       }
10294 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
10295 +               ns, atomic_read(&ns->count), _file, _line);
10296 +       atomic_inc(&ns->count);
10297  }
10298  
10299 -static inline void get_nsproxy(struct nsproxy *ns)
10300 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
10301 +
10302 +static inline void __put_nsproxy(struct nsproxy *ns,
10303 +       const char *_file, int _line)
10304  {
10305 -       atomic_inc(&ns->count);
10306 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
10307 +               ns, atomic_read(&ns->count), _file, _line);
10308 +       if (atomic_dec_and_test(&ns->count)) {
10309 +               free_nsproxy(ns);
10310 +       }
10311  }
10312  
10313  #ifdef CONFIG_CGROUP_NS
10314 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/pid.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/pid.h
10315 --- linux-2.6.24-rc7/include/linux/pid.h        2007-11-29 01:12:25 +0100
10316 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/pid.h  2007-12-18 00:40:01 +0100
10317 @@ -8,7 +8,8 @@ enum pid_type
10318         PIDTYPE_PID,
10319         PIDTYPE_PGID,
10320         PIDTYPE_SID,
10321 -       PIDTYPE_MAX
10322 +       PIDTYPE_MAX,
10323 +       PIDTYPE_REALPID
10324  };
10325  
10326  /*
10327 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/proc_fs.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/proc_fs.h
10328 --- linux-2.6.24-rc7/include/linux/proc_fs.h    2007-12-31 17:58:28 +0100
10329 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/proc_fs.h      2007-12-31 12:34:43 +0100
10330 @@ -59,6 +59,7 @@ struct proc_dir_entry {
10331         nlink_t nlink;
10332         uid_t uid;
10333         gid_t gid;
10334 +       int vx_flags;
10335         loff_t size;
10336         const struct inode_operations *proc_iops;
10337         /*
10338 @@ -256,13 +257,20 @@ static inline void kclist_add(struct kco
10339  extern void kclist_add(struct kcore_list *, void *, size_t);
10340  #endif
10341  
10342 +struct vx_info;
10343 +struct nx_info;
10344 +
10345  union proc_op {
10346         int (*proc_get_link)(struct inode *, struct dentry **, struct vfsmount **);
10347         int (*proc_read)(struct task_struct *task, char *page);
10348 +       int (*proc_vs_read)(char *page);
10349 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
10350 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
10351  };
10352  
10353  struct proc_inode {
10354         struct pid *pid;
10355 +       int vx_flags;
10356         int fd;
10357         union proc_op op;
10358         struct proc_dir_entry *pde;
10359 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/reiserfs_fs.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/reiserfs_fs.h
10360 --- linux-2.6.24-rc7/include/linux/reiserfs_fs.h        2007-11-29 01:12:25 +0100
10361 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/reiserfs_fs.h  2007-12-13 13:25:40 +0100
10362 @@ -837,6 +837,10 @@ struct stat_data_v1 {
10363  #define REISERFS_COMPR_FL     FS_COMPR_FL
10364  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
10365  
10366 +/* unfortunately reiserfs sdattr is only 16 bit */
10367 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
10368 +#define REISERFS_IUNLINK_FL   (FS_IUNLINK_FL >> 16)
10369 +
10370  /* persistent flags that file inherits from the parent directory */
10371  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
10372                                 REISERFS_SYNC_FL |      \
10373 @@ -846,6 +850,14 @@ struct stat_data_v1 {
10374                                 REISERFS_COMPR_FL |     \
10375                                 REISERFS_NOTAIL_FL )
10376  
10377 +#ifdef CONFIG_VSERVER_LEGACY
10378 +#define REISERFS_FL_USER_VISIBLE       (REISERFS_IUNLINK_FL|0x80FF)
10379 +#define REISERFS_FL_USER_MODIFIABLE    (REISERFS_IUNLINK_FL|0x80FF)
10380 +#else
10381 +#define REISERFS_FL_USER_VISIBLE       0x80FF
10382 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
10383 +#endif
10384 +
10385  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
10386     address blocks) */
10387  struct stat_data {
10388 @@ -1911,6 +1923,7 @@ static inline void reiserfs_update_sd(st
10389  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
10390  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
10391  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
10392 +int reiserfs_sync_flags(struct inode *inode);
10393  
10394  /* namei.c */
10395  void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
10396 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/reiserfs_fs_sb.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/reiserfs_fs_sb.h
10397 --- linux-2.6.24-rc7/include/linux/reiserfs_fs_sb.h     2007-11-29 01:12:25 +0100
10398 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/reiserfs_fs_sb.h       2007-12-13 13:25:40 +0100
10399 @@ -456,6 +456,7 @@ enum reiserfs_mount_options {
10400         REISERFS_POSIXACL,
10401         REISERFS_BARRIER_NONE,
10402         REISERFS_BARRIER_FLUSH,
10403 +       REISERFS_TAGGED,
10404  
10405         /* Actions on error */
10406         REISERFS_ERROR_PANIC,
10407 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/sched.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/sched.h
10408 --- linux-2.6.24-rc7/include/linux/sched.h      2007-12-31 17:58:28 +0100
10409 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/sched.h        2007-12-31 12:34:43 +0100
10410 @@ -27,6 +27,7 @@
10411  #define CLONE_NEWUSER          0x10000000      /* New user namespace */
10412  #define CLONE_NEWPID           0x20000000      /* New pid namespace */
10413  #define CLONE_NEWNET           0x40000000      /* New network namespace */
10414 +#define CLONE_KTHREAD          0x80000000      /* clone a kernel thread */
10415  
10416  /*
10417   * Scheduling policies
10418 @@ -72,7 +73,6 @@ struct sched_param {
10419  #include <linux/fs_struct.h>
10420  #include <linux/compiler.h>
10421  #include <linux/completion.h>
10422 -#include <linux/pid.h>
10423  #include <linux/percpu.h>
10424  #include <linux/topology.h>
10425  #include <linux/proportions.h>
10426 @@ -88,6 +88,7 @@ struct sched_param {
10427  #include <linux/hrtimer.h>
10428  #include <linux/task_io_accounting.h>
10429  #include <linux/kobject.h>
10430 +#include <linux/pid.h>
10431  
10432  #include <asm/processor.h>
10433  
10434 @@ -99,7 +100,7 @@ struct bio;
10435   * List of flags we want to share for kernel threads,
10436   * if only because they are not used by them anyway.
10437   */
10438 -#define CLONE_KERNEL   (CLONE_FS | CLONE_FILES | CLONE_SIGHAND)
10439 +#define CLONE_KERNEL   (CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_KTHREAD)
10440  
10441  /*
10442   * These are the constant used to fake the fixed-point load-average
10443 @@ -320,25 +321,27 @@ extern void arch_unmap_area_topdown(stru
10444   * The mm counters are not protected by its page_table_lock,
10445   * so must be incremented atomically.
10446   */
10447 -#define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
10448 -#define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
10449 -#define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
10450 -#define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
10451 -#define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
10452 -
10453 +#define __set_mm_counter(mm, member, value) \
10454 +       atomic_long_set(&(mm)->_##member, value)
10455 +#define get_mm_counter(mm, member) \
10456 +       ((unsigned long)atomic_long_read(&(mm)->_##member))
10457  #else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
10458  /*
10459   * The mm counters are protected by its page_table_lock,
10460   * so can be incremented directly.
10461   */
10462 -#define set_mm_counter(mm, member, value) (mm)->_##member = (value)
10463 +#define __set_mm_counter(mm, member, value) (mm)->_##member = (value)
10464  #define get_mm_counter(mm, member) ((mm)->_##member)
10465 -#define add_mm_counter(mm, member, value) (mm)->_##member += (value)
10466 -#define inc_mm_counter(mm, member) (mm)->_##member++
10467 -#define dec_mm_counter(mm, member) (mm)->_##member--
10468  
10469  #endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
10470  
10471 +#define set_mm_counter(mm, member, value) \
10472 +       vx_ ## member ## pages_sub((mm), (get_mm_counter(mm, member) - value))
10473 +#define add_mm_counter(mm, member, value) \
10474 +       vx_ ## member ## pages_add((mm), (value))
10475 +#define inc_mm_counter(mm, member) vx_ ## member ## pages_inc((mm))
10476 +#define dec_mm_counter(mm, member) vx_ ## member ## pages_dec((mm))
10477 +
10478  #define get_mm_rss(mm)                                 \
10479         (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
10480  #define update_hiwater_rss(mm) do {                    \
10481 @@ -1071,6 +1074,14 @@ struct task_struct {
10482         void *security;
10483  #endif
10484         struct audit_context *audit_context;
10485 +
10486 +/* vserver context data */
10487 +       struct vx_info *vx_info;
10488 +       struct nx_info *nx_info;
10489 +
10490 +       xid_t xid;
10491 +       nid_t nid;
10492 +
10493         seccomp_t seccomp;
10494  
10495  /* Thread group tracking */
10496 @@ -1265,6 +1276,11 @@ struct pid_namespace;
10497   * see also pid_nr() etc in include/linux/pid.h
10498   */
10499  
10500 +#include <linux/vserver/base.h>
10501 +#include <linux/vserver/context.h>
10502 +#include <linux/vserver/debug.h>
10503 +#include <linux/vserver/pid.h>
10504 +
10505  static inline pid_t task_pid_nr(struct task_struct *tsk)
10506  {
10507         return tsk->pid;
10508 @@ -1274,7 +1290,7 @@ pid_t task_pid_nr_ns(struct task_struct 
10509  
10510  static inline pid_t task_pid_vnr(struct task_struct *tsk)
10511  {
10512 -       return pid_vnr(task_pid(tsk));
10513 +       return vx_map_pid(pid_vnr(task_pid(tsk)));
10514  }
10515  
10516  
10517 @@ -1287,7 +1303,7 @@ pid_t task_tgid_nr_ns(struct task_struct
10518  
10519  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
10520  {
10521 -       return pid_vnr(task_tgid(tsk));
10522 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
10523  }
10524  
10525  
10526 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/shmem_fs.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/shmem_fs.h
10527 --- linux-2.6.24-rc7/include/linux/shmem_fs.h   2006-11-30 21:19:39 +0100
10528 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/shmem_fs.h     2007-12-13 13:25:51 +0100
10529 @@ -8,6 +8,9 @@
10530  
10531  #define SHMEM_NR_DIRECT 16
10532  
10533 +#define TMPFS_SUPER_MAGIC      0x01021994
10534 +
10535 +
10536  struct shmem_inode_info {
10537         spinlock_t              lock;
10538         unsigned long           flags;
10539 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/stat.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/stat.h
10540 --- linux-2.6.24-rc7/include/linux/stat.h       2007-07-09 13:20:01 +0200
10541 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/stat.h 2007-12-13 13:25:41 +0100
10542 @@ -66,6 +66,7 @@ struct kstat {
10543         unsigned int    nlink;
10544         uid_t           uid;
10545         gid_t           gid;
10546 +       tag_t           tag;
10547         dev_t           rdev;
10548         loff_t          size;
10549         struct timespec  atime;
10550 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/sunrpc/auth.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/sunrpc/auth.h
10551 --- linux-2.6.24-rc7/include/linux/sunrpc/auth.h        2007-11-29 01:02:23 +0100
10552 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/sunrpc/auth.h  2007-12-13 13:25:51 +0100
10553 @@ -25,6 +25,7 @@
10554  struct auth_cred {
10555         uid_t   uid;
10556         gid_t   gid;
10557 +       tag_t   tag;
10558         struct group_info *group_info;
10559  };
10560  
10561 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/sunrpc/clnt.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/sunrpc/clnt.h
10562 --- linux-2.6.24-rc7/include/linux/sunrpc/clnt.h        2007-11-29 01:12:25 +0100
10563 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/sunrpc/clnt.h  2007-12-13 13:25:51 +0100
10564 @@ -43,7 +43,8 @@ struct rpc_clnt {
10565         unsigned int            cl_softrtry : 1,/* soft timeouts */
10566                                 cl_intr     : 1,/* interruptible */
10567                                 cl_discrtry : 1,/* disconnect before retry */
10568 -                               cl_autobind : 1;/* use getport() */
10569 +                               cl_autobind : 1,/* use getport() */
10570 +                               cl_tag      : 1;/* context tagging */
10571  
10572         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
10573  
10574 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/syscalls.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/syscalls.h
10575 --- linux-2.6.24-rc7/include/linux/syscalls.h   2007-11-29 01:02:23 +0100
10576 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/syscalls.h     2007-12-13 13:25:46 +0100
10577 @@ -294,6 +294,8 @@ asmlinkage long sys_symlink(const char _
10578  asmlinkage long sys_unlink(const char __user *pathname);
10579  asmlinkage long sys_rename(const char __user *oldname,
10580                                 const char __user *newname);
10581 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
10582 +                               umode_t mode);
10583  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
10584  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
10585  
10586 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/sysctl.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/sysctl.h
10587 --- linux-2.6.24-rc7/include/linux/sysctl.h     2007-12-31 17:58:28 +0100
10588 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/sysctl.h       2007-12-31 12:40:05 +0100
10589 @@ -70,6 +70,7 @@ enum
10590         CTL_ABI=9,              /* Binary emulation */
10591         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
10592         CTL_ARLAN=254,          /* arlan wireless driver */
10593 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
10594         CTL_S390DBF=5677,       /* s390 debug */
10595         CTL_SUNRPC=7249,        /* sunrpc debug */
10596         CTL_PM=9899,            /* frv power management */
10597 @@ -105,6 +106,7 @@ enum
10598         KERN_CAP_BSET=14,       /* int: capability bounding set */
10599         KERN_PANIC=15,          /* int: panic timeout */
10600         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
10601 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
10602  
10603         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
10604         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
10605 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/sysfs.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/sysfs.h
10606 --- linux-2.6.24-rc7/include/linux/sysfs.h      2007-11-29 01:12:25 +0100
10607 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/sysfs.h        2007-12-13 13:25:51 +0100
10608 @@ -17,6 +17,8 @@
10609  #include <linux/list.h>
10610  #include <asm/atomic.h>
10611  
10612 +#define SYSFS_SUPER_MAGIC      0x62656572
10613 +
10614  struct kobject;
10615  struct module;
10616  
10617 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/time.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/time.h
10618 --- linux-2.6.24-rc7/include/linux/time.h       2007-11-29 01:12:25 +0100
10619 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/time.h 2007-12-13 13:25:12 +0100
10620 @@ -178,6 +178,9 @@ static inline void timespec_add_ns(struc
10621         }
10622         a->tv_nsec = ns;
10623  }
10624 +
10625 +#include <linux/vs_time.h>
10626 +
10627  #endif /* __KERNEL__ */
10628  
10629  #define NFDBITS                        __NFDBITS
10630 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/types.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/types.h
10631 --- linux-2.6.24-rc7/include/linux/types.h      2007-11-29 01:12:25 +0100
10632 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/types.h        2007-12-13 13:25:26 +0100
10633 @@ -36,6 +36,9 @@ typedef __kernel_uid32_t      uid_t;
10634  typedef __kernel_gid32_t       gid_t;
10635  typedef __kernel_uid16_t        uid16_t;
10636  typedef __kernel_gid16_t        gid16_t;
10637 +typedef unsigned int           xid_t;
10638 +typedef unsigned int           nid_t;
10639 +typedef unsigned int           tag_t;
10640  
10641  typedef unsigned long          uintptr_t;
10642  
10643 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vroot.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vroot.h
10644 --- linux-2.6.24-rc7/include/linux/vroot.h      1970-01-01 01:00:00 +0100
10645 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vroot.h        2007-12-13 13:25:46 +0100
10646 @@ -0,0 +1,51 @@
10647 +
10648 +/*
10649 + * include/linux/vroot.h
10650 + *
10651 + * written by Herbert Pötzl, 9/11/2002
10652 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
10653 + *
10654 + * Copyright (C) 2002-2007 by Herbert Pötzl.
10655 + * Redistribution of this file is permitted under the
10656 + * GNU General Public License.
10657 + */
10658 +
10659 +#ifndef _LINUX_VROOT_H
10660 +#define _LINUX_VROOT_H
10661 +
10662 +
10663 +#ifdef __KERNEL__
10664 +
10665 +/* Possible states of device */
10666 +enum {
10667 +       Vr_unbound,
10668 +       Vr_bound,
10669 +};
10670 +
10671 +struct vroot_device {
10672 +       int             vr_number;
10673 +       int             vr_refcnt;
10674 +
10675 +       struct semaphore        vr_ctl_mutex;
10676 +       struct block_device    *vr_device;
10677 +       int                     vr_state;
10678 +};
10679 +
10680 +
10681 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
10682 +
10683 +extern int register_vroot_grb(vroot_grb_func *);
10684 +extern int unregister_vroot_grb(vroot_grb_func *);
10685 +
10686 +#endif /* __KERNEL__ */
10687 +
10688 +#define MAX_VROOT_DEFAULT      8
10689 +
10690 +/*
10691 + * IOCTL commands --- we will commandeer 0x56 ('V')
10692 + */
10693 +
10694 +#define VROOT_SET_DEV          0x5600
10695 +#define VROOT_CLR_DEV          0x5601
10696 +
10697 +#endif /* _LINUX_VROOT_H */
10698 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vs_base.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vs_base.h
10699 --- linux-2.6.24-rc7/include/linux/vs_base.h    1970-01-01 01:00:00 +0100
10700 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vs_base.h      2007-12-18 01:15:29 +0100
10701 @@ -0,0 +1,10 @@
10702 +#ifndef _VS_BASE_H
10703 +#define _VS_BASE_H
10704 +
10705 +#include "vserver/base.h"
10706 +#include "vserver/check.h"
10707 +#include "vserver/debug.h"
10708 +
10709 +#else
10710 +#warning duplicate inclusion
10711 +#endif
10712 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vs_context.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vs_context.h
10713 --- linux-2.6.24-rc7/include/linux/vs_context.h 1970-01-01 01:00:00 +0100
10714 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vs_context.h   2007-12-18 01:05:13 +0100
10715 @@ -0,0 +1,225 @@
10716 +#ifndef _VS_CONTEXT_H
10717 +#define _VS_CONTEXT_H
10718 +
10719 +#include "vserver/base.h"
10720 +#include "vserver/check.h"
10721 +#include "vserver/context.h"
10722 +#include "vserver/history.h"
10723 +#include "vserver/debug.h"
10724 +
10725 +
10726 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
10727 +
10728 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
10729 +       const char *_file, int _line, void *_here)
10730 +{
10731 +       if (!vxi)
10732 +               return NULL;
10733 +
10734 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
10735 +               vxi, vxi ? vxi->vx_id : 0,
10736 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
10737 +               _file, _line);
10738 +       __vxh_get_vx_info(vxi, _here);
10739 +
10740 +       atomic_inc(&vxi->vx_usecnt);
10741 +       return vxi;
10742 +}
10743 +
10744 +
10745 +extern void free_vx_info(struct vx_info *);
10746 +
10747 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
10748 +
10749 +static inline void __put_vx_info(struct vx_info *vxi,
10750 +       const char *_file, int _line, void *_here)
10751 +{
10752 +       if (!vxi)
10753 +               return;
10754 +
10755 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
10756 +               vxi, vxi ? vxi->vx_id : 0,
10757 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
10758 +               _file, _line);
10759 +       __vxh_put_vx_info(vxi, _here);
10760 +
10761 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
10762 +               free_vx_info(vxi);
10763 +}
10764 +
10765 +
10766 +#define init_vx_info(p, i) \
10767 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
10768 +
10769 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
10770 +       const char *_file, int _line, void *_here)
10771 +{
10772 +       if (vxi) {
10773 +               vxlprintk(VXD_CBIT(xid, 3),
10774 +                       "init_vx_info(%p[#%d.%d])",
10775 +                       vxi, vxi ? vxi->vx_id : 0,
10776 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
10777 +                       _file, _line);
10778 +               __vxh_init_vx_info(vxi, vxp, _here);
10779 +
10780 +               atomic_inc(&vxi->vx_usecnt);
10781 +       }
10782 +       *vxp = vxi;
10783 +}
10784 +
10785 +
10786 +#define set_vx_info(p, i) \
10787 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
10788 +
10789 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
10790 +       const char *_file, int _line, void *_here)
10791 +{
10792 +       struct vx_info *vxo;
10793 +
10794 +       if (!vxi)
10795 +               return;
10796 +
10797 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
10798 +               vxi, vxi ? vxi->vx_id : 0,
10799 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
10800 +               _file, _line);
10801 +       __vxh_set_vx_info(vxi, vxp, _here);
10802 +
10803 +       atomic_inc(&vxi->vx_usecnt);
10804 +       vxo = xchg(vxp, vxi);
10805 +       BUG_ON(vxo);
10806 +}
10807 +
10808 +
10809 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
10810 +
10811 +static inline void __clr_vx_info(struct vx_info **vxp,
10812 +       const char *_file, int _line, void *_here)
10813 +{
10814 +       struct vx_info *vxo;
10815 +
10816 +       vxo = xchg(vxp, NULL);
10817 +       if (!vxo)
10818 +               return;
10819 +
10820 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
10821 +               vxo, vxo ? vxo->vx_id : 0,
10822 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
10823 +               _file, _line);
10824 +       __vxh_clr_vx_info(vxo, vxp, _here);
10825 +
10826 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
10827 +               free_vx_info(vxo);
10828 +}
10829 +
10830 +
10831 +#define claim_vx_info(v, p) \
10832 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
10833 +
10834 +static inline void __claim_vx_info(struct vx_info *vxi,
10835 +       struct task_struct *task,
10836 +       const char *_file, int _line, void *_here)
10837 +{
10838 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
10839 +               vxi, vxi ? vxi->vx_id : 0,
10840 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
10841 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
10842 +               task, _file, _line);
10843 +       __vxh_claim_vx_info(vxi, task, _here);
10844 +
10845 +       atomic_inc(&vxi->vx_tasks);
10846 +}
10847 +
10848 +
10849 +extern void unhash_vx_info(struct vx_info *);
10850 +
10851 +#define release_vx_info(v, p) \
10852 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
10853 +
10854 +static inline void __release_vx_info(struct vx_info *vxi,
10855 +       struct task_struct *task,
10856 +       const char *_file, int _line, void *_here)
10857 +{
10858 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
10859 +               vxi, vxi ? vxi->vx_id : 0,
10860 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
10861 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
10862 +               task, _file, _line);
10863 +       __vxh_release_vx_info(vxi, task, _here);
10864 +
10865 +       might_sleep();
10866 +
10867 +       if (atomic_dec_and_test(&vxi->vx_tasks))
10868 +               unhash_vx_info(vxi);
10869 +}
10870 +
10871 +
10872 +#define task_get_vx_info(p) \
10873 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
10874 +
10875 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
10876 +       const char *_file, int _line, void *_here)
10877 +{
10878 +       struct vx_info *vxi;
10879 +
10880 +       task_lock(p);
10881 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
10882 +               p, _file, _line);
10883 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
10884 +       task_unlock(p);
10885 +       return vxi;
10886 +}
10887 +
10888 +
10889 +static inline void __wakeup_vx_info(struct vx_info *vxi)
10890 +{
10891 +       if (waitqueue_active(&vxi->vx_wait))
10892 +               wake_up_interruptible(&vxi->vx_wait);
10893 +}
10894 +
10895 +
10896 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
10897 +
10898 +static inline void __enter_vx_info(struct vx_info *vxi,
10899 +       struct vx_info_save *vxis, const char *_file, int _line)
10900 +{
10901 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
10902 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
10903 +               current->xid, current->vx_info, _file, _line);
10904 +       vxis->vxi = xchg(&current->vx_info, vxi);
10905 +       vxis->xid = current->xid;
10906 +       current->xid = vxi ? vxi->vx_id : 0;
10907 +}
10908 +
10909 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
10910 +
10911 +static inline void __leave_vx_info(struct vx_info_save *vxis,
10912 +       const char *_file, int _line)
10913 +{
10914 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
10915 +               vxis, vxis->xid, vxis->vxi, current,
10916 +               current->xid, current->vx_info, _file, _line);
10917 +       (void)xchg(&current->vx_info, vxis->vxi);
10918 +       current->xid = vxis->xid;
10919 +}
10920 +
10921 +
10922 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
10923 +{
10924 +       vxis->vxi = xchg(&current->vx_info, NULL);
10925 +       vxis->xid = xchg(&current->xid, (xid_t)0);
10926 +}
10927 +
10928 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
10929 +{
10930 +       (void)xchg(&current->xid, vxis->xid);
10931 +       (void)xchg(&current->vx_info, vxis->vxi);
10932 +}
10933 +
10934 +extern void exit_vx_info(struct task_struct *, int);
10935 +extern void exit_vx_info_early(struct task_struct *, int);
10936 +
10937 +
10938 +#else
10939 +#warning duplicate inclusion
10940 +#endif
10941 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vs_cowbl.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vs_cowbl.h
10942 --- linux-2.6.24-rc7/include/linux/vs_cowbl.h   1970-01-01 01:00:00 +0100
10943 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vs_cowbl.h     2007-12-13 13:25:25 +0100
10944 @@ -0,0 +1,44 @@
10945 +#ifndef _VS_COWBL_H
10946 +#define _VS_COWBL_H
10947 +
10948 +#include <linux/fs.h>
10949 +#include <linux/dcache.h>
10950 +#include <linux/namei.h>
10951 +
10952 +extern struct dentry *cow_break_link(const char *pathname);
10953 +
10954 +static inline int cow_check_and_break(struct nameidata *nd)
10955 +{
10956 +       struct inode *inode = nd->dentry->d_inode;
10957 +       int error = 0;
10958 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(nd->mnt))
10959 +               return -EROFS;
10960 +       if (IS_COW(inode)) {
10961 +               if (IS_COW_LINK(inode)) {
10962 +                       struct dentry *new_dentry, *old_dentry = nd->dentry;
10963 +                       char *path, *buf;
10964 +
10965 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
10966 +                       if (!buf) {
10967 +                               return -ENOMEM;
10968 +                       }
10969 +                       path = d_path(nd->dentry, nd->mnt, buf, PATH_MAX);
10970 +                       new_dentry = cow_break_link(path);
10971 +                       kfree(buf);
10972 +                       if (!IS_ERR(new_dentry)) {
10973 +                               nd->dentry = new_dentry;
10974 +                               dput(old_dentry);
10975 +                       } else
10976 +                               error = PTR_ERR(new_dentry);
10977 +               } else {
10978 +                       inode->i_flags &= ~(S_IUNLINK | S_IMMUTABLE);
10979 +                       inode->i_ctime = CURRENT_TIME;
10980 +                       mark_inode_dirty(inode);
10981 +               }
10982 +       }
10983 +       return error;
10984 +}
10985 +
10986 +#else
10987 +#warning duplicate inclusion
10988 +#endif
10989 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vs_cvirt.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vs_cvirt.h
10990 --- linux-2.6.24-rc7/include/linux/vs_cvirt.h   1970-01-01 01:00:00 +0100
10991 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vs_cvirt.h     2007-12-18 01:06:05 +0100
10992 @@ -0,0 +1,50 @@
10993 +#ifndef _VS_CVIRT_H
10994 +#define _VS_CVIRT_H
10995 +
10996 +#include "vserver/cvirt.h"
10997 +#include "vserver/context.h"
10998 +#include "vserver/base.h"
10999 +#include "vserver/check.h"
11000 +#include "vserver/debug.h"
11001 +
11002 +
11003 +static inline void vx_activate_task(struct task_struct *p)
11004 +{
11005 +       struct vx_info *vxi;
11006 +
11007 +       if ((vxi = p->vx_info)) {
11008 +               vx_update_load(vxi);
11009 +               atomic_inc(&vxi->cvirt.nr_running);
11010 +       }
11011 +}
11012 +
11013 +static inline void vx_deactivate_task(struct task_struct *p)
11014 +{
11015 +       struct vx_info *vxi;
11016 +
11017 +       if ((vxi = p->vx_info)) {
11018 +               vx_update_load(vxi);
11019 +               atomic_dec(&vxi->cvirt.nr_running);
11020 +       }
11021 +}
11022 +
11023 +static inline void vx_uninterruptible_inc(struct task_struct *p)
11024 +{
11025 +       struct vx_info *vxi;
11026 +
11027 +       if ((vxi = p->vx_info))
11028 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
11029 +}
11030 +
11031 +static inline void vx_uninterruptible_dec(struct task_struct *p)
11032 +{
11033 +       struct vx_info *vxi;
11034 +
11035 +       if ((vxi = p->vx_info))
11036 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
11037 +}
11038 +
11039 +
11040 +#else
11041 +#warning duplicate inclusion
11042 +#endif
11043 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vs_dlimit.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vs_dlimit.h
11044 --- linux-2.6.24-rc7/include/linux/vs_dlimit.h  1970-01-01 01:00:00 +0100
11045 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vs_dlimit.h    2007-12-13 13:25:25 +0100
11046 @@ -0,0 +1,209 @@
11047 +#ifndef _VS_DLIMIT_H
11048 +#define _VS_DLIMIT_H
11049 +
11050 +#include "vserver/dlimit.h"
11051 +#include "vserver/base.h"
11052 +#include "vserver/debug.h"
11053 +
11054 +
11055 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
11056 +
11057 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
11058 +       const char *_file, int _line)
11059 +{
11060 +       if (!dli)
11061 +               return NULL;
11062 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
11063 +               dli, dli ? dli->dl_tag : 0,
11064 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
11065 +               _file, _line);
11066 +       atomic_inc(&dli->dl_usecnt);
11067 +       return dli;
11068 +}
11069 +
11070 +
11071 +#define free_dl_info(i) \
11072 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
11073 +
11074 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
11075 +
11076 +static inline void __put_dl_info(struct dl_info *dli,
11077 +       const char *_file, int _line)
11078 +{
11079 +       if (!dli)
11080 +               return;
11081 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
11082 +               dli, dli ? dli->dl_tag : 0,
11083 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
11084 +               _file, _line);
11085 +       if (atomic_dec_and_test(&dli->dl_usecnt))
11086 +               free_dl_info(dli);
11087 +}
11088 +
11089 +
11090 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
11091 +
11092 +static inline int __dl_alloc_space(struct super_block *sb,
11093 +       tag_t tag, dlsize_t nr, const char *file, int line)
11094 +{
11095 +       struct dl_info *dli = NULL;
11096 +       int ret = 0;
11097 +
11098 +       if (nr == 0)
11099 +               goto out;
11100 +       dli = locate_dl_info(sb, tag);
11101 +       if (!dli)
11102 +               goto out;
11103 +
11104 +       spin_lock(&dli->dl_lock);
11105 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
11106 +       if (!ret)
11107 +               dli->dl_space_used += nr;
11108 +       spin_unlock(&dli->dl_lock);
11109 +       put_dl_info(dli);
11110 +out:
11111 +       vxlprintk(VXD_CBIT(dlim, 1),
11112 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
11113 +               sb, tag, __dlimit_char(dli), (long long)nr,
11114 +               ret, file, line);
11115 +       return ret;
11116 +}
11117 +
11118 +static inline void __dl_free_space(struct super_block *sb,
11119 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
11120 +{
11121 +       struct dl_info *dli = NULL;
11122 +
11123 +       if (nr == 0)
11124 +               goto out;
11125 +       dli = locate_dl_info(sb, tag);
11126 +       if (!dli)
11127 +               goto out;
11128 +
11129 +       spin_lock(&dli->dl_lock);
11130 +       if (dli->dl_space_used > nr)
11131 +               dli->dl_space_used -= nr;
11132 +       else
11133 +               dli->dl_space_used = 0;
11134 +       spin_unlock(&dli->dl_lock);
11135 +       put_dl_info(dli);
11136 +out:
11137 +       vxlprintk(VXD_CBIT(dlim, 1),
11138 +               "FREE  (%p,#%d)%c %lld bytes",
11139 +               sb, tag, __dlimit_char(dli), (long long)nr,
11140 +               _file, _line);
11141 +}
11142 +
11143 +static inline int __dl_alloc_inode(struct super_block *sb,
11144 +       tag_t tag, const char *_file, int _line)
11145 +{
11146 +       struct dl_info *dli;
11147 +       int ret = 0;
11148 +
11149 +       dli = locate_dl_info(sb, tag);
11150 +       if (!dli)
11151 +               goto out;
11152 +
11153 +       spin_lock(&dli->dl_lock);
11154 +       ret = (dli->dl_inodes_used >= dli->dl_inodes_total);
11155 +       if (!ret)
11156 +               dli->dl_inodes_used++;
11157 +       spin_unlock(&dli->dl_lock);
11158 +       put_dl_info(dli);
11159 +out:
11160 +       vxlprintk(VXD_CBIT(dlim, 0),
11161 +               "ALLOC (%p,#%d)%c inode (%d)",
11162 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
11163 +       return ret;
11164 +}
11165 +
11166 +static inline void __dl_free_inode(struct super_block *sb,
11167 +       tag_t tag, const char *_file, int _line)
11168 +{
11169 +       struct dl_info *dli;
11170 +
11171 +       dli = locate_dl_info(sb, tag);
11172 +       if (!dli)
11173 +               goto out;
11174 +
11175 +       spin_lock(&dli->dl_lock);
11176 +       if (dli->dl_inodes_used > 1)
11177 +               dli->dl_inodes_used--;
11178 +       else
11179 +               dli->dl_inodes_used = 0;
11180 +       spin_unlock(&dli->dl_lock);
11181 +       put_dl_info(dli);
11182 +out:
11183 +       vxlprintk(VXD_CBIT(dlim, 0),
11184 +               "FREE  (%p,#%d)%c inode",
11185 +               sb, tag, __dlimit_char(dli), _file, _line);
11186 +}
11187 +
11188 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
11189 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
11190 +       const char *_file, int _line)
11191 +{
11192 +       struct dl_info *dli;
11193 +       uint64_t broot, bfree;
11194 +
11195 +       dli = locate_dl_info(sb, tag);
11196 +       if (!dli)
11197 +               return;
11198 +
11199 +       spin_lock(&dli->dl_lock);
11200 +       broot = (dli->dl_space_total -
11201 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
11202 +               >> sb->s_blocksize_bits;
11203 +       bfree = (dli->dl_space_total - dli->dl_space_used)
11204 +                       >> sb->s_blocksize_bits;
11205 +       spin_unlock(&dli->dl_lock);
11206 +
11207 +       vxlprintk(VXD_CBIT(dlim, 2),
11208 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
11209 +               (long long)bfree, (long long)broot,
11210 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
11211 +               _file, _line);
11212 +       if (free_blocks) {
11213 +               if (*free_blocks > bfree)
11214 +                       *free_blocks = bfree;
11215 +       }
11216 +       if (root_blocks) {
11217 +               if (*root_blocks > broot)
11218 +                       *root_blocks = broot;
11219 +       }
11220 +       put_dl_info(dli);
11221 +}
11222 +
11223 +#define DLIMIT_ALLOC_SPACE(in, bytes) \
11224 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
11225 +               __FILE__, __LINE__ )
11226 +
11227 +#define DLIMIT_FREE_SPACE(in, bytes) \
11228 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
11229 +               __FILE__, __LINE__ )
11230 +
11231 +#define DLIMIT_ALLOC_BLOCK(in, nr) \
11232 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, \
11233 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
11234 +               __FILE__, __LINE__ )
11235 +
11236 +#define DLIMIT_FREE_BLOCK(in, nr) \
11237 +       __dl_free_space((in)->i_sb, (in)->i_tag, \
11238 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
11239 +               __FILE__, __LINE__ )
11240 +
11241 +
11242 +#define DLIMIT_ALLOC_INODE(in) \
11243 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
11244 +
11245 +#define DLIMIT_FREE_INODE(in) \
11246 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
11247 +
11248 +
11249 +#define DLIMIT_ADJUST_BLOCK(sb, tag, fb, rb) \
11250 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
11251 +
11252 +
11253 +#else
11254 +#warning duplicate inclusion
11255 +#endif
11256 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vs_limit.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vs_limit.h
11257 --- linux-2.6.24-rc7/include/linux/vs_limit.h   1970-01-01 01:00:00 +0100
11258 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vs_limit.h     2007-12-13 13:25:25 +0100
11259 @@ -0,0 +1,140 @@
11260 +#ifndef _VS_LIMIT_H
11261 +#define _VS_LIMIT_H
11262 +
11263 +#include "vserver/limit.h"
11264 +#include "vserver/base.h"
11265 +#include "vserver/context.h"
11266 +#include "vserver/debug.h"
11267 +#include "vserver/context.h"
11268 +#include "vserver/limit_int.h"
11269 +
11270 +
11271 +#define vx_acc_cres(v, d, p, r) \
11272 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
11273 +
11274 +#define vx_acc_cres_cond(x, d, p, r) \
11275 +       __vx_acc_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
11276 +       r, d, p, __FILE__, __LINE__)
11277 +
11278 +
11279 +#define vx_add_cres(v, a, p, r) \
11280 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
11281 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
11282 +
11283 +#define vx_add_cres_cond(x, a, p, r) \
11284 +       __vx_add_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
11285 +       r, a, p, __FILE__, __LINE__)
11286 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
11287 +
11288 +
11289 +/* process and file limits */
11290 +
11291 +#define vx_nproc_inc(p) \
11292 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
11293 +
11294 +#define vx_nproc_dec(p) \
11295 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
11296 +
11297 +#define vx_files_inc(f) \
11298 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
11299 +
11300 +#define vx_files_dec(f) \
11301 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
11302 +
11303 +#define vx_locks_inc(l) \
11304 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
11305 +
11306 +#define vx_locks_dec(l) \
11307 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
11308 +
11309 +#define vx_openfd_inc(f) \
11310 +       vx_acc_cres(current->vx_info, 1, (void *)(long)(f), VLIMIT_OPENFD)
11311 +
11312 +#define vx_openfd_dec(f) \
11313 +       vx_acc_cres(current->vx_info,-1, (void *)(long)(f), VLIMIT_OPENFD)
11314 +
11315 +
11316 +#define vx_cres_avail(v, n, r) \
11317 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
11318 +
11319 +
11320 +#define vx_nproc_avail(n) \
11321 +       vx_cres_avail(current->vx_info, n, RLIMIT_NPROC)
11322 +
11323 +#define vx_files_avail(n) \
11324 +       vx_cres_avail(current->vx_info, n, RLIMIT_NOFILE)
11325 +
11326 +#define vx_locks_avail(n) \
11327 +       vx_cres_avail(current->vx_info, n, RLIMIT_LOCKS)
11328 +
11329 +#define vx_openfd_avail(n) \
11330 +       vx_cres_avail(current->vx_info, n, VLIMIT_OPENFD)
11331 +
11332 +
11333 +/* dentry limits */
11334 +
11335 +#define vx_dentry_inc(d) do {                                          \
11336 +       if (atomic_read(&d->d_count) == 1)                              \
11337 +               vx_acc_cres(current->vx_info, 1, d, VLIMIT_DENTRY);     \
11338 +       } while (0)
11339 +
11340 +#define vx_dentry_dec(d) do {                                          \
11341 +       if (atomic_read(&d->d_count) == 0)                              \
11342 +               vx_acc_cres(current->vx_info,-1, d, VLIMIT_DENTRY);     \
11343 +       } while (0)
11344 +
11345 +#define vx_dentry_avail(n) \
11346 +       vx_cres_avail(current->vx_info, n, VLIMIT_DENTRY)
11347 +
11348 +
11349 +/* socket limits */
11350 +
11351 +#define vx_sock_inc(s) \
11352 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
11353 +
11354 +#define vx_sock_dec(s) \
11355 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
11356 +
11357 +#define vx_sock_avail(n) \
11358 +       vx_cres_avail(current->vx_info, n, VLIMIT_NSOCK)
11359 +
11360 +
11361 +/* ipc resource limits */
11362 +
11363 +#define vx_ipcmsg_add(v, u, a) \
11364 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
11365 +
11366 +#define vx_ipcmsg_sub(v, u, a) \
11367 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
11368 +
11369 +#define vx_ipcmsg_avail(v, a) \
11370 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
11371 +
11372 +
11373 +#define vx_ipcshm_add(v, k, a) \
11374 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
11375 +
11376 +#define vx_ipcshm_sub(v, k, a) \
11377 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
11378 +
11379 +#define vx_ipcshm_avail(v, a) \
11380 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
11381 +
11382 +
11383 +#define vx_semary_inc(a) \
11384 +       vx_acc_cres(current->vx_info, 1, a, VLIMIT_SEMARY)
11385 +
11386 +#define vx_semary_dec(a) \
11387 +       vx_acc_cres(current->vx_info, -1, a, VLIMIT_SEMARY)
11388 +
11389 +
11390 +#define vx_nsems_add(a,n) \
11391 +       vx_add_cres(current->vx_info, n, a, VLIMIT_NSEMS)
11392 +
11393 +#define vx_nsems_sub(a,n) \
11394 +       vx_sub_cres(current->vx_info, n, a, VLIMIT_NSEMS)
11395 +
11396 +
11397 +#else
11398 +#warning duplicate inclusion
11399 +#endif
11400 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vs_memory.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vs_memory.h
11401 --- linux-2.6.24-rc7/include/linux/vs_memory.h  1970-01-01 01:00:00 +0100
11402 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vs_memory.h    2007-12-13 13:25:25 +0100
11403 @@ -0,0 +1,159 @@
11404 +#ifndef _VS_MEMORY_H
11405 +#define _VS_MEMORY_H
11406 +
11407 +#include "vserver/limit.h"
11408 +#include "vserver/base.h"
11409 +#include "vserver/context.h"
11410 +#include "vserver/debug.h"
11411 +#include "vserver/context.h"
11412 +#include "vserver/limit_int.h"
11413 +
11414 +
11415 +#define __acc_add_long(a, v)   (*(v) += (a))
11416 +#define __acc_inc_long(v)      (++*(v))
11417 +#define __acc_dec_long(v)      (--*(v))
11418 +
11419 +#if    NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
11420 +#define __acc_add_atomic(a, v) atomic_long_add(a, v)
11421 +#define __acc_inc_atomic(v)    atomic_long_inc(v)
11422 +#define __acc_dec_atomic(v)    atomic_long_dec(v)
11423 +#else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
11424 +#define __acc_add_atomic(a, v) __acc_add_long(a, v)
11425 +#define __acc_inc_atomic(v)    __acc_inc_long(v)
11426 +#define __acc_dec_atomic(v)    __acc_dec_long(v)
11427 +#endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
11428 +
11429 +
11430 +#define vx_acc_page(m, d, v, r) do {                                   \
11431 +       if ((d) > 0)                                                    \
11432 +               __acc_inc_long(&(m)->v);                                \
11433 +       else                                                            \
11434 +               __acc_dec_long(&(m)->v);                                \
11435 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
11436 +} while (0)
11437 +
11438 +#define vx_acc_page_atomic(m, d, v, r) do {                            \
11439 +       if ((d) > 0)                                                    \
11440 +               __acc_inc_atomic(&(m)->v);                              \
11441 +       else                                                            \
11442 +               __acc_dec_atomic(&(m)->v);                              \
11443 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
11444 +} while (0)
11445 +
11446 +
11447 +#define vx_acc_pages(m, p, v, r) do {                                  \
11448 +       unsigned long __p = (p);                                        \
11449 +       __acc_add_long(__p, &(m)->v);                                   \
11450 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
11451 +} while (0)
11452 +
11453 +#define vx_acc_pages_atomic(m, p, v, r) do {                           \
11454 +       unsigned long __p = (p);                                        \
11455 +       __acc_add_atomic(__p, &(m)->v);                                 \
11456 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
11457 +} while (0)
11458 +
11459 +
11460 +
11461 +#define vx_acc_vmpage(m, d) \
11462 +       vx_acc_page(m, d, total_vm,  RLIMIT_AS)
11463 +#define vx_acc_vmlpage(m, d) \
11464 +       vx_acc_page(m, d, locked_vm, RLIMIT_MEMLOCK)
11465 +#define vx_acc_file_rsspage(m, d) \
11466 +       vx_acc_page_atomic(m, d, _file_rss, VLIMIT_MAPPED)
11467 +#define vx_acc_anon_rsspage(m, d) \
11468 +       vx_acc_page_atomic(m, d, _anon_rss, VLIMIT_ANON)
11469 +
11470 +#define vx_acc_vmpages(m, p) \
11471 +       vx_acc_pages(m, p, total_vm,  RLIMIT_AS)
11472 +#define vx_acc_vmlpages(m, p) \
11473 +       vx_acc_pages(m, p, locked_vm, RLIMIT_MEMLOCK)
11474 +#define vx_acc_file_rsspages(m, p) \
11475 +       vx_acc_pages_atomic(m, p, _file_rss, VLIMIT_MAPPED)
11476 +#define vx_acc_anon_rsspages(m, p) \
11477 +       vx_acc_pages_atomic(m, p, _anon_rss, VLIMIT_ANON)
11478 +
11479 +#define vx_pages_add(s, r, p)  __vx_add_cres(s, r, p, 0, __FILE__, __LINE__)
11480 +#define vx_pages_sub(s, r, p)  vx_pages_add(s, r, -(p))
11481 +
11482 +#define vx_vmpages_inc(m)              vx_acc_vmpage(m, 1)
11483 +#define vx_vmpages_dec(m)              vx_acc_vmpage(m, -1)
11484 +#define vx_vmpages_add(m, p)           vx_acc_vmpages(m, p)
11485 +#define vx_vmpages_sub(m, p)           vx_acc_vmpages(m, -(p))
11486 +
11487 +#define vx_vmlocked_inc(m)             vx_acc_vmlpage(m, 1)
11488 +#define vx_vmlocked_dec(m)             vx_acc_vmlpage(m, -1)
11489 +#define vx_vmlocked_add(m, p)          vx_acc_vmlpages(m, p)
11490 +#define vx_vmlocked_sub(m, p)          vx_acc_vmlpages(m, -(p))
11491 +
11492 +#define vx_file_rsspages_inc(m)                vx_acc_file_rsspage(m, 1)
11493 +#define vx_file_rsspages_dec(m)                vx_acc_file_rsspage(m, -1)
11494 +#define vx_file_rsspages_add(m, p)     vx_acc_file_rsspages(m, p)
11495 +#define vx_file_rsspages_sub(m, p)     vx_acc_file_rsspages(m, -(p))
11496 +
11497 +#define vx_anon_rsspages_inc(m)                vx_acc_anon_rsspage(m, 1)
11498 +#define vx_anon_rsspages_dec(m)                vx_acc_anon_rsspage(m, -1)
11499 +#define vx_anon_rsspages_add(m, p)     vx_acc_anon_rsspages(m, p)
11500 +#define vx_anon_rsspages_sub(m, p)     vx_acc_anon_rsspages(m, -(p))
11501 +
11502 +
11503 +#define vx_pages_avail(m, p, r) \
11504 +       __vx_cres_avail((m)->mm_vx_info, r, p, __FILE__, __LINE__)
11505 +
11506 +#define vx_vmpages_avail(m, p) vx_pages_avail(m, p, RLIMIT_AS)
11507 +#define vx_vmlocked_avail(m, p)        vx_pages_avail(m, p, RLIMIT_MEMLOCK)
11508 +#define vx_anon_avail(m, p)    vx_pages_avail(m, p, VLIMIT_ANON)
11509 +#define vx_mapped_avail(m, p)  vx_pages_avail(m, p, VLIMIT_MAPPED)
11510 +
11511 +#define vx_rss_avail(m, p) \
11512 +       __vx_cres_array_avail((m)->mm_vx_info, VLA_RSS, p, __FILE__, __LINE__)
11513 +
11514 +
11515 +enum {
11516 +       VXPT_UNKNOWN = 0,
11517 +       VXPT_ANON,
11518 +       VXPT_NONE,
11519 +       VXPT_FILE,
11520 +       VXPT_SWAP,
11521 +       VXPT_WRITE
11522 +};
11523 +
11524 +#if 0
11525 +#define        vx_page_fault(mm, vma, type, ret)
11526 +#else
11527 +
11528 +static inline
11529 +void __vx_page_fault(struct mm_struct *mm,
11530 +       struct vm_area_struct *vma, int type, int ret)
11531 +{
11532 +       struct vx_info *vxi = mm->mm_vx_info;
11533 +       int what;
11534 +/*
11535 +       static char *page_type[6] =
11536 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
11537 +       static char *page_what[4] =
11538 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
11539 +*/
11540 +
11541 +       if (!vxi)
11542 +               return;
11543 +
11544 +       what = (ret & 0x3);
11545 +
11546 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
11547 +               type, what, ret, page_type[type], page_what[what]);
11548 +*/
11549 +       if (ret & VM_FAULT_WRITE)
11550 +               what |= 0x4;
11551 +       atomic_inc(&vxi->cacct.page[type][what]);
11552 +}
11553 +
11554 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
11555 +#endif
11556 +
11557 +
11558 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
11559 +
11560 +#else
11561 +#warning duplicate inclusion
11562 +#endif
11563 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vs_network.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vs_network.h
11564 --- linux-2.6.24-rc7/include/linux/vs_network.h 1970-01-01 01:00:00 +0100
11565 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vs_network.h   2007-12-18 01:05:27 +0100
11566 @@ -0,0 +1,186 @@
11567 +#ifndef _NX_VS_NETWORK_H
11568 +#define _NX_VS_NETWORK_H
11569 +
11570 +#include "vserver/context.h"
11571 +#include "vserver/network.h"
11572 +#include "vserver/base.h"
11573 +#include "vserver/check.h"
11574 +#include "vserver/debug.h"
11575 +
11576 +
11577 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
11578 +
11579 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
11580 +       const char *_file, int _line)
11581 +{
11582 +       if (!nxi)
11583 +               return NULL;
11584 +
11585 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
11586 +               nxi, nxi ? nxi->nx_id : 0,
11587 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
11588 +               _file, _line);
11589 +
11590 +       atomic_inc(&nxi->nx_usecnt);
11591 +       return nxi;
11592 +}
11593 +
11594 +
11595 +extern void free_nx_info(struct nx_info *);
11596 +
11597 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
11598 +
11599 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
11600 +{
11601 +       if (!nxi)
11602 +               return;
11603 +
11604 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
11605 +               nxi, nxi ? nxi->nx_id : 0,
11606 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
11607 +               _file, _line);
11608 +
11609 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
11610 +               free_nx_info(nxi);
11611 +}
11612 +
11613 +
11614 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
11615 +
11616 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
11617 +               const char *_file, int _line)
11618 +{
11619 +       if (nxi) {
11620 +               vxlprintk(VXD_CBIT(nid, 3),
11621 +                       "init_nx_info(%p[#%d.%d])",
11622 +                       nxi, nxi ? nxi->nx_id : 0,
11623 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
11624 +                       _file, _line);
11625 +
11626 +               atomic_inc(&nxi->nx_usecnt);
11627 +       }
11628 +       *nxp = nxi;
11629 +}
11630 +
11631 +
11632 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
11633 +
11634 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
11635 +       const char *_file, int _line)
11636 +{
11637 +       struct nx_info *nxo;
11638 +
11639 +       if (!nxi)
11640 +               return;
11641 +
11642 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
11643 +               nxi, nxi ? nxi->nx_id : 0,
11644 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
11645 +               _file, _line);
11646 +
11647 +       atomic_inc(&nxi->nx_usecnt);
11648 +       nxo = xchg(nxp, nxi);
11649 +       BUG_ON(nxo);
11650 +}
11651 +
11652 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
11653 +
11654 +static inline void __clr_nx_info(struct nx_info **nxp,
11655 +       const char *_file, int _line)
11656 +{
11657 +       struct nx_info *nxo;
11658 +
11659 +       nxo = xchg(nxp, NULL);
11660 +       if (!nxo)
11661 +               return;
11662 +
11663 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
11664 +               nxo, nxo ? nxo->nx_id : 0,
11665 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
11666 +               _file, _line);
11667 +
11668 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
11669 +               free_nx_info(nxo);
11670 +}
11671 +
11672 +
11673 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
11674 +
11675 +static inline void __claim_nx_info(struct nx_info *nxi,
11676 +       struct task_struct *task, const char *_file, int _line)
11677 +{
11678 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
11679 +               nxi, nxi ? nxi->nx_id : 0,
11680 +               nxi?atomic_read(&nxi->nx_usecnt):0,
11681 +               nxi?atomic_read(&nxi->nx_tasks):0,
11682 +               task, _file, _line);
11683 +
11684 +       atomic_inc(&nxi->nx_tasks);
11685 +}
11686 +
11687 +
11688 +extern void unhash_nx_info(struct nx_info *);
11689 +
11690 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
11691 +
11692 +static inline void __release_nx_info(struct nx_info *nxi,
11693 +       struct task_struct *task, const char *_file, int _line)
11694 +{
11695 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
11696 +               nxi, nxi ? nxi->nx_id : 0,
11697 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
11698 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
11699 +               task, _file, _line);
11700 +
11701 +       might_sleep();
11702 +
11703 +       if (atomic_dec_and_test(&nxi->nx_tasks))
11704 +               unhash_nx_info(nxi);
11705 +}
11706 +
11707 +
11708 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
11709 +
11710 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
11711 +       const char *_file, int _line)
11712 +{
11713 +       struct nx_info *nxi;
11714 +
11715 +       task_lock(p);
11716 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
11717 +               p, _file, _line);
11718 +       nxi = __get_nx_info(p->nx_info, _file, _line);
11719 +       task_unlock(p);
11720 +       return nxi;
11721 +}
11722 +
11723 +
11724 +
11725 +
11726 +static inline int addr_in_nx_info(struct nx_info *nxi, uint32_t addr)
11727 +{
11728 +       int n, i;
11729 +
11730 +       if (!nxi)
11731 +               return 1;
11732 +
11733 +       n = nxi->nbipv4;
11734 +       if (n && (nxi->ipv4[0] == 0))
11735 +               return 1;
11736 +       for (i = 0; i < n; i++) {
11737 +               if (nxi->ipv4[i] == addr)
11738 +                       return 1;
11739 +       }
11740 +       return 0;
11741 +}
11742 +
11743 +static inline void exit_nx_info(struct task_struct *p)
11744 +{
11745 +       if (p->nx_info)
11746 +               release_nx_info(p->nx_info, p);
11747 +}
11748 +
11749 +
11750 +#else
11751 +#warning duplicate inclusion
11752 +#endif
11753 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vs_pid.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vs_pid.h
11754 --- linux-2.6.24-rc7/include/linux/vs_pid.h     1970-01-01 01:00:00 +0100
11755 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vs_pid.h       2007-12-18 01:10:20 +0100
11756 @@ -0,0 +1,95 @@
11757 +#ifndef _VS_PID_H
11758 +#define _VS_PID_H
11759 +
11760 +#include "vserver/base.h"
11761 +#include "vserver/check.h"
11762 +#include "vserver/context.h"
11763 +#include "vserver/debug.h"
11764 +#include "vserver/pid.h"
11765 +#include <linux/pid_namespace.h>
11766 +
11767 +
11768 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
11769 +
11770 +static inline
11771 +int vx_proc_task_visible(struct task_struct *task)
11772 +{
11773 +       if ((task->pid == 1) &&
11774 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
11775 +               /* show a blend through init */
11776 +               goto visible;
11777 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
11778 +               goto visible;
11779 +       return 0;
11780 +visible:
11781 +       return 1;
11782 +}
11783 +
11784 +#define find_task_by_real_pid find_task_by_pid
11785 +
11786 +#if 0
11787 +
11788 +static inline
11789 +struct task_struct *vx_find_proc_task_by_pid(int pid)
11790 +{
11791 +       struct task_struct *task = find_task_by_real_pid(pid);
11792 +
11793 +       if (task && !vx_proc_task_visible(task)) {
11794 +               vxdprintk(VXD_CBIT(misc, 6),
11795 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
11796 +                       task, task->xid, task->pid,
11797 +                       current, current->xid, current->pid);
11798 +               task = NULL;
11799 +       }
11800 +       return task;
11801 +}
11802 +
11803 +#endif
11804 +
11805 +static inline
11806 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
11807 +{
11808 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
11809 +
11810 +       if (task && !vx_proc_task_visible(task)) {
11811 +               vxdprintk(VXD_CBIT(misc, 6),
11812 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
11813 +                       task, task->xid, task->pid,
11814 +                       current, current->xid, current->pid);
11815 +               put_task_struct(task);
11816 +               task = NULL;
11817 +       }
11818 +       return task;
11819 +}
11820 +
11821 +#if 0
11822 +
11823 +static inline
11824 +struct task_struct *vx_child_reaper(struct task_struct *p)
11825 +{
11826 +       struct vx_info *vxi = p->vx_info;
11827 +       struct task_struct *reaper = child_reaper(p);
11828 +
11829 +       if (!vxi)
11830 +               goto out;
11831 +
11832 +       BUG_ON(!p->vx_info->vx_reaper);
11833 +
11834 +       /* child reaper for the guest reaper */
11835 +       if (vxi->vx_reaper == p)
11836 +               goto out;
11837 +
11838 +       reaper = vxi->vx_reaper;
11839 +out:
11840 +       vxdprintk(VXD_CBIT(xid, 7),
11841 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
11842 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
11843 +       return reaper;
11844 +}
11845 +
11846 +#endif
11847 +
11848 +
11849 +#else
11850 +#warning duplicate inclusion
11851 +#endif
11852 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vs_sched.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vs_sched.h
11853 --- linux-2.6.24-rc7/include/linux/vs_sched.h   1970-01-01 01:00:00 +0100
11854 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vs_sched.h     2007-12-13 13:25:25 +0100
11855 @@ -0,0 +1,110 @@
11856 +#ifndef _VS_SCHED_H
11857 +#define _VS_SCHED_H
11858 +
11859 +#include "vserver/base.h"
11860 +#include "vserver/context.h"
11861 +#include "vserver/sched.h"
11862 +
11863 +
11864 +#define VAVAVOOM_RATIO          50
11865 +
11866 +#define MAX_PRIO_BIAS           20
11867 +#define MIN_PRIO_BIAS          -20
11868 +
11869 +
11870 +#ifdef CONFIG_VSERVER_HARDCPU
11871 +
11872 +/*
11873 + * effective_prio - return the priority that is based on the static
11874 + * priority but is modified by bonuses/penalties.
11875 + *
11876 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
11877 + * into a -4 ... 0 ... +4 bonus/penalty range.
11878 + *
11879 + * Additionally, we scale another amount based on the number of
11880 + * CPU tokens currently held by the context, if the process is
11881 + * part of a context (and the appropriate SCHED flag is set).
11882 + * This ranges from -5 ... 0 ... +15, quadratically.
11883 + *
11884 + * So, the total bonus is -9 .. 0 .. +19
11885 + * We use ~50% of the full 0...39 priority range so that:
11886 + *
11887 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
11888 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
11889 + *    unless that context is far exceeding its CPU allocation.
11890 + *
11891 + * Both properties are important to certain workloads.
11892 + */
11893 +static inline
11894 +int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
11895 +{
11896 +       int vavavoom, max;
11897 +
11898 +       /* lots of tokens = lots of vavavoom
11899 +        *      no tokens = no vavavoom      */
11900 +       if ((vavavoom = sched_pc->tokens) >= 0) {
11901 +               max = sched_pc->tokens_max;
11902 +               vavavoom = max - vavavoom;
11903 +               max = max * max;
11904 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
11905 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
11906 +               return vavavoom;
11907 +       }
11908 +       return 0;
11909 +}
11910 +
11911 +
11912 +static inline
11913 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
11914 +{
11915 +       struct vx_info *vxi = p->vx_info;
11916 +       struct _vx_sched_pc *sched_pc;
11917 +
11918 +       if (!vxi)
11919 +               return prio;
11920 +
11921 +       sched_pc = &vx_cpu(vxi, sched_pc);
11922 +       if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
11923 +               int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
11924 +
11925 +               sched_pc->vavavoom = vavavoom;
11926 +               prio += vavavoom;
11927 +       }
11928 +       prio += sched_pc->prio_bias;
11929 +       return prio;
11930 +}
11931 +
11932 +#else /* !CONFIG_VSERVER_HARDCPU */
11933 +
11934 +static inline
11935 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
11936 +{
11937 +       struct vx_info *vxi = p->vx_info;
11938 +
11939 +       if (vxi)
11940 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
11941 +       return prio;
11942 +}
11943 +
11944 +#endif /* CONFIG_VSERVER_HARDCPU */
11945 +
11946 +
11947 +static inline void vx_account_user(struct vx_info *vxi,
11948 +       cputime_t cputime, int nice)
11949 +{
11950 +       if (!vxi)
11951 +               return;
11952 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
11953 +}
11954 +
11955 +static inline void vx_account_system(struct vx_info *vxi,
11956 +       cputime_t cputime, int idle)
11957 +{
11958 +       if (!vxi)
11959 +               return;
11960 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
11961 +}
11962 +
11963 +#else
11964 +#warning duplicate inclusion
11965 +#endif
11966 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vs_socket.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vs_socket.h
11967 --- linux-2.6.24-rc7/include/linux/vs_socket.h  1970-01-01 01:00:00 +0100
11968 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vs_socket.h    2007-12-13 13:25:25 +0100
11969 @@ -0,0 +1,67 @@
11970 +#ifndef _VS_SOCKET_H
11971 +#define _VS_SOCKET_H
11972 +
11973 +#include "vserver/debug.h"
11974 +#include "vserver/base.h"
11975 +#include "vserver/cacct.h"
11976 +#include "vserver/context.h"
11977 +
11978 +
11979 +/* socket accounting */
11980 +
11981 +#include <linux/socket.h>
11982 +
11983 +static inline int vx_sock_type(int family)
11984 +{
11985 +       switch (family) {
11986 +       case PF_UNSPEC:
11987 +               return VXA_SOCK_UNSPEC;
11988 +       case PF_UNIX:
11989 +               return VXA_SOCK_UNIX;
11990 +       case PF_INET:
11991 +               return VXA_SOCK_INET;
11992 +       case PF_INET6:
11993 +               return VXA_SOCK_INET6;
11994 +       case PF_PACKET:
11995 +               return VXA_SOCK_PACKET;
11996 +       default:
11997 +               return VXA_SOCK_OTHER;
11998 +       }
11999 +}
12000 +
12001 +#define vx_acc_sock(v, f, p, s) \
12002 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
12003 +
12004 +static inline void __vx_acc_sock(struct vx_info *vxi,
12005 +       int family, int pos, int size, char *file, int line)
12006 +{
12007 +       if (vxi) {
12008 +               int type = vx_sock_type(family);
12009 +
12010 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
12011 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
12012 +       }
12013 +}
12014 +
12015 +#define vx_sock_recv(sk, s) \
12016 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
12017 +#define vx_sock_send(sk, s) \
12018 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
12019 +#define vx_sock_fail(sk, s) \
12020 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
12021 +
12022 +
12023 +#define sock_vx_init(s) do {           \
12024 +       (s)->sk_xid = 0;                \
12025 +       (s)->sk_vx_info = NULL;         \
12026 +       } while (0)
12027 +
12028 +#define sock_nx_init(s) do {           \
12029 +       (s)->sk_nid = 0;                \
12030 +       (s)->sk_nx_info = NULL;         \
12031 +       } while (0)
12032 +
12033 +
12034 +#else
12035 +#warning duplicate inclusion
12036 +#endif
12037 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vs_tag.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vs_tag.h
12038 --- linux-2.6.24-rc7/include/linux/vs_tag.h     1970-01-01 01:00:00 +0100
12039 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vs_tag.h       2007-12-13 13:25:25 +0100
12040 @@ -0,0 +1,43 @@
12041 +#ifndef _VS_TAG_H
12042 +#define _VS_TAG_H
12043 +
12044 +#include <linux/vserver/tag.h>
12045 +
12046 +/* check conditions */
12047 +
12048 +#define DX_ADMIN       0x0001
12049 +#define DX_WATCH       0x0002
12050 +#define DX_HOSTID      0x0008
12051 +
12052 +#define DX_IDENT       0x0010
12053 +
12054 +#define DX_ARG_MASK    0x0010
12055 +
12056 +
12057 +#define dx_task_tag(t) ((t)->xid)
12058 +
12059 +#define dx_current_tag() dx_task_tag(current)
12060 +
12061 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
12062 +
12063 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
12064 +
12065 +
12066 +/*
12067 + * check current context for ADMIN/WATCH and
12068 + * optionally against supplied argument
12069 + */
12070 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
12071 +{
12072 +       if (mode & DX_ARG_MASK) {
12073 +               if ((mode & DX_IDENT) && (id == cid))
12074 +                       return 1;
12075 +       }
12076 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
12077 +               ((mode & DX_WATCH) && (cid == 1)) ||
12078 +               ((mode & DX_HOSTID) && (id == 0)));
12079 +}
12080 +
12081 +#else
12082 +#warning duplicate inclusion
12083 +#endif
12084 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vs_time.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vs_time.h
12085 --- linux-2.6.24-rc7/include/linux/vs_time.h    1970-01-01 01:00:00 +0100
12086 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vs_time.h      2007-12-13 13:25:25 +0100
12087 @@ -0,0 +1,19 @@
12088 +#ifndef _VS_TIME_H
12089 +#define _VS_TIME_H
12090 +
12091 +
12092 +/* time faking stuff */
12093 +
12094 +#ifdef CONFIG_VSERVER_VTIME
12095 +
12096 +extern void vx_gettimeofday(struct timeval *tv);
12097 +extern int vx_settimeofday(struct timespec *ts);
12098 +
12099 +#else
12100 +#define        vx_gettimeofday(t)      do_gettimeofday(t)
12101 +#define        vx_settimeofday(t)      do_settimeofday(t)
12102 +#endif
12103 +
12104 +#else
12105 +#warning duplicate inclusion
12106 +#endif
12107 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/Kbuild linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/Kbuild
12108 --- linux-2.6.24-rc7/include/linux/vserver/Kbuild       1970-01-01 01:00:00 +0100
12109 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/Kbuild 2007-12-13 13:25:26 +0100
12110 @@ -0,0 +1,9 @@
12111 +
12112 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
12113 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
12114 +       inode_cmd.h sched_cmd.h signal_cmd.h debug_cmd.h
12115 +
12116 +unifdef-y += switch.h network.h monitor.h inode.h
12117 +
12118 +unifdef-y += legacy.h
12119 +
12120 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/base.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/base.h
12121 --- linux-2.6.24-rc7/include/linux/vserver/base.h       1970-01-01 01:00:00 +0100
12122 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/base.h 2007-12-18 01:01:50 +0100
12123 @@ -0,0 +1,151 @@
12124 +#ifndef _VX_BASE_H
12125 +#define _VX_BASE_H
12126 +
12127 +
12128 +/* context state changes */
12129 +
12130 +enum {
12131 +       VSC_STARTUP = 1,
12132 +       VSC_SHUTDOWN,
12133 +
12134 +       VSC_NETUP,
12135 +       VSC_NETDOWN,
12136 +};
12137 +
12138 +
12139 +
12140 +#define vx_task_xid(t) ((t)->xid)
12141 +
12142 +#define vx_current_xid() vx_task_xid(current)
12143 +
12144 +#define current_vx_info() (current->vx_info)
12145 +
12146 +
12147 +#define nx_task_nid(t) ((t)->nid)
12148 +
12149 +#define nx_current_nid() nx_task_nid(current)
12150 +
12151 +#define current_nx_info() (current->nx_info)
12152 +
12153 +
12154 +/* generic flag merging */
12155 +
12156 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
12157 +
12158 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
12159 +
12160 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
12161 +
12162 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
12163 +
12164 +
12165 +/* context flags */
12166 +
12167 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
12168 +
12169 +#define vx_current_flags()     __vx_flags(current->vx_info)
12170 +
12171 +#define vx_info_flags(v, m, f) \
12172 +       vs_check_flags(__vx_flags(v), m, f)
12173 +
12174 +#define task_vx_flags(t, m, f) \
12175 +       ((t) && vx_info_flags((t)->vx_info, m, f))
12176 +
12177 +#define vx_flags(m, f) vx_info_flags(current->vx_info, m, f)
12178 +
12179 +
12180 +/* context caps */
12181 +
12182 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
12183 +
12184 +#define vx_current_ccaps()     __vx_ccaps(current->vx_info)
12185 +
12186 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
12187 +
12188 +#define vx_ccaps(c)    vx_info_ccaps(current->vx_info, (c))
12189 +
12190 +
12191 +
12192 +/* network flags */
12193 +
12194 +#define __nx_flags(v)  ((v) ? (v)->nx_flags : 0)
12195 +
12196 +#define nx_current_flags()     __nx_flags(current->nx_info)
12197 +
12198 +#define nx_info_flags(v, m, f) \
12199 +       vs_check_flags(__nx_flags(v), m, f)
12200 +
12201 +#define task_nx_flags(t, m, f) \
12202 +       ((t) && nx_info_flags((t)->nx_info, m, f))
12203 +
12204 +#define nx_flags(m, f) nx_info_flags(current->nx_info, m, f)
12205 +
12206 +
12207 +/* network caps */
12208 +
12209 +#define __nx_ncaps(v)  ((v) ? (v)->nx_ncaps : 0)
12210 +
12211 +#define nx_current_ncaps()     __nx_ncaps(current->nx_info)
12212 +
12213 +#define nx_info_ncaps(v, c)    (__nx_ncaps(v) & (c))
12214 +
12215 +#define nx_ncaps(c)    nx_info_ncaps(current->nx_info, c)
12216 +
12217 +
12218 +/* context mask capabilities */
12219 +
12220 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
12221 +
12222 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
12223 +
12224 +#define vx_mcaps(c)    vx_info_mcaps(current->vx_info, c)
12225 +
12226 +
12227 +/* context bcap mask */
12228 +
12229 +#define __vx_bcaps(v)  ((v) ? (v)->vx_bcaps : ~0 )
12230 +
12231 +#define vx_current_bcaps()     __vx_bcaps(current->vx_info)
12232 +
12233 +#define vx_info_bcaps(v, c)    (__vx_bcaps(v) & (c))
12234 +
12235 +#define vx_bcaps(c)    vx_info_bcaps(current->vx_info, c)
12236 +
12237 +
12238 +#define vx_info_cap_bset(v)    ((v) ? (v)->vx_cap_bset : cap_bset)
12239 +
12240 +#define vx_current_cap_bset()  vx_info_cap_bset(current->vx_info)
12241 +
12242 +
12243 +#define __vx_info_mbcap(v, b) \
12244 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
12245 +       vx_info_bcaps(v, b) : (b))
12246 +
12247 +#define vx_info_mbcap(v, b)    __vx_info_mbcap(v, cap_t(b))
12248 +
12249 +#define task_vx_mbcap(t, b) \
12250 +       vx_info_mbcap((t)->vx_info, (t)->b)
12251 +
12252 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
12253 +
12254 +#define vx_cap_raised(v, c, f) (vx_info_mbcap(v, c) & CAP_TO_MASK(f))
12255 +
12256 +#define vx_capable(b, c) (capable(b) || \
12257 +       (cap_raised(current->cap_effective, b) && vx_ccaps(c)))
12258 +
12259 +
12260 +#define vx_current_initpid(n) \
12261 +       (current->vx_info && \
12262 +       (current->vx_info->vx_initpid == (n)))
12263 +
12264 +
12265 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
12266 +
12267 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
12268 +
12269 +
12270 +#define __nx_state(v)  ((v) ? ((v)->nx_state) : 0)
12271 +
12272 +#define nx_info_state(v, m)    (__nx_state(v) & (m))
12273 +
12274 +#endif
12275 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/cacct.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/cacct.h
12276 --- linux-2.6.24-rc7/include/linux/vserver/cacct.h      1970-01-01 01:00:00 +0100
12277 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/cacct.h        2007-12-13 13:25:37 +0100
12278 @@ -0,0 +1,15 @@
12279 +#ifndef _VX_CACCT_H
12280 +#define _VX_CACCT_H
12281 +
12282 +
12283 +enum sock_acc_field {
12284 +       VXA_SOCK_UNSPEC = 0,
12285 +       VXA_SOCK_UNIX,
12286 +       VXA_SOCK_INET,
12287 +       VXA_SOCK_INET6,
12288 +       VXA_SOCK_PACKET,
12289 +       VXA_SOCK_OTHER,
12290 +       VXA_SOCK_SIZE   /* array size */
12291 +};
12292 +
12293 +#endif /* _VX_CACCT_H */
12294 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/cacct_cmd.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/cacct_cmd.h
12295 --- linux-2.6.24-rc7/include/linux/vserver/cacct_cmd.h  1970-01-01 01:00:00 +0100
12296 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/cacct_cmd.h    2007-12-13 13:25:43 +0100
12297 @@ -0,0 +1,23 @@
12298 +#ifndef _VX_CACCT_CMD_H
12299 +#define _VX_CACCT_CMD_H
12300 +
12301 +
12302 +/* virtual host info name commands */
12303 +
12304 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
12305 +
12306 +struct vcmd_sock_stat_v0 {
12307 +       uint32_t field;
12308 +       uint32_t count[3];
12309 +       uint64_t total[3];
12310 +};
12311 +
12312 +
12313 +#ifdef __KERNEL__
12314 +
12315 +#include <linux/compiler.h>
12316 +
12317 +extern int vc_sock_stat(struct vx_info *, void __user *);
12318 +
12319 +#endif /* __KERNEL__ */
12320 +#endif /* _VX_CACCT_CMD_H */
12321 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/cacct_def.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/cacct_def.h
12322 --- linux-2.6.24-rc7/include/linux/vserver/cacct_def.h  1970-01-01 01:00:00 +0100
12323 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/cacct_def.h    2007-12-13 13:25:43 +0100
12324 @@ -0,0 +1,43 @@
12325 +#ifndef _VX_CACCT_DEF_H
12326 +#define _VX_CACCT_DEF_H
12327 +
12328 +#include <asm/atomic.h>
12329 +#include <linux/vserver/cacct.h>
12330 +
12331 +
12332 +struct _vx_sock_acc {
12333 +       atomic_long_t count;
12334 +       atomic_long_t total;
12335 +};
12336 +
12337 +/* context sub struct */
12338 +
12339 +struct _vx_cacct {
12340 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
12341 +       atomic_t slab[8];
12342 +       atomic_t page[6][8];
12343 +};
12344 +
12345 +#ifdef CONFIG_VSERVER_DEBUG
12346 +
12347 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
12348 +{
12349 +       int i, j;
12350 +
12351 +       printk("\t_vx_cacct:");
12352 +       for (i = 0; i < 6; i++) {
12353 +               struct _vx_sock_acc *ptr = cacct->sock[i];
12354 +
12355 +               printk("\t [%d] =", i);
12356 +               for (j = 0; j < 3; j++) {
12357 +                       printk(" [%d] = %8lu, %8lu", j,
12358 +                               atomic_long_read(&ptr[j].count),
12359 +                               atomic_long_read(&ptr[j].total));
12360 +               }
12361 +               printk("\n");
12362 +       }
12363 +}
12364 +
12365 +#endif
12366 +
12367 +#endif /* _VX_CACCT_DEF_H */
12368 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/cacct_int.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/cacct_int.h
12369 --- linux-2.6.24-rc7/include/linux/vserver/cacct_int.h  1970-01-01 01:00:00 +0100
12370 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/cacct_int.h    2007-12-13 13:25:37 +0100
12371 @@ -0,0 +1,21 @@
12372 +#ifndef _VX_CACCT_INT_H
12373 +#define _VX_CACCT_INT_H
12374 +
12375 +
12376 +#ifdef __KERNEL__
12377 +
12378 +static inline
12379 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
12380 +{
12381 +       return atomic_long_read(&cacct->sock[type][pos].count);
12382 +}
12383 +
12384 +
12385 +static inline
12386 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
12387 +{
12388 +       return atomic_long_read(&cacct->sock[type][pos].total);
12389 +}
12390 +
12391 +#endif /* __KERNEL__ */
12392 +#endif /* _VX_CACCT_INT_H */
12393 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/check.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/check.h
12394 --- linux-2.6.24-rc7/include/linux/vserver/check.h      1970-01-01 01:00:00 +0100
12395 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/check.h        2007-12-18 01:02:45 +0100
12396 @@ -0,0 +1,89 @@
12397 +#ifndef _VS_CHECK_H
12398 +#define _VS_CHECK_H
12399 +
12400 +
12401 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
12402 +
12403 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
12404 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
12405 +#else
12406 +#define MIN_D_CONTEXT  65536
12407 +#endif
12408 +
12409 +/* check conditions */
12410 +
12411 +#define VS_ADMIN       0x0001
12412 +#define VS_WATCH       0x0002
12413 +#define VS_HIDE                0x0004
12414 +#define VS_HOSTID      0x0008
12415 +
12416 +#define VS_IDENT       0x0010
12417 +#define VS_EQUIV       0x0020
12418 +#define VS_PARENT      0x0040
12419 +#define VS_CHILD       0x0080
12420 +
12421 +#define VS_ARG_MASK    0x00F0
12422 +
12423 +#define VS_DYNAMIC     0x0100
12424 +#define VS_STATIC      0x0200
12425 +
12426 +#define VS_ATR_MASK    0x0F00
12427 +
12428 +#ifdef CONFIG_VSERVER_PRIVACY
12429 +#define VS_ADMIN_P     (0)
12430 +#define VS_WATCH_P     (0)
12431 +#else
12432 +#define VS_ADMIN_P     VS_ADMIN
12433 +#define VS_WATCH_P     VS_WATCH
12434 +#endif
12435 +
12436 +#define VS_HARDIRQ     0x1000
12437 +#define VS_SOFTIRQ     0x2000
12438 +#define VS_IRQ         0x4000
12439 +
12440 +#define VS_IRQ_MASK    0xF000
12441 +
12442 +#include <linux/hardirq.h>
12443 +
12444 +/*
12445 + * check current context for ADMIN/WATCH and
12446 + * optionally against supplied argument
12447 + */
12448 +static inline int __vs_check(int cid, int id, unsigned int mode)
12449 +{
12450 +       if (mode & VS_ARG_MASK) {
12451 +               if ((mode & VS_IDENT) && (id == cid))
12452 +                       return 1;
12453 +       }
12454 +       if (mode & VS_ATR_MASK) {
12455 +               if ((mode & VS_DYNAMIC) &&
12456 +                       (id >= MIN_D_CONTEXT) &&
12457 +                       (id <= MAX_S_CONTEXT))
12458 +                       return 1;
12459 +               if ((mode & VS_STATIC) &&
12460 +                       (id > 1) && (id < MIN_D_CONTEXT))
12461 +                       return 1;
12462 +       }
12463 +       if (mode & VS_IRQ_MASK) {
12464 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
12465 +                       return 1;
12466 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
12467 +                       return 1;
12468 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
12469 +                       return 1;
12470 +       }
12471 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
12472 +               ((mode & VS_WATCH) && (cid == 1)) ||
12473 +               ((mode & VS_HOSTID) && (id == 0)));
12474 +}
12475 +
12476 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
12477 +
12478 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
12479 +
12480 +
12481 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
12482 +
12483 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
12484 +
12485 +#endif
12486 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/context.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/context.h
12487 --- linux-2.6.24-rc7/include/linux/vserver/context.h    1970-01-01 01:00:00 +0100
12488 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/context.h      2007-12-13 13:25:29 +0100
12489 @@ -0,0 +1,172 @@
12490 +#ifndef _VX_CONTEXT_H
12491 +#define _VX_CONTEXT_H
12492 +
12493 +#include <linux/types.h>
12494 +#include <linux/capability.h>
12495 +
12496 +
12497 +#define VX_DYNAMIC_ID  ((uint32_t)-1)          /* id for dynamic context */
12498 +
12499 +/* context flags */
12500 +
12501 +#define VXF_INFO_SCHED         0x00000002
12502 +#define VXF_INFO_NPROC         0x00000004
12503 +#define VXF_INFO_PRIVATE       0x00000008
12504 +
12505 +#define VXF_INFO_INIT          0x00000010
12506 +#define VXF_INFO_HIDE          0x00000020
12507 +#define VXF_INFO_ULIMIT                0x00000040
12508 +#define VXF_INFO_NSPACE                0x00000080
12509 +
12510 +#define VXF_SCHED_HARD         0x00000100
12511 +#define VXF_SCHED_PRIO         0x00000200
12512 +#define VXF_SCHED_PAUSE                0x00000400
12513 +
12514 +#define VXF_VIRT_MEM           0x00010000
12515 +#define VXF_VIRT_UPTIME                0x00020000
12516 +#define VXF_VIRT_CPU           0x00040000
12517 +#define VXF_VIRT_LOAD          0x00080000
12518 +#define VXF_VIRT_TIME          0x00100000
12519 +
12520 +#define VXF_HIDE_MOUNT         0x01000000
12521 +#define VXF_HIDE_NETIF         0x02000000
12522 +#define VXF_HIDE_VINFO         0x04000000
12523 +
12524 +#define VXF_STATE_SETUP                (1ULL << 32)
12525 +#define VXF_STATE_INIT         (1ULL << 33)
12526 +#define VXF_STATE_ADMIN                (1ULL << 34)
12527 +
12528 +#define VXF_SC_HELPER          (1ULL << 36)
12529 +#define VXF_REBOOT_KILL                (1ULL << 37)
12530 +#define VXF_PERSISTENT         (1ULL << 38)
12531 +
12532 +#define VXF_FORK_RSS           (1ULL << 48)
12533 +#define VXF_PROLIFIC           (1ULL << 49)
12534 +
12535 +#define VXF_IGNEG_NICE         (1ULL << 52)
12536 +
12537 +#define VXF_ONE_TIME           (0x0007ULL << 32)
12538 +
12539 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
12540 +
12541 +
12542 +/* context migration */
12543 +
12544 +#define VXM_SET_INIT           0x00000001
12545 +#define VXM_SET_REAPER         0x00000002
12546 +
12547 +/* context caps */
12548 +
12549 +#define VXC_CAP_MASK           0x00000000
12550 +
12551 +#define VXC_SET_UTSNAME                0x00000001
12552 +#define VXC_SET_RLIMIT         0x00000002
12553 +
12554 +#define VXC_RAW_ICMP           0x00000100
12555 +#define VXC_SYSLOG             0x00001000
12556 +
12557 +#define VXC_SECURE_MOUNT       0x00010000
12558 +#define VXC_SECURE_REMOUNT     0x00020000
12559 +#define VXC_BINARY_MOUNT       0x00040000
12560 +
12561 +#define VXC_QUOTA_CTL          0x00100000
12562 +#define VXC_ADMIN_MAPPER       0x00200000
12563 +#define VXC_ADMIN_CLOOP                0x00400000
12564 +
12565 +
12566 +#ifdef __KERNEL__
12567 +
12568 +#include <linux/list.h>
12569 +#include <linux/spinlock.h>
12570 +#include <linux/rcupdate.h>
12571 +
12572 +#include "limit_def.h"
12573 +#include "sched_def.h"
12574 +#include "cvirt_def.h"
12575 +#include "cacct_def.h"
12576 +
12577 +struct _vx_info_pc {
12578 +       struct _vx_sched_pc sched_pc;
12579 +       struct _vx_cvirt_pc cvirt_pc;
12580 +};
12581 +
12582 +struct vx_info {
12583 +       struct hlist_node vx_hlist;             /* linked list of contexts */
12584 +       xid_t vx_id;                            /* context id */
12585 +       atomic_t vx_usecnt;                     /* usage count */
12586 +       atomic_t vx_tasks;                      /* tasks count */
12587 +       struct vx_info *vx_parent;              /* parent context */
12588 +       int vx_state;                           /* context state */
12589 +
12590 +       unsigned long vx_nsmask;                /* assignment mask */
12591 +       struct nsproxy *vx_nsproxy;             /* private namespace */
12592 +       struct fs_struct *vx_fs;                /* private namespace fs */
12593 +
12594 +       uint64_t vx_flags;                      /* context flags */
12595 +       uint64_t vx_bcaps;                      /* bounding caps (system) */
12596 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
12597 +       kernel_cap_t vx_cap_bset;               /* the guest's bset */
12598 +
12599 +       struct task_struct *vx_reaper;          /* guest reaper process */
12600 +       pid_t vx_initpid;                       /* PID of guest init */
12601 +
12602 +       struct _vx_limit limit;                 /* vserver limits */
12603 +       struct _vx_sched sched;                 /* vserver scheduler */
12604 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
12605 +       struct _vx_cacct cacct;                 /* context accounting */
12606 +
12607 +#ifndef CONFIG_SMP
12608 +       struct _vx_info_pc info_pc;             /* per cpu data */
12609 +#else
12610 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
12611 +#endif
12612 +
12613 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
12614 +       int reboot_cmd;                         /* last sys_reboot() cmd */
12615 +       int exit_code;                          /* last process exit code */
12616 +
12617 +       char vx_name[65];                       /* vserver name */
12618 +};
12619 +
12620 +#ifndef CONFIG_SMP
12621 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
12622 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
12623 +#else
12624 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
12625 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
12626 +#endif
12627 +
12628 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
12629 +
12630 +
12631 +struct vx_info_save {
12632 +       struct vx_info *vxi;
12633 +       xid_t xid;
12634 +};
12635 +
12636 +
12637 +/* status flags */
12638 +
12639 +#define VXS_HASHED     0x0001
12640 +#define VXS_PAUSED     0x0010
12641 +#define VXS_SHUTDOWN   0x0100
12642 +#define VXS_HELPER     0x1000
12643 +#define VXS_RELEASED   0x8000
12644 +
12645 +
12646 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
12647 +extern void release_vx_info(struct vx_info *, struct task_struct *);
12648 +
12649 +extern struct vx_info *lookup_vx_info(int);
12650 +extern struct vx_info *lookup_or_create_vx_info(int);
12651 +
12652 +extern int get_xid_list(int, unsigned int *, int);
12653 +extern int xid_is_hashed(xid_t);
12654 +
12655 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
12656 +
12657 +extern long vs_state_change(struct vx_info *, unsigned int);
12658 +
12659 +
12660 +#endif /* __KERNEL__ */
12661 +#endif /* _VX_CONTEXT_H */
12662 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/context_cmd.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/context_cmd.h
12663 --- linux-2.6.24-rc7/include/linux/vserver/context_cmd.h        1970-01-01 01:00:00 +0100
12664 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/context_cmd.h  2007-12-13 13:25:43 +0100
12665 @@ -0,0 +1,123 @@
12666 +#ifndef _VX_CONTEXT_CMD_H
12667 +#define _VX_CONTEXT_CMD_H
12668 +
12669 +
12670 +/* vinfo commands */
12671 +
12672 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
12673 +
12674 +#ifdef __KERNEL__
12675 +extern int vc_task_xid(uint32_t, void __user *);
12676 +
12677 +#endif /* __KERNEL__ */
12678 +
12679 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
12680 +
12681 +struct vcmd_vx_info_v0 {
12682 +       uint32_t xid;
12683 +       uint32_t initpid;
12684 +       /* more to come */
12685 +};
12686 +
12687 +#ifdef __KERNEL__
12688 +extern int vc_vx_info(struct vx_info *, void __user *);
12689 +
12690 +#endif /* __KERNEL__ */
12691 +
12692 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
12693 +
12694 +struct vcmd_ctx_stat_v0 {
12695 +       uint32_t usecnt;
12696 +       uint32_t tasks;
12697 +       /* more to come */
12698 +};
12699 +
12700 +#ifdef __KERNEL__
12701 +extern int vc_ctx_stat(struct vx_info *, void __user *);
12702 +
12703 +#endif /* __KERNEL__ */
12704 +
12705 +/* context commands */
12706 +
12707 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
12708 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
12709 +
12710 +struct vcmd_ctx_create {
12711 +       uint64_t flagword;
12712 +};
12713 +
12714 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
12715 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
12716 +
12717 +struct vcmd_ctx_migrate {
12718 +       uint64_t flagword;
12719 +};
12720 +
12721 +#ifdef __KERNEL__
12722 +extern int vc_ctx_create(uint32_t, void __user *);
12723 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
12724 +
12725 +#endif /* __KERNEL__ */
12726 +
12727 +
12728 +/* flag commands */
12729 +
12730 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
12731 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
12732 +
12733 +struct vcmd_ctx_flags_v0 {
12734 +       uint64_t flagword;
12735 +       uint64_t mask;
12736 +};
12737 +
12738 +#ifdef __KERNEL__
12739 +extern int vc_get_cflags(struct vx_info *, void __user *);
12740 +extern int vc_set_cflags(struct vx_info *, void __user *);
12741 +
12742 +#endif /* __KERNEL__ */
12743 +
12744 +
12745 +/* context caps commands */
12746 +
12747 +#define VCMD_get_ccaps_v0      VC_CMD(FLAGS, 3, 0)
12748 +#define VCMD_set_ccaps_v0      VC_CMD(FLAGS, 4, 0)
12749 +
12750 +struct vcmd_ctx_caps_v0 {
12751 +       uint64_t bcaps;
12752 +       uint64_t ccaps;
12753 +       uint64_t cmask;
12754 +};
12755 +
12756 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
12757 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
12758 +
12759 +struct vcmd_ctx_caps_v1 {
12760 +       uint64_t ccaps;
12761 +       uint64_t cmask;
12762 +};
12763 +
12764 +#ifdef __KERNEL__
12765 +extern int vc_get_ccaps_v0(struct vx_info *, void __user *);
12766 +extern int vc_set_ccaps_v0(struct vx_info *, void __user *);
12767 +extern int vc_get_ccaps(struct vx_info *, void __user *);
12768 +extern int vc_set_ccaps(struct vx_info *, void __user *);
12769 +
12770 +#endif /* __KERNEL__ */
12771 +
12772 +
12773 +/* bcaps commands */
12774 +
12775 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
12776 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
12777 +
12778 +struct vcmd_bcaps {
12779 +       uint64_t bcaps;
12780 +       uint64_t bmask;
12781 +};
12782 +
12783 +#ifdef __KERNEL__
12784 +extern int vc_get_bcaps(struct vx_info *, void __user *);
12785 +extern int vc_set_bcaps(struct vx_info *, void __user *);
12786 +
12787 +#endif /* __KERNEL__ */
12788 +#endif /* _VX_CONTEXT_CMD_H */
12789 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/cvirt.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/cvirt.h
12790 --- linux-2.6.24-rc7/include/linux/vserver/cvirt.h      1970-01-01 01:00:00 +0100
12791 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/cvirt.h        2007-12-13 13:25:37 +0100
12792 @@ -0,0 +1,20 @@
12793 +#ifndef _VX_CVIRT_H
12794 +#define _VX_CVIRT_H
12795 +
12796 +
12797 +#ifdef __KERNEL__
12798 +
12799 +struct timespec;
12800 +
12801 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12802 +
12803 +
12804 +struct vx_info;
12805 +
12806 +void vx_update_load(struct vx_info *);
12807 +
12808 +
12809 +int vx_do_syslog(int, char __user *, int);
12810 +
12811 +#endif /* __KERNEL__ */
12812 +#endif /* _VX_CVIRT_H */
12813 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/cvirt_cmd.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/cvirt_cmd.h
12814 --- linux-2.6.24-rc7/include/linux/vserver/cvirt_cmd.h  1970-01-01 01:00:00 +0100
12815 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/cvirt_cmd.h    2007-12-13 13:25:43 +0100
12816 @@ -0,0 +1,53 @@
12817 +#ifndef _VX_CVIRT_CMD_H
12818 +#define _VX_CVIRT_CMD_H
12819 +
12820 +
12821 +/* virtual host info name commands */
12822 +
12823 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
12824 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
12825 +
12826 +struct vcmd_vhi_name_v0 {
12827 +       uint32_t field;
12828 +       char name[65];
12829 +};
12830 +
12831 +
12832 +enum vhi_name_field {
12833 +       VHIN_CONTEXT = 0,
12834 +       VHIN_SYSNAME,
12835 +       VHIN_NODENAME,
12836 +       VHIN_RELEASE,
12837 +       VHIN_VERSION,
12838 +       VHIN_MACHINE,
12839 +       VHIN_DOMAINNAME,
12840 +};
12841 +
12842 +
12843 +#ifdef __KERNEL__
12844 +
12845 +#include <linux/compiler.h>
12846 +
12847 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
12848 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
12849 +
12850 +#endif /* __KERNEL__ */
12851 +
12852 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
12853 +
12854 +struct vcmd_virt_stat_v0 {
12855 +       uint64_t offset;
12856 +       uint64_t uptime;
12857 +       uint32_t nr_threads;
12858 +       uint32_t nr_running;
12859 +       uint32_t nr_uninterruptible;
12860 +       uint32_t nr_onhold;
12861 +       uint32_t nr_forks;
12862 +       uint32_t load[3];
12863 +};
12864 +
12865 +#ifdef __KERNEL__
12866 +extern int vc_virt_stat(struct vx_info *, void __user *);
12867 +
12868 +#endif /* __KERNEL__ */
12869 +#endif /* _VX_CVIRT_CMD_H */
12870 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/cvirt_def.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/cvirt_def.h
12871 --- linux-2.6.24-rc7/include/linux/vserver/cvirt_def.h  1970-01-01 01:00:00 +0100
12872 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/cvirt_def.h    2007-12-18 01:08:19 +0100
12873 @@ -0,0 +1,80 @@
12874 +#ifndef _VX_CVIRT_DEF_H
12875 +#define _VX_CVIRT_DEF_H
12876 +
12877 +#include <linux/jiffies.h>
12878 +#include <linux/spinlock.h>
12879 +#include <linux/wait.h>
12880 +#include <linux/time.h>
12881 +#include <asm/atomic.h>
12882 +
12883 +
12884 +struct _vx_usage_stat {
12885 +       uint64_t user;
12886 +       uint64_t nice;
12887 +       uint64_t system;
12888 +       uint64_t softirq;
12889 +       uint64_t irq;
12890 +       uint64_t idle;
12891 +       uint64_t iowait;
12892 +};
12893 +
12894 +struct _vx_syslog {
12895 +       wait_queue_head_t log_wait;
12896 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
12897 +
12898 +       unsigned long log_start;        /* next char to be read by syslog() */
12899 +       unsigned long con_start;        /* next char to be sent to consoles */
12900 +       unsigned long log_end;  /* most-recently-written-char + 1 */
12901 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
12902 +
12903 +       char log_buf[1024];
12904 +};
12905 +
12906 +
12907 +/* context sub struct */
12908 +
12909 +struct _vx_cvirt {
12910 +       atomic_t nr_threads;            /* number of current threads */
12911 +       atomic_t nr_running;            /* number of running threads */
12912 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
12913 +
12914 +       atomic_t nr_onhold;             /* processes on hold */
12915 +       uint32_t onhold_last;           /* jiffies when put on hold */
12916 +
12917 +       struct timeval bias_tv;         /* time offset to the host */
12918 +       struct timespec bias_idle;
12919 +       struct timespec bias_uptime;    /* context creation point */
12920 +       uint64_t bias_clock;            /* offset in clock_t */
12921 +
12922 +       spinlock_t load_lock;           /* lock for the load averages */
12923 +       atomic_t load_updates;          /* nr of load updates done so far */
12924 +       uint32_t load_last;             /* last time load was calculated */
12925 +       uint32_t load[3];               /* load averages 1,5,15 */
12926 +
12927 +       atomic_t total_forks;           /* number of forks so far */
12928 +
12929 +       struct _vx_syslog syslog;
12930 +};
12931 +
12932 +struct _vx_cvirt_pc {
12933 +       struct _vx_usage_stat cpustat;
12934 +};
12935 +
12936 +
12937 +#ifdef CONFIG_VSERVER_DEBUG
12938 +
12939 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
12940 +{
12941 +       printk("\t_vx_cvirt:\n");
12942 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
12943 +               atomic_read(&cvirt->nr_threads),
12944 +               atomic_read(&cvirt->nr_running),
12945 +               atomic_read(&cvirt->nr_uninterruptible),
12946 +               atomic_read(&cvirt->nr_onhold));
12947 +       /* add rest here */
12948 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
12949 +}
12950 +
12951 +#endif
12952 +
12953 +#endif /* _VX_CVIRT_DEF_H */
12954 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/debug.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/debug.h
12955 --- linux-2.6.24-rc7/include/linux/vserver/debug.h      1970-01-01 01:00:00 +0100
12956 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/debug.h        2007-12-13 13:25:42 +0100
12957 @@ -0,0 +1,124 @@
12958 +#ifndef _VX_DEBUG_H
12959 +#define _VX_DEBUG_H
12960 +
12961 +
12962 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
12963 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
12964 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
12965 +
12966 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
12967 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
12968 +#define VXF_DEV                "%p[%lu,%d:%d]"
12969 +
12970 +
12971 +#define __FUNC__       __func__
12972 +
12973 +
12974 +#define vxd_path(d, m)                                         \
12975 +       ({ static char _buffer[PATH_MAX];                       \
12976 +          d_path(d, m, _buffer, sizeof(_buffer)); })
12977 +
12978 +#define vxd_cond_path(n)                                       \
12979 +       ((n) ? vxd_path((n)->dentry, (n)->mnt) : "<null>" )
12980 +
12981 +
12982 +#ifdef CONFIG_VSERVER_DEBUG
12983 +
12984 +extern unsigned int vx_debug_switch;
12985 +extern unsigned int vx_debug_xid;
12986 +extern unsigned int vx_debug_nid;
12987 +extern unsigned int vx_debug_tag;
12988 +extern unsigned int vx_debug_net;
12989 +extern unsigned int vx_debug_limit;
12990 +extern unsigned int vx_debug_cres;
12991 +extern unsigned int vx_debug_dlim;
12992 +extern unsigned int vx_debug_quota;
12993 +extern unsigned int vx_debug_cvirt;
12994 +extern unsigned int vx_debug_space;
12995 +extern unsigned int vx_debug_misc;
12996 +
12997 +
12998 +#define VX_LOGLEVEL    "vxD: "
12999 +
13000 +#define vxdprintk(c, f, x...)                                  \
13001 +       do {                                                    \
13002 +               if (c)                                          \
13003 +                       printk(VX_LOGLEVEL f "\n" , ##x);       \
13004 +       } while (0)
13005 +
13006 +#define vxlprintk(c, f, x...)                                  \
13007 +       do {                                                    \
13008 +               if (c)                                          \
13009 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
13010 +       } while (0)
13011 +
13012 +#define vxfprintk(c, f, x...)                                  \
13013 +       do {                                                    \
13014 +               if (c)                                          \
13015 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
13016 +       } while (0)
13017 +
13018 +
13019 +struct vx_info;
13020 +
13021 +void dump_vx_info(struct vx_info *, int);
13022 +void dump_vx_info_inactive(int);
13023 +
13024 +#else  /* CONFIG_VSERVER_DEBUG */
13025 +
13026 +#define vx_debug_switch 0
13027 +#define vx_debug_xid   0
13028 +#define vx_debug_nid   0
13029 +#define vx_debug_tag   0
13030 +#define vx_debug_net   0
13031 +#define vx_debug_limit 0
13032 +#define vx_debug_cres  0
13033 +#define vx_debug_dlim  0
13034 +#define vx_debug_cvirt 0
13035 +
13036 +#define vxdprintk(x...) do { } while (0)
13037 +#define vxlprintk(x...) do { } while (0)
13038 +#define vxfprintk(x...) do { } while (0)
13039 +
13040 +#endif /* CONFIG_VSERVER_DEBUG */
13041 +
13042 +
13043 +#ifdef CONFIG_VSERVER_WARN
13044 +
13045 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
13046 +#define VX_WARN_TASK   "[»%s«,%u:#%u|%u] "
13047 +#define VX_WARN_XID    "[xid #%u] "
13048 +#define VX_WARN_NID    "[nid #%u] "
13049 +
13050 +#define vxwprintk(c, f, x...)                                  \
13051 +       do {                                                    \
13052 +               if (c)                                          \
13053 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
13054 +       } while (0)
13055 +
13056 +#else  /* CONFIG_VSERVER_WARN */
13057 +
13058 +#define vxwprintk(x...) do { } while (0)
13059 +
13060 +#endif /* CONFIG_VSERVER_WARN */
13061 +
13062 +#define vxwprintk_task(c, f, x...)                             \
13063 +       vxwprintk(c, VX_WARN_TASK f,                            \
13064 +               current->comm, current->pid,                    \
13065 +               current->xid, current->nid, ##x)
13066 +#define vxwprintk_xid(c, f, x...)                              \
13067 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
13068 +#define vxwprintk_nid(c, f, x...)                              \
13069 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
13070 +
13071 +#ifdef CONFIG_VSERVER_DEBUG
13072 +#define vxd_assert_lock(l)     assert_spin_locked(l)
13073 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
13074 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
13075 +#else
13076 +#define vxd_assert_lock(l)     do { } while (0)
13077 +#define vxd_assert(c, f, x...) do { } while (0)
13078 +#endif
13079 +
13080 +
13081 +#endif /* _VX_DEBUG_H */
13082 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/debug_cmd.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/debug_cmd.h
13083 --- linux-2.6.24-rc7/include/linux/vserver/debug_cmd.h  1970-01-01 01:00:00 +0100
13084 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/debug_cmd.h    2007-12-13 13:25:43 +0100
13085 @@ -0,0 +1,58 @@
13086 +#ifndef _VX_DEBUG_CMD_H
13087 +#define _VX_DEBUG_CMD_H
13088 +
13089 +
13090 +/* debug commands */
13091 +
13092 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
13093 +
13094 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
13095 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
13096 +
13097 +struct  vcmd_read_history_v0 {
13098 +       uint32_t index;
13099 +       uint32_t count;
13100 +       char __user *data;
13101 +};
13102 +
13103 +struct  vcmd_read_monitor_v0 {
13104 +       uint32_t index;
13105 +       uint32_t count;
13106 +       char __user *data;
13107 +};
13108 +
13109 +
13110 +#ifdef __KERNEL__
13111 +
13112 +#ifdef CONFIG_COMPAT
13113 +
13114 +#include <asm/compat.h>
13115 +
13116 +struct vcmd_read_history_v0_x32 {
13117 +       uint32_t index;
13118 +       uint32_t count;
13119 +       compat_uptr_t data_ptr;
13120 +};
13121 +
13122 +struct vcmd_read_monitor_v0_x32 {
13123 +       uint32_t index;
13124 +       uint32_t count;
13125 +       compat_uptr_t data_ptr;
13126 +};
13127 +
13128 +#endif  /* CONFIG_COMPAT */
13129 +
13130 +extern int vc_dump_history(uint32_t);
13131 +
13132 +extern int vc_read_history(uint32_t, void __user *);
13133 +extern int vc_read_monitor(uint32_t, void __user *);
13134 +
13135 +#ifdef CONFIG_COMPAT
13136 +
13137 +extern int vc_read_history_x32(uint32_t, void __user *);
13138 +extern int vc_read_monitor_x32(uint32_t, void __user *);
13139 +
13140 +#endif  /* CONFIG_COMPAT */
13141 +
13142 +#endif /* __KERNEL__ */
13143 +#endif /* _VX_DEBUG_CMD_H */
13144 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/dlimit.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/dlimit.h
13145 --- linux-2.6.24-rc7/include/linux/vserver/dlimit.h     1970-01-01 01:00:00 +0100
13146 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/dlimit.h       2007-12-13 13:25:46 +0100
13147 @@ -0,0 +1,53 @@
13148 +#ifndef _VX_DLIMIT_H
13149 +#define _VX_DLIMIT_H
13150 +
13151 +#include "switch.h"
13152 +
13153 +
13154 +#ifdef __KERNEL__
13155 +
13156 +/*      keep in sync with CDLIM_INFINITY       */
13157 +
13158 +#define DLIM_INFINITY          (~0ULL)
13159 +
13160 +#include <linux/spinlock.h>
13161 +
13162 +struct super_block;
13163 +
13164 +struct dl_info {
13165 +       struct hlist_node dl_hlist;             /* linked list of contexts */
13166 +       struct rcu_head dl_rcu;                 /* the rcu head */
13167 +       tag_t dl_tag;                           /* context tag */
13168 +       atomic_t dl_usecnt;                     /* usage count */
13169 +       atomic_t dl_refcnt;                     /* reference count */
13170 +
13171 +       struct super_block *dl_sb;              /* associated superblock */
13172 +
13173 +       spinlock_t dl_lock;                     /* protect the values */
13174 +
13175 +       unsigned long long dl_space_used;       /* used space in bytes */
13176 +       unsigned long long dl_space_total;      /* maximum space in bytes */
13177 +       unsigned long dl_inodes_used;           /* used inodes */
13178 +       unsigned long dl_inodes_total;          /* maximum inodes */
13179 +
13180 +       unsigned int dl_nrlmult;                /* non root limit mult */
13181 +};
13182 +
13183 +struct rcu_head;
13184 +
13185 +extern void rcu_free_dl_info(struct rcu_head *);
13186 +extern void unhash_dl_info(struct dl_info *);
13187 +
13188 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
13189 +
13190 +
13191 +struct kstatfs;
13192 +
13193 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
13194 +
13195 +typedef uint64_t dlsize_t;
13196 +
13197 +#endif /* __KERNEL__ */
13198 +#else  /* _VX_DLIMIT_H */
13199 +#warning duplicate inclusion
13200 +#endif /* _VX_DLIMIT_H */
13201 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/dlimit_cmd.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/dlimit_cmd.h
13202 --- linux-2.6.24-rc7/include/linux/vserver/dlimit_cmd.h 1970-01-01 01:00:00 +0100
13203 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/dlimit_cmd.h   2007-12-13 13:25:43 +0100
13204 @@ -0,0 +1,74 @@
13205 +#ifndef _VX_DLIMIT_CMD_H
13206 +#define _VX_DLIMIT_CMD_H
13207 +
13208 +
13209 +/*  dlimit vserver commands */
13210 +
13211 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
13212 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
13213 +
13214 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
13215 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
13216 +
13217 +struct vcmd_ctx_dlimit_base_v0 {
13218 +       const char __user *name;
13219 +       uint32_t flags;
13220 +};
13221 +
13222 +struct vcmd_ctx_dlimit_v0 {
13223 +       const char __user *name;
13224 +       uint32_t space_used;                    /* used space in kbytes */
13225 +       uint32_t space_total;                   /* maximum space in kbytes */
13226 +       uint32_t inodes_used;                   /* used inodes */
13227 +       uint32_t inodes_total;                  /* maximum inodes */
13228 +       uint32_t reserved;                      /* reserved for root in % */
13229 +       uint32_t flags;
13230 +};
13231 +
13232 +#define CDLIM_UNSET            ((uint32_t)0UL)
13233 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
13234 +#define CDLIM_KEEP             ((uint32_t)~1UL)
13235 +
13236 +#ifdef __KERNEL__
13237 +
13238 +#ifdef CONFIG_COMPAT
13239 +
13240 +#include <asm/compat.h>
13241 +
13242 +struct vcmd_ctx_dlimit_base_v0_x32 {
13243 +       compat_uptr_t name_ptr;
13244 +       uint32_t flags;
13245 +};
13246 +
13247 +struct vcmd_ctx_dlimit_v0_x32 {
13248 +       compat_uptr_t name_ptr;
13249 +       uint32_t space_used;                    /* used space in kbytes */
13250 +       uint32_t space_total;                   /* maximum space in kbytes */
13251 +       uint32_t inodes_used;                   /* used inodes */
13252 +       uint32_t inodes_total;                  /* maximum inodes */
13253 +       uint32_t reserved;                      /* reserved for root in % */
13254 +       uint32_t flags;
13255 +};
13256 +
13257 +#endif /* CONFIG_COMPAT */
13258 +
13259 +#include <linux/compiler.h>
13260 +
13261 +extern int vc_add_dlimit(uint32_t, void __user *);
13262 +extern int vc_rem_dlimit(uint32_t, void __user *);
13263 +
13264 +extern int vc_set_dlimit(uint32_t, void __user *);
13265 +extern int vc_get_dlimit(uint32_t, void __user *);
13266 +
13267 +#ifdef CONFIG_COMPAT
13268 +
13269 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
13270 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
13271 +
13272 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
13273 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
13274 +
13275 +#endif /* CONFIG_COMPAT */
13276 +
13277 +#endif /* __KERNEL__ */
13278 +#endif /* _VX_DLIMIT_CMD_H */
13279 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/global.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/global.h
13280 --- linux-2.6.24-rc7/include/linux/vserver/global.h     1970-01-01 01:00:00 +0100
13281 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/global.h       2007-12-15 00:32:17 +0100
13282 @@ -0,0 +1,20 @@
13283 +#ifndef _VX_GLOBAL_H
13284 +#define _VX_GLOBAL_H
13285 +
13286 +
13287 +extern atomic_t vx_global_ctotal;
13288 +extern atomic_t vx_global_cactive;
13289 +
13290 +extern atomic_t nx_global_ctotal;
13291 +extern atomic_t nx_global_cactive;
13292 +
13293 +extern atomic_t vs_global_nsproxy;
13294 +extern atomic_t vs_global_fs;
13295 +extern atomic_t vs_global_mnt_ns;
13296 +extern atomic_t vs_global_uts_ns;
13297 +extern atomic_t vs_global_ipc_ns;
13298 +extern atomic_t vs_global_user_ns;
13299 +extern atomic_t vs_global_pid_ns;
13300 +
13301 +
13302 +#endif /* _VX_GLOBAL_H */
13303 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/history.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/history.h
13304 --- linux-2.6.24-rc7/include/linux/vserver/history.h    1970-01-01 01:00:00 +0100
13305 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/history.h      2007-12-13 13:25:42 +0100
13306 @@ -0,0 +1,197 @@
13307 +#ifndef _VX_HISTORY_H
13308 +#define _VX_HISTORY_H
13309 +
13310 +
13311 +enum {
13312 +       VXH_UNUSED = 0,
13313 +       VXH_THROW_OOPS = 1,
13314 +
13315 +       VXH_GET_VX_INFO,
13316 +       VXH_PUT_VX_INFO,
13317 +       VXH_INIT_VX_INFO,
13318 +       VXH_SET_VX_INFO,
13319 +       VXH_CLR_VX_INFO,
13320 +       VXH_CLAIM_VX_INFO,
13321 +       VXH_RELEASE_VX_INFO,
13322 +       VXH_ALLOC_VX_INFO,
13323 +       VXH_DEALLOC_VX_INFO,
13324 +       VXH_HASH_VX_INFO,
13325 +       VXH_UNHASH_VX_INFO,
13326 +       VXH_LOC_VX_INFO,
13327 +       VXH_LOOKUP_VX_INFO,
13328 +       VXH_CREATE_VX_INFO,
13329 +};
13330 +
13331 +struct _vxhe_vxi {
13332 +       struct vx_info *ptr;
13333 +       unsigned xid;
13334 +       unsigned usecnt;
13335 +       unsigned tasks;
13336 +};
13337 +
13338 +struct _vxhe_set_clr {
13339 +       void *data;
13340 +};
13341 +
13342 +struct _vxhe_loc_lookup {
13343 +       unsigned arg;
13344 +};
13345 +
13346 +struct _vx_hist_entry {
13347 +       void *loc;
13348 +       unsigned short seq;
13349 +       unsigned short type;
13350 +       struct _vxhe_vxi vxi;
13351 +       union {
13352 +               struct _vxhe_set_clr sc;
13353 +               struct _vxhe_loc_lookup ll;
13354 +       };
13355 +};
13356 +
13357 +#ifdef CONFIG_VSERVER_HISTORY
13358 +
13359 +extern unsigned volatile int vxh_active;
13360 +
13361 +struct _vx_hist_entry *vxh_advance(void *loc);
13362 +
13363 +
13364 +static inline
13365 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
13366 +{
13367 +       entry->vxi.ptr = vxi;
13368 +       if (vxi) {
13369 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
13370 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
13371 +               entry->vxi.xid = vxi->vx_id;
13372 +       }
13373 +}
13374 +
13375 +
13376 +#define        __HERE__ current_text_addr()
13377 +
13378 +#define __VXH_BODY(__type, __data, __here)     \
13379 +       struct _vx_hist_entry *entry;           \
13380 +                                               \
13381 +       preempt_disable();                      \
13382 +       entry = vxh_advance(__here);            \
13383 +       __data;                                 \
13384 +       entry->type = __type;                   \
13385 +       preempt_enable();
13386 +
13387 +
13388 +       /* pass vxi only */
13389 +
13390 +#define __VXH_SMPL                             \
13391 +       __vxh_copy_vxi(entry, vxi)
13392 +
13393 +static inline
13394 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
13395 +{
13396 +       __VXH_BODY(__type, __VXH_SMPL, __here)
13397 +}
13398 +
13399 +       /* pass vxi and data (void *) */
13400 +
13401 +#define __VXH_DATA                             \
13402 +       __vxh_copy_vxi(entry, vxi);             \
13403 +       entry->sc.data = data
13404 +
13405 +static inline
13406 +void   __vxh_data(struct vx_info *vxi, void *data,
13407 +                       int __type, void *__here)
13408 +{
13409 +       __VXH_BODY(__type, __VXH_DATA, __here)
13410 +}
13411 +
13412 +       /* pass vxi and arg (long) */
13413 +
13414 +#define __VXH_LONG                             \
13415 +       __vxh_copy_vxi(entry, vxi);             \
13416 +       entry->ll.arg = arg
13417 +
13418 +static inline
13419 +void   __vxh_long(struct vx_info *vxi, long arg,
13420 +                       int __type, void *__here)
13421 +{
13422 +       __VXH_BODY(__type, __VXH_LONG, __here)
13423 +}
13424 +
13425 +
13426 +static inline
13427 +void   __vxh_throw_oops(void *__here)
13428 +{
13429 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
13430 +       /* prevent further acquisition */
13431 +       vxh_active = 0;
13432 +}
13433 +
13434 +
13435 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
13436 +
13437 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
13438 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
13439 +
13440 +#define __vxh_init_vx_info(v, d, h) \
13441 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
13442 +#define __vxh_set_vx_info(v, d, h) \
13443 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
13444 +#define __vxh_clr_vx_info(v, d, h) \
13445 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
13446 +
13447 +#define __vxh_claim_vx_info(v, d, h) \
13448 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
13449 +#define __vxh_release_vx_info(v, d, h) \
13450 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
13451 +
13452 +#define vxh_alloc_vx_info(v) \
13453 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
13454 +#define vxh_dealloc_vx_info(v) \
13455 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
13456 +
13457 +#define vxh_hash_vx_info(v) \
13458 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
13459 +#define vxh_unhash_vx_info(v) \
13460 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
13461 +
13462 +#define vxh_loc_vx_info(v, l) \
13463 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
13464 +#define vxh_lookup_vx_info(v, l) \
13465 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
13466 +#define vxh_create_vx_info(v, l) \
13467 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
13468 +
13469 +extern void vxh_dump_history(void);
13470 +
13471 +
13472 +#else  /* CONFIG_VSERVER_HISTORY */
13473 +
13474 +#define        __HERE__        0
13475 +
13476 +#define vxh_throw_oops()               do { } while (0)
13477 +
13478 +#define __vxh_get_vx_info(v, h)                do { } while (0)
13479 +#define __vxh_put_vx_info(v, h)                do { } while (0)
13480 +
13481 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
13482 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
13483 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
13484 +
13485 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
13486 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
13487 +
13488 +#define vxh_alloc_vx_info(v)           do { } while (0)
13489 +#define vxh_dealloc_vx_info(v)         do { } while (0)
13490 +
13491 +#define vxh_hash_vx_info(v)            do { } while (0)
13492 +#define vxh_unhash_vx_info(v)          do { } while (0)
13493 +
13494 +#define vxh_loc_vx_info(v, l)          do { } while (0)
13495 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
13496 +#define vxh_create_vx_info(v, l)       do { } while (0)
13497 +
13498 +#define vxh_dump_history()             do { } while (0)
13499 +
13500 +
13501 +#endif /* CONFIG_VSERVER_HISTORY */
13502 +
13503 +#endif /* _VX_HISTORY_H */
13504 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/inode.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/inode.h
13505 --- linux-2.6.24-rc7/include/linux/vserver/inode.h      1970-01-01 01:00:00 +0100
13506 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/inode.h        2007-12-13 13:25:38 +0100
13507 @@ -0,0 +1,38 @@
13508 +#ifndef _VX_INODE_H
13509 +#define _VX_INODE_H
13510 +
13511 +
13512 +#define IATTR_TAG      0x01000000
13513 +
13514 +#define IATTR_ADMIN    0x00000001
13515 +#define IATTR_WATCH    0x00000002
13516 +#define IATTR_HIDE     0x00000004
13517 +#define IATTR_FLAGS    0x00000007
13518 +
13519 +#define IATTR_BARRIER  0x00010000
13520 +#define IATTR_IUNLINK  0x00020000
13521 +#define IATTR_IMMUTABLE 0x00040000
13522 +
13523 +#ifdef __KERNEL__
13524 +
13525 +
13526 +#ifdef CONFIG_VSERVER_PROC_SECURE
13527 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
13528 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
13529 +#else
13530 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
13531 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
13532 +#endif
13533 +
13534 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
13535 +
13536 +#endif /* __KERNEL__ */
13537 +
13538 +/* inode ioctls */
13539 +
13540 +#define FIOC_GETXFLG   _IOR('x', 5, long)
13541 +#define FIOC_SETXFLG   _IOW('x', 6, long)
13542 +
13543 +#else  /* _VX_INODE_H */
13544 +#warning duplicate inclusion
13545 +#endif /* _VX_INODE_H */
13546 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/inode_cmd.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/inode_cmd.h
13547 --- linux-2.6.24-rc7/include/linux/vserver/inode_cmd.h  1970-01-01 01:00:00 +0100
13548 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/inode_cmd.h    2007-12-13 13:25:43 +0100
13549 @@ -0,0 +1,59 @@
13550 +#ifndef _VX_INODE_CMD_H
13551 +#define _VX_INODE_CMD_H
13552 +
13553 +
13554 +/*  inode vserver commands */
13555 +
13556 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
13557 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
13558 +
13559 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
13560 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
13561 +
13562 +struct vcmd_ctx_iattr_v1 {
13563 +       const char __user *name;
13564 +       uint32_t xid;
13565 +       uint32_t flags;
13566 +       uint32_t mask;
13567 +};
13568 +
13569 +struct vcmd_ctx_fiattr_v0 {
13570 +       uint32_t xid;
13571 +       uint32_t flags;
13572 +       uint32_t mask;
13573 +};
13574 +
13575 +
13576 +#ifdef __KERNEL__
13577 +
13578 +
13579 +#ifdef CONFIG_COMPAT
13580 +
13581 +#include <asm/compat.h>
13582 +
13583 +struct vcmd_ctx_iattr_v1_x32 {
13584 +       compat_uptr_t name_ptr;
13585 +       uint32_t xid;
13586 +       uint32_t flags;
13587 +       uint32_t mask;
13588 +};
13589 +
13590 +#endif /* CONFIG_COMPAT */
13591 +
13592 +#include <linux/compiler.h>
13593 +
13594 +extern int vc_get_iattr(void __user *);
13595 +extern int vc_set_iattr(void __user *);
13596 +
13597 +extern int vc_fget_iattr(uint32_t, void __user *);
13598 +extern int vc_fset_iattr(uint32_t, void __user *);
13599 +
13600 +#ifdef CONFIG_COMPAT
13601 +
13602 +extern int vc_get_iattr_x32(void __user *);
13603 +extern int vc_set_iattr_x32(void __user *);
13604 +
13605 +#endif /* CONFIG_COMPAT */
13606 +
13607 +#endif /* __KERNEL__ */
13608 +#endif /* _VX_INODE_CMD_H */
13609 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/legacy.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/legacy.h
13610 --- linux-2.6.24-rc7/include/linux/vserver/legacy.h     1970-01-01 01:00:00 +0100
13611 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/legacy.h       2007-12-13 13:25:52 +0100
13612 @@ -0,0 +1,49 @@
13613 +#ifndef _VX_LEGACY_H
13614 +#define _VX_LEGACY_H
13615 +
13616 +#include "switch.h"
13617 +
13618 +
13619 +/*  compatibiliy vserver commands */
13620 +
13621 +#define VCMD_new_s_context     VC_CMD(COMPAT, 1, 1)
13622 +#define VCMD_set_ipv4root      VC_CMD(COMPAT, 2, 3)
13623 +
13624 +#define VCMD_create_context    VC_CMD(VSETUP, 1, 0)
13625 +
13626 +/*  compatibiliy vserver arguments */
13627 +
13628 +struct vcmd_new_s_context_v1 {
13629 +       uint32_t remove_cap;
13630 +       uint32_t flags;
13631 +};
13632 +
13633 +struct vcmd_set_ipv4root_v3 {
13634 +       /* number of pairs in id */
13635 +       uint32_t broadcast;
13636 +       struct {
13637 +               uint32_t ip;
13638 +               uint32_t mask;
13639 +       } nx_mask_pair[NB_IPV4ROOT];
13640 +};
13641 +
13642 +
13643 +#define VX_INFO_LOCK           1       /* Can't request a new vx_id */
13644 +#define VX_INFO_NPROC          4       /* Limit number of processes in a context */
13645 +#define VX_INFO_PRIVATE                8       /* Noone can join this security context */
13646 +#define VX_INFO_INIT           16      /* This process wants to become the */
13647 +                                       /* logical process 1 of the security */
13648 +                                       /* context */
13649 +#define VX_INFO_HIDEINFO       32      /* Hide some information in /proc */
13650 +#define VX_INFO_ULIMIT         64      /* Use ulimit of the current process */
13651 +                                       /* to become the global limits */
13652 +                                       /* of the context */
13653 +#define VX_INFO_NAMESPACE      128     /* save private namespace */
13654 +
13655 +
13656 +#ifdef __KERNEL__
13657 +extern int vc_new_s_context(uint32_t, void __user *);
13658 +extern int vc_set_ipv4root(uint32_t, void __user *);
13659 +
13660 +#endif /* __KERNEL__ */
13661 +#endif /* _VX_LEGACY_H */
13662 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/limit.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/limit.h
13663 --- linux-2.6.24-rc7/include/linux/vserver/limit.h      1970-01-01 01:00:00 +0100
13664 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/limit.h        2007-12-13 13:25:42 +0100
13665 @@ -0,0 +1,68 @@
13666 +#ifndef _VX_LIMIT_H
13667 +#define _VX_LIMIT_H
13668 +
13669 +
13670 +#define VLIMIT_NSOCK   16
13671 +#define VLIMIT_OPENFD  17
13672 +#define VLIMIT_ANON    18
13673 +#define VLIMIT_SHMEM   19
13674 +#define VLIMIT_SEMARY  20
13675 +#define VLIMIT_NSEMS   21
13676 +#define VLIMIT_DENTRY  22
13677 +#define VLIMIT_MAPPED  23
13678 +
13679 +
13680 +#ifdef __KERNEL__
13681 +
13682 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
13683 +
13684 +/*     keep in sync with CRLIM_INFINITY */
13685 +
13686 +#define        VLIM_INFINITY   (~0ULL)
13687 +
13688 +#ifndef RLIM_INFINITY
13689 +#warning RLIM_INFINITY is undefined
13690 +#endif
13691 +
13692 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
13693 +
13694 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
13695 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
13696 +
13697 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
13698 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
13699 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
13700 +
13701 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
13702 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
13703 +
13704 +typedef atomic_long_t rlim_atomic_t;
13705 +typedef unsigned long rlim_t;
13706 +
13707 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
13708 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
13709 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
13710 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
13711 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
13712 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
13713 +
13714 +
13715 +#if    (RLIM_INFINITY == VLIM_INFINITY)
13716 +#define        VX_VLIM(r) ((long long)(long)(r))
13717 +#define        VX_RLIM(v) ((rlim_t)(v))
13718 +#else
13719 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
13720 +               ? VLIM_INFINITY : (long long)(r))
13721 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
13722 +               ? RLIM_INFINITY : (rlim_t)(v))
13723 +#endif
13724 +
13725 +struct sysinfo;
13726 +
13727 +void vx_vsi_meminfo(struct sysinfo *);
13728 +void vx_vsi_swapinfo(struct sysinfo *);
13729 +
13730 +#define NUM_LIMITS     24
13731 +
13732 +#endif /* __KERNEL__ */
13733 +#endif /* _VX_LIMIT_H */
13734 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/limit_cmd.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/limit_cmd.h
13735 --- linux-2.6.24-rc7/include/linux/vserver/limit_cmd.h  1970-01-01 01:00:00 +0100
13736 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/limit_cmd.h    2007-12-13 13:25:43 +0100
13737 @@ -0,0 +1,69 @@
13738 +#ifndef _VX_LIMIT_CMD_H
13739 +#define _VX_LIMIT_CMD_H
13740 +
13741 +
13742 +/*  rlimit vserver commands */
13743 +
13744 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
13745 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
13746 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
13747 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
13748 +
13749 +struct vcmd_ctx_rlimit_v0 {
13750 +       uint32_t id;
13751 +       uint64_t minimum;
13752 +       uint64_t softlimit;
13753 +       uint64_t maximum;
13754 +};
13755 +
13756 +struct vcmd_ctx_rlimit_mask_v0 {
13757 +       uint32_t minimum;
13758 +       uint32_t softlimit;
13759 +       uint32_t maximum;
13760 +};
13761 +
13762 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
13763 +
13764 +struct vcmd_rlimit_stat_v0 {
13765 +       uint32_t id;
13766 +       uint32_t hits;
13767 +       uint64_t value;
13768 +       uint64_t minimum;
13769 +       uint64_t maximum;
13770 +};
13771 +
13772 +#define CRLIM_UNSET            (0ULL)
13773 +#define CRLIM_INFINITY         (~0ULL)
13774 +#define CRLIM_KEEP             (~1ULL)
13775 +
13776 +#ifdef __KERNEL__
13777 +
13778 +#ifdef CONFIG_IA32_EMULATION
13779 +
13780 +struct vcmd_ctx_rlimit_v0_x32 {
13781 +       uint32_t id;
13782 +       uint64_t minimum;
13783 +       uint64_t softlimit;
13784 +       uint64_t maximum;
13785 +} __attribute__ ((aligned (4)));
13786 +
13787 +#endif /* CONFIG_IA32_EMULATION */
13788 +
13789 +#include <linux/compiler.h>
13790 +
13791 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
13792 +extern int vc_get_rlimit(struct vx_info *, void __user *);
13793 +extern int vc_set_rlimit(struct vx_info *, void __user *);
13794 +extern int vc_reset_minmax(struct vx_info *, void __user *);
13795 +
13796 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
13797 +
13798 +#ifdef CONFIG_IA32_EMULATION
13799 +
13800 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
13801 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
13802 +
13803 +#endif /* CONFIG_IA32_EMULATION */
13804 +
13805 +#endif /* __KERNEL__ */
13806 +#endif /* _VX_LIMIT_CMD_H */
13807 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/limit_def.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/limit_def.h
13808 --- linux-2.6.24-rc7/include/linux/vserver/limit_def.h  1970-01-01 01:00:00 +0100
13809 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/limit_def.h    2007-12-13 13:25:43 +0100
13810 @@ -0,0 +1,47 @@
13811 +#ifndef _VX_LIMIT_DEF_H
13812 +#define _VX_LIMIT_DEF_H
13813 +
13814 +#include <asm/atomic.h>
13815 +#include <asm/resource.h>
13816 +
13817 +#include "limit.h"
13818 +
13819 +
13820 +struct _vx_res_limit {
13821 +       rlim_t soft;            /* Context soft limit */
13822 +       rlim_t hard;            /* Context hard limit */
13823 +
13824 +       rlim_atomic_t rcur;     /* Current value */
13825 +       rlim_t rmin;            /* Context minimum */
13826 +       rlim_t rmax;            /* Context maximum */
13827 +
13828 +       atomic_t lhit;          /* Limit hits */
13829 +};
13830 +
13831 +/* context sub struct */
13832 +
13833 +struct _vx_limit {
13834 +       struct _vx_res_limit res[NUM_LIMITS];
13835 +};
13836 +
13837 +#ifdef CONFIG_VSERVER_DEBUG
13838 +
13839 +static inline void __dump_vx_limit(struct _vx_limit *limit)
13840 +{
13841 +       int i;
13842 +
13843 +       printk("\t_vx_limit:");
13844 +       for (i = 0; i < NUM_LIMITS; i++) {
13845 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
13846 +                       i, (unsigned long)__rlim_get(limit, i),
13847 +                       (unsigned long)__rlim_rmin(limit, i),
13848 +                       (unsigned long)__rlim_rmax(limit, i),
13849 +                       (long)__rlim_soft(limit, i),
13850 +                       (long)__rlim_hard(limit, i),
13851 +                       atomic_read(&__rlim_lhit(limit, i)));
13852 +       }
13853 +}
13854 +
13855 +#endif
13856 +
13857 +#endif /* _VX_LIMIT_DEF_H */
13858 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/limit_int.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/limit_int.h
13859 --- linux-2.6.24-rc7/include/linux/vserver/limit_int.h  1970-01-01 01:00:00 +0100
13860 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/limit_int.h    2007-12-13 13:25:42 +0100
13861 @@ -0,0 +1,198 @@
13862 +#ifndef _VX_LIMIT_INT_H
13863 +#define _VX_LIMIT_INT_H
13864 +
13865 +#include "context.h"
13866 +
13867 +#ifdef __KERNEL__
13868 +
13869 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
13870 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
13871 +
13872 +extern const char *vlimit_name[NUM_LIMITS];
13873 +
13874 +static inline void __vx_acc_cres(struct vx_info *vxi,
13875 +       int res, int dir, void *_data, char *_file, int _line)
13876 +{
13877 +       if (VXD_RCRES_COND(res))
13878 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
13879 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
13880 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
13881 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
13882 +       if (!vxi)
13883 +               return;
13884 +
13885 +       if (dir > 0)
13886 +               __rlim_inc(&vxi->limit, res);
13887 +       else
13888 +               __rlim_dec(&vxi->limit, res);
13889 +}
13890 +
13891 +static inline void __vx_add_cres(struct vx_info *vxi,
13892 +       int res, int amount, void *_data, char *_file, int _line)
13893 +{
13894 +       if (VXD_RCRES_COND(res))
13895 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
13896 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
13897 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
13898 +                       amount, _data, _file, _line);
13899 +       if (amount == 0)
13900 +               return;
13901 +       if (!vxi)
13902 +               return;
13903 +       __rlim_add(&vxi->limit, res, amount);
13904 +}
13905 +
13906 +static inline
13907 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
13908 +{
13909 +       int cond = (value > __rlim_rmax(limit, res));
13910 +
13911 +       if (cond)
13912 +               __rlim_rmax(limit, res) = value;
13913 +       return cond;
13914 +}
13915 +
13916 +static inline
13917 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
13918 +{
13919 +       int cond = (value < __rlim_rmin(limit, res));
13920 +
13921 +       if (cond)
13922 +               __rlim_rmin(limit, res) = value;
13923 +       return cond;
13924 +}
13925 +
13926 +static inline
13927 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
13928 +{
13929 +       if (!__vx_cres_adjust_max(limit, res, value))
13930 +               __vx_cres_adjust_min(limit, res, value);
13931 +}
13932 +
13933 +
13934 +/*     return values:
13935 +        +1 ... no limit hit
13936 +        -1 ... over soft limit
13937 +         0 ... over hard limit         */
13938 +
13939 +static inline int __vx_cres_avail(struct vx_info *vxi,
13940 +       int res, int num, char *_file, int _line)
13941 +{
13942 +       struct _vx_limit *limit;
13943 +       rlim_t value;
13944 +
13945 +       if (VXD_RLIMIT_COND(res))
13946 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
13947 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
13948 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
13949 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
13950 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
13951 +                       num, _file, _line);
13952 +       if (!vxi)
13953 +               return 1;
13954 +
13955 +       limit = &vxi->limit;
13956 +       value = __rlim_get(limit, res);
13957 +
13958 +       if (!__vx_cres_adjust_max(limit, res, value))
13959 +               __vx_cres_adjust_min(limit, res, value);
13960 +
13961 +       if (num == 0)
13962 +               return 1;
13963 +
13964 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
13965 +               return -1;
13966 +       if (value + num <= __rlim_soft(limit, res))
13967 +               return -1;
13968 +
13969 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
13970 +               return 1;
13971 +       if (value + num <= __rlim_hard(limit, res))
13972 +               return 1;
13973 +
13974 +       __rlim_hit(limit, res);
13975 +       return 0;
13976 +}
13977 +
13978 +
13979 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
13980 +
13981 +static inline
13982 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
13983 +{
13984 +       rlim_t value, sum = 0;
13985 +       int res;
13986 +
13987 +       while ((res = *array++)) {
13988 +               value = __rlim_get(limit, res);
13989 +               __vx_cres_fixup(limit, res, value);
13990 +               sum += value;
13991 +       }
13992 +       return sum;
13993 +}
13994 +
13995 +static inline
13996 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
13997 +{
13998 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
13999 +       int res = *array;
14000 +
14001 +       if (value == __rlim_get(limit, res))
14002 +               return value;
14003 +
14004 +       __rlim_set(limit, res, value);
14005 +       /* now adjust min/max */
14006 +       if (!__vx_cres_adjust_max(limit, res, value))
14007 +               __vx_cres_adjust_min(limit, res, value);
14008 +
14009 +       return value;
14010 +}
14011 +
14012 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
14013 +       const int *array, int num, char *_file, int _line)
14014 +{
14015 +       struct _vx_limit *limit;
14016 +       rlim_t value = 0;
14017 +       int res;
14018 +
14019 +       if (num == 0)
14020 +               return 1;
14021 +       if (!vxi)
14022 +               return 1;
14023 +
14024 +       limit = &vxi->limit;
14025 +       res = *array;
14026 +       value = __vx_cres_array_sum(limit, array + 1);
14027 +
14028 +       __rlim_set(limit, res, value);
14029 +       __vx_cres_fixup(limit, res, value);
14030 +
14031 +       return __vx_cres_avail(vxi, res, num, _file, _line);
14032 +}
14033 +
14034 +
14035 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
14036 +{
14037 +       rlim_t value;
14038 +       int res;
14039 +
14040 +       /* complex resources first */
14041 +       if ((id < 0) || (id == RLIMIT_RSS))
14042 +               __vx_cres_array_fixup(limit, VLA_RSS);
14043 +
14044 +       for (res = 0; res < NUM_LIMITS; res++) {
14045 +               if ((id > 0) && (res != id))
14046 +                       continue;
14047 +
14048 +               value = __rlim_get(limit, res);
14049 +               __vx_cres_fixup(limit, res, value);
14050 +
14051 +               /* not supposed to happen, maybe warn? */
14052 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
14053 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
14054 +       }
14055 +}
14056 +
14057 +
14058 +#endif /* __KERNEL__ */
14059 +#endif /* _VX_LIMIT_INT_H */
14060 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/monitor.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/monitor.h
14061 --- linux-2.6.24-rc7/include/linux/vserver/monitor.h    1970-01-01 01:00:00 +0100
14062 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/monitor.h      2007-12-13 13:25:42 +0100
14063 @@ -0,0 +1,95 @@
14064 +#ifndef _VX_MONITOR_H
14065 +#define _VX_MONITOR_H
14066 +
14067 +
14068 +enum {
14069 +       VXM_UNUSED = 0,
14070 +
14071 +       VXM_SYNC = 0x10,
14072 +
14073 +       VXM_UPDATE = 0x20,
14074 +       VXM_UPDATE_1,
14075 +       VXM_UPDATE_2,
14076 +
14077 +       VXM_RQINFO_1 = 0x24,
14078 +       VXM_RQINFO_2,
14079 +
14080 +       VXM_ACTIVATE = 0x40,
14081 +       VXM_DEACTIVATE,
14082 +       VXM_IDLE,
14083 +
14084 +       VXM_HOLD = 0x44,
14085 +       VXM_UNHOLD,
14086 +
14087 +       VXM_MIGRATE = 0x48,
14088 +       VXM_RESCHED,
14089 +
14090 +       /* all other bits are flags */
14091 +       VXM_SCHED = 0x80,
14092 +};
14093 +
14094 +struct _vxm_update_1 {
14095 +       uint32_t tokens_max;
14096 +       uint32_t fill_rate;
14097 +       uint32_t interval;
14098 +};
14099 +
14100 +struct _vxm_update_2 {
14101 +       uint32_t tokens_min;
14102 +       uint32_t fill_rate;
14103 +       uint32_t interval;
14104 +};
14105 +
14106 +struct _vxm_rqinfo_1 {
14107 +       uint16_t running;
14108 +       uint16_t onhold;
14109 +       uint16_t iowait;
14110 +       uint16_t uintr;
14111 +       uint32_t idle_tokens;
14112 +};
14113 +
14114 +struct _vxm_rqinfo_2 {
14115 +       uint32_t norm_time;
14116 +       uint32_t idle_time;
14117 +       uint32_t idle_skip;
14118 +};
14119 +
14120 +struct _vxm_sched {
14121 +       uint32_t tokens;
14122 +       uint32_t norm_time;
14123 +       uint32_t idle_time;
14124 +};
14125 +
14126 +struct _vxm_task {
14127 +       uint16_t pid;
14128 +       uint16_t state;
14129 +};
14130 +
14131 +struct _vxm_event {
14132 +       uint32_t jif;
14133 +       union {
14134 +               uint32_t seq;
14135 +               uint32_t sec;
14136 +       };
14137 +       union {
14138 +               uint32_t tokens;
14139 +               uint32_t nsec;
14140 +               struct _vxm_task tsk;
14141 +       };
14142 +};
14143 +
14144 +struct _vx_mon_entry {
14145 +       uint16_t type;
14146 +       uint16_t xid;
14147 +       union {
14148 +               struct _vxm_event ev;
14149 +               struct _vxm_sched sd;
14150 +               struct _vxm_update_1 u1;
14151 +               struct _vxm_update_2 u2;
14152 +               struct _vxm_rqinfo_1 q1;
14153 +               struct _vxm_rqinfo_2 q2;
14154 +       };
14155 +};
14156 +
14157 +
14158 +#endif /* _VX_MONITOR_H */
14159 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/network.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/network.h
14160 --- linux-2.6.24-rc7/include/linux/vserver/network.h    1970-01-01 01:00:00 +0100
14161 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/network.h      2007-12-13 13:25:30 +0100
14162 @@ -0,0 +1,142 @@
14163 +#ifndef _VX_NETWORK_H
14164 +#define _VX_NETWORK_H
14165 +
14166 +#include <linux/types.h>
14167 +
14168 +
14169 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
14170 +
14171 +#define NX_DYNAMIC_ID  ((uint32_t)-1)          /* id for dynamic context */
14172 +
14173 +#define NB_IPV4ROOT    16
14174 +
14175 +
14176 +/* network flags */
14177 +
14178 +#define NXF_INFO_PRIVATE       0x00000008
14179 +
14180 +#define NXF_STATE_SETUP                (1ULL << 32)
14181 +#define NXF_STATE_ADMIN                (1ULL << 34)
14182 +
14183 +#define NXF_SC_HELPER          (1ULL << 36)
14184 +#define NXF_PERSISTENT         (1ULL << 38)
14185 +
14186 +#define NXF_ONE_TIME           (0x0005ULL << 32)
14187 +
14188 +#define NXF_INIT_SET           (NXF_STATE_ADMIN)
14189 +
14190 +
14191 +/* address types */
14192 +
14193 +#define NXA_TYPE_IPV4          1
14194 +#define NXA_TYPE_IPV6          2
14195 +
14196 +#define NXA_MOD_BCAST          (1 << 8)
14197 +
14198 +#define NXA_TYPE_ANY           ((uint16_t)-1)
14199 +
14200 +
14201 +#ifdef __KERNEL__
14202 +
14203 +#include <linux/list.h>
14204 +#include <linux/spinlock.h>
14205 +#include <linux/rcupdate.h>
14206 +#include <asm/atomic.h>
14207 +
14208 +
14209 +struct nx_info {
14210 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
14211 +       nid_t nx_id;                    /* vnet id */
14212 +       atomic_t nx_usecnt;             /* usage count */
14213 +       atomic_t nx_tasks;              /* tasks count */
14214 +       int nx_state;                   /* context state */
14215 +
14216 +       uint64_t nx_flags;              /* network flag word */
14217 +       uint64_t nx_ncaps;              /* network capabilities */
14218 +
14219 +       int nbipv4;
14220 +       __u32 ipv4[NB_IPV4ROOT];        /* Process can only bind to these IPs */
14221 +                                       /* The first one is used to connect */
14222 +                                       /* and for bind any service */
14223 +                                       /* The other must be used explicity */
14224 +       __u32 mask[NB_IPV4ROOT];        /* Netmask for each ipv4 */
14225 +                                       /* Used to select the proper source */
14226 +                                       /* address for sockets */
14227 +       __u32 v4_bcast;                 /* Broadcast address to receive UDP  */
14228 +
14229 +       char nx_name[65];               /* network context name */
14230 +};
14231 +
14232 +
14233 +/* status flags */
14234 +
14235 +#define NXS_HASHED      0x0001
14236 +#define NXS_SHUTDOWN    0x0100
14237 +#define NXS_RELEASED    0x8000
14238 +
14239 +/* check conditions */
14240 +
14241 +#define NX_ADMIN       0x0001
14242 +#define NX_WATCH       0x0002
14243 +#define NX_BLEND       0x0004
14244 +#define NX_HOSTID      0x0008
14245 +
14246 +#define NX_IDENT       0x0010
14247 +#define NX_EQUIV       0x0020
14248 +#define NX_PARENT      0x0040
14249 +#define NX_CHILD       0x0080
14250 +
14251 +#define NX_ARG_MASK    0x00F0
14252 +
14253 +#define NX_DYNAMIC     0x0100
14254 +#define NX_STATIC      0x0200
14255 +
14256 +#define NX_ATR_MASK    0x0F00
14257 +
14258 +
14259 +extern struct nx_info *lookup_nx_info(int);
14260 +
14261 +extern int get_nid_list(int, unsigned int *, int);
14262 +extern int nid_is_hashed(nid_t);
14263 +
14264 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
14265 +
14266 +extern long vs_net_change(struct nx_info *, unsigned int);
14267 +
14268 +struct in_ifaddr;
14269 +struct net_device;
14270 +
14271 +#ifdef CONFIG_INET
14272 +int ifa_in_nx_info(struct in_ifaddr *, struct nx_info *);
14273 +int dev_in_nx_info(struct net_device *, struct nx_info *);
14274 +
14275 +#else /* CONFIG_INET */
14276 +static inline
14277 +int ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
14278 +{
14279 +       return 1;
14280 +}
14281 +
14282 +static inline
14283 +int dev_in_nx_info(struct net_device *d, struct nx_info *n)
14284 +{
14285 +       return 1;
14286 +}
14287 +#endif /* CONFIG_INET */
14288 +
14289 +struct sock;
14290 +
14291 +#ifdef CONFIG_INET
14292 +int nx_addr_conflict(struct nx_info *, uint32_t, const struct sock *);
14293 +#else /* CONFIG_INET */
14294 +static inline
14295 +int nx_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
14296 +{
14297 +       return 1;
14298 +}
14299 +#endif /* CONFIG_INET */
14300 +
14301 +#endif /* __KERNEL__ */
14302 +#else  /* _VX_NETWORK_H */
14303 +#warning duplicate inclusion
14304 +#endif /* _VX_NETWORK_H */
14305 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/network_cmd.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/network_cmd.h
14306 --- linux-2.6.24-rc7/include/linux/vserver/network_cmd.h        1970-01-01 01:00:00 +0100
14307 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/network_cmd.h  2007-12-13 13:25:43 +0100
14308 @@ -0,0 +1,89 @@
14309 +#ifndef _VX_NETWORK_CMD_H
14310 +#define _VX_NETWORK_CMD_H
14311 +
14312 +
14313 +/* vinfo commands */
14314 +
14315 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
14316 +
14317 +#ifdef __KERNEL__
14318 +extern int vc_task_nid(uint32_t, void __user *);
14319 +
14320 +#endif /* __KERNEL__ */
14321 +
14322 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
14323 +
14324 +struct vcmd_nx_info_v0 {
14325 +       uint32_t nid;
14326 +       /* more to come */
14327 +};
14328 +
14329 +#ifdef __KERNEL__
14330 +extern int vc_nx_info(struct nx_info *, void __user *);
14331 +
14332 +#endif /* __KERNEL__ */
14333 +
14334 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
14335 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
14336 +
14337 +struct  vcmd_net_create {
14338 +       uint64_t flagword;
14339 +};
14340 +
14341 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
14342 +
14343 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
14344 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
14345 +
14346 +struct vcmd_net_addr_v0 {
14347 +       uint16_t type;
14348 +       uint16_t count;
14349 +       uint32_t ip[4];
14350 +       uint32_t mask[4];
14351 +       /* more to come */
14352 +};
14353 +
14354 +
14355 +#ifdef __KERNEL__
14356 +extern int vc_net_create(uint32_t, void __user *);
14357 +extern int vc_net_migrate(struct nx_info *, void __user *);
14358 +
14359 +extern int vc_net_add(struct nx_info *, void __user *);
14360 +extern int vc_net_remove(struct nx_info *, void __user *);
14361 +
14362 +#endif /* __KERNEL__ */
14363 +
14364 +
14365 +/* flag commands */
14366 +
14367 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
14368 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
14369 +
14370 +struct vcmd_net_flags_v0 {
14371 +       uint64_t flagword;
14372 +       uint64_t mask;
14373 +};
14374 +
14375 +#ifdef __KERNEL__
14376 +extern int vc_get_nflags(struct nx_info *, void __user *);
14377 +extern int vc_set_nflags(struct nx_info *, void __user *);
14378 +
14379 +#endif /* __KERNEL__ */
14380 +
14381 +
14382 +/* network caps commands */
14383 +
14384 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
14385 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
14386 +
14387 +struct vcmd_net_caps_v0 {
14388 +       uint64_t ncaps;
14389 +       uint64_t cmask;
14390 +};
14391 +
14392 +#ifdef __KERNEL__
14393 +extern int vc_get_ncaps(struct nx_info *, void __user *);
14394 +extern int vc_set_ncaps(struct nx_info *, void __user *);
14395 +
14396 +#endif /* __KERNEL__ */
14397 +#endif /* _VX_CONTEXT_CMD_H */
14398 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/percpu.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/percpu.h
14399 --- linux-2.6.24-rc7/include/linux/vserver/percpu.h     1970-01-01 01:00:00 +0100
14400 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/percpu.h       2007-12-13 13:25:51 +0100
14401 @@ -0,0 +1,14 @@
14402 +#ifndef _VX_PERCPU_H
14403 +#define _VX_PERCPU_H
14404 +
14405 +#include "cvirt_def.h"
14406 +#include "sched_def.h"
14407 +
14408 +struct _vx_percpu {
14409 +       struct _vx_cvirt_pc cvirt;
14410 +       struct _vx_sched_pc sched;
14411 +};
14412 +
14413 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
14414 +
14415 +#endif /* _VX_PERCPU_H */
14416 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/pid.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/pid.h
14417 --- linux-2.6.24-rc7/include/linux/vserver/pid.h        1970-01-01 01:00:00 +0100
14418 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/pid.h  2007-12-18 00:48:01 +0100
14419 @@ -0,0 +1,51 @@
14420 +#ifndef _VSERVER_PID_H
14421 +#define _VSERVER_PID_H
14422 +
14423 +/* pid faking stuff */
14424 +
14425 +#define vx_info_map_pid(v, p) \
14426 +       __vx_info_map_pid((v), (p), __FUNC__, __FILE__, __LINE__)
14427 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
14428 +#define vx_map_pid(p) vx_info_map_pid(current->vx_info, p)
14429 +#define vx_map_tgid(p) vx_map_pid(p)
14430 +
14431 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
14432 +       const char *func, const char *file, int line)
14433 +{
14434 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
14435 +               vxfprintk(VXD_CBIT(cvirt, 2),
14436 +                       "vx_map_tgid: %p/%llx: %d -> %d",
14437 +                       vxi, (long long)vxi->vx_flags, pid,
14438 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
14439 +                       func, file, line);
14440 +               if (pid == 0)
14441 +                       return 0;
14442 +               if (pid == vxi->vx_initpid)
14443 +                       return 1;
14444 +       }
14445 +       return pid;
14446 +}
14447 +
14448 +#define vx_info_rmap_pid(v, p) \
14449 +       __vx_info_rmap_pid((v), (p), __FUNC__, __FILE__, __LINE__)
14450 +#define vx_rmap_pid(p) vx_info_rmap_pid(current->vx_info, p)
14451 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
14452 +
14453 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
14454 +       const char *func, const char *file, int line)
14455 +{
14456 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
14457 +               vxfprintk(VXD_CBIT(cvirt, 2),
14458 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
14459 +                       vxi, (long long)vxi->vx_flags, pid,
14460 +                       (pid == 1) ? vxi->vx_initpid : pid,
14461 +                       func, file, line);
14462 +               if ((pid == 1) && vxi->vx_initpid)
14463 +                       return vxi->vx_initpid;
14464 +               if (pid == vxi->vx_initpid)
14465 +                       return ~0U;
14466 +       }
14467 +       return pid;
14468 +}
14469 +
14470 +#endif
14471 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/sched.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/sched.h
14472 --- linux-2.6.24-rc7/include/linux/vserver/sched.h      1970-01-01 01:00:00 +0100
14473 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/sched.h        2007-12-13 13:25:37 +0100
14474 @@ -0,0 +1,26 @@
14475 +#ifndef _VX_SCHED_H
14476 +#define _VX_SCHED_H
14477 +
14478 +
14479 +#ifdef __KERNEL__
14480 +
14481 +struct timespec;
14482 +
14483 +void vx_vsi_uptime(struct timespec *, struct timespec *);
14484 +
14485 +
14486 +struct vx_info;
14487 +
14488 +void vx_update_load(struct vx_info *);
14489 +
14490 +
14491 +int vx_tokens_recalc(struct _vx_sched_pc *,
14492 +       unsigned long *, unsigned long *, int [2]);
14493 +
14494 +void vx_update_sched_param(struct _vx_sched *sched,
14495 +       struct _vx_sched_pc *sched_pc);
14496 +
14497 +#endif /* __KERNEL__ */
14498 +#else  /* _VX_SCHED_H */
14499 +#warning duplicate inclusion
14500 +#endif /* _VX_SCHED_H */
14501 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/sched_cmd.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/sched_cmd.h
14502 --- linux-2.6.24-rc7/include/linux/vserver/sched_cmd.h  1970-01-01 01:00:00 +0100
14503 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/sched_cmd.h    2007-12-13 13:25:43 +0100
14504 @@ -0,0 +1,108 @@
14505 +#ifndef _VX_SCHED_CMD_H
14506 +#define _VX_SCHED_CMD_H
14507 +
14508 +
14509 +/*  sched vserver commands */
14510 +
14511 +#define VCMD_set_sched_v2      VC_CMD(SCHED, 1, 2)
14512 +#define VCMD_set_sched_v3      VC_CMD(SCHED, 1, 3)
14513 +#define VCMD_set_sched_v4      VC_CMD(SCHED, 1, 4)
14514 +
14515 +struct vcmd_set_sched_v2 {
14516 +       int32_t fill_rate;
14517 +       int32_t interval;
14518 +       int32_t tokens;
14519 +       int32_t tokens_min;
14520 +       int32_t tokens_max;
14521 +       uint64_t cpu_mask;
14522 +};
14523 +
14524 +struct vcmd_set_sched_v3 {
14525 +       uint32_t set_mask;
14526 +       int32_t fill_rate;
14527 +       int32_t interval;
14528 +       int32_t tokens;
14529 +       int32_t tokens_min;
14530 +       int32_t tokens_max;
14531 +       int32_t priority_bias;
14532 +};
14533 +
14534 +struct vcmd_set_sched_v4 {
14535 +       uint32_t set_mask;
14536 +       int32_t fill_rate;
14537 +       int32_t interval;
14538 +       int32_t tokens;
14539 +       int32_t tokens_min;
14540 +       int32_t tokens_max;
14541 +       int32_t prio_bias;
14542 +       int32_t cpu_id;
14543 +       int32_t bucket_id;
14544 +};
14545 +
14546 +#define VCMD_set_sched         VC_CMD(SCHED, 1, 5)
14547 +#define VCMD_get_sched         VC_CMD(SCHED, 2, 5)
14548 +
14549 +struct vcmd_sched_v5 {
14550 +       uint32_t mask;
14551 +       int32_t cpu_id;
14552 +       int32_t bucket_id;
14553 +       int32_t fill_rate[2];
14554 +       int32_t interval[2];
14555 +       int32_t tokens;
14556 +       int32_t tokens_min;
14557 +       int32_t tokens_max;
14558 +       int32_t prio_bias;
14559 +};
14560 +
14561 +#define VXSM_FILL_RATE         0x0001
14562 +#define VXSM_INTERVAL          0x0002
14563 +#define VXSM_FILL_RATE2                0x0004
14564 +#define VXSM_INTERVAL2         0x0008
14565 +#define VXSM_TOKENS            0x0010
14566 +#define VXSM_TOKENS_MIN                0x0020
14567 +#define VXSM_TOKENS_MAX                0x0040
14568 +#define VXSM_PRIO_BIAS         0x0100
14569 +
14570 +#define VXSM_IDLE_TIME         0x0200
14571 +#define VXSM_FORCE             0x0400
14572 +
14573 +#define        VXSM_V3_MASK            0x0173
14574 +#define        VXSM_SET_MASK           0x01FF
14575 +
14576 +#define VXSM_CPU_ID            0x1000
14577 +#define VXSM_BUCKET_ID         0x2000
14578 +
14579 +#define VXSM_MSEC              0x4000
14580 +
14581 +#define SCHED_KEEP             (-2)    /* only for v2 */
14582 +
14583 +#ifdef __KERNEL__
14584 +
14585 +#include <linux/compiler.h>
14586 +
14587 +extern int vc_set_sched_v2(struct vx_info *, void __user *);
14588 +extern int vc_set_sched_v3(struct vx_info *, void __user *);
14589 +extern int vc_set_sched_v4(struct vx_info *, void __user *);
14590 +extern int vc_set_sched(struct vx_info *, void __user *);
14591 +extern int vc_get_sched(struct vx_info *, void __user *);
14592 +
14593 +#endif /* __KERNEL__ */
14594 +
14595 +#define VCMD_sched_info                VC_CMD(SCHED, 3, 0)
14596 +
14597 +struct vcmd_sched_info {
14598 +       int32_t cpu_id;
14599 +       int32_t bucket_id;
14600 +       uint64_t user_msec;
14601 +       uint64_t sys_msec;
14602 +       uint64_t hold_msec;
14603 +       uint32_t token_usec;
14604 +       int32_t vavavoom;
14605 +};
14606 +
14607 +#ifdef __KERNEL__
14608 +
14609 +extern int vc_sched_info(struct vx_info *, void __user *);
14610 +
14611 +#endif /* __KERNEL__ */
14612 +#endif /* _VX_SCHED_CMD_H */
14613 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/sched_def.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/sched_def.h
14614 --- linux-2.6.24-rc7/include/linux/vserver/sched_def.h  1970-01-01 01:00:00 +0100
14615 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/sched_def.h    2007-12-13 13:25:43 +0100
14616 @@ -0,0 +1,68 @@
14617 +#ifndef _VX_SCHED_DEF_H
14618 +#define _VX_SCHED_DEF_H
14619 +
14620 +#include <linux/spinlock.h>
14621 +#include <linux/jiffies.h>
14622 +#include <linux/cpumask.h>
14623 +#include <asm/atomic.h>
14624 +#include <asm/param.h>
14625 +
14626 +
14627 +/* context sub struct */
14628 +
14629 +struct _vx_sched {
14630 +       spinlock_t tokens_lock;         /* lock for token bucket */
14631 +
14632 +       int tokens;                     /* number of CPU tokens */
14633 +       int fill_rate[2];               /* Fill rate: add X tokens... */
14634 +       int interval[2];                /* Divisor:   per Y jiffies   */
14635 +       int tokens_min;                 /* Limit:     minimum for unhold */
14636 +       int tokens_max;                 /* Limit:     no more than N tokens */
14637 +
14638 +       int prio_bias;                  /* bias offset for priority */
14639 +
14640 +       unsigned update_mask;           /* which features should be updated */
14641 +       cpumask_t update;               /* CPUs which should update */
14642 +};
14643 +
14644 +struct _vx_sched_pc {
14645 +       int tokens;                     /* number of CPU tokens */
14646 +       int flags;                      /* bucket flags */
14647 +
14648 +       int fill_rate[2];               /* Fill rate: add X tokens... */
14649 +       int interval[2];                /* Divisor:   per Y jiffies   */
14650 +       int tokens_min;                 /* Limit:     minimum for unhold */
14651 +       int tokens_max;                 /* Limit:     no more than N tokens */
14652 +
14653 +       int prio_bias;                  /* bias offset for priority */
14654 +       int vavavoom;                   /* last calculated vavavoom */
14655 +
14656 +       unsigned long norm_time;        /* last time accounted */
14657 +       unsigned long idle_time;        /* non linear time for fair sched */
14658 +       unsigned long token_time;       /* token time for accounting */
14659 +       unsigned long onhold;           /* jiffies when put on hold */
14660 +
14661 +       uint64_t user_ticks;            /* token tick events */
14662 +       uint64_t sys_ticks;             /* token tick events */
14663 +       uint64_t hold_ticks;            /* token ticks paused */
14664 +};
14665 +
14666 +
14667 +#define VXSF_ONHOLD    0x0001
14668 +#define VXSF_IDLE_TIME 0x0100
14669 +
14670 +#ifdef CONFIG_VSERVER_DEBUG
14671 +
14672 +static inline void __dump_vx_sched(struct _vx_sched *sched)
14673 +{
14674 +       printk("\t_vx_sched:\n");
14675 +       printk("\t tokens: %4d/%4d, %4d/%4d, %4d, %4d\n",
14676 +               sched->fill_rate[0], sched->interval[0],
14677 +               sched->fill_rate[1], sched->interval[1],
14678 +               sched->tokens_min, sched->tokens_max);
14679 +       printk("\t priority = %4d\n", sched->prio_bias);
14680 +}
14681 +
14682 +#endif
14683 +
14684 +#endif /* _VX_SCHED_DEF_H */
14685 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/signal.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/signal.h
14686 --- linux-2.6.24-rc7/include/linux/vserver/signal.h     1970-01-01 01:00:00 +0100
14687 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/signal.h       2007-12-13 13:25:38 +0100
14688 @@ -0,0 +1,14 @@
14689 +#ifndef _VX_SIGNAL_H
14690 +#define _VX_SIGNAL_H
14691 +
14692 +
14693 +#ifdef __KERNEL__
14694 +
14695 +struct vx_info;
14696 +
14697 +int vx_info_kill(struct vx_info *, int, int);
14698 +
14699 +#endif /* __KERNEL__ */
14700 +#else  /* _VX_SIGNAL_H */
14701 +#warning duplicate inclusion
14702 +#endif /* _VX_SIGNAL_H */
14703 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/signal_cmd.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/signal_cmd.h
14704 --- linux-2.6.24-rc7/include/linux/vserver/signal_cmd.h 1970-01-01 01:00:00 +0100
14705 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/signal_cmd.h   2007-12-13 13:25:43 +0100
14706 @@ -0,0 +1,43 @@
14707 +#ifndef _VX_SIGNAL_CMD_H
14708 +#define _VX_SIGNAL_CMD_H
14709 +
14710 +
14711 +/*  signalling vserver commands */
14712 +
14713 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
14714 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
14715 +
14716 +struct vcmd_ctx_kill_v0 {
14717 +       int32_t pid;
14718 +       int32_t sig;
14719 +};
14720 +
14721 +struct vcmd_wait_exit_v0 {
14722 +       int32_t reboot_cmd;
14723 +       int32_t exit_code;
14724 +};
14725 +
14726 +#ifdef __KERNEL__
14727 +
14728 +extern int vc_ctx_kill(struct vx_info *, void __user *);
14729 +extern int vc_wait_exit(struct vx_info *, void __user *);
14730 +
14731 +#endif /* __KERNEL__ */
14732 +
14733 +/*  process alteration commands */
14734 +
14735 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
14736 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
14737 +
14738 +struct vcmd_pflags_v0 {
14739 +       uint32_t flagword;
14740 +       uint32_t mask;
14741 +};
14742 +
14743 +#ifdef __KERNEL__
14744 +
14745 +extern int vc_get_pflags(uint32_t pid, void __user *);
14746 +extern int vc_set_pflags(uint32_t pid, void __user *);
14747 +
14748 +#endif /* __KERNEL__ */
14749 +#endif /* _VX_SIGNAL_CMD_H */
14750 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/space.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/space.h
14751 --- linux-2.6.24-rc7/include/linux/vserver/space.h      1970-01-01 01:00:00 +0100
14752 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/space.h        2007-12-13 13:25:49 +0100
14753 @@ -0,0 +1,13 @@
14754 +#ifndef _VX_SPACE_H
14755 +#define _VX_SPACE_H
14756 +
14757 +
14758 +#include <linux/types.h>
14759 +
14760 +struct vx_info;
14761 +
14762 +int vx_set_space(struct vx_info *vxi, unsigned long mask);
14763 +
14764 +#else  /* _VX_SPACE_H */
14765 +#warning duplicate inclusion
14766 +#endif /* _VX_SPACE_H */
14767 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/space_cmd.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/space_cmd.h
14768 --- linux-2.6.24-rc7/include/linux/vserver/space_cmd.h  1970-01-01 01:00:00 +0100
14769 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/space_cmd.h    2007-12-13 13:25:43 +0100
14770 @@ -0,0 +1,26 @@
14771 +#ifndef _VX_SPACE_CMD_H
14772 +#define _VX_SPACE_CMD_H
14773 +
14774 +
14775 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
14776 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 1)
14777 +
14778 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
14779 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 1)
14780 +
14781 +#define VCMD_get_space_mask    VC_CMD(PROCALT, 4, 0)
14782 +
14783 +
14784 +struct vcmd_space_mask {
14785 +       uint64_t mask;
14786 +};
14787 +
14788 +
14789 +#ifdef __KERNEL__
14790 +
14791 +extern int vc_enter_space(struct vx_info *, void __user *);
14792 +extern int vc_set_space(struct vx_info *, void __user *);
14793 +extern int vc_get_space_mask(struct vx_info *, void __user *);
14794 +
14795 +#endif /* __KERNEL__ */
14796 +#endif /* _VX_SPACE_CMD_H */
14797 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/switch.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/switch.h
14798 --- linux-2.6.24-rc7/include/linux/vserver/switch.h     1970-01-01 01:00:00 +0100
14799 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/switch.h       2007-12-13 13:25:30 +0100
14800 @@ -0,0 +1,95 @@
14801 +#ifndef _VX_SWITCH_H
14802 +#define _VX_SWITCH_H
14803 +
14804 +#include <linux/types.h>
14805 +
14806 +
14807 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
14808 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
14809 +#define VC_VERSION(c)          ((c) & 0xFFF)
14810 +
14811 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
14812 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
14813 +
14814 +/*
14815 +
14816 +  Syscall Matrix V2.8
14817 +
14818 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
14819 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
14820 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
14821 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14822 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICES|       |
14823 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
14824 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14825 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
14826 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
14827 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14828 +  MEMORY |       |       |       |       |       |       | |SWAP   |       |
14829 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
14830 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14831 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
14832 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
14833 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14834 +  DISK   |       |       |       |       |DLIMIT |       | |INODE  |       |
14835 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
14836 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14837 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
14838 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
14839 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
14840 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |       |       |
14841 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
14842 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14843 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
14844 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
14845 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14846 +
14847 +*/
14848 +
14849 +#define VC_CAT_VERSION         0
14850 +
14851 +#define VC_CAT_VSETUP          1
14852 +#define VC_CAT_VHOST           2
14853 +
14854 +#define VC_CAT_VPROC           9
14855 +#define VC_CAT_PROCALT         10
14856 +#define VC_CAT_PROCMIG         11
14857 +#define VC_CAT_PROCTRL         12
14858 +
14859 +#define VC_CAT_SCHED           14
14860 +
14861 +#define VC_CAT_VNET            25
14862 +#define VC_CAT_NETALT          26
14863 +#define VC_CAT_NETMIG          27
14864 +#define VC_CAT_NETCTRL         28
14865 +
14866 +#define VC_CAT_DLIMIT          36
14867 +#define VC_CAT_INODE           38
14868 +
14869 +#define VC_CAT_VSTAT           40
14870 +#define VC_CAT_VINFO           46
14871 +#define VC_CAT_EVENT           48
14872 +
14873 +#define VC_CAT_FLAGS           52
14874 +#define VC_CAT_DEBUG           56
14875 +#define VC_CAT_RLIMIT          60
14876 +
14877 +#define VC_CAT_SYSTEST         61
14878 +#define VC_CAT_COMPAT          63
14879 +
14880 +/*  query version */
14881 +
14882 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
14883 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
14884 +
14885 +
14886 +#ifdef __KERNEL__
14887 +
14888 +#include <linux/errno.h>
14889 +
14890 +
14891 +#else  /* __KERNEL__ */
14892 +#define __user
14893 +#endif /* __KERNEL__ */
14894 +
14895 +#endif /* _VX_SWITCH_H */
14896 diff -NurpP --minimal linux-2.6.24-rc7/include/linux/vserver/tag.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/tag.h
14897 --- linux-2.6.24-rc7/include/linux/vserver/tag.h        1970-01-01 01:00:00 +0100
14898 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/linux/vserver/tag.h  2007-12-13 13:25:41 +0100
14899 @@ -0,0 +1,140 @@
14900 +#ifndef _DX_TAG_H
14901 +#define _DX_TAG_H
14902 +
14903 +
14904 +#define DX_TAG(in)     (IS_TAGGED(in))
14905 +
14906 +
14907 +#ifdef CONFIG_DX_TAG_NFSD
14908 +#define DX_TAG_NFSD    1
14909 +#else
14910 +#define DX_TAG_NFSD    0
14911 +#endif
14912 +
14913 +
14914 +#ifdef CONFIG_TAGGING_NONE
14915 +
14916 +#define MAX_UID                0xFFFFFFFF
14917 +#define MAX_GID                0xFFFFFFFF
14918 +
14919 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
14920 +
14921 +#define TAGINO_UID(cond, uid, tag)     (uid)
14922 +#define TAGINO_GID(cond, gid, tag)     (gid)
14923 +
14924 +#endif
14925 +
14926 +
14927 +#ifdef CONFIG_TAGGING_GID16
14928 +
14929 +#define MAX_UID                0xFFFFFFFF
14930 +#define MAX_GID                0x0000FFFF
14931 +
14932 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14933 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
14934 +
14935 +#define TAGINO_UID(cond, uid, tag)     (uid)
14936 +#define TAGINO_GID(cond, gid, tag)     \
14937 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
14938 +
14939 +#endif
14940 +
14941 +
14942 +#ifdef CONFIG_TAGGING_ID24
14943 +
14944 +#define MAX_UID                0x00FFFFFF
14945 +#define MAX_GID                0x00FFFFFF
14946 +
14947 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14948 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
14949 +
14950 +#define TAGINO_UID(cond, uid, tag)     \
14951 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
14952 +#define TAGINO_GID(cond, gid, tag)     \
14953 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
14954 +
14955 +#endif
14956 +
14957 +
14958 +#ifdef CONFIG_TAGGING_UID16
14959 +
14960 +#define MAX_UID                0x0000FFFF
14961 +#define MAX_GID                0xFFFFFFFF
14962 +
14963 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14964 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
14965 +
14966 +#define TAGINO_UID(cond, uid, tag)     \
14967 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
14968 +#define TAGINO_GID(cond, gid, tag)     (gid)
14969 +
14970 +#endif
14971 +
14972 +
14973 +#ifdef CONFIG_TAGGING_INTERN
14974 +
14975 +#define MAX_UID                0xFFFFFFFF
14976 +#define MAX_GID                0xFFFFFFFF
14977 +
14978 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14979 +       ((cond) ? (tag) : 0)
14980 +
14981 +#define TAGINO_UID(cond, uid, tag)     (uid)
14982 +#define TAGINO_GID(cond, gid, tag)     (gid)
14983 +
14984 +#endif
14985 +
14986 +
14987 +#ifndef CONFIG_TAGGING_NONE
14988 +#define dx_current_fstag(sb)   \
14989 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
14990 +#else
14991 +#define dx_current_fstag(sb)   (0)
14992 +#endif
14993 +
14994 +#ifndef CONFIG_TAGGING_INTERN
14995 +#define TAGINO_TAG(cond, tag)  (0)
14996 +#else
14997 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
14998 +#endif
14999 +
15000 +#define INOTAG_UID(cond, uid, gid)     \
15001 +       ((cond) ? ((uid) & MAX_UID) : (uid))
15002 +#define INOTAG_GID(cond, uid, gid)     \
15003 +       ((cond) ? ((gid) & MAX_GID) : (gid))
15004 +
15005 +
15006 +static inline uid_t dx_map_uid(uid_t uid)
15007 +{
15008 +       if ((uid > MAX_UID) && (uid != -1))
15009 +               uid = -2;
15010 +       return (uid & MAX_UID);
15011 +}
15012 +
15013 +static inline gid_t dx_map_gid(gid_t gid)
15014 +{
15015 +       if ((gid > MAX_GID) && (gid != -1))
15016 +               gid = -2;
15017 +       return (gid & MAX_GID);
15018 +}
15019 +
15020 +
15021 +#ifdef CONFIG_VSERVER_LEGACY
15022 +#define FIOC_GETTAG    _IOR('x', 1, long)
15023 +#define FIOC_SETTAG    _IOW('x', 2, long)
15024 +#define FIOC_SETTAGJ   _IOW('x', 3, long)
15025 +#endif
15026 +
15027 +#ifdef CONFIG_PROPAGATE
15028 +
15029 +int dx_parse_tag(char *string, tag_t *tag, int remove);
15030 +
15031 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
15032 +
15033 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
15034 +
15035 +#else
15036 +#define dx_propagate_tag(n, i) do { } while (0)
15037 +#endif
15038 +
15039 +#endif /* _DX_TAG_H */
15040 diff -NurpP --minimal linux-2.6.24-rc7/include/net/af_unix.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/net/af_unix.h
15041 --- linux-2.6.24-rc7/include/net/af_unix.h      2007-11-29 01:12:26 +0100
15042 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/net/af_unix.h        2007-12-13 13:25:30 +0100
15043 @@ -4,6 +4,7 @@
15044  #include <linux/socket.h>
15045  #include <linux/un.h>
15046  #include <linux/mutex.h>
15047 +#include <linux/vs_base.h>
15048  #include <net/sock.h>
15049  
15050  extern void unix_inflight(struct file *fp);
15051 diff -NurpP --minimal linux-2.6.24-rc7/include/net/inet_hashtables.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/net/inet_hashtables.h
15052 --- linux-2.6.24-rc7/include/net/inet_hashtables.h      2007-12-31 17:58:28 +0100
15053 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/net/inet_hashtables.h        2007-12-31 12:34:43 +0100
15054 @@ -323,6 +323,26 @@ out:
15055                 wake_up(&hashinfo->lhash_wait);
15056  }
15057  
15058 +/*
15059 + *      Check if a given address matches for an inet socket
15060 + *
15061 + *      nxi:   the socket's nx_info if any
15062 + *      addr:  to be verified address
15063 + *      saddr: socket addresses
15064 + */
15065 +static inline int inet_addr_match (
15066 +       struct nx_info *nxi,
15067 +       uint32_t addr,
15068 +       uint32_t saddr)
15069 +{
15070 +       if (addr && (saddr == addr))
15071 +               return 1;
15072 +       if (!saddr)
15073 +               return addr_in_nx_info(nxi, addr);
15074 +       return 0;
15075 +}
15076 +
15077 +
15078  extern struct sock *__inet_lookup_listener(struct inet_hashinfo *hashinfo,
15079                                            const __be32 daddr,
15080                                            const unsigned short hnum,
15081 diff -NurpP --minimal linux-2.6.24-rc7/include/net/inet_sock.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/net/inet_sock.h
15082 --- linux-2.6.24-rc7/include/net/inet_sock.h    2007-11-29 01:12:26 +0100
15083 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/net/inet_sock.h      2007-12-13 16:56:23 +0100
15084 @@ -114,6 +114,7 @@ struct inet_sock {
15085         /* Socket demultiplex comparisons on incoming packets. */
15086         __be32                  daddr;
15087         __be32                  rcv_saddr;
15088 +       __be32                  rcv_saddr2;     /* Second bound ipv4 addr, for ipv4root */
15089         __be16                  dport;
15090         __u16                   num;
15091         __be32                  saddr;
15092 @@ -194,7 +195,9 @@ static inline int inet_sk_ehashfn(const 
15093  
15094  static inline int inet_iif(const struct sk_buff *skb)
15095  {
15096 -       return ((struct rtable *)skb->dst)->rt_iif;
15097 +       struct rtable *rt = (struct rtable *)skb->dst;
15098 +
15099 +       return rt->rt_iif;
15100  }
15101  
15102  #endif /* _INET_SOCK_H */
15103 diff -NurpP --minimal linux-2.6.24-rc7/include/net/inet_timewait_sock.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/net/inet_timewait_sock.h
15104 --- linux-2.6.24-rc7/include/net/inet_timewait_sock.h   2007-11-29 01:12:26 +0100
15105 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/net/inet_timewait_sock.h     2007-12-13 13:25:30 +0100
15106 @@ -116,6 +116,10 @@ struct inet_timewait_sock {
15107  #define tw_hash                        __tw_common.skc_hash
15108  #define tw_prot                        __tw_common.skc_prot
15109  #define tw_net                 __tw_common.skc_net
15110 +#define tw_xid                 __tw_common.skc_xid
15111 +#define tw_vx_info             __tw_common.skc_vx_info
15112 +#define tw_nid                 __tw_common.skc_nid
15113 +#define tw_nx_info             __tw_common.skc_nx_info
15114         volatile unsigned char  tw_substate;
15115         /* 3 bits hole, try to pack */
15116         unsigned char           tw_rcv_wscale;
15117 diff -NurpP --minimal linux-2.6.24-rc7/include/net/route.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/net/route.h
15118 --- linux-2.6.24-rc7/include/net/route.h        2007-12-31 17:58:28 +0100
15119 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/net/route.h  2008-01-11 00:33:42 +0100
15120 @@ -27,12 +27,16 @@
15121  #include <net/dst.h>
15122  #include <net/inetpeer.h>
15123  #include <net/flow.h>
15124 +#include <net/sock.h>
15125  #include <linux/in_route.h>
15126  #include <linux/rtnetlink.h>
15127  #include <linux/route.h>
15128  #include <linux/ip.h>
15129  #include <linux/cache.h>
15130  #include <linux/security.h>
15131 +#include <linux/vs_base.h>
15132 +#include <linux/vs_network.h>
15133 +#include <linux/in.h>
15134  
15135  #ifndef __KERNEL__
15136  #warning This file is not supposed to be used outside of kernel.
15137 @@ -141,6 +145,59 @@ static inline char rt_tos2priority(u8 to
15138         return ip_tos2prio[IPTOS_TOS(tos)>>1];
15139  }
15140  
15141 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
15142 +
15143 +static inline int ip_find_src(struct nx_info *nxi, struct rtable **rp, struct flowi *fl)
15144 +{
15145 +       int err;
15146 +       int i, n = nxi->nbipv4;
15147 +       u32 ipv4root = nxi->ipv4[0];
15148 +
15149 +       if (ipv4root == 0)
15150 +               return 0;
15151 +
15152 +       if (fl->fl4_src == 0) {
15153 +               if (n > 1) {
15154 +                       u32 foundsrc;
15155 +
15156 +                       err = __ip_route_output_key(rp, fl);
15157 +                       if (err) {
15158 +                               fl->fl4_src = ipv4root;
15159 +                               err = __ip_route_output_key(rp, fl);
15160 +                       }
15161 +                       if (err)
15162 +                               return err;
15163 +
15164 +                       foundsrc = (*rp)->rt_src;
15165 +                       ip_rt_put(*rp);
15166 +
15167 +                       for (i=0; i<n; i++){
15168 +                               u32 mask = nxi->mask[i];
15169 +                               u32 ipv4 = nxi->ipv4[i];
15170 +                               u32 net4 = ipv4 & mask;
15171 +
15172 +                               if (foundsrc == ipv4) {
15173 +                                       fl->fl4_src = ipv4;
15174 +                                       break;
15175 +                               }
15176 +                               if (!fl->fl4_src && (foundsrc & mask) == net4)
15177 +                                       fl->fl4_src = ipv4;
15178 +                       }
15179 +               }
15180 +               if (fl->fl4_src == 0)
15181 +                       fl->fl4_src = (fl->fl4_dst == IPI_LOOPBACK)
15182 +                               ? IPI_LOOPBACK : ipv4root;
15183 +       } else {
15184 +               for (i=0; i<n; i++) {
15185 +                       if (nxi->ipv4[i] == fl->fl4_src)
15186 +                               break;
15187 +               }
15188 +               if (i == n)
15189 +                       return -EPERM;
15190 +       }
15191 +       return 0;
15192 +}
15193 +
15194  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
15195                                    __be32 src, u32 tos, int oif, u8 protocol,
15196                                    __be16 sport, __be16 dport, struct sock *sk,
15197 @@ -156,7 +213,27 @@ static inline int ip_route_connect(struc
15198                                          .dport = dport } } };
15199  
15200         int err;
15201 -       if (!dst || !src) {
15202 +       struct nx_info *nx_info = current->nx_info;
15203 +
15204 +       if (sk)
15205 +               nx_info = sk->sk_nx_info;
15206 +       vxdprintk(VXD_CBIT(net, 4),
15207 +               "ip_route_connect(%p) %p,%p;%lx",
15208 +               sk, nx_info, sk->sk_socket,
15209 +               (sk->sk_socket?sk->sk_socket->flags:0));
15210 +
15211 +       if (nx_info) {
15212 +               err = ip_find_src(nx_info, rp, &fl);
15213 +               if (err)
15214 +                       return err;
15215 +               if (fl.fl4_dst == IPI_LOOPBACK && !nx_check(0, VS_ADMIN))
15216 +                       fl.fl4_dst = nx_info->ipv4[0];
15217 +#ifdef CONFIG_VSERVER_REMAP_SADDR
15218 +               if (fl.fl4_src == IPI_LOOPBACK && !nx_check(0, VS_ADMIN))
15219 +                       fl.fl4_src = nx_info->ipv4[0];
15220 +#endif
15221 +       }
15222 +       if (!fl.fl4_dst || !fl.fl4_src) {
15223                 err = __ip_route_output_key(rp, &fl);
15224                 if (err)
15225                         return err;
15226 diff -NurpP --minimal linux-2.6.24-rc7/include/net/sock.h linux-2.6.24-rc7-vs2.2.0.5.0.7/include/net/sock.h
15227 --- linux-2.6.24-rc7/include/net/sock.h 2007-12-31 17:58:28 +0100
15228 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/include/net/sock.h   2007-12-31 12:34:43 +0100
15229 @@ -122,6 +122,10 @@ struct sock_common {
15230         unsigned int            skc_hash;
15231         struct proto            *skc_prot;
15232         struct net              *skc_net;
15233 +       xid_t                   skc_xid;
15234 +       struct vx_info          *skc_vx_info;
15235 +       nid_t                   skc_nid;
15236 +       struct nx_info          *skc_nx_info;
15237  };
15238  
15239  /**
15240 @@ -199,6 +203,10 @@ struct sock {
15241  #define sk_hash                        __sk_common.skc_hash
15242  #define sk_prot                        __sk_common.skc_prot
15243  #define sk_net                 __sk_common.skc_net
15244 +#define sk_xid                 __sk_common.skc_xid
15245 +#define sk_vx_info             __sk_common.skc_vx_info
15246 +#define sk_nid                 __sk_common.skc_nid
15247 +#define sk_nx_info             __sk_common.skc_nx_info
15248         unsigned char           sk_shutdown : 2,
15249                                 sk_no_check : 2,
15250                                 sk_userlocks : 4;
15251 diff -NurpP --minimal linux-2.6.24-rc7/init/main.c linux-2.6.24-rc7-vs2.2.0.5.0.7/init/main.c
15252 --- linux-2.6.24-rc7/init/main.c        2007-11-29 01:12:30 +0100
15253 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/init/main.c  2007-12-13 13:25:51 +0100
15254 @@ -57,6 +57,7 @@
15255  #include <linux/device.h>
15256  #include <linux/kthread.h>
15257  #include <linux/sched.h>
15258 +#include <linux/vserver/percpu.h>
15259  
15260  #include <asm/io.h>
15261  #include <asm/bugs.h>
15262 @@ -370,12 +371,14 @@ EXPORT_SYMBOL(__per_cpu_offset);
15263  
15264  static void __init setup_per_cpu_areas(void)
15265  {
15266 -       unsigned long size, i;
15267 +       unsigned long size, vspc, i;
15268         char *ptr;
15269         unsigned long nr_possible_cpus = num_possible_cpus();
15270  
15271 +       vspc = PERCPU_PERCTX * CONFIG_VSERVER_CONTEXTS;
15272 +
15273         /* Copy section for each CPU (we discard the original) */
15274 -       size = ALIGN(PERCPU_ENOUGH_ROOM, PAGE_SIZE);
15275 +       size = ALIGN(PERCPU_ENOUGH_ROOM + vspc, PAGE_SIZE);
15276         ptr = alloc_bootmem_pages(size * nr_possible_cpus);
15277  
15278         for_each_possible_cpu(i) {
15279 diff -NurpP --minimal linux-2.6.24-rc7/ipc/mqueue.c linux-2.6.24-rc7-vs2.2.0.5.0.7/ipc/mqueue.c
15280 --- linux-2.6.24-rc7/ipc/mqueue.c       2007-12-31 17:58:28 +0100
15281 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/ipc/mqueue.c 2008-01-01 18:20:23 +0100
15282 @@ -31,6 +31,8 @@
15283  #include <linux/mutex.h>
15284  #include <linux/nsproxy.h>
15285  #include <linux/pid.h>
15286 +#include <linux/vs_context.h>
15287 +#include <linux/vs_limit.h>
15288  
15289  #include <net/sock.h>
15290  #include "util.h"
15291 @@ -71,6 +73,7 @@ struct mqueue_inode_info {
15292         struct sigevent notify;
15293         struct pid* notify_owner;
15294         struct user_struct *user;       /* user who created, for accounting */
15295 +       struct vx_info *vxi;
15296         struct sock *notify_sock;
15297         struct sk_buff *notify_cookie;
15298  
15299 @@ -119,6 +122,7 @@ static struct inode *mqueue_get_inode(st
15300                         struct mqueue_inode_info *info;
15301                         struct task_struct *p = current;
15302                         struct user_struct *u = p->user;
15303 +                       struct vx_info *vxi = p->vx_info;
15304                         unsigned long mq_bytes, mq_msg_tblsz;
15305  
15306                         inode->i_fop = &mqueue_file_operations;
15307 @@ -133,6 +137,7 @@ static struct inode *mqueue_get_inode(st
15308                         info->notify_owner = NULL;
15309                         info->qsize = 0;
15310                         info->user = NULL;      /* set when all is ok */
15311 +                       info->vxi = NULL;
15312                         memset(&info->attr, 0, sizeof(info->attr));
15313                         info->attr.mq_maxmsg = DFLT_MSGMAX;
15314                         info->attr.mq_msgsize = DFLT_MSGSIZEMAX;
15315 @@ -147,22 +152,26 @@ static struct inode *mqueue_get_inode(st
15316                         spin_lock(&mq_lock);
15317                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
15318                             u->mq_bytes + mq_bytes >
15319 -                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur) {
15320 +                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur ||
15321 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
15322                                 spin_unlock(&mq_lock);
15323                                 goto out_inode;
15324                         }
15325                         u->mq_bytes += mq_bytes;
15326 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
15327                         spin_unlock(&mq_lock);
15328  
15329                         info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
15330                         if (!info->messages) {
15331                                 spin_lock(&mq_lock);
15332                                 u->mq_bytes -= mq_bytes;
15333 +                               vx_ipcmsg_sub(vxi, u, mq_bytes);
15334                                 spin_unlock(&mq_lock);
15335                                 goto out_inode;
15336                         }
15337                         /* all is ok */
15338                         info->user = get_uid(u);
15339 +                       info->vxi = get_vx_info(vxi);
15340                 } else if (S_ISDIR(mode)) {
15341                         inc_nlink(inode);
15342                         /* Some things misbehave if size == 0 on a directory */
15343 @@ -253,10 +262,14 @@ static void mqueue_delete_inode(struct i
15344                    (info->attr.mq_maxmsg * info->attr.mq_msgsize));
15345         user = info->user;
15346         if (user) {
15347 +               struct vx_info *vxi = info->vxi;
15348 +
15349                 spin_lock(&mq_lock);
15350                 user->mq_bytes -= mq_bytes;
15351 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
15352                 queues_count--;
15353                 spin_unlock(&mq_lock);
15354 +               put_vx_info(vxi);
15355                 free_uid(user);
15356         }
15357  }
15358 @@ -744,7 +757,7 @@ asmlinkage long sys_mq_unlink(const char
15359         if (inode)
15360                 atomic_inc(&inode->i_count);
15361  
15362 -       err = vfs_unlink(dentry->d_parent->d_inode, dentry);
15363 +       err = vfs_unlink(dentry->d_parent->d_inode, dentry, NULL);
15364  out_err:
15365         dput(dentry);
15366  
15367 diff -NurpP --minimal linux-2.6.24-rc7/ipc/msg.c linux-2.6.24-rc7-vs2.2.0.5.0.7/ipc/msg.c
15368 --- linux-2.6.24-rc7/ipc/msg.c  2007-11-29 01:12:30 +0100
15369 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/ipc/msg.c    2007-12-13 13:25:48 +0100
15370 @@ -36,6 +36,7 @@
15371  #include <linux/seq_file.h>
15372  #include <linux/rwsem.h>
15373  #include <linux/nsproxy.h>
15374 +#include <linux/vs_base.h>
15375  
15376  #include <asm/current.h>
15377  #include <asm/uaccess.h>
15378 @@ -191,6 +192,7 @@ static int newque(struct ipc_namespace *
15379  
15380         msq->q_perm.mode = msgflg & S_IRWXUGO;
15381         msq->q_perm.key = key;
15382 +       msq->q_perm.xid = vx_current_xid();
15383  
15384         msq->q_perm.security = NULL;
15385         retval = security_msg_queue_alloc(msq);
15386 diff -NurpP --minimal linux-2.6.24-rc7/ipc/sem.c linux-2.6.24-rc7-vs2.2.0.5.0.7/ipc/sem.c
15387 --- linux-2.6.24-rc7/ipc/sem.c  2007-11-29 01:12:30 +0100
15388 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/ipc/sem.c    2007-12-13 13:25:48 +0100
15389 @@ -82,6 +82,8 @@
15390  #include <linux/seq_file.h>
15391  #include <linux/rwsem.h>
15392  #include <linux/nsproxy.h>
15393 +#include <linux/vs_base.h>
15394 +#include <linux/vs_limit.h>
15395  
15396  #include <asm/uaccess.h>
15397  #include "util.h"
15398 @@ -274,6 +276,7 @@ static int newary(struct ipc_namespace *
15399  
15400         sma->sem_perm.mode = (semflg & S_IRWXUGO);
15401         sma->sem_perm.key = key;
15402 +       sma->sem_perm.xid = vx_current_xid();
15403  
15404         sma->sem_perm.security = NULL;
15405         retval = security_sem_alloc(sma);
15406 @@ -289,6 +292,9 @@ static int newary(struct ipc_namespace *
15407                 return id;
15408         }
15409         ns->used_sems += nsems;
15410 +       /* FIXME: obsoleted? */
15411 +       vx_semary_inc(sma);
15412 +       vx_nsems_add(sma, nsems);
15413  
15414         sma->sem_perm.id = sem_buildid(id, sma->sem_perm.seq);
15415         sma->sem_base = (struct sem *) &sma[1];
15416 diff -NurpP --minimal linux-2.6.24-rc7/ipc/shm.c linux-2.6.24-rc7-vs2.2.0.5.0.7/ipc/shm.c
15417 --- linux-2.6.24-rc7/ipc/shm.c  2007-11-29 01:12:30 +0100
15418 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/ipc/shm.c    2007-12-13 13:25:48 +0100
15419 @@ -38,6 +38,8 @@
15420  #include <linux/rwsem.h>
15421  #include <linux/nsproxy.h>
15422  #include <linux/mount.h>
15423 +#include <linux/vs_context.h>
15424 +#include <linux/vs_limit.h>
15425  
15426  #include <asm/uaccess.h>
15427  
15428 @@ -218,7 +220,12 @@ static void shm_open(struct vm_area_stru
15429   */
15430  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
15431  {
15432 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15433 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
15434 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15435 +
15436 +       vx_ipcshm_sub(vxi, shp, numpages);
15437 +       ns->shm_tot -= numpages;
15438 +
15439         shm_rmid(ns, shp);
15440         shm_unlock(shp);
15441         if (!is_file_hugepages(shp->shm_file))
15442 @@ -228,6 +235,7 @@ static void shm_destroy(struct ipc_names
15443                                                 shp->mlock_user);
15444         fput (shp->shm_file);
15445         security_shm_free(shp);
15446 +       put_vx_info(vxi);
15447         ipc_rcu_putref(shp);
15448  }
15449  
15450 @@ -398,11 +406,15 @@ static int newseg(struct ipc_namespace *
15451         if (ns->shm_tot + numpages > ns->shm_ctlall)
15452                 return -ENOSPC;
15453  
15454 +       if (!vx_ipcshm_avail(current->vx_info, numpages))
15455 +               return -ENOSPC;
15456 +
15457         shp = ipc_rcu_alloc(sizeof(*shp));
15458         if (!shp)
15459                 return -ENOMEM;
15460  
15461         shp->shm_perm.key = key;
15462 +       shp->shm_perm.xid = vx_current_xid();
15463         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
15464         shp->mlock_user = NULL;
15465  
15466 @@ -456,6 +468,7 @@ static int newseg(struct ipc_namespace *
15467         ns->shm_tot += numpages;
15468         error = shp->shm_perm.id;
15469         shm_unlock(shp);
15470 +       vx_ipcshm_add(current->vx_info, key, numpages);
15471         return error;
15472  
15473  no_id:
15474 diff -NurpP --minimal linux-2.6.24-rc7/ipc/util.c linux-2.6.24-rc7-vs2.2.0.5.0.7/ipc/util.c
15475 --- linux-2.6.24-rc7/ipc/util.c 2007-11-29 01:12:30 +0100
15476 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/ipc/util.c   2007-12-13 13:25:48 +0100
15477 @@ -33,6 +33,8 @@
15478  #include <linux/audit.h>
15479  #include <linux/nsproxy.h>
15480  #include <linux/rwsem.h>
15481 +#include <linux/vs_base.h>
15482 +#include <linux/vserver/global.h>
15483  
15484  #include <asm/unistd.h>
15485  
15486 @@ -72,6 +74,7 @@ static struct ipc_namespace *clone_ipc_n
15487                 goto err_shm;
15488  
15489         kref_init(&ns->kref);
15490 +       atomic_inc(&vs_global_ipc_ns);
15491         return ns;
15492  
15493  err_shm:
15494 @@ -108,6 +111,7 @@ void free_ipc_ns(struct kref *kref)
15495         sem_exit_ns(ns);
15496         msg_exit_ns(ns);
15497         shm_exit_ns(ns);
15498 +       atomic_dec(&vs_global_ipc_ns);
15499         kfree(ns);
15500  }
15501  
15502 diff -NurpP --minimal linux-2.6.24-rc7/kernel/Makefile linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/Makefile
15503 --- linux-2.6.24-rc7/kernel/Makefile    2007-11-29 01:12:30 +0100
15504 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/Makefile      2007-12-13 13:25:26 +0100
15505 @@ -11,6 +11,8 @@ obj-y     = sched.o fork.o exec_domain.o
15506             hrtimer.o rwsem.o latency.o nsproxy.o srcu.o \
15507             utsname.o notifier.o
15508  
15509 +obj-y += vserver/
15510 +
15511  obj-$(CONFIG_SYSCTL) += sysctl_check.o
15512  obj-$(CONFIG_STACKTRACE) += stacktrace.o
15513  obj-y += time/
15514 diff -NurpP --minimal linux-2.6.24-rc7/kernel/capability.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/capability.c
15515 --- linux-2.6.24-rc7/kernel/capability.c        2007-11-29 01:12:30 +0100
15516 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/capability.c  2007-12-13 13:25:43 +0100
15517 @@ -13,6 +13,7 @@
15518  #include <linux/security.h>
15519  #include <linux/syscalls.h>
15520  #include <linux/pid_namespace.h>
15521 +#include <linux/vs_context.h>
15522  #include <asm/uaccess.h>
15523  
15524  /*
15525 @@ -98,6 +99,8 @@ static inline int cap_set_pg(int pgrp_nr
15526  
15527         pgrp = find_vpid(pgrp_nr);
15528         do_each_pid_task(pgrp, PIDTYPE_PGID, g) {
15529 +               if (!vx_check(g->xid, VS_ADMIN_P | VS_IDENT))
15530 +                       continue;
15531                 target = g;
15532                 while_each_thread(g, target) {
15533                         if (!security_capset_check(target, effective,
15534 @@ -240,8 +243,12 @@ int __capable(struct task_struct *t, int
15535         return 0;
15536  }
15537  
15538 +#include <linux/vserver/base.h>
15539  int capable(int cap)
15540  {
15541 +       /* here for now so we don't require task locking */
15542 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
15543 +               return 0;
15544         return __capable(current, cap);
15545  }
15546  EXPORT_SYMBOL(capable);
15547 diff -NurpP --minimal linux-2.6.24-rc7/kernel/cgroup.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/cgroup.c
15548 --- linux-2.6.24-rc7/kernel/cgroup.c    2007-11-29 01:12:30 +0100
15549 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/cgroup.c      2007-12-13 16:01:10 +0100
15550 @@ -2611,7 +2611,7 @@ int cgroup_clone(struct task_struct *tsk
15551         }
15552  
15553         /* Create the cgroup directory, which also creates the cgroup */
15554 -       ret = vfs_mkdir(inode, dentry, S_IFDIR | 0755);
15555 +       ret = vfs_mkdir(inode, dentry, S_IFDIR | 0755, NULL);
15556         child = __d_cgrp(dentry);
15557         dput(dentry);
15558         if (ret) {
15559 diff -NurpP --minimal linux-2.6.24-rc7/kernel/compat.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/compat.c
15560 --- linux-2.6.24-rc7/kernel/compat.c    2007-11-29 01:12:30 +0100
15561 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/compat.c      2007-12-13 13:25:36 +0100
15562 @@ -811,7 +811,7 @@ asmlinkage long compat_sys_time(compat_t
15563         compat_time_t i;
15564         struct timeval tv;
15565  
15566 -       do_gettimeofday(&tv);
15567 +       vx_gettimeofday(&tv);
15568         i = tv.tv_sec;
15569  
15570         if (tloc) {
15571 @@ -835,7 +835,7 @@ asmlinkage long compat_sys_stime(compat_
15572         if (err)
15573                 return err;
15574  
15575 -       do_settimeofday(&tv);
15576 +       vx_settimeofday(&tv);
15577         return 0;
15578  }
15579  
15580 diff -NurpP --minimal linux-2.6.24-rc7/kernel/exit.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/exit.c
15581 --- linux-2.6.24-rc7/kernel/exit.c      2007-12-31 17:58:28 +0100
15582 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/exit.c        2007-12-31 12:45:36 +0100
15583 @@ -44,6 +44,11 @@
15584  #include <linux/resource.h>
15585  #include <linux/blkdev.h>
15586  #include <linux/task_io_accounting_ops.h>
15587 +#include <linux/vs_limit.h>
15588 +#include <linux/vs_context.h>
15589 +#include <linux/vs_network.h>
15590 +#include <linux/vs_pid.h>
15591 +#include <linux/vserver/global.h>
15592  
15593  #include <asm/uaccess.h>
15594  #include <asm/unistd.h>
15595 @@ -440,9 +445,11 @@ static void close_files(struct files_str
15596                                         filp_close(file, files);
15597                                         cond_resched();
15598                                 }
15599 +                               vx_openfd_dec(i);
15600                         }
15601                         i++;
15602                         set >>= 1;
15603 +                       cond_resched();
15604                 }
15605         }
15606  }
15607 @@ -522,6 +529,7 @@ static void __put_fs_struct(struct fs_st
15608                         dput(fs->altroot);
15609                         mntput(fs->altrootmnt);
15610                 }
15611 +               atomic_dec(&vs_global_fs);
15612                 kmem_cache_free(fs_cachep, fs);
15613         }
15614  }
15615 @@ -1010,6 +1018,8 @@ fastcall NORET_TYPE void do_exit(long co
15616                 module_put(tsk->binfmt->module);
15617  
15618         proc_exit_connector(tsk);
15619 +       /* needs to stay before exit_notify() */
15620 +       exit_vx_info_early(tsk, code);
15621         exit_notify(tsk);
15622  #ifdef CONFIG_NUMA
15623         mpol_free(tsk->mempolicy);
15624 @@ -1042,6 +1052,10 @@ fastcall NORET_TYPE void do_exit(long co
15625         if (tsk->splice_pipe)
15626                 __free_pipe_info(tsk->splice_pipe);
15627  
15628 +       /* needs to stay after exit_notify() */
15629 +       exit_vx_info(tsk, code);
15630 +       exit_nx_info(tsk);
15631 +
15632         preempt_disable();
15633         /* causes final put_task_struct in finish_task_switch(). */
15634         tsk->state = TASK_DEAD;
15635 diff -NurpP --minimal linux-2.6.24-rc7/kernel/fork.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/fork.c
15636 --- linux-2.6.24-rc7/kernel/fork.c      2007-12-31 17:58:28 +0100
15637 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/fork.c        2007-12-31 12:45:36 +0100
15638 @@ -51,6 +51,11 @@
15639  #include <linux/random.h>
15640  #include <linux/tty.h>
15641  #include <linux/proc_fs.h>
15642 +#include <linux/vs_context.h>
15643 +#include <linux/vs_network.h>
15644 +#include <linux/vs_limit.h>
15645 +#include <linux/vs_memory.h>
15646 +#include <linux/vserver/global.h>
15647  
15648  #include <asm/pgtable.h>
15649  #include <asm/pgalloc.h>
15650 @@ -111,6 +116,8 @@ void free_task(struct task_struct *tsk)
15651         prop_local_destroy_single(&tsk->dirties);
15652         free_thread_info(tsk->stack);
15653         rt_mutex_debug_task_free(tsk);
15654 +       clr_vx_info(&tsk->vx_info);
15655 +       clr_nx_info(&tsk->nx_info);
15656         free_task_struct(tsk);
15657  }
15658  EXPORT_SYMBOL(free_task);
15659 @@ -227,6 +234,8 @@ static int dup_mmap(struct mm_struct *mm
15660         mm->free_area_cache = oldmm->mmap_base;
15661         mm->cached_hole_size = ~0UL;
15662         mm->map_count = 0;
15663 +       __set_mm_counter(mm, file_rss, 0);
15664 +       __set_mm_counter(mm, anon_rss, 0);
15665         cpus_clear(mm->cpu_vm_mask);
15666         mm->mm_rb = RB_ROOT;
15667         rb_link = &mm->mm_rb.rb_node;
15668 @@ -238,7 +247,7 @@ static int dup_mmap(struct mm_struct *mm
15669  
15670                 if (mpnt->vm_flags & VM_DONTCOPY) {
15671                         long pages = vma_pages(mpnt);
15672 -                       mm->total_vm -= pages;
15673 +                       vx_vmpages_sub(mm, pages);
15674                         vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
15675                                                                 -pages);
15676                         continue;
15677 @@ -339,7 +348,7 @@ __cacheline_aligned_in_smp DEFINE_SPINLO
15678  
15679  #include <linux/init_task.h>
15680  
15681 -static struct mm_struct * mm_init(struct mm_struct * mm)
15682 +static struct mm_struct * mm_init(struct mm_struct * mm, struct vx_info *vxi)
15683  {
15684         atomic_set(&mm->mm_users, 1);
15685         atomic_set(&mm->mm_count, 1);
15686 @@ -349,8 +358,8 @@ static struct mm_struct * mm_init(struct
15687                                   : MMF_DUMP_FILTER_DEFAULT;
15688         mm->core_waiters = 0;
15689         mm->nr_ptes = 0;
15690 -       set_mm_counter(mm, file_rss, 0);
15691 -       set_mm_counter(mm, anon_rss, 0);
15692 +       __set_mm_counter(mm, file_rss, 0);
15693 +       __set_mm_counter(mm, anon_rss, 0);
15694         spin_lock_init(&mm->page_table_lock);
15695         rwlock_init(&mm->ioctx_list_lock);
15696         mm->ioctx_list = NULL;
15697 @@ -359,6 +368,7 @@ static struct mm_struct * mm_init(struct
15698  
15699         if (likely(!mm_alloc_pgd(mm))) {
15700                 mm->def_flags = 0;
15701 +               set_vx_info(&mm->mm_vx_info, vxi);
15702                 return mm;
15703         }
15704         free_mm(mm);
15705 @@ -375,7 +385,7 @@ struct mm_struct * mm_alloc(void)
15706         mm = allocate_mm();
15707         if (mm) {
15708                 memset(mm, 0, sizeof(*mm));
15709 -               mm = mm_init(mm);
15710 +               mm = mm_init(mm, current->vx_info);
15711         }
15712         return mm;
15713  }
15714 @@ -390,6 +400,7 @@ void fastcall __mmdrop(struct mm_struct 
15715         BUG_ON(mm == &init_mm);
15716         mm_free_pgd(mm);
15717         destroy_context(mm);
15718 +       clr_vx_info(&mm->mm_vx_info);
15719         free_mm(mm);
15720  }
15721  
15722 @@ -504,12 +515,13 @@ static struct mm_struct *dup_mm(struct t
15723                 goto fail_nomem;
15724  
15725         memcpy(mm, oldmm, sizeof(*mm));
15726 +       mm->mm_vx_info = NULL;
15727  
15728         /* Initializing for Swap token stuff */
15729         mm->token_priority = 0;
15730         mm->last_interval = 0;
15731  
15732 -       if (!mm_init(mm))
15733 +       if (!mm_init(mm, oldmm->mm_vx_info))
15734                 goto fail_nomem;
15735  
15736         if (init_new_context(tsk, mm))
15737 @@ -535,6 +547,7 @@ fail_nocontext:
15738          * If init_new_context() failed, we cannot use mmput() to free the mm
15739          * because it calls destroy_context()
15740          */
15741 +       clr_vx_info(&mm->mm_vx_info);
15742         mm_free_pgd(mm);
15743         free_mm(mm);
15744         return NULL;
15745 @@ -605,6 +618,7 @@ static struct fs_struct *__copy_fs_struc
15746                         fs->altroot = NULL;
15747                 }
15748                 read_unlock(&old->lock);
15749 +               atomic_inc(&vs_global_fs);
15750         }
15751         return fs;
15752  }
15753 @@ -723,6 +737,8 @@ static struct files_struct *dup_fd(struc
15754                 struct file *f = *old_fds++;
15755                 if (f) {
15756                         get_file(f);
15757 +                       /* TODO: sum it first for check and performance */
15758 +                       vx_openfd_inc(open_files - i);
15759                 } else {
15760                         /*
15761                          * The fd may be claimed in the fd bitmap but not yet
15762 @@ -980,6 +996,8 @@ static struct task_struct *copy_process(
15763         int retval;
15764         struct task_struct *p;
15765         int cgroup_callbacks_done = 0;
15766 +       struct vx_info *vxi;
15767 +       struct nx_info *nxi;
15768  
15769         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
15770                 return ERR_PTR(-EINVAL);
15771 @@ -1014,12 +1032,28 @@ static struct task_struct *copy_process(
15772         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
15773         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
15774  #endif
15775 +       init_vx_info(&p->vx_info, current->vx_info);
15776 +       init_nx_info(&p->nx_info, current->nx_info);
15777 +
15778 +       /* check vserver memory */
15779 +       if (p->mm && !(clone_flags & CLONE_VM)) {
15780 +               if (vx_vmpages_avail(p->mm, p->mm->total_vm))
15781 +                       vx_pages_add(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15782 +               else
15783 +                       goto bad_fork_free;
15784 +       }
15785 +       if (p->mm && vx_flags(VXF_FORK_RSS, 0)) {
15786 +               if (!vx_rss_avail(p->mm, get_mm_counter(p->mm, file_rss)))
15787 +                       goto bad_fork_cleanup_vm;
15788 +       }
15789         retval = -EAGAIN;
15790 +       if (!vx_nproc_avail(1))
15791 +               goto bad_fork_cleanup_vm;
15792         if (atomic_read(&p->user->processes) >=
15793                         p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
15794                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
15795                     p->user != current->nsproxy->user_ns->root_user)
15796 -                       goto bad_fork_free;
15797 +                       goto bad_fork_cleanup_vm;
15798         }
15799  
15800         atomic_inc(&p->user->__count);
15801 @@ -1309,6 +1343,18 @@ static struct task_struct *copy_process(
15802  
15803         total_forks++;
15804         spin_unlock(&current->sighand->siglock);
15805 +
15806 +       /* p is copy of current */
15807 +       vxi = p->vx_info;
15808 +       if (vxi) {
15809 +               claim_vx_info(vxi, p);
15810 +               atomic_inc(&vxi->cvirt.nr_threads);
15811 +               atomic_inc(&vxi->cvirt.total_forks);
15812 +               vx_nproc_inc(p);
15813 +       }
15814 +       nxi = p->nx_info;
15815 +       if (nxi)
15816 +               claim_nx_info(nxi, p);
15817         write_unlock_irq(&tasklist_lock);
15818         proc_fork_connector(p);
15819         cgroup_post_fork(p);
15820 @@ -1353,6 +1399,9 @@ bad_fork_cleanup_count:
15821         put_group_info(p->group_info);
15822         atomic_dec(&p->user->processes);
15823         free_uid(p->user);
15824 +bad_fork_cleanup_vm:
15825 +       if (p->mm && !(clone_flags & CLONE_VM))
15826 +               vx_pages_sub(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15827  bad_fork_free:
15828         free_task(p);
15829  fork_out:
15830 @@ -1411,6 +1460,13 @@ long do_fork(unsigned long clone_flags,
15831         int trace = 0;
15832         long nr;
15833  
15834 +       /* kernel threads are host only */
15835 +       if ((clone_flags & CLONE_KTHREAD) && !vx_check(0, VS_ADMIN)) {
15836 +               vxwprintk_task(1, "tried to spawn a kernel thread.");
15837 +//             free_pid(pid);
15838 +               return -EPERM;
15839 +       }
15840 +
15841         if (unlikely(current->ptrace)) {
15842                 trace = fork_traceflag (clone_flags);
15843                 if (trace)
15844 diff -NurpP --minimal linux-2.6.24-rc7/kernel/kthread.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/kthread.c
15845 --- linux-2.6.24-rc7/kernel/kthread.c   2007-11-29 01:02:26 +0100
15846 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/kthread.c     2007-12-13 15:03:55 +0100
15847 @@ -13,6 +13,7 @@
15848  #include <linux/file.h>
15849  #include <linux/module.h>
15850  #include <linux/mutex.h>
15851 +#include <linux/vs_pid.h>
15852  #include <asm/semaphore.h>
15853  
15854  static DEFINE_SPINLOCK(kthread_create_lock);
15855 @@ -96,7 +97,7 @@ static void create_kthread(struct kthrea
15856         } else {
15857                 wait_for_completion(&create->started);
15858                 read_lock(&tasklist_lock);
15859 -               create->result = find_task_by_pid(pid);
15860 +               create->result = find_task_by_real_pid(pid);
15861                 read_unlock(&tasklist_lock);
15862         }
15863         complete(&create->done);
15864 diff -NurpP --minimal linux-2.6.24-rc7/kernel/nsproxy.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/nsproxy.c
15865 --- linux-2.6.24-rc7/kernel/nsproxy.c   2007-11-29 01:12:31 +0100
15866 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/nsproxy.c     2008-01-04 15:41:02 +0100
15867 @@ -20,6 +20,8 @@
15868  #include <linux/mnt_namespace.h>
15869  #include <linux/utsname.h>
15870  #include <linux/pid_namespace.h>
15871 +#include <linux/vserver/global.h>
15872 +#include <linux/vserver/debug.h>
15873  #include <net/net_namespace.h>
15874  
15875  static struct kmem_cache *nsproxy_cachep;
15876 @@ -37,6 +39,9 @@ static inline struct nsproxy *clone_nspr
15877         if (ns) {
15878                 memcpy(ns, orig, sizeof(struct nsproxy));
15879                 atomic_set(&ns->count, 1);
15880 +               vxdprintk(VXD_CBIT(space, 2), "clone_nsproxy(%p[%u] = %p[1]",
15881 +                       orig, atomic_read(&orig->count), ns);
15882 +               atomic_inc(&vs_global_nsproxy);
15883         }
15884         return ns;
15885  }
15886 @@ -46,47 +51,51 @@ static inline struct nsproxy *clone_nspr
15887   * Return the newly created nsproxy.  Do not attach this to the task,
15888   * leave it to the caller to do proper locking and attach it to task.
15889   */
15890 -static struct nsproxy *create_new_namespaces(unsigned long flags,
15891 -                       struct task_struct *tsk, struct fs_struct *new_fs)
15892 +static struct nsproxy *unshare_namespaces(unsigned long flags,
15893 +                       struct nsproxy *orig, struct fs_struct *new_fs)
15894  {
15895         struct nsproxy *new_nsp;
15896         int err;
15897  
15898 -       new_nsp = clone_nsproxy(tsk->nsproxy);
15899 +       vxdprintk(VXD_CBIT(space, 4),
15900 +               "unshare_namespaces(0x%08lx,%p,%p)",
15901 +               flags, orig, new_fs);
15902 +
15903 +       new_nsp = clone_nsproxy(orig);
15904         if (!new_nsp)
15905                 return ERR_PTR(-ENOMEM);
15906  
15907 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
15908 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
15909         if (IS_ERR(new_nsp->mnt_ns)) {
15910                 err = PTR_ERR(new_nsp->mnt_ns);
15911                 goto out_ns;
15912         }
15913  
15914 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
15915 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
15916         if (IS_ERR(new_nsp->uts_ns)) {
15917                 err = PTR_ERR(new_nsp->uts_ns);
15918                 goto out_uts;
15919         }
15920  
15921 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
15922 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
15923         if (IS_ERR(new_nsp->ipc_ns)) {
15924                 err = PTR_ERR(new_nsp->ipc_ns);
15925                 goto out_ipc;
15926         }
15927  
15928 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
15929 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
15930         if (IS_ERR(new_nsp->pid_ns)) {
15931                 err = PTR_ERR(new_nsp->pid_ns);
15932                 goto out_pid;
15933         }
15934  
15935 -       new_nsp->user_ns = copy_user_ns(flags, tsk->nsproxy->user_ns);
15936 +       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
15937         if (IS_ERR(new_nsp->user_ns)) {
15938                 err = PTR_ERR(new_nsp->user_ns);
15939                 goto out_user;
15940         }
15941  
15942 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
15943 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
15944         if (IS_ERR(new_nsp->net_ns)) {
15945                 err = PTR_ERR(new_nsp->net_ns);
15946                 goto out_net;
15947 @@ -114,6 +123,37 @@ out_ns:
15948         return ERR_PTR(err);
15949  }
15950  
15951 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
15952 +                       struct fs_struct *new_fs)
15953 +{
15954 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
15955 +}
15956 +
15957 +/*
15958 + * copies the nsproxy, setting refcount to 1, and grabbing a
15959 + * reference to all contained namespaces.
15960 + */
15961 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
15962 +{
15963 +       struct nsproxy *ns = clone_nsproxy(orig);
15964 +
15965 +       if (ns) {
15966 +               if (ns->mnt_ns)
15967 +                       get_mnt_ns(ns->mnt_ns);
15968 +               if (ns->uts_ns)
15969 +                       get_uts_ns(ns->uts_ns);
15970 +               if (ns->ipc_ns)
15971 +                       get_ipc_ns(ns->ipc_ns);
15972 +               if (ns->pid_ns)
15973 +                       get_pid_ns(ns->pid_ns);
15974 +               if (ns->user_ns)
15975 +                       get_user_ns(ns->user_ns);
15976 +               if (ns->net_ns)
15977 +                       get_net(ns->net_ns);
15978 +       }
15979 +       return ns;
15980 +}
15981 +
15982  /*
15983   * called from clone.  This now handles copy for nsproxy and all
15984   * namespaces therein.
15985 @@ -121,9 +161,12 @@ out_ns:
15986  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
15987  {
15988         struct nsproxy *old_ns = tsk->nsproxy;
15989 -       struct nsproxy *new_ns;
15990 +       struct nsproxy *new_ns = NULL;
15991         int err = 0;
15992  
15993 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
15994 +               flags, tsk, old_ns);
15995 +
15996         if (!old_ns)
15997                 return 0;
15998  
15999 @@ -154,6 +197,9 @@ int copy_namespaces(unsigned long flags,
16000  
16001  out:
16002         put_nsproxy(old_ns);
16003 +       vxdprintk(VXD_CBIT(space, 3),
16004 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
16005 +               flags, tsk, old_ns, err, new_ns);
16006         return err;
16007  }
16008  
16009 @@ -170,6 +216,7 @@ void free_nsproxy(struct nsproxy *ns)
16010         if (ns->user_ns)
16011                 put_user_ns(ns->user_ns);
16012         put_net(ns->net_ns);
16013 +       atomic_dec(&vs_global_nsproxy);
16014         kmem_cache_free(nsproxy_cachep, ns);
16015  }
16016  
16017 @@ -182,6 +229,10 @@ int unshare_nsproxy_namespaces(unsigned 
16018  {
16019         int err = 0;
16020  
16021 +       vxdprintk(VXD_CBIT(space, 4),
16022 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
16023 +               unshare_flags, current->nsproxy);
16024 +
16025         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
16026                                CLONE_NEWUSER | CLONE_NEWNET)))
16027                 return 0;
16028 diff -NurpP --minimal linux-2.6.24-rc7/kernel/pid.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/pid.c
16029 --- linux-2.6.24-rc7/kernel/pid.c       2007-11-29 01:12:31 +0100
16030 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/pid.c 2007-12-17 23:41:44 +0100
16031 @@ -35,6 +35,8 @@
16032  #include <linux/pid_namespace.h>
16033  #include <linux/init_task.h>
16034  #include <linux/syscalls.h>
16035 +#include <linux/vs_pid.h>
16036 +#include <linux/vserver/global.h>
16037  
16038  #define pid_hashfn(nr, ns)     \
16039         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
16040 @@ -304,7 +306,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
16041  
16042  struct pid *find_vpid(int nr)
16043  {
16044 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
16045 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
16046  }
16047  EXPORT_SYMBOL_GPL(find_vpid);
16048  
16049 @@ -360,6 +362,9 @@ void fastcall transfer_pid(struct task_s
16050  struct task_struct * fastcall pid_task(struct pid *pid, enum pid_type type)
16051  {
16052         struct task_struct *result = NULL;
16053 +
16054 +       if (type == PIDTYPE_REALPID)
16055 +               type = PIDTYPE_PID;
16056         if (pid) {
16057                 struct hlist_node *first;
16058                 first = rcu_dereference(pid->tasks[type].first);
16059 @@ -388,14 +393,14 @@ EXPORT_SYMBOL(find_task_by_pid);
16060  
16061  struct task_struct *find_task_by_vpid(pid_t vnr)
16062  {
16063 -       return find_task_by_pid_type_ns(PIDTYPE_PID, vnr,
16064 +       return find_task_by_pid_type_ns(PIDTYPE_PID, vx_rmap_pid(vnr),
16065                         current->nsproxy->pid_ns);
16066  }
16067  EXPORT_SYMBOL(find_task_by_vpid);
16068  
16069  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
16070  {
16071 -       return find_task_by_pid_type_ns(PIDTYPE_PID, nr, ns);
16072 +       return find_task_by_pid_type_ns(PIDTYPE_PID, vx_rmap_pid(nr), ns);
16073  }
16074  EXPORT_SYMBOL(find_task_by_pid_ns);
16075  
16076 @@ -440,7 +445,7 @@ pid_t pid_nr_ns(struct pid *pid, struct 
16077                 if (upid->ns == ns)
16078                         nr = upid->nr;
16079         }
16080 -       return nr;
16081 +       return vx_map_pid(nr);
16082  }
16083  
16084  pid_t task_pid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
16085 @@ -556,6 +561,7 @@ static struct pid_namespace *create_pid_
16086                 goto out_free_map;
16087  
16088         kref_init(&ns->kref);
16089 +       atomic_inc(&vs_global_pid_ns);
16090         ns->last_pid = 0;
16091         ns->child_reaper = NULL;
16092         ns->level = level;
16093 @@ -584,6 +590,7 @@ static void destroy_pid_namespace(struct
16094  
16095         for (i = 0; i < PIDMAP_ENTRIES; i++)
16096                 kfree(ns->pidmap[i].page);
16097 +       atomic_dec(&vs_global_pid_ns);
16098         kmem_cache_free(pid_ns_cachep, ns);
16099  }
16100  
16101 diff -NurpP --minimal linux-2.6.24-rc7/kernel/posix-timers.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/posix-timers.c
16102 --- linux-2.6.24-rc7/kernel/posix-timers.c      2007-11-29 01:12:31 +0100
16103 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/posix-timers.c        2007-12-13 13:25:45 +0100
16104 @@ -47,6 +47,7 @@
16105  #include <linux/wait.h>
16106  #include <linux/workqueue.h>
16107  #include <linux/module.h>
16108 +#include <linux/vs_context.h>
16109  
16110  /*
16111   * Management arrays for POSIX timers.  Timers are kept in slab memory
16112 @@ -298,6 +299,12 @@ void do_schedule_next_timer(struct sigin
16113  
16114  int posix_timer_event(struct k_itimer *timr,int si_private)
16115  {
16116 +       struct vx_info_save vxis;
16117 +       struct vx_info *vxi;
16118 +       int ret;
16119 +
16120 +       vxi = task_get_vx_info(timr->it_process);
16121 +       enter_vx_info(vxi, &vxis);
16122         memset(&timr->sigq->info, 0, sizeof(siginfo_t));
16123         timr->sigq->info.si_sys_private = si_private;
16124         /* Send signal to the process that owns this timer.*/
16125 @@ -310,11 +317,11 @@ int posix_timer_event(struct k_itimer *t
16126  
16127         if (timr->it_sigev_notify & SIGEV_THREAD_ID) {
16128                 struct task_struct *leader;
16129 -               int ret = send_sigqueue(timr->it_sigev_signo, timr->sigq,
16130 -                                       timr->it_process);
16131  
16132 +               ret = send_sigqueue(timr->it_sigev_signo, timr->sigq,
16133 +                                   timr->it_process);
16134                 if (likely(ret >= 0))
16135 -                       return ret;
16136 +                       goto out;
16137  
16138                 timr->it_sigev_notify = SIGEV_SIGNAL;
16139                 leader = timr->it_process->group_leader;
16140 @@ -322,8 +329,12 @@ int posix_timer_event(struct k_itimer *t
16141                 timr->it_process = leader;
16142         }
16143  
16144 -       return send_group_sigqueue(timr->it_sigev_signo, timr->sigq,
16145 +       ret = send_group_sigqueue(timr->it_sigev_signo, timr->sigq,
16146                                    timr->it_process);
16147 +out:
16148 +       leave_vx_info(&vxis);
16149 +       put_vx_info(vxi);
16150 +       return ret;
16151  }
16152  EXPORT_SYMBOL_GPL(posix_timer_event);
16153  
16154 diff -NurpP --minimal linux-2.6.24-rc7/kernel/printk.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/printk.c
16155 --- linux-2.6.24-rc7/kernel/printk.c    2008-01-11 12:00:51 +0100
16156 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/printk.c      2008-01-11 04:30:10 +0100
16157 @@ -33,6 +33,7 @@
16158  #include <linux/bootmem.h>
16159  #include <linux/syscalls.h>
16160  #include <linux/jiffies.h>
16161 +#include <linux/vs_cvirt.h>
16162  
16163  #include <asm/uaccess.h>
16164  
16165 @@ -291,18 +292,13 @@ int do_syslog(int type, char __user *buf
16166         unsigned long i, j, limit, count;
16167         int do_clear = 0;
16168         char c;
16169 -       int error = 0;
16170 +       int error;
16171  
16172         error = security_syslog(type);
16173         if (error)
16174                 return error;
16175  
16176 -       switch (type) {
16177 -       case 0:         /* Close log */
16178 -               break;
16179 -       case 1:         /* Open log */
16180 -               break;
16181 -       case 2:         /* Read from log */
16182 +       if ((type >= 2) && (type <= 4)) {
16183                 error = -EINVAL;
16184                 if (!buf || len < 0)
16185                         goto out;
16186 @@ -313,6 +309,16 @@ int do_syslog(int type, char __user *buf
16187                         error = -EFAULT;
16188                         goto out;
16189                 }
16190 +       }
16191 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
16192 +               return vx_do_syslog(type, buf, len);
16193 +
16194 +       switch (type) {
16195 +       case 0:         /* Close log */
16196 +               break;
16197 +       case 1:         /* Open log */
16198 +               break;
16199 +       case 2:         /* Read from log */
16200                 error = wait_event_interruptible(log_wait,
16201                                                         (log_start - log_end));
16202                 if (error)
16203 @@ -337,16 +343,6 @@ int do_syslog(int type, char __user *buf
16204                 do_clear = 1;
16205                 /* FALL THRU */
16206         case 3:         /* Read last kernel messages */
16207 -               error = -EINVAL;
16208 -               if (!buf || len < 0)
16209 -                       goto out;
16210 -               error = 0;
16211 -               if (!len)
16212 -                       goto out;
16213 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
16214 -                       error = -EFAULT;
16215 -                       goto out;
16216 -               }
16217                 count = len;
16218                 if (count > log_buf_len)
16219                         count = log_buf_len;
16220 diff -NurpP --minimal linux-2.6.24-rc7/kernel/ptrace.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/ptrace.c
16221 --- linux-2.6.24-rc7/kernel/ptrace.c    2008-01-11 12:00:51 +0100
16222 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/ptrace.c      2008-01-11 04:30:10 +0100
16223 @@ -20,6 +20,7 @@
16224  #include <linux/signal.h>
16225  #include <linux/audit.h>
16226  #include <linux/pid_namespace.h>
16227 +#include <linux/vs_context.h>
16228  
16229  #include <asm/pgtable.h>
16230  #include <asm/uaccess.h>
16231 @@ -146,6 +147,11 @@ int __ptrace_may_attach(struct task_stru
16232                 dumpable = get_dumpable(task->mm);
16233         if (!dumpable && !capable(CAP_SYS_PTRACE))
16234                 return -EPERM;
16235 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
16236 +               return -EPERM;
16237 +       if (!vx_check(task->xid, VS_IDENT) &&
16238 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
16239 +               return -EACCES;
16240  
16241         return security_ptrace(current, task);
16242  }
16243 @@ -479,6 +485,10 @@ asmlinkage long sys_ptrace(long request,
16244                 goto out;
16245         }
16246  
16247 +       ret = -EPERM;
16248 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
16249 +               goto out_put_task_struct;
16250 +
16251         if (request == PTRACE_ATTACH) {
16252                 ret = ptrace_attach(child);
16253                 /*
16254 diff -NurpP --minimal linux-2.6.24-rc7/kernel/sched.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/sched.c
16255 --- linux-2.6.24-rc7/kernel/sched.c     2007-12-31 17:58:28 +0100
16256 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/sched.c       2007-12-31 12:34:43 +0100
16257 @@ -63,6 +63,8 @@
16258  #include <linux/reciprocal_div.h>
16259  #include <linux/unistd.h>
16260  #include <linux/pagemap.h>
16261 +#include <linux/vs_sched.h>
16262 +#include <linux/vs_cvirt.h>
16263  
16264  #include <asm/tlb.h>
16265  #include <asm/irq_regs.h>
16266 @@ -336,6 +338,16 @@ struct rq {
16267         struct task_struct *migration_thread;
16268         struct list_head migration_queue;
16269  #endif
16270 +       unsigned long norm_time;
16271 +       unsigned long idle_time;
16272 +#ifdef CONFIG_VSERVER_IDLETIME
16273 +       int idle_skip;
16274 +#endif
16275 +#ifdef CONFIG_VSERVER_HARDCPU
16276 +       struct list_head hold_queue;
16277 +       unsigned long nr_onhold;
16278 +       int idle_tokens;
16279 +#endif
16280  
16281  #ifdef CONFIG_SCHEDSTATS
16282         /* latency stats */
16283 @@ -941,6 +953,7 @@ static void set_load_weight(struct task_
16284  
16285  static void enqueue_task(struct rq *rq, struct task_struct *p, int wakeup)
16286  {
16287 +       // BUG_ON(p->state & TASK_ONHOLD);
16288         sched_info_queued(p);
16289         p->sched_class->enqueue_task(rq, p, wakeup);
16290         p->se.on_rq = 1;
16291 @@ -1113,6 +1126,9 @@ struct migration_req {
16292         struct completion done;
16293  };
16294  
16295 +#include "sched_mon.h"
16296 +
16297 +
16298  /*
16299   * The task's runqueue lock must be held.
16300   * Returns true if you have to wait for migration thread.
16301 @@ -1122,6 +1138,7 @@ migrate_task(struct task_struct *p, int 
16302  {
16303         struct rq *rq = task_rq(p);
16304  
16305 +       vxm_migrate_task(p, rq, dest_cpu);
16306         /*
16307          * If the task is not on a runqueue (and not running), then
16308          * it is sufficient to simply update the task's cpu field.
16309 @@ -1518,6 +1535,12 @@ static int try_to_wake_up(struct task_st
16310  
16311         rq = task_rq_lock(p, &flags);
16312         old_state = p->state;
16313 +
16314 +       /* we need to unhold suspended tasks
16315 +       if (old_state & TASK_ONHOLD) {
16316 +               vx_unhold_task(p, rq);
16317 +               old_state = p->state;
16318 +       } */
16319         if (!(old_state & state))
16320                 goto out;
16321  
16322 @@ -3359,13 +3382,16 @@ unsigned long long task_sched_runtime(st
16323  void account_user_time(struct task_struct *p, cputime_t cputime)
16324  {
16325         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16326 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16327         cputime64_t tmp;
16328 +       int nice = (TASK_NICE(p) > 0);
16329  
16330         p->utime = cputime_add(p->utime, cputime);
16331 +       vx_account_user(vxi, cputime, nice);
16332  
16333         /* Add user time to cpustat. */
16334         tmp = cputime_to_cputime64(cputime);
16335 -       if (TASK_NICE(p) > 0)
16336 +       if (nice)
16337                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
16338         else
16339                 cpustat->user = cputime64_add(cpustat->user, tmp);
16340 @@ -3410,6 +3436,7 @@ void account_system_time(struct task_str
16341                          cputime_t cputime)
16342  {
16343         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16344 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16345         struct rq *rq = this_rq();
16346         cputime64_t tmp;
16347  
16348 @@ -3417,6 +3444,7 @@ void account_system_time(struct task_str
16349                 return account_guest_time(p, cputime);
16350  
16351         p->stime = cputime_add(p->stime, cputime);
16352 +       vx_account_system(vxi, cputime, (p == rq->idle));
16353  
16354         /* Add system time to cpustat. */
16355         tmp = cputime_to_cputime64(cputime);
16356 @@ -4157,7 +4185,7 @@ asmlinkage long sys_nice(int increment)
16357                 nice = 19;
16358  
16359         if (increment < 0 && !can_nice(current, nice))
16360 -               return -EPERM;
16361 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
16362  
16363         retval = security_task_setnice(current, nice);
16364         if (retval)
16365 diff -NurpP --minimal linux-2.6.24-rc7/kernel/sched_fair.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/sched_fair.c
16366 --- linux-2.6.24-rc7/kernel/sched_fair.c        2007-12-31 17:58:28 +0100
16367 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/sched_fair.c  2007-12-31 12:34:43 +0100
16368 @@ -538,6 +538,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
16369         check_spread(cfs_rq, se);
16370         if (se != cfs_rq->curr)
16371                 __enqueue_entity(cfs_rq, se);
16372 +       if (entity_is_task(se))
16373 +               vx_activate_task(task_of(se));
16374         account_entity_enqueue(cfs_rq, se);
16375  }
16376  
16377 @@ -565,6 +567,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
16378  
16379         if (se != cfs_rq->curr)
16380                 __dequeue_entity(cfs_rq, se);
16381 +       if (entity_is_task(se))
16382 +               vx_deactivate_task(task_of(se));
16383         account_entity_dequeue(cfs_rq, se);
16384  }
16385  
16386 diff -NurpP --minimal linux-2.6.24-rc7/kernel/sched_hard.h linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/sched_hard.h
16387 --- linux-2.6.24-rc7/kernel/sched_hard.h        1970-01-01 01:00:00 +0100
16388 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/sched_hard.h  2007-12-13 13:25:37 +0100
16389 @@ -0,0 +1,324 @@
16390 +
16391 +#ifdef CONFIG_VSERVER_IDLELIMIT
16392 +
16393 +/*
16394 + * vx_idle_resched - reschedule after maxidle
16395 + */
16396 +static inline
16397 +void vx_idle_resched(struct rq *rq)
16398 +{
16399 +       /* maybe have a better criterion for paused */
16400 +       if (!--rq->idle_tokens && !list_empty(&rq->hold_queue))
16401 +               set_need_resched();
16402 +}
16403 +
16404 +#else /* !CONFIG_VSERVER_IDLELIMIT */
16405 +
16406 +#define vx_idle_resched(rq)
16407 +
16408 +#endif /* CONFIG_VSERVER_IDLELIMIT */
16409 +
16410 +
16411 +
16412 +#ifdef CONFIG_VSERVER_IDLETIME
16413 +
16414 +#define vx_set_rq_min_skip(rq, min)            \
16415 +       (rq)->idle_skip = (min)
16416 +
16417 +#define vx_save_min_skip(ret, min, val)                \
16418 +       __vx_save_min_skip(ret, min, val)
16419 +
16420 +static inline
16421 +void __vx_save_min_skip(int ret, int *min, int val)
16422 +{
16423 +       if (ret > -2)
16424 +               return;
16425 +       if ((*min > val) || !*min)
16426 +               *min = val;
16427 +}
16428 +
16429 +static inline
16430 +int vx_try_skip(struct rq *rq, int cpu)
16431 +{
16432 +       /* artificially advance time */
16433 +       if (rq->idle_skip > 0) {
16434 +               vxdprintk(list_empty(&rq->hold_queue),
16435 +                       "hold queue empty on cpu %d", cpu);
16436 +               rq->idle_time += rq->idle_skip;
16437 +               vxm_idle_skip(rq, cpu);
16438 +               return 1;
16439 +       }
16440 +       return 0;
16441 +}
16442 +
16443 +#else /* !CONFIG_VSERVER_IDLETIME */
16444 +
16445 +#define vx_set_rq_min_skip(rq, min)            \
16446 +       ({ int dummy = (min); dummy; })
16447 +
16448 +#define vx_save_min_skip(ret, min, val)
16449 +
16450 +static inline
16451 +int vx_try_skip(struct rq *rq, int cpu)
16452 +{
16453 +       return 0;
16454 +}
16455 +
16456 +#endif /* CONFIG_VSERVER_IDLETIME */
16457 +
16458 +
16459 +
16460 +#ifdef CONFIG_VSERVER_HARDCPU
16461 +
16462 +#define vx_set_rq_max_idle(rq, max)            \
16463 +       (rq)->idle_tokens = (max)
16464 +
16465 +#define vx_save_max_idle(ret, min, val)                \
16466 +       __vx_save_max_idle(ret, min, val)
16467 +
16468 +static inline
16469 +void __vx_save_max_idle(int ret, int *min, int val)
16470 +{
16471 +       if (*min > val)
16472 +               *min = val;
16473 +}
16474 +
16475 +
16476 +/*
16477 + * vx_hold_task - put a task on the hold queue
16478 + */
16479 +static inline
16480 +void vx_hold_task(struct task_struct *p, struct rq *rq)
16481 +{
16482 +       __deactivate_task(p, rq);
16483 +       p->state |= TASK_ONHOLD;
16484 +       /* a new one on hold */
16485 +       rq->nr_onhold++;
16486 +       vxm_hold_task(p, rq);
16487 +       list_add_tail(&p->run_list, &rq->hold_queue);
16488 +}
16489 +
16490 +/*
16491 + * vx_unhold_task - put a task back to the runqueue
16492 + */
16493 +static inline
16494 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
16495 +{
16496 +       list_del(&p->run_list);
16497 +       /* one less waiting */
16498 +       rq->nr_onhold--;
16499 +       p->state &= ~TASK_ONHOLD;
16500 +       enqueue_task(p, rq->expired);
16501 +       inc_nr_running(p, rq);
16502 +       vxm_unhold_task(p, rq);
16503 +
16504 +       if (p->static_prio < rq->best_expired_prio)
16505 +               rq->best_expired_prio = p->static_prio;
16506 +}
16507 +
16508 +unsigned long nr_onhold(void)
16509 +{
16510 +       unsigned long i, sum = 0;
16511 +
16512 +       for_each_online_cpu(i)
16513 +               sum += cpu_rq(i)->nr_onhold;
16514 +
16515 +       return sum;
16516 +}
16517 +
16518 +
16519 +
16520 +static inline
16521 +int __vx_tokens_avail(struct _vx_sched_pc *sched_pc)
16522 +{
16523 +       return sched_pc->tokens;
16524 +}
16525 +
16526 +static inline
16527 +void __vx_consume_token(struct _vx_sched_pc *sched_pc)
16528 +{
16529 +       sched_pc->tokens--;
16530 +}
16531 +
16532 +static inline
16533 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
16534 +{
16535 +       struct vx_info *vxi = p->vx_info;
16536 +
16537 +       if (vx_info_flags(vxi, VXF_SCHED_HARD|VXF_SCHED_PRIO, 0)) {
16538 +               struct _vx_sched_pc *sched_pc =
16539 +                       &vx_per_cpu(vxi, sched_pc, cpu);
16540 +               int tokens;
16541 +
16542 +               /* maybe we can simplify that to decrement
16543 +                  the token counter unconditional? */
16544 +
16545 +               if ((tokens = __vx_tokens_avail(sched_pc)) > 0)
16546 +                       __vx_consume_token(sched_pc);
16547 +
16548 +               /* for tokens > 0, one token was consumed */
16549 +               if (tokens < 2)
16550 +                       slice = 0;
16551 +       }
16552 +       vxm_need_resched(p, slice, cpu);
16553 +       return (slice == 0);
16554 +}
16555 +
16556 +
16557 +#define vx_set_rq_time(rq, time) do {  \
16558 +       rq->norm_time = time;           \
16559 +} while (0)
16560 +
16561 +
16562 +static inline
16563 +void vx_try_unhold(struct rq *rq, int cpu)
16564 +{
16565 +       struct vx_info *vxi = NULL;
16566 +       struct list_head *l, *n;
16567 +       int maxidle = HZ;
16568 +       int minskip = 0;
16569 +
16570 +       /* nothing to do? what about pause? */
16571 +       if (list_empty(&rq->hold_queue))
16572 +               return;
16573 +
16574 +       list_for_each_safe(l, n, &rq->hold_queue) {
16575 +               int ret, delta_min[2];
16576 +               struct _vx_sched_pc *sched_pc;
16577 +               struct task_struct *p;
16578 +
16579 +               p = list_entry(l, struct task_struct, run_list);
16580 +               /* don't bother with same context */
16581 +               if (vxi == p->vx_info)
16582 +                       continue;
16583 +
16584 +               vxi = p->vx_info;
16585 +               /* ignore paused contexts */
16586 +               if (vx_info_flags(vxi, VXF_SCHED_PAUSE, 0))
16587 +                       continue;
16588 +
16589 +               sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
16590 +
16591 +               /* recalc tokens */
16592 +               vxm_sched_info(sched_pc, vxi, cpu);
16593 +               ret = vx_tokens_recalc(sched_pc,
16594 +                       &rq->norm_time, &rq->idle_time, delta_min);
16595 +               vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
16596 +
16597 +               if (ret > 0) {
16598 +                       /* we found a runable context */
16599 +                       vx_unhold_task(p, rq);
16600 +                       break;
16601 +               }
16602 +               vx_save_max_idle(ret, &maxidle, delta_min[0]);
16603 +               vx_save_min_skip(ret, &minskip, delta_min[1]);
16604 +       }
16605 +       vx_set_rq_max_idle(rq, maxidle);
16606 +       vx_set_rq_min_skip(rq, minskip);
16607 +       vxm_rq_max_min(rq, cpu);
16608 +}
16609 +
16610 +
16611 +static inline
16612 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
16613 +{
16614 +       struct vx_info *vxi = next->vx_info;
16615 +       struct _vx_sched_pc *sched_pc;
16616 +       int delta_min[2];
16617 +       int flags, ret;
16618 +
16619 +       if (!vxi)
16620 +               return 1;
16621 +
16622 +       flags = vxi->vx_flags;
16623 +
16624 +       if (unlikely(vs_check_flags(flags, VXF_SCHED_PAUSE, 0)))
16625 +               goto put_on_hold;
16626 +       if (!vs_check_flags(flags, VXF_SCHED_HARD | VXF_SCHED_PRIO, 0))
16627 +               return 1;
16628 +
16629 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
16630 +#ifdef CONFIG_SMP
16631 +       /* update scheduler params */
16632 +       if (cpu_isset(cpu, vxi->sched.update)) {
16633 +               vx_update_sched_param(&vxi->sched, sched_pc);
16634 +               vxm_update_sched(sched_pc, vxi, cpu);
16635 +               cpu_clear(cpu, vxi->sched.update);
16636 +       }
16637 +#endif
16638 +       vxm_sched_info(sched_pc, vxi, cpu);
16639 +       ret  = vx_tokens_recalc(sched_pc,
16640 +               &rq->norm_time, &rq->idle_time, delta_min);
16641 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
16642 +
16643 +       if (!vs_check_flags(flags, VXF_SCHED_HARD, 0))
16644 +               return 1;
16645 +
16646 +       if (unlikely(ret < 0)) {
16647 +               vx_save_max_idle(ret, &rq->idle_tokens, delta_min[0]);
16648 +               vx_save_min_skip(ret, &rq->idle_skip, delta_min[1]);
16649 +               vxm_rq_max_min(rq, cpu);
16650 +       put_on_hold:
16651 +               vx_hold_task(next, rq);
16652 +               return 0;
16653 +       }
16654 +       return 1;
16655 +}
16656 +
16657 +
16658 +#else /* CONFIG_VSERVER_HARDCPU */
16659 +
16660 +static inline
16661 +void vx_hold_task(struct task_struct *p, struct rq *rq)
16662 +{
16663 +       return;
16664 +}
16665 +
16666 +static inline
16667 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
16668 +{
16669 +       return;
16670 +}
16671 +
16672 +unsigned long nr_onhold(void)
16673 +{
16674 +       return 0;
16675 +}
16676 +
16677 +
16678 +static inline
16679 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
16680 +{
16681 +       return (slice == 0);
16682 +}
16683 +
16684 +
16685 +#define vx_set_rq_time(rq, time)
16686 +
16687 +static inline
16688 +void vx_try_unhold(struct rq *rq, int cpu)
16689 +{
16690 +       return;
16691 +}
16692 +
16693 +static inline
16694 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
16695 +{
16696 +       struct vx_info *vxi = next->vx_info;
16697 +       struct _vx_sched_pc *sched_pc;
16698 +       int delta_min[2];
16699 +       int ret;
16700 +
16701 +       if (!vx_info_flags(vxi, VXF_SCHED_PRIO, 0))
16702 +               return 1;
16703 +
16704 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
16705 +       vxm_sched_info(sched_pc, vxi, cpu);
16706 +       ret  = vx_tokens_recalc(sched_pc,
16707 +               &rq->norm_time, &rq->idle_time, delta_min);
16708 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
16709 +       return 1;
16710 +}
16711 +
16712 +#endif /* CONFIG_VSERVER_HARDCPU */
16713 +
16714 diff -NurpP --minimal linux-2.6.24-rc7/kernel/sched_mon.h linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/sched_mon.h
16715 --- linux-2.6.24-rc7/kernel/sched_mon.h 1970-01-01 01:00:00 +0100
16716 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/sched_mon.h   2007-12-13 13:25:42 +0100
16717 @@ -0,0 +1,200 @@
16718 +
16719 +#include <linux/vserver/monitor.h>
16720 +
16721 +#ifdef  CONFIG_VSERVER_MONITOR
16722 +
16723 +#ifdef CONFIG_VSERVER_HARDCPU
16724 +#define HARDCPU(x) (x)
16725 +#else
16726 +#define HARDCPU(x) (0)
16727 +#endif
16728 +
16729 +#ifdef CONFIG_VSERVER_IDLETIME
16730 +#define IDLETIME(x) (x)
16731 +#else
16732 +#define IDLETIME(x) (0)
16733 +#endif
16734 +
16735 +struct _vx_mon_entry *vxm_advance(int cpu);
16736 +
16737 +
16738 +static inline
16739 +void   __vxm_basic(struct _vx_mon_entry *entry, xid_t xid, int type)
16740 +{
16741 +       entry->type = type;
16742 +       entry->xid = xid;
16743 +}
16744 +
16745 +static inline
16746 +void   __vxm_sync(int cpu)
16747 +{
16748 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16749 +
16750 +       __vxm_basic(entry, 0, VXM_SYNC);
16751 +       entry->ev.sec = xtime.tv_sec;
16752 +       entry->ev.nsec = xtime.tv_nsec;
16753 +}
16754 +
16755 +static inline
16756 +void   __vxm_task(struct task_struct *p, int type)
16757 +{
16758 +       struct _vx_mon_entry *entry = vxm_advance(task_cpu(p));
16759 +
16760 +       __vxm_basic(entry, p->xid, type);
16761 +       entry->ev.tsk.pid = p->pid;
16762 +       entry->ev.tsk.state = p->state;
16763 +}
16764 +
16765 +static inline
16766 +void   __vxm_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16767 +{
16768 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16769 +
16770 +       __vxm_basic(entry, vxi->vx_id, (VXM_SCHED | s->flags));
16771 +       entry->sd.tokens = s->tokens;
16772 +       entry->sd.norm_time = s->norm_time;
16773 +       entry->sd.idle_time = s->idle_time;
16774 +}
16775 +
16776 +static inline
16777 +void   __vxm_rqinfo1(struct rq *q, int cpu)
16778 +{
16779 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16780 +
16781 +       entry->type = VXM_RQINFO_1;
16782 +       entry->xid = ((unsigned long)q >> 16) & 0xffff;
16783 +       entry->q1.running = q->nr_running;
16784 +       entry->q1.onhold = HARDCPU(q->nr_onhold);
16785 +       entry->q1.iowait = atomic_read(&q->nr_iowait);
16786 +       entry->q1.uintr = q->nr_uninterruptible;
16787 +       entry->q1.idle_tokens = IDLETIME(q->idle_tokens);
16788 +}
16789 +
16790 +static inline
16791 +void   __vxm_rqinfo2(struct rq *q, int cpu)
16792 +{
16793 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16794 +
16795 +       entry->type = VXM_RQINFO_2;
16796 +       entry->xid = (unsigned long)q & 0xffff;
16797 +       entry->q2.norm_time = q->norm_time;
16798 +       entry->q2.idle_time = q->idle_time;
16799 +       entry->q2.idle_skip = IDLETIME(q->idle_skip);
16800 +}
16801 +
16802 +static inline
16803 +void   __vxm_update(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16804 +{
16805 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16806 +
16807 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE);
16808 +       entry->ev.tokens = s->tokens;
16809 +}
16810 +
16811 +static inline
16812 +void   __vxm_update1(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16813 +{
16814 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16815 +
16816 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_1);
16817 +       entry->u1.tokens_max = s->tokens_max;
16818 +       entry->u1.fill_rate = s->fill_rate[0];
16819 +       entry->u1.interval = s->interval[0];
16820 +}
16821 +
16822 +static inline
16823 +void   __vxm_update2(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16824 +{
16825 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16826 +
16827 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_2);
16828 +       entry->u2.tokens_min = s->tokens_min;
16829 +       entry->u2.fill_rate = s->fill_rate[1];
16830 +       entry->u2.interval = s->interval[1];
16831 +}
16832 +
16833 +
16834 +#define        vxm_activate_task(p,q)          __vxm_task(p, VXM_ACTIVATE)
16835 +#define        vxm_activate_idle(p,q)          __vxm_task(p, VXM_IDLE)
16836 +#define        vxm_deactivate_task(p,q)        __vxm_task(p, VXM_DEACTIVATE)
16837 +#define        vxm_hold_task(p,q)              __vxm_task(p, VXM_HOLD)
16838 +#define        vxm_unhold_task(p,q)            __vxm_task(p, VXM_UNHOLD)
16839 +
16840 +static inline
16841 +void   vxm_migrate_task(struct task_struct *p, struct rq *rq, int dest)
16842 +{
16843 +       __vxm_task(p, VXM_MIGRATE);
16844 +       __vxm_rqinfo1(rq, task_cpu(p));
16845 +       __vxm_rqinfo2(rq, task_cpu(p));
16846 +}
16847 +
16848 +static inline
16849 +void   vxm_idle_skip(struct rq *rq, int cpu)
16850 +{
16851 +       __vxm_rqinfo1(rq, cpu);
16852 +       __vxm_rqinfo2(rq, cpu);
16853 +}
16854 +
16855 +static inline
16856 +void   vxm_need_resched(struct task_struct *p, int slice, int cpu)
16857 +{
16858 +       if (slice)
16859 +               return;
16860 +
16861 +       __vxm_task(p, VXM_RESCHED);
16862 +}
16863 +
16864 +static inline
16865 +void   vxm_sync(unsigned long now, int cpu)
16866 +{
16867 +       if (!CONFIG_VSERVER_MONITOR_SYNC ||
16868 +               (now % CONFIG_VSERVER_MONITOR_SYNC))
16869 +               return;
16870 +
16871 +       __vxm_sync(cpu);
16872 +}
16873 +
16874 +#define        vxm_sched_info(s,v,c)           __vxm_sched(s,v,c)
16875 +
16876 +static inline
16877 +void   vxm_tokens_recalc(struct _vx_sched_pc *s, struct rq *rq,
16878 +       struct vx_info *vxi, int cpu)
16879 +{
16880 +       __vxm_sched(s, vxi, cpu);
16881 +       __vxm_rqinfo2(rq, cpu);
16882 +}
16883 +
16884 +static inline
16885 +void   vxm_update_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16886 +{
16887 +       __vxm_sched(s, vxi, cpu);
16888 +       __vxm_update(s, vxi, cpu);
16889 +       __vxm_update1(s, vxi, cpu);
16890 +       __vxm_update2(s, vxi, cpu);
16891 +}
16892 +
16893 +static inline
16894 +void   vxm_rq_max_min(struct rq *rq, int cpu)
16895 +{
16896 +       __vxm_rqinfo1(rq, cpu);
16897 +       __vxm_rqinfo2(rq, cpu);
16898 +}
16899 +
16900 +#else  /* CONFIG_VSERVER_MONITOR */
16901 +
16902 +#define        vxm_activate_task(t,q)          do { } while (0)
16903 +#define        vxm_activate_idle(t,q)          do { } while (0)
16904 +#define        vxm_deactivate_task(t,q)        do { } while (0)
16905 +#define        vxm_hold_task(t,q)              do { } while (0)
16906 +#define        vxm_unhold_task(t,q)            do { } while (0)
16907 +#define        vxm_migrate_task(t,q,d)         do { } while (0)
16908 +#define        vxm_idle_skip(q,c)              do { } while (0)
16909 +#define        vxm_need_resched(t,s,c)         do { } while (0)
16910 +#define        vxm_sync(s,c)                   do { } while (0)
16911 +#define        vxm_sched_info(s,v,c)           do { } while (0)
16912 +#define        vxm_tokens_recalc(s,q,v,c)      do { } while (0)
16913 +#define        vxm_update_sched(s,v,c)         do { } while (0)
16914 +#define        vxm_rq_max_min(q,c)             do { } while (0)
16915 +
16916 +#endif /* CONFIG_VSERVER_MONITOR */
16917 +
16918 diff -NurpP --minimal linux-2.6.24-rc7/kernel/signal.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/signal.c
16919 --- linux-2.6.24-rc7/kernel/signal.c    2007-11-29 01:12:31 +0100
16920 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/signal.c      2008-01-11 03:51:27 +0100
16921 @@ -26,6 +26,8 @@
16922  #include <linux/freezer.h>
16923  #include <linux/pid_namespace.h>
16924  #include <linux/nsproxy.h>
16925 +#include <linux/vs_context.h>
16926 +#include <linux/vs_pid.h>
16927  
16928  #include <asm/param.h>
16929  #include <asm/uaccess.h>
16930 @@ -530,6 +532,14 @@ static int check_kill_permission(int sig
16931         if (!valid_signal(sig))
16932                 return error;
16933  
16934 +       if ((info != SEND_SIG_NOINFO) &&
16935 +               (is_si_special(info) || !SI_FROMUSER(info)))
16936 +               goto skip;
16937 +
16938 +       vxdprintk(VXD_CBIT(misc, 7),
16939 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
16940 +               sig, info, t, vx_task_xid(t), t->pid);
16941 +
16942         if (info == SEND_SIG_NOINFO || (!is_si_special(info) && SI_FROMUSER(info))) {
16943                 error = audit_signal_info(sig, t); /* Let audit system see the signal */
16944                 if (error)
16945 @@ -543,6 +553,14 @@ static int check_kill_permission(int sig
16946                 return error;
16947         }
16948  
16949 +       error = -ESRCH;
16950 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
16951 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
16952 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
16953 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
16954 +               return error;
16955 +       }
16956 +skip:
16957         return security_task_kill(t, info, sig, 0);
16958  }
16959  
16960 @@ -1075,7 +1093,7 @@ int kill_pid_info(int sig, struct siginf
16961  
16962         p = pid_task(pid, PIDTYPE_PID);
16963         error = -ESRCH;
16964 -       if (p)
16965 +       if (p && vx_check(vx_task_xid(p), VS_IDENT))
16966                 error = group_send_sig_info(sig, info, p);
16967  
16968         if (unlikely(sig_needs_tasklist(sig)))
16969 @@ -1150,7 +1168,9 @@ static int kill_something_info(int sig, 
16970  
16971                 read_lock(&tasklist_lock);
16972                 for_each_process(p) {
16973 -                       if (p->pid > 1 && !same_thread_group(p, current)) {
16974 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
16975 +                               p->pid > 1 && !same_thread_group(p, current) &&
16976 +                               !vx_current_initpid(p->pid)) {
16977                                 int err = group_send_sig_info(sig, info, p);
16978                                 ++count;
16979                                 if (err != -EPERM)
16980 @@ -1866,6 +1886,11 @@ relock:
16981                 if (is_global_init(current))
16982                         continue;
16983  
16984 +               /* virtual init is protected against user signals */
16985 +               if ((info->si_code == SI_USER) &&
16986 +                       vx_current_initpid(current->pid))
16987 +                       continue;
16988 +
16989                 if (sig_kernel_stop(signr)) {
16990                         /*
16991                          * The default action is to stop all threads in
16992 diff -NurpP --minimal linux-2.6.24-rc7/kernel/softirq.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/softirq.c
16993 --- linux-2.6.24-rc7/kernel/softirq.c   2007-11-29 01:12:31 +0100
16994 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/softirq.c     2007-12-13 13:25:12 +0100
16995 @@ -19,6 +19,7 @@
16996  #include <linux/rcupdate.h>
16997  #include <linux/smp.h>
16998  #include <linux/tick.h>
16999 +#include <linux/vs_context.h>
17000  
17001  #include <asm/irq.h>
17002  /*
17003 diff -NurpP --minimal linux-2.6.24-rc7/kernel/sys.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/sys.c
17004 --- linux-2.6.24-rc7/kernel/sys.c       2007-12-31 17:58:28 +0100
17005 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/sys.c 2007-12-31 12:34:43 +0100
17006 @@ -38,6 +38,7 @@
17007  #include <linux/syscalls.h>
17008  #include <linux/kprobes.h>
17009  #include <linux/user_namespace.h>
17010 +#include <linux/vs_pid.h>
17011  
17012  #include <asm/uaccess.h>
17013  #include <asm/io.h>
17014 @@ -116,7 +117,10 @@ static int set_one_prio(struct task_stru
17015                 goto out;
17016         }
17017         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
17018 -               error = -EACCES;
17019 +               if (vx_flags(VXF_IGNEG_NICE, 0))
17020 +                       error = 0;
17021 +               else
17022 +                       error = -EACCES;
17023                 goto out;
17024         }
17025         no_nice = security_task_setnice(p, niceval);
17026 @@ -164,6 +168,8 @@ asmlinkage long sys_setpriority(int whic
17027                         else
17028                                 pgrp = task_pgrp(current);
17029                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
17030 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
17031 +                                       continue;
17032                                 error = set_one_prio(p, niceval, error);
17033                         } while_each_pid_task(pgrp, PIDTYPE_PGID, p);
17034                         break;
17035 @@ -224,6 +230,8 @@ asmlinkage long sys_getpriority(int whic
17036                         else
17037                                 pgrp = task_pgrp(current);
17038                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
17039 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
17040 +                                       continue;
17041                                 niceval = 20 - task_nice(p);
17042                                 if (niceval > retval)
17043                                         retval = niceval;
17044 @@ -353,6 +361,9 @@ void kernel_power_off(void)
17045         machine_power_off();
17046  }
17047  EXPORT_SYMBOL_GPL(kernel_power_off);
17048 +
17049 +long vs_reboot(unsigned int, void __user *);
17050 +
17051  /*
17052   * Reboot system call: for obvious reasons only root may call it,
17053   * and even root needs to set up some magic numbers in the registers
17054 @@ -383,6 +394,9 @@ asmlinkage long sys_reboot(int magic1, i
17055         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
17056                 cmd = LINUX_REBOOT_CMD_HALT;
17057  
17058 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
17059 +               return vs_reboot(cmd, arg);
17060 +
17061         lock_kernel();
17062         switch (cmd) {
17063         case LINUX_REBOOT_CMD_RESTART:
17064 @@ -1358,7 +1372,7 @@ asmlinkage long sys_sethostname(char __u
17065         int errno;
17066         char tmp[__NEW_UTS_LEN];
17067  
17068 -       if (!capable(CAP_SYS_ADMIN))
17069 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
17070                 return -EPERM;
17071         if (len < 0 || len > __NEW_UTS_LEN)
17072                 return -EINVAL;
17073 @@ -1403,7 +1417,7 @@ asmlinkage long sys_setdomainname(char _
17074         int errno;
17075         char tmp[__NEW_UTS_LEN];
17076  
17077 -       if (!capable(CAP_SYS_ADMIN))
17078 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
17079                 return -EPERM;
17080         if (len < 0 || len > __NEW_UTS_LEN)
17081                 return -EINVAL;
17082 @@ -1470,7 +1484,7 @@ asmlinkage long sys_setrlimit(unsigned i
17083                 return -EINVAL;
17084         old_rlim = current->signal->rlim + resource;
17085         if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
17086 -           !capable(CAP_SYS_RESOURCE))
17087 +           !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
17088                 return -EPERM;
17089         if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > NR_OPEN)
17090                 return -EPERM;
17091 diff -NurpP --minimal linux-2.6.24-rc7/kernel/sysctl.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/sysctl.c
17092 --- linux-2.6.24-rc7/kernel/sysctl.c    2007-12-31 17:58:28 +0100
17093 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/sysctl.c      2007-12-31 12:34:43 +0100
17094 @@ -105,6 +105,7 @@ static int ngroups_max = NGROUPS_MAX;
17095  #ifdef CONFIG_KMOD
17096  extern char modprobe_path[];
17097  #endif
17098 +extern char vshelper_path[];
17099  #ifdef CONFIG_CHR_DEV_SG
17100  extern int sg_big_buff;
17101  #endif
17102 @@ -492,6 +493,15 @@ static struct ctl_table kern_table[] = {
17103                 .strategy       = &sysctl_string,
17104         },
17105  #endif
17106 +       {
17107 +               .ctl_name       = KERN_VSHELPER,
17108 +               .procname       = "vshelper",
17109 +               .data           = &vshelper_path,
17110 +               .maxlen         = 256,
17111 +               .mode           = 0644,
17112 +               .proc_handler   = &proc_dostring,
17113 +               .strategy       = &sysctl_string,
17114 +       },
17115  #ifdef CONFIG_CHR_DEV_SG
17116         {
17117                 .ctl_name       = KERN_SG_BIG_BUFF,
17118 diff -NurpP --minimal linux-2.6.24-rc7/kernel/sysctl_check.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/sysctl_check.c
17119 --- linux-2.6.24-rc7/kernel/sysctl_check.c      2007-12-31 17:58:28 +0100
17120 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/sysctl_check.c        2007-12-31 12:34:43 +0100
17121 @@ -44,6 +44,7 @@ static struct trans_ctl_table trans_kern
17122  
17123         { KERN_PANIC,                   "panic" },
17124         { KERN_REALROOTDEV,             "real-root-dev" },
17125 +       { KERN_VSHELPER,                "vshelper", },
17126  
17127         { KERN_SPARC_REBOOT,            "reboot-cmd" },
17128         { KERN_CTLALTDEL,               "ctrl-alt-del" },
17129 @@ -1222,6 +1223,22 @@ static struct trans_ctl_table trans_frv_
17130         {}
17131  };
17132  
17133 +static struct trans_ctl_table trans_vserver_table[] = {
17134 +       { 1,    "debug_switch" },
17135 +       { 2,    "debug_xid" },
17136 +       { 3,    "debug_nid" },
17137 +       { 4,    "debug_tag" },
17138 +       { 5,    "debug_net" },
17139 +       { 6,    "debug_limit" },
17140 +       { 7,    "debug_cres" },
17141 +       { 8,    "debug_dlim" },
17142 +       { 9,    "debug_quota" },
17143 +       { 10,   "debug_cvirt" },
17144 +       { 11,   "debug_space" },
17145 +       { 12,   "debug_misc" },
17146 +       {}
17147 +};
17148 +
17149  static struct trans_ctl_table trans_root_table[] = {
17150         { CTL_KERN,     "kernel",       trans_kern_table },
17151         { CTL_VM,       "vm",           trans_vm_table },
17152 @@ -1238,6 +1255,7 @@ static struct trans_ctl_table trans_root
17153         { CTL_SUNRPC,   "sunrpc",       trans_sunrpc_table },
17154         { CTL_PM,       "pm",           trans_pm_table },
17155         { CTL_FRV,      "frv",          trans_frv_table },
17156 +       { CTL_VSERVER,  "vserver",      trans_vserver_table },
17157         {}
17158  };
17159  
17160 diff -NurpP --minimal linux-2.6.24-rc7/kernel/time.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/time.c
17161 --- linux-2.6.24-rc7/kernel/time.c      2007-11-29 01:12:31 +0100
17162 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/time.c        2007-12-13 13:25:36 +0100
17163 @@ -58,6 +58,7 @@ EXPORT_SYMBOL(sys_tz);
17164  asmlinkage long sys_time(time_t __user * tloc)
17165  {
17166         time_t i = get_seconds();
17167 +/*     FIXME: do_gettimeofday(&tv) -> vx_gettimeofday(&tv) */
17168  
17169         if (tloc) {
17170                 if (put_user(i,tloc))
17171 @@ -87,7 +88,7 @@ asmlinkage long sys_stime(time_t __user 
17172         if (err)
17173                 return err;
17174  
17175 -       do_settimeofday(&tv);
17176 +       vx_settimeofday(&tv);
17177         return 0;
17178  }
17179  
17180 @@ -97,7 +98,7 @@ asmlinkage long sys_gettimeofday(struct 
17181  {
17182         if (likely(tv != NULL)) {
17183                 struct timeval ktv;
17184 -               do_gettimeofday(&ktv);
17185 +               vx_gettimeofday(&ktv);
17186                 if (copy_to_user(tv, &ktv, sizeof(ktv)))
17187                         return -EFAULT;
17188         }
17189 @@ -171,7 +172,7 @@ int do_sys_settimeofday(struct timespec 
17190                 /* SMP safe, again the code in arch/foo/time.c should
17191                  * globally block out interrupts when it runs.
17192                  */
17193 -               return do_settimeofday(tv);
17194 +               return vx_settimeofday(tv);
17195         }
17196         return 0;
17197  }
17198 @@ -295,7 +296,7 @@ void getnstimeofday(struct timespec *tv)
17199  {
17200         struct timeval x;
17201  
17202 -       do_gettimeofday(&x);
17203 +       vx_gettimeofday(&x);
17204         tv->tv_sec = x.tv_sec;
17205         tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
17206  }
17207 diff -NurpP --minimal linux-2.6.24-rc7/kernel/timer.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/timer.c
17208 --- linux-2.6.24-rc7/kernel/timer.c     2007-12-31 17:58:28 +0100
17209 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/timer.c       2007-12-31 12:34:43 +0100
17210 @@ -37,6 +37,10 @@
17211  #include <linux/delay.h>
17212  #include <linux/tick.h>
17213  #include <linux/kallsyms.h>
17214 +#include <linux/vs_base.h>
17215 +#include <linux/vs_cvirt.h>
17216 +#include <linux/vs_pid.h>
17217 +#include <linux/vserver/sched.h>
17218  
17219  #include <asm/uaccess.h>
17220  #include <asm/unistd.h>
17221 @@ -946,12 +950,6 @@ asmlinkage unsigned long sys_alarm(unsig
17222  
17223  #endif
17224  
17225 -#ifndef __alpha__
17226 -
17227 -/*
17228 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
17229 - * should be moved into arch/i386 instead?
17230 - */
17231  
17232  /**
17233   * sys_getpid - return the thread group id of the current process
17234 @@ -980,10 +978,23 @@ asmlinkage long sys_getppid(void)
17235         rcu_read_lock();
17236         pid = task_ppid_nr_ns(current, current->nsproxy->pid_ns);
17237         rcu_read_unlock();
17238 +       return vx_map_pid(pid);
17239 +}
17240  
17241 -       return pid;
17242 +#ifdef __alpha__
17243 +
17244 +/*
17245 + * The Alpha uses getxpid, getxuid, and getxgid instead.
17246 + */
17247 +
17248 +asmlinkage long do_getxpid(long *ppid)
17249 +{
17250 +       *ppid = sys_getppid();
17251 +       return sys_getpid();
17252  }
17253  
17254 +#else /* _alpha_ */
17255 +
17256  asmlinkage long sys_getuid(void)
17257  {
17258         /* Only we change this so SMP safe */
17259 @@ -1144,6 +1155,8 @@ int do_sysinfo(struct sysinfo *info)
17260                         tp.tv_nsec = tp.tv_nsec - NSEC_PER_SEC;
17261                         tp.tv_sec++;
17262                 }
17263 +               if (vx_flags(VXF_VIRT_UPTIME, 0))
17264 +                       vx_vsi_uptime(&tp, NULL);
17265                 info->uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0);
17266  
17267                 info->loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
17268 diff -NurpP --minimal linux-2.6.24-rc7/kernel/user.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/user.c
17269 --- linux-2.6.24-rc7/kernel/user.c      2007-12-31 17:58:28 +0100
17270 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/user.c        2008-01-04 13:33:13 +0100
17271 @@ -162,7 +162,7 @@ static void user_attr_init(struct subsys
17272  /* Create "/sys/kernel/uids/<uid>" directory and
17273   *  "/sys/kernel/uids/<uid>/cpu_share" file for this user.
17274   */
17275 -static int user_kobject_create(struct user_struct *up)
17276 +static int user_kobject_create(struct user_namespace *ns, struct user_struct *up)
17277  {
17278         struct kset *kset = &up->kset;
17279         struct kobject *kobj = &kset->kobj;
17280 @@ -170,7 +170,7 @@ static int user_kobject_create(struct us
17281  
17282         memset(kset, 0, sizeof(struct kset));
17283         kobj->parent = &uids_kobject;   /* create under /sys/kernel/uids dir */
17284 -       kobject_set_name(kobj, "%d", up->uid);
17285 +       kobject_set_name(kobj, "%p:%d", ns, up->uid);
17286         kset_init(kset);
17287         user_attr_init(&up->user_attr, "cpu_share", 0644);
17288  
17289 @@ -205,7 +205,7 @@ int __init uids_kobject_init(void)
17290  
17291         error = kobject_add(&uids_kobject);
17292         if (!error)
17293 -               error = user_kobject_create(&root_user);
17294 +               error = user_kobject_create(&init_user_ns, &root_user);
17295  
17296         return error;
17297  }
17298 @@ -267,7 +267,8 @@ static inline void free_user(struct user
17299  
17300  #else  /* CONFIG_FAIR_USER_SCHED && CONFIG_SYSFS */
17301  
17302 -static inline int user_kobject_create(struct user_struct *up) { return 0; }
17303 +static inline int user_kobject_create(struct user_namespace *ns,
17304 +                                     struct user_struct *up) { return 0; }
17305  static inline void uids_mutex_lock(void) { }
17306  static inline void uids_mutex_unlock(void) { }
17307  
17308 @@ -370,7 +371,7 @@ struct user_struct * alloc_uid(struct us
17309                         return NULL;
17310                 }
17311  
17312 -               if (user_kobject_create(new)) {
17313 +               if (user_kobject_create(ns, new)) {
17314                         sched_destroy_user(new);
17315                         key_put(new->uid_keyring);
17316                         key_put(new->session_keyring);
17317 diff -NurpP --minimal linux-2.6.24-rc7/kernel/user_namespace.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/user_namespace.c
17318 --- linux-2.6.24-rc7/kernel/user_namespace.c    2007-11-29 01:02:27 +0100
17319 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/user_namespace.c      2007-12-15 00:33:23 +0100
17320 @@ -9,6 +9,7 @@
17321  #include <linux/version.h>
17322  #include <linux/nsproxy.h>
17323  #include <linux/user_namespace.h>
17324 +#include <linux/vserver/global.h>
17325  
17326  struct user_namespace init_user_ns = {
17327         .kref = {
17328 @@ -37,6 +38,7 @@ static struct user_namespace *clone_user
17329                 return ERR_PTR(-ENOMEM);
17330  
17331         kref_init(&ns->kref);
17332 +       atomic_inc(&vs_global_user_ns);
17333  
17334         for (n = 0; n < UIDHASH_SZ; ++n)
17335                 INIT_HLIST_HEAD(ns->uidhash_table + n);
17336 @@ -82,6 +84,7 @@ void free_user_ns(struct kref *kref)
17337  
17338         ns = container_of(kref, struct user_namespace, kref);
17339         release_uids(ns);
17340 +       atomic_dec(&vs_global_user_ns);
17341         kfree(ns);
17342  }
17343  
17344 diff -NurpP --minimal linux-2.6.24-rc7/kernel/utsname.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/utsname.c
17345 --- linux-2.6.24-rc7/kernel/utsname.c   2007-11-29 01:02:27 +0100
17346 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/utsname.c     2007-12-13 13:25:48 +0100
17347 @@ -14,6 +14,7 @@
17348  #include <linux/utsname.h>
17349  #include <linux/version.h>
17350  #include <linux/err.h>
17351 +#include <linux/vserver/global.h>
17352  
17353  /*
17354   * Clone a new ns copying an original utsname, setting refcount to 1
17355 @@ -32,6 +33,7 @@ static struct uts_namespace *clone_uts_n
17356         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
17357         up_read(&uts_sem);
17358         kref_init(&ns->kref);
17359 +       atomic_inc(&vs_global_uts_ns);
17360         return ns;
17361  }
17362  
17363 @@ -62,5 +64,6 @@ void free_uts_ns(struct kref *kref)
17364         struct uts_namespace *ns;
17365  
17366         ns = container_of(kref, struct uts_namespace, kref);
17367 +       atomic_dec(&vs_global_uts_ns);
17368         kfree(ns);
17369  }
17370 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/Kconfig linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/Kconfig
17371 --- linux-2.6.24-rc7/kernel/vserver/Kconfig     1970-01-01 01:00:00 +0100
17372 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/Kconfig       2007-12-13 14:27:07 +0100
17373 @@ -0,0 +1,283 @@
17374 +#
17375 +# Linux VServer configuration
17376 +#
17377 +
17378 +menu "Linux VServer"
17379 +
17380 +config VSERVER_LEGACY
17381 +       bool    "Enable Legacy Kernel API"
17382 +       depends on EXPERIMENTAL
17383 +       default n
17384 +       help
17385 +         This enables the legacy API used in vs1.xx, maintaining
17386 +         compatibility with older vserver tools, and guest images
17387 +         that are configured using the legacy method.
17388 +
17389 +config VSERVER_LEGACY_VERSION
17390 +       bool    "Show a Legacy Version ID"
17391 +       depends on VSERVER_LEGACY
17392 +       default n
17393 +       help
17394 +         This shows a special legacy version to very old tools
17395 +         which do not handle the current version correctly.
17396 +
17397 +         Warning: recent tools are not able to utilize the
17398 +         newer APIs when this is enabled, so some features will
17399 +         not be available. Better avoid it, unless you really,
17400 +         really need it for backwards compatibility.
17401 +
17402 +config VSERVER_DYNAMIC_IDS
17403 +       bool    "Enable dynamic context IDs"
17404 +       depends on EXPERIMENTAL && VSERVER_LEGACY
17405 +       default n
17406 +       help
17407 +         This enables support of in kernel dynamic context IDs,
17408 +         which is deprecated and will probably be removed in the
17409 +         next release.
17410 +
17411 +config VSERVER_LEGACYNET
17412 +       bool    "Enable Legacy Networking Kernel API"
17413 +       depends on EXPERIMENTAL
17414 +       default n
17415 +       help
17416 +         This enables the legacy networking API which is used
17417 +         by older tools (pre 0.30.210) to set up the network
17418 +         context (chbind).
17419 +
17420 +config VSERVER_REMAP_SADDR
17421 +       bool    "Remap Source IP Address"
17422 +       depends on EXPERIMENTAL
17423 +       default n
17424 +       help
17425 +         This allows to remap the source IP address of 'local'
17426 +         connections from 127.0.0.1 to the first assigned
17427 +         guest IP.
17428 +
17429 +config VSERVER_COWBL
17430 +       bool    "Enable COW Immutable Link Breaking"
17431 +       default y
17432 +       help
17433 +         This enables the COW (Copy-On-Write) link break code.
17434 +         It allows you to treat unified files like normal files
17435 +         when writing to them (which will implicitely break the
17436 +         link and create a copy of the unified file)
17437 +
17438 +config VSERVER_VTIME
17439 +       bool    "Enable Virtualized Guest Time"
17440 +       depends on EXPERIMENTAL
17441 +       default n
17442 +       help
17443 +         This enables per guest time offsets to allow for
17444 +         adjusting the system clock individually per guest.
17445 +         this adds some overhead to the time functions and
17446 +         therefore should not be enabled without good reason.
17447 +
17448 +config VSERVER_PROC_SECURE
17449 +       bool    "Enable Proc Security"
17450 +       depends on PROC_FS
17451 +       default y
17452 +       help
17453 +         This configures ProcFS security to initially hide
17454 +         non-process entries for all contexts except the main and
17455 +         spectator context (i.e. for all guests), which is a secure
17456 +         default.
17457 +
17458 +         (note: on 1.2x the entries were visible by default)
17459 +
17460 +config VSERVER_HARDCPU
17461 +       bool    "Enable Hard CPU Limits"
17462 +       default y
17463 +       help
17464 +         Activate the Hard CPU Limits
17465 +
17466 +         This will compile in code that allows the Token Bucket
17467 +         Scheduler to put processes on hold when a context's
17468 +         tokens are depleted (provided that its per-context
17469 +         sched_hard flag is set).
17470 +
17471 +         Processes belonging to that context will not be able
17472 +         to consume CPU resources again until a per-context
17473 +         configured minimum of tokens has been reached.
17474 +
17475 +config VSERVER_IDLETIME
17476 +       bool    "Avoid idle CPUs by skipping Time"
17477 +       depends on VSERVER_HARDCPU
17478 +       default y
17479 +       help
17480 +         This option allows the scheduler to artificially
17481 +         advance time (per cpu) when otherwise the idle
17482 +         task would be scheduled, thus keeping the cpu
17483 +         busy and sharing the available resources among
17484 +         certain contexts.
17485 +
17486 +config VSERVER_IDLELIMIT
17487 +       bool    "Limit the IDLE task"
17488 +       depends on VSERVER_HARDCPU
17489 +       default n
17490 +       help
17491 +         Limit the idle slices, so the the next context
17492 +         will be scheduled as soon as possible.
17493 +
17494 +         This might improve interactivity and latency, but
17495 +         will also marginally increase scheduling overhead.
17496 +
17497 +choice
17498 +       prompt  "Persistent Inode Tagging"
17499 +       default TAGGING_ID24
17500 +       help
17501 +         This adds persistent context information to filesystems
17502 +         mounted with the tagxid option. Tagging is a requirement
17503 +         for per-context disk limits and per-context quota.
17504 +
17505 +
17506 +config TAGGING_NONE
17507 +       bool    "Disabled"
17508 +       help
17509 +         do not store per-context information in inodes.
17510 +
17511 +config TAGGING_UID16
17512 +       bool    "UID16/GID32"
17513 +       help
17514 +         reduces UID to 16 bit, but leaves GID at 32 bit.
17515 +
17516 +config TAGGING_GID16
17517 +       bool    "UID32/GID16"
17518 +       help
17519 +         reduces GID to 16 bit, but leaves UID at 32 bit.
17520 +
17521 +config TAGGING_ID24
17522 +       bool    "UID24/GID24"
17523 +       help
17524 +         uses the upper 8bit from UID and GID for XID tagging
17525 +         which leaves 24bit for UID/GID each, which should be
17526 +         more than sufficient for normal use.
17527 +
17528 +config TAGGING_INTERN
17529 +       bool    "UID32/GID32"
17530 +       help
17531 +         this uses otherwise reserved inode fields in the on
17532 +         disk representation, which limits the use to a few
17533 +         filesystems (currently ext2 and ext3)
17534 +
17535 +endchoice
17536 +
17537 +config TAG_NFSD
17538 +       bool    "Tag NFSD User Auth and Files"
17539 +       default n
17540 +       help
17541 +         Enable this if you do want the in-kernel NFS
17542 +         Server to use the tagging specified above.
17543 +         (will require patched clients too)
17544 +
17545 +config PROPAGATE
17546 +       bool    "Enable Inode Tag Propagation"
17547 +       default n
17548 +       depends on EXPERIMENTAL
17549 +       help
17550 +         This allows for the tagid= mount option to specify
17551 +         a tagid which is to be used for the entire mount
17552 +         tree.
17553 +
17554 +config VSERVER_PRIVACY
17555 +       bool    "Honor Privacy Aspects of Guests"
17556 +       default y
17557 +       help
17558 +         When enabled, most context checks will disallow
17559 +         access to structures assigned to a specific context,
17560 +         like ptys or loop devices.
17561 +
17562 +config VSERVER_CONTEXTS
17563 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
17564 +       range 1 65533
17565 +       default "768"   if 64BIT
17566 +       default "256"
17567 +       help
17568 +         This setting will optimize certain data structures
17569 +         and memory allocations according to the expected
17570 +         maximum.
17571 +
17572 +         note: this is not a strict upper limit.
17573 +
17574 +config VSERVER_WARN
17575 +       bool    "VServer Warnings"
17576 +       default y
17577 +       help
17578 +         This enables various runtime warnings, which will
17579 +         notify about potential manipulation attempts or
17580 +         resource shortage. It is generally considered to
17581 +         be a good idea to have that enabled.
17582 +
17583 +config VSERVER_DEBUG
17584 +       bool    "VServer Debugging Code"
17585 +       default n
17586 +       help
17587 +         Set this to yes if you want to be able to activate
17588 +         debugging output at runtime. It adds a very small
17589 +         overhead to all vserver related functions and
17590 +         increases the kernel size by about 20k.
17591 +
17592 +config VSERVER_HISTORY
17593 +       bool    "VServer History Tracing"
17594 +       depends on VSERVER_DEBUG
17595 +       default n
17596 +       help
17597 +         Set this to yes if you want to record the history of
17598 +         linux-vserver activities, so they can be replayed in
17599 +         the event of a kernel panic or oops.
17600 +
17601 +config VSERVER_HISTORY_SIZE
17602 +       int     "Per-CPU History Size (32-65536)"
17603 +       depends on VSERVER_HISTORY
17604 +       range 32 65536
17605 +       default 64
17606 +       help
17607 +         This allows you to specify the number of entries in
17608 +         the per-CPU history buffer.
17609 +
17610 +config VSERVER_MONITOR
17611 +       bool    "VServer Scheduling Monitor"
17612 +       depends on VSERVER_DEBUG
17613 +       default n
17614 +       help
17615 +         Set this to yes if you want to record the scheduling
17616 +         decisions, so that they can be relayed to userspace
17617 +         for detailed analysis.
17618 +
17619 +config VSERVER_MONITOR_SIZE
17620 +       int     "Per-CPU Monitor Queue Size (32-65536)"
17621 +       depends on VSERVER_MONITOR
17622 +       range 32 65536
17623 +       default 1024
17624 +       help
17625 +         This allows you to specify the number of entries in
17626 +         the per-CPU scheduling monitor buffer.
17627 +
17628 +config VSERVER_MONITOR_SYNC
17629 +       int     "Per-CPU Monitor Sync Interval (0-65536)"
17630 +       depends on VSERVER_MONITOR
17631 +       range 0 65536
17632 +       default 256
17633 +       help
17634 +         This allows you to specify the interval in ticks
17635 +         when a time sync entry is inserted.
17636 +
17637 +endmenu
17638 +
17639 +
17640 +config VSERVER
17641 +       bool
17642 +       default y
17643 +       select USER_NS
17644 +       select SYSVIPC
17645 +
17646 +config VSERVER_SECURITY
17647 +       bool
17648 +       depends on SECURITY
17649 +       default y
17650 +       select SECURITY_CAPABILITIES
17651 +
17652 +config VSERVER_NGNET
17653 +       bool
17654 +       depends on EXPERIMENTAL && !VSERVER_LEGACYNET
17655 +       default y
17656 +
17657 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/Makefile linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/Makefile
17658 --- linux-2.6.24-rc7/kernel/vserver/Makefile    1970-01-01 01:00:00 +0100
17659 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/Makefile      2007-12-13 13:25:26 +0100
17660 @@ -0,0 +1,17 @@
17661 +#
17662 +# Makefile for the Linux vserver routines.
17663 +#
17664 +
17665 +
17666 +obj-y          += vserver.o
17667 +
17668 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
17669 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o dlimit.o
17670 +
17671 +vserver-$(CONFIG_PROC_FS) += proc.o
17672 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
17673 +vserver-$(CONFIG_VSERVER_LEGACY) += legacy.o
17674 +vserver-$(CONFIG_VSERVER_LEGACYNET) += legacynet.o
17675 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
17676 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
17677 +
17678 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/cacct.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/cacct.c
17679 --- linux-2.6.24-rc7/kernel/vserver/cacct.c     1970-01-01 01:00:00 +0100
17680 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/cacct.c       2007-12-13 13:25:37 +0100
17681 @@ -0,0 +1,44 @@
17682 +/*
17683 + *  linux/kernel/vserver/cacct.c
17684 + *
17685 + *  Virtual Server: Context Accounting
17686 + *
17687 + *  Copyright (C) 2006-2007 Herbert Pötzl
17688 + *
17689 + *  V0.01  added accounting stats
17690 + *
17691 + */
17692 +
17693 +#include <linux/types.h>
17694 +#include <linux/sched.h>
17695 +#include <linux/vs_context.h>
17696 +#include <linux/vserver/switch.h>
17697 +#include <linux/vserver/cacct_cmd.h>
17698 +#include <linux/vserver/cacct_int.h>
17699 +
17700 +#include <asm/errno.h>
17701 +#include <asm/uaccess.h>
17702 +
17703 +
17704 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
17705 +{
17706 +       struct vcmd_sock_stat_v0 vc_data;
17707 +       int j, field;
17708 +
17709 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17710 +               return -EFAULT;
17711 +
17712 +       field = vc_data.field;
17713 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
17714 +               return -EINVAL;
17715 +
17716 +       for (j = 0; j < 3; j++) {
17717 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
17718 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
17719 +       }
17720 +
17721 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17722 +               return -EFAULT;
17723 +       return 0;
17724 +}
17725 +
17726 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/cacct_init.h linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/cacct_init.h
17727 --- linux-2.6.24-rc7/kernel/vserver/cacct_init.h        1970-01-01 01:00:00 +0100
17728 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/cacct_init.h  2007-12-13 13:25:43 +0100
17729 @@ -0,0 +1,25 @@
17730 +
17731 +
17732 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
17733 +{
17734 +       int i, j;
17735 +
17736 +
17737 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17738 +               for (j = 0; j < 3; j++) {
17739 +                       atomic_set(&cacct->sock[i][j].count, 0);
17740 +                       atomic_set(&cacct->sock[i][j].total, 0);
17741 +               }
17742 +       }
17743 +       for (i = 0; i < 8; i++)
17744 +               atomic_set(&cacct->slab[i], 0);
17745 +       for (i = 0; i < 5; i++)
17746 +               for (j = 0; j < 4; j++)
17747 +                       atomic_set(&cacct->page[i][j], 0);
17748 +}
17749 +
17750 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
17751 +{
17752 +       return;
17753 +}
17754 +
17755 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/cacct_proc.h linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/cacct_proc.h
17756 --- linux-2.6.24-rc7/kernel/vserver/cacct_proc.h        1970-01-01 01:00:00 +0100
17757 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/cacct_proc.h  2007-12-13 13:25:43 +0100
17758 @@ -0,0 +1,53 @@
17759 +#ifndef _VX_CACCT_PROC_H
17760 +#define _VX_CACCT_PROC_H
17761 +
17762 +#include <linux/vserver/cacct_int.h>
17763 +
17764 +
17765 +#define VX_SOCKA_TOP   \
17766 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
17767 +
17768 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
17769 +{
17770 +       int i, j, length = 0;
17771 +       static char *type[VXA_SOCK_SIZE] = {
17772 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
17773 +       };
17774 +
17775 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
17776 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17777 +               length += sprintf(buffer + length, "%s:", type[i]);
17778 +               for (j = 0; j < 3; j++) {
17779 +                       length += sprintf(buffer + length,
17780 +                               "\t%10lu/%-10lu",
17781 +                               vx_sock_count(cacct, i, j),
17782 +                               vx_sock_total(cacct, i, j));
17783 +               }
17784 +               buffer[length++] = '\n';
17785 +       }
17786 +
17787 +       length += sprintf(buffer + length, "\n");
17788 +       length += sprintf(buffer + length,
17789 +               "slab:\t %8u %8u %8u %8u\n",
17790 +               atomic_read(&cacct->slab[1]),
17791 +               atomic_read(&cacct->slab[4]),
17792 +               atomic_read(&cacct->slab[0]),
17793 +               atomic_read(&cacct->slab[2]));
17794 +
17795 +       length += sprintf(buffer + length, "\n");
17796 +       for (i = 0; i < 5; i++) {
17797 +               length += sprintf(buffer + length,
17798 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
17799 +                       atomic_read(&cacct->page[i][0]),
17800 +                       atomic_read(&cacct->page[i][1]),
17801 +                       atomic_read(&cacct->page[i][2]),
17802 +                       atomic_read(&cacct->page[i][3]),
17803 +                       atomic_read(&cacct->page[i][4]),
17804 +                       atomic_read(&cacct->page[i][5]),
17805 +                       atomic_read(&cacct->page[i][6]),
17806 +                       atomic_read(&cacct->page[i][7]));
17807 +       }
17808 +       return length;
17809 +}
17810 +
17811 +#endif /* _VX_CACCT_PROC_H */
17812 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/context.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/context.c
17813 --- linux-2.6.24-rc7/kernel/vserver/context.c   1970-01-01 01:00:00 +0100
17814 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/context.c     2007-12-13 15:54:52 +0100
17815 @@ -0,0 +1,1110 @@
17816 +/*
17817 + *  linux/kernel/vserver/context.c
17818 + *
17819 + *  Virtual Server: Context Support
17820 + *
17821 + *  Copyright (C) 2003-2007  Herbert Pötzl
17822 + *
17823 + *  V0.01  context helper
17824 + *  V0.02  vx_ctx_kill syscall command
17825 + *  V0.03  replaced context_info calls
17826 + *  V0.04  redesign of struct (de)alloc
17827 + *  V0.05  rlimit basic implementation
17828 + *  V0.06  task_xid and info commands
17829 + *  V0.07  context flags and caps
17830 + *  V0.08  switch to RCU based hash
17831 + *  V0.09  revert to non RCU for now
17832 + *  V0.10  and back to working RCU hash
17833 + *  V0.11  and back to locking again
17834 + *  V0.12  referenced context store
17835 + *  V0.13  separate per cpu data
17836 + *  V0.14  changed vcmds to vxi arg
17837 + *  V0.15  added context stat
17838 + *  V0.16  have __create claim() the vxi
17839 + *
17840 + */
17841 +
17842 +#include <linux/slab.h>
17843 +#include <linux/types.h>
17844 +#include <linux/security.h>
17845 +#include <linux/mnt_namespace.h>
17846 +#include <linux/pid_namespace.h>
17847 +
17848 +#include <linux/sched.h>
17849 +#include <linux/vserver/context.h>
17850 +#include <linux/vserver/network.h>
17851 +#include <linux/vserver/legacy.h>
17852 +#include <linux/vserver/debug.h>
17853 +#include <linux/vserver/limit.h>
17854 +#include <linux/vserver/limit_int.h>
17855 +#include <linux/vserver/space.h>
17856 +
17857 +#include <linux/vs_context.h>
17858 +#include <linux/vs_limit.h>
17859 +#include <linux/vs_pid.h>
17860 +#include <linux/vserver/context_cmd.h>
17861 +
17862 +#include <linux/err.h>
17863 +#include <asm/errno.h>
17864 +
17865 +#include "cvirt_init.h"
17866 +#include "cacct_init.h"
17867 +#include "limit_init.h"
17868 +#include "sched_init.h"
17869 +
17870 +
17871 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
17872 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
17873 +
17874 +
17875 +/*     now inactive context structures */
17876 +
17877 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
17878 +
17879 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
17880 +
17881 +
17882 +/*     __alloc_vx_info()
17883 +
17884 +       * allocate an initialized vx_info struct
17885 +       * doesn't make it visible (hash)                        */
17886 +
17887 +static struct vx_info *__alloc_vx_info(xid_t xid)
17888 +{
17889 +       struct vx_info *new = NULL;
17890 +       int cpu;
17891 +
17892 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
17893 +
17894 +       /* would this benefit from a slab cache? */
17895 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
17896 +       if (!new)
17897 +               return 0;
17898 +
17899 +       memset(new, 0, sizeof(struct vx_info));
17900 +#ifdef CONFIG_SMP
17901 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
17902 +       if (!new->ptr_pc)
17903 +               goto error;
17904 +#endif
17905 +       new->vx_id = xid;
17906 +       INIT_HLIST_NODE(&new->vx_hlist);
17907 +       atomic_set(&new->vx_usecnt, 0);
17908 +       atomic_set(&new->vx_tasks, 0);
17909 +       new->vx_parent = NULL;
17910 +       new->vx_state = 0;
17911 +       init_waitqueue_head(&new->vx_wait);
17912 +
17913 +       /* prepare reaper */
17914 +       get_task_struct(init_pid_ns.child_reaper);
17915 +       new->vx_reaper = init_pid_ns.child_reaper;
17916 +
17917 +       /* rest of init goes here */
17918 +       vx_info_init_limit(&new->limit);
17919 +       vx_info_init_sched(&new->sched);
17920 +       vx_info_init_cvirt(&new->cvirt);
17921 +       vx_info_init_cacct(&new->cacct);
17922 +
17923 +       /* per cpu data structures */
17924 +       for_each_possible_cpu(cpu) {
17925 +               vx_info_init_sched_pc(
17926 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
17927 +               vx_info_init_cvirt_pc(
17928 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
17929 +       }
17930 +
17931 +       new->vx_flags = VXF_INIT_SET;
17932 +       new->vx_bcaps = CAP_INIT_EFF_SET;
17933 +       new->vx_ccaps = 0;
17934 +       new->vx_cap_bset = cap_bset;
17935 +
17936 +       new->reboot_cmd = 0;
17937 +       new->exit_code = 0;
17938 +
17939 +       vxdprintk(VXD_CBIT(xid, 0),
17940 +               "alloc_vx_info(%d) = %p", xid, new);
17941 +       vxh_alloc_vx_info(new);
17942 +       atomic_inc(&vx_global_ctotal);
17943 +       return new;
17944 +#ifdef CONFIG_SMP
17945 +error:
17946 +       kfree(new);
17947 +       return 0;
17948 +#endif
17949 +}
17950 +
17951 +/*     __dealloc_vx_info()
17952 +
17953 +       * final disposal of vx_info                             */
17954 +
17955 +static void __dealloc_vx_info(struct vx_info *vxi)
17956 +{
17957 +       int cpu;
17958 +
17959 +       vxdprintk(VXD_CBIT(xid, 0),
17960 +               "dealloc_vx_info(%p)", vxi);
17961 +       vxh_dealloc_vx_info(vxi);
17962 +
17963 +       vxi->vx_id = -1;
17964 +
17965 +       vx_info_exit_limit(&vxi->limit);
17966 +       vx_info_exit_sched(&vxi->sched);
17967 +       vx_info_exit_cvirt(&vxi->cvirt);
17968 +       vx_info_exit_cacct(&vxi->cacct);
17969 +
17970 +       for_each_possible_cpu(cpu) {
17971 +               vx_info_exit_sched_pc(
17972 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
17973 +               vx_info_exit_cvirt_pc(
17974 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
17975 +       }
17976 +
17977 +       vxi->vx_state |= VXS_RELEASED;
17978 +
17979 +#ifdef CONFIG_SMP
17980 +       free_percpu(vxi->ptr_pc);
17981 +#endif
17982 +       kfree(vxi);
17983 +       atomic_dec(&vx_global_ctotal);
17984 +}
17985 +
17986 +static void __shutdown_vx_info(struct vx_info *vxi)
17987 +{
17988 +       struct nsproxy *nsproxy;
17989 +       struct fs_struct *fs;
17990 +
17991 +       might_sleep();
17992 +
17993 +       vxi->vx_state |= VXS_SHUTDOWN;
17994 +       vs_state_change(vxi, VSC_SHUTDOWN);
17995 +
17996 +       nsproxy = xchg(&vxi->vx_nsproxy, NULL);
17997 +       fs = xchg(&vxi->vx_fs, NULL);
17998 +
17999 +       if (nsproxy)
18000 +               put_nsproxy(nsproxy);
18001 +       if (fs)
18002 +               put_fs_struct(fs);
18003 +}
18004 +
18005 +/* exported stuff */
18006 +
18007 +void free_vx_info(struct vx_info *vxi)
18008 +{
18009 +       unsigned long flags;
18010 +
18011 +       /* check for reference counts first */
18012 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
18013 +       BUG_ON(atomic_read(&vxi->vx_tasks));
18014 +
18015 +       /* context must not be hashed */
18016 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
18017 +
18018 +       /* context shutdown is mandatory */
18019 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
18020 +
18021 +       BUG_ON(vxi->vx_nsproxy);
18022 +       BUG_ON(vxi->vx_fs);
18023 +
18024 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
18025 +       hlist_del(&vxi->vx_hlist);
18026 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
18027 +
18028 +       __dealloc_vx_info(vxi);
18029 +}
18030 +
18031 +
18032 +/*     hash table for vx_info hash */
18033 +
18034 +#define VX_HASH_SIZE   13
18035 +
18036 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
18037 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
18038 +
18039 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
18040 +
18041 +
18042 +static inline unsigned int __hashval(xid_t xid)
18043 +{
18044 +       return (xid % VX_HASH_SIZE);
18045 +}
18046 +
18047 +
18048 +
18049 +/*     __hash_vx_info()
18050 +
18051 +       * add the vxi to the global hash table
18052 +       * requires the hash_lock to be held                     */
18053 +
18054 +static inline void __hash_vx_info(struct vx_info *vxi)
18055 +{
18056 +       struct hlist_head *head;
18057 +
18058 +       vxd_assert_lock(&vx_info_hash_lock);
18059 +       vxdprintk(VXD_CBIT(xid, 4),
18060 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
18061 +       vxh_hash_vx_info(vxi);
18062 +
18063 +       /* context must not be hashed */
18064 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
18065 +
18066 +       vxi->vx_state |= VXS_HASHED;
18067 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
18068 +       hlist_add_head(&vxi->vx_hlist, head);
18069 +       atomic_inc(&vx_global_cactive);
18070 +}
18071 +
18072 +/*     __unhash_vx_info()
18073 +
18074 +       * remove the vxi from the global hash table
18075 +       * requires the hash_lock to be held                     */
18076 +
18077 +static inline void __unhash_vx_info(struct vx_info *vxi)
18078 +{
18079 +       unsigned long flags;
18080 +
18081 +       vxd_assert_lock(&vx_info_hash_lock);
18082 +       vxdprintk(VXD_CBIT(xid, 4),
18083 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
18084 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
18085 +       vxh_unhash_vx_info(vxi);
18086 +
18087 +       /* context must be hashed */
18088 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
18089 +       /* but without tasks */
18090 +       BUG_ON(atomic_read(&vxi->vx_tasks));
18091 +
18092 +       vxi->vx_state &= ~VXS_HASHED;
18093 +       hlist_del_init(&vxi->vx_hlist);
18094 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
18095 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
18096 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
18097 +       atomic_dec(&vx_global_cactive);
18098 +}
18099 +
18100 +
18101 +/*     __lookup_vx_info()
18102 +
18103 +       * requires the hash_lock to be held
18104 +       * doesn't increment the vx_refcnt                       */
18105 +
18106 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
18107 +{
18108 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
18109 +       struct hlist_node *pos;
18110 +       struct vx_info *vxi;
18111 +
18112 +       vxd_assert_lock(&vx_info_hash_lock);
18113 +       hlist_for_each(pos, head) {
18114 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
18115 +
18116 +               if (vxi->vx_id == xid)
18117 +                       goto found;
18118 +       }
18119 +       vxi = NULL;
18120 +found:
18121 +       vxdprintk(VXD_CBIT(xid, 0),
18122 +               "__lookup_vx_info(#%u): %p[#%u]",
18123 +               xid, vxi, vxi ? vxi->vx_id : 0);
18124 +       vxh_lookup_vx_info(vxi, xid);
18125 +       return vxi;
18126 +}
18127 +
18128 +
18129 +/*     __vx_dynamic_id()
18130 +
18131 +       * find unused dynamic xid
18132 +       * requires the hash_lock to be held                     */
18133 +
18134 +static inline xid_t __vx_dynamic_id(void)
18135 +{
18136 +       static xid_t seq = MAX_S_CONTEXT;
18137 +       xid_t barrier = seq;
18138 +
18139 +       vxd_assert_lock(&vx_info_hash_lock);
18140 +       do {
18141 +               if (++seq > MAX_S_CONTEXT)
18142 +                       seq = MIN_D_CONTEXT;
18143 +               if (!__lookup_vx_info(seq)) {
18144 +                       vxdprintk(VXD_CBIT(xid, 4),
18145 +                               "__vx_dynamic_id: [#%d]", seq);
18146 +                       return seq;
18147 +               }
18148 +       } while (barrier != seq);
18149 +       return 0;
18150 +}
18151 +
18152 +#ifdef CONFIG_VSERVER_LEGACY
18153 +
18154 +/*     __loc_vx_info()
18155 +
18156 +       * locate or create the requested context
18157 +       * get() it and if new hash it                           */
18158 +
18159 +static struct vx_info *__loc_vx_info(int id, int *err)
18160 +{
18161 +       struct vx_info *new, *vxi = NULL;
18162 +
18163 +       vxdprintk(VXD_CBIT(xid, 1), "loc_vx_info(%d)*", id);
18164 +
18165 +       if (!(new = __alloc_vx_info(id))) {
18166 +               *err = -ENOMEM;
18167 +               return NULL;
18168 +       }
18169 +
18170 +       /* required to make dynamic xids unique */
18171 +       spin_lock(&vx_info_hash_lock);
18172 +
18173 +       /* dynamic context requested */
18174 +       if (id == VX_DYNAMIC_ID) {
18175 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
18176 +               id = __vx_dynamic_id();
18177 +               if (!id) {
18178 +                       printk(KERN_ERR "no dynamic context available.\n");
18179 +                       goto out_unlock;
18180 +               }
18181 +               new->vx_id = id;
18182 +#else
18183 +               printk(KERN_ERR "dynamic contexts disabled.\n");
18184 +               goto out_unlock;
18185 +#endif
18186 +       }
18187 +       /* existing context requested */
18188 +       else if ((vxi = __lookup_vx_info(id))) {
18189 +               /* context in setup is not available */
18190 +               if (vxi->vx_flags & VXF_STATE_SETUP) {
18191 +                       vxdprintk(VXD_CBIT(xid, 0),
18192 +                               "loc_vx_info(%d) = %p (not available)", id, vxi);
18193 +                       vxi = NULL;
18194 +                       *err = -EBUSY;
18195 +               } else {
18196 +                       vxdprintk(VXD_CBIT(xid, 0),
18197 +                               "loc_vx_info(%d) = %p (found)", id, vxi);
18198 +                       get_vx_info(vxi);
18199 +                       *err = 0;
18200 +               }
18201 +               goto out_unlock;
18202 +       }
18203 +
18204 +       /* new context requested */
18205 +       vxdprintk(VXD_CBIT(xid, 0),
18206 +               "loc_vx_info(%d) = %p (new)", id, new);
18207 +       __hash_vx_info(get_vx_info(new));
18208 +       vxi = new, new = NULL;
18209 +       *err = 1;
18210 +
18211 +out_unlock:
18212 +       spin_unlock(&vx_info_hash_lock);
18213 +       vxh_loc_vx_info(vxi, id);
18214 +       if (new)
18215 +               __dealloc_vx_info(new);
18216 +       return vxi;
18217 +}
18218 +
18219 +#endif
18220 +
18221 +/*     __create_vx_info()
18222 +
18223 +       * create the requested context
18224 +       * get(), claim() and hash it                            */
18225 +
18226 +static struct vx_info *__create_vx_info(int id)
18227 +{
18228 +       struct vx_info *new, *vxi = NULL;
18229 +
18230 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
18231 +
18232 +       if (!(new = __alloc_vx_info(id)))
18233 +               return ERR_PTR(-ENOMEM);
18234 +
18235 +       /* required to make dynamic xids unique */
18236 +       spin_lock(&vx_info_hash_lock);
18237 +
18238 +       /* dynamic context requested */
18239 +       if (id == VX_DYNAMIC_ID) {
18240 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
18241 +               id = __vx_dynamic_id();
18242 +               if (!id) {
18243 +                       printk(KERN_ERR "no dynamic context available.\n");
18244 +                       vxi = ERR_PTR(-EAGAIN);
18245 +                       goto out_unlock;
18246 +               }
18247 +               new->vx_id = id;
18248 +#else
18249 +               printk(KERN_ERR "dynamic contexts disabled.\n");
18250 +               vxi = ERR_PTR(-EINVAL);
18251 +               goto out_unlock;
18252 +#endif
18253 +       }
18254 +       /* static context requested */
18255 +       else if ((vxi = __lookup_vx_info(id))) {
18256 +               vxdprintk(VXD_CBIT(xid, 0),
18257 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
18258 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
18259 +                       vxi = ERR_PTR(-EBUSY);
18260 +               else
18261 +                       vxi = ERR_PTR(-EEXIST);
18262 +               goto out_unlock;
18263 +       }
18264 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
18265 +       /* dynamic xid creation blocker */
18266 +       else if (id >= MIN_D_CONTEXT) {
18267 +               vxdprintk(VXD_CBIT(xid, 0),
18268 +                       "create_vx_info(%d) (dynamic rejected)", id);
18269 +               vxi = ERR_PTR(-EINVAL);
18270 +               goto out_unlock;
18271 +       }
18272 +#endif
18273 +
18274 +       /* new context */
18275 +       vxdprintk(VXD_CBIT(xid, 0),
18276 +               "create_vx_info(%d) = %p (new)", id, new);
18277 +       claim_vx_info(new, NULL);
18278 +       __hash_vx_info(get_vx_info(new));
18279 +       vxi = new, new = NULL;
18280 +
18281 +out_unlock:
18282 +       spin_unlock(&vx_info_hash_lock);
18283 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
18284 +       if (new)
18285 +               __dealloc_vx_info(new);
18286 +       return vxi;
18287 +}
18288 +
18289 +
18290 +/*     exported stuff                                          */
18291 +
18292 +
18293 +void unhash_vx_info(struct vx_info *vxi)
18294 +{
18295 +       __shutdown_vx_info(vxi);
18296 +       spin_lock(&vx_info_hash_lock);
18297 +       __unhash_vx_info(vxi);
18298 +       spin_unlock(&vx_info_hash_lock);
18299 +       __wakeup_vx_info(vxi);
18300 +}
18301 +
18302 +
18303 +/*     lookup_vx_info()
18304 +
18305 +       * search for a vx_info and get() it
18306 +       * negative id means current                             */
18307 +
18308 +struct vx_info *lookup_vx_info(int id)
18309 +{
18310 +       struct vx_info *vxi = NULL;
18311 +
18312 +       if (id < 0) {
18313 +               vxi = get_vx_info(current->vx_info);
18314 +       } else if (id > 1) {
18315 +               spin_lock(&vx_info_hash_lock);
18316 +               vxi = get_vx_info(__lookup_vx_info(id));
18317 +               spin_unlock(&vx_info_hash_lock);
18318 +       }
18319 +       return vxi;
18320 +}
18321 +
18322 +/*     xid_is_hashed()
18323 +
18324 +       * verify that xid is still hashed                       */
18325 +
18326 +int xid_is_hashed(xid_t xid)
18327 +{
18328 +       int hashed;
18329 +
18330 +       spin_lock(&vx_info_hash_lock);
18331 +       hashed = (__lookup_vx_info(xid) != NULL);
18332 +       spin_unlock(&vx_info_hash_lock);
18333 +       return hashed;
18334 +}
18335 +
18336 +#ifdef CONFIG_VSERVER_LEGACY
18337 +
18338 +struct vx_info *lookup_or_create_vx_info(int id)
18339 +{
18340 +       int err;
18341 +
18342 +       return __loc_vx_info(id, &err);
18343 +}
18344 +
18345 +#endif
18346 +
18347 +#ifdef CONFIG_PROC_FS
18348 +
18349 +/*     get_xid_list()
18350 +
18351 +       * get a subset of hashed xids for proc
18352 +       * assumes size is at least one                          */
18353 +
18354 +int get_xid_list(int index, unsigned int *xids, int size)
18355 +{
18356 +       int hindex, nr_xids = 0;
18357 +
18358 +       /* only show current and children */
18359 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
18360 +               if (index > 0)
18361 +                       return 0;
18362 +               xids[nr_xids] = vx_current_xid();
18363 +               return 1;
18364 +       }
18365 +
18366 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
18367 +               struct hlist_head *head = &vx_info_hash[hindex];
18368 +               struct hlist_node *pos;
18369 +
18370 +               spin_lock(&vx_info_hash_lock);
18371 +               hlist_for_each(pos, head) {
18372 +                       struct vx_info *vxi;
18373 +
18374 +                       if (--index > 0)
18375 +                               continue;
18376 +
18377 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
18378 +                       xids[nr_xids] = vxi->vx_id;
18379 +                       if (++nr_xids >= size) {
18380 +                               spin_unlock(&vx_info_hash_lock);
18381 +                               goto out;
18382 +                       }
18383 +               }
18384 +               /* keep the lock time short */
18385 +               spin_unlock(&vx_info_hash_lock);
18386 +       }
18387 +out:
18388 +       return nr_xids;
18389 +}
18390 +#endif
18391 +
18392 +#ifdef CONFIG_VSERVER_DEBUG
18393 +
18394 +void   dump_vx_info_inactive(int level)
18395 +{
18396 +       struct hlist_node *entry, *next;
18397 +
18398 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
18399 +               struct vx_info *vxi =
18400 +                       list_entry(entry, struct vx_info, vx_hlist);
18401 +
18402 +               dump_vx_info(vxi, level);
18403 +       }
18404 +}
18405 +
18406 +#endif
18407 +
18408 +#if 0
18409 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
18410 +{
18411 +       struct user_struct *new_user, *old_user;
18412 +
18413 +       if (!p || !vxi)
18414 +               BUG();
18415 +
18416 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
18417 +               return -EACCES;
18418 +
18419 +       new_user = alloc_uid(vxi->vx_id, p->uid);
18420 +       if (!new_user)
18421 +               return -ENOMEM;
18422 +
18423 +       old_user = p->user;
18424 +       if (new_user != old_user) {
18425 +               atomic_inc(&new_user->processes);
18426 +               atomic_dec(&old_user->processes);
18427 +               p->user = new_user;
18428 +       }
18429 +       free_uid(old_user);
18430 +       return 0;
18431 +}
18432 +#endif
18433 +
18434 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
18435 +{
18436 +       p->cap_effective &= vxi->vx_cap_bset;
18437 +       p->cap_inheritable &= vxi->vx_cap_bset;
18438 +       p->cap_permitted &= vxi->vx_cap_bset;
18439 +}
18440 +
18441 +
18442 +#include <linux/file.h>
18443 +
18444 +static int vx_openfd_task(struct task_struct *tsk)
18445 +{
18446 +       struct files_struct *files = tsk->files;
18447 +       struct fdtable *fdt;
18448 +       const unsigned long *bptr;
18449 +       int count, total;
18450 +
18451 +       /* no rcu_read_lock() because of spin_lock() */
18452 +       spin_lock(&files->file_lock);
18453 +       fdt = files_fdtable(files);
18454 +       bptr = fdt->open_fds->fds_bits;
18455 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
18456 +       for (total = 0; count > 0; count--) {
18457 +               if (*bptr)
18458 +                       total += hweight_long(*bptr);
18459 +               bptr++;
18460 +       }
18461 +       spin_unlock(&files->file_lock);
18462 +       return total;
18463 +}
18464 +
18465 +
18466 +/*     for *space compatibility */
18467 +
18468 +asmlinkage long sys_unshare(unsigned long);
18469 +
18470 +/*
18471 + *     migrate task to new context
18472 + *     gets vxi, puts old_vxi on change
18473 + *     optionally unshares namespaces (hack)
18474 + */
18475 +
18476 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
18477 +{
18478 +       struct vx_info *old_vxi;
18479 +       int ret = 0;
18480 +
18481 +       if (!p || !vxi)
18482 +               BUG();
18483 +
18484 +       vxdprintk(VXD_CBIT(xid, 5),
18485 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
18486 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
18487 +
18488 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
18489 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
18490 +               return -EACCES;
18491 +
18492 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
18493 +               return -EFAULT;
18494 +
18495 +       old_vxi = task_get_vx_info(p);
18496 +       if (old_vxi == vxi)
18497 +               goto out;
18498 +
18499 +//     if (!(ret = vx_migrate_user(p, vxi))) {
18500 +               int openfd;
18501 +
18502 +               task_lock(p);
18503 +               openfd = vx_openfd_task(p);
18504 +
18505 +               if (old_vxi) {
18506 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
18507 +                       atomic_dec(&old_vxi->cvirt.nr_running);
18508 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
18509 +                       /* FIXME: what about the struct files here? */
18510 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
18511 +                       /* account for the executable */
18512 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
18513 +               }
18514 +               atomic_inc(&vxi->cvirt.nr_threads);
18515 +               atomic_inc(&vxi->cvirt.nr_running);
18516 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
18517 +               /* FIXME: what about the struct files here? */
18518 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
18519 +               /* account for the executable */
18520 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
18521 +
18522 +               if (old_vxi) {
18523 +                       release_vx_info(old_vxi, p);
18524 +                       clr_vx_info(&p->vx_info);
18525 +               }
18526 +               claim_vx_info(vxi, p);
18527 +               set_vx_info(&p->vx_info, vxi);
18528 +               p->xid = vxi->vx_id;
18529 +
18530 +               vxdprintk(VXD_CBIT(xid, 5),
18531 +                       "moved task %p into vxi:%p[#%d]",
18532 +                       p, vxi, vxi->vx_id);
18533 +
18534 +               vx_mask_cap_bset(vxi, p);
18535 +               task_unlock(p);
18536 +
18537 +               /* hack for *spaces to provide compatibility */
18538 +               if (unshare) {
18539 +                       struct nsproxy *old_nsp, *new_nsp;
18540 +
18541 +                       ret = unshare_nsproxy_namespaces(
18542 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
18543 +                               &new_nsp, NULL);
18544 +                       if (ret)
18545 +                               goto out;
18546 +
18547 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
18548 +                       vx_set_space(vxi, CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER);
18549 +                       put_nsproxy(old_nsp);
18550 +               }
18551 +//     }
18552 +out:
18553 +       put_vx_info(old_vxi);
18554 +       return ret;
18555 +}
18556 +
18557 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
18558 +{
18559 +       struct task_struct *old_reaper;
18560 +
18561 +       if (!vxi)
18562 +               return -EINVAL;
18563 +
18564 +       vxdprintk(VXD_CBIT(xid, 6),
18565 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
18566 +               vxi, vxi->vx_id, p, p->xid, p->pid);
18567 +
18568 +       old_reaper = vxi->vx_reaper;
18569 +       if (old_reaper == p)
18570 +               return 0;
18571 +
18572 +       /* set new child reaper */
18573 +       get_task_struct(p);
18574 +       vxi->vx_reaper = p;
18575 +       put_task_struct(old_reaper);
18576 +       return 0;
18577 +}
18578 +
18579 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
18580 +{
18581 +       if (!vxi)
18582 +               return -EINVAL;
18583 +
18584 +       vxdprintk(VXD_CBIT(xid, 6),
18585 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
18586 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
18587 +
18588 +       vxi->vx_flags &= ~VXF_STATE_INIT;
18589 +       vxi->vx_initpid = p->tgid;
18590 +       return 0;
18591 +}
18592 +
18593 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
18594 +{
18595 +       vxdprintk(VXD_CBIT(xid, 6),
18596 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
18597 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
18598 +
18599 +       vxi->exit_code = code;
18600 +       vxi->vx_initpid = 0;
18601 +}
18602 +
18603 +
18604 +void vx_set_persistent(struct vx_info *vxi)
18605 +{
18606 +       vxdprintk(VXD_CBIT(xid, 6),
18607 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
18608 +
18609 +       get_vx_info(vxi);
18610 +       claim_vx_info(vxi, NULL);
18611 +}
18612 +
18613 +void vx_clear_persistent(struct vx_info *vxi)
18614 +{
18615 +       vxdprintk(VXD_CBIT(xid, 6),
18616 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
18617 +
18618 +       release_vx_info(vxi, NULL);
18619 +       put_vx_info(vxi);
18620 +}
18621 +
18622 +void vx_update_persistent(struct vx_info *vxi)
18623 +{
18624 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
18625 +               vx_set_persistent(vxi);
18626 +       else
18627 +               vx_clear_persistent(vxi);
18628 +}
18629 +
18630 +
18631 +/*     task must be current or locked          */
18632 +
18633 +void   exit_vx_info(struct task_struct *p, int code)
18634 +{
18635 +       struct vx_info *vxi = p->vx_info;
18636 +
18637 +       if (vxi) {
18638 +               atomic_dec(&vxi->cvirt.nr_threads);
18639 +               vx_nproc_dec(p);
18640 +
18641 +               vxi->exit_code = code;
18642 +               release_vx_info(vxi, p);
18643 +       }
18644 +}
18645 +
18646 +void   exit_vx_info_early(struct task_struct *p, int code)
18647 +{
18648 +       struct vx_info *vxi = p->vx_info;
18649 +
18650 +       if (vxi) {
18651 +               if (vxi->vx_initpid == p->tgid)
18652 +                       vx_exit_init(vxi, p, code);
18653 +               if (vxi->vx_reaper == p)
18654 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
18655 +       }
18656 +}
18657 +
18658 +
18659 +/* vserver syscall commands below here */
18660 +
18661 +/* taks xid and vx_info functions */
18662 +
18663 +#include <asm/uaccess.h>
18664 +
18665 +
18666 +int vc_task_xid(uint32_t id, void __user *data)
18667 +{
18668 +       xid_t xid;
18669 +
18670 +       if (id) {
18671 +               struct task_struct *tsk;
18672 +
18673 +               if (!vx_check(0, VS_ADMIN | VS_WATCH))
18674 +                       return -EPERM;
18675 +
18676 +               read_lock(&tasklist_lock);
18677 +               tsk = find_task_by_real_pid(id);
18678 +               xid = (tsk) ? tsk->xid : -ESRCH;
18679 +               read_unlock(&tasklist_lock);
18680 +       } else
18681 +               xid = vx_current_xid();
18682 +       return xid;
18683 +}
18684 +
18685 +
18686 +int vc_vx_info(struct vx_info *vxi, void __user *data)
18687 +{
18688 +       struct vcmd_vx_info_v0 vc_data;
18689 +
18690 +       vc_data.xid = vxi->vx_id;
18691 +       vc_data.initpid = vxi->vx_initpid;
18692 +
18693 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18694 +               return -EFAULT;
18695 +       return 0;
18696 +}
18697 +
18698 +
18699 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
18700 +{
18701 +       struct vcmd_ctx_stat_v0 vc_data;
18702 +
18703 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
18704 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
18705 +
18706 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18707 +               return -EFAULT;
18708 +       return 0;
18709 +}
18710 +
18711 +
18712 +/* context functions */
18713 +
18714 +int vc_ctx_create(uint32_t xid, void __user *data)
18715 +{
18716 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
18717 +       struct vx_info *new_vxi;
18718 +       int ret;
18719 +
18720 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18721 +               return -EFAULT;
18722 +
18723 +       if ((xid > MAX_S_CONTEXT) && (xid != VX_DYNAMIC_ID))
18724 +               return -EINVAL;
18725 +       if (xid < 2)
18726 +               return -EINVAL;
18727 +
18728 +       new_vxi = __create_vx_info(xid);
18729 +       if (IS_ERR(new_vxi))
18730 +               return PTR_ERR(new_vxi);
18731 +
18732 +       /* initial flags */
18733 +       new_vxi->vx_flags = vc_data.flagword;
18734 +
18735 +       ret = -ENOEXEC;
18736 +       if (vs_state_change(new_vxi, VSC_STARTUP))
18737 +               goto out;
18738 +
18739 +       ret = vx_migrate_task(current, new_vxi, (!data));
18740 +       if (ret)
18741 +               goto out;
18742 +
18743 +       /* return context id on success */
18744 +       ret = new_vxi->vx_id;
18745 +
18746 +       /* get a reference for persistent contexts */
18747 +       if ((vc_data.flagword & VXF_PERSISTENT))
18748 +               vx_set_persistent(new_vxi);
18749 +out:
18750 +       release_vx_info(new_vxi, NULL);
18751 +       put_vx_info(new_vxi);
18752 +       return ret;
18753 +}
18754 +
18755 +
18756 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
18757 +{
18758 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
18759 +       int ret;
18760 +
18761 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18762 +               return -EFAULT;
18763 +
18764 +       ret = vx_migrate_task(current, vxi, 0);
18765 +       if (ret)
18766 +               return ret;
18767 +       if (vc_data.flagword & VXM_SET_INIT)
18768 +               ret = vx_set_init(vxi, current);
18769 +       if (ret)
18770 +               return ret;
18771 +       if (vc_data.flagword & VXM_SET_REAPER)
18772 +               ret = vx_set_reaper(vxi, current);
18773 +       return ret;
18774 +}
18775 +
18776 +
18777 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
18778 +{
18779 +       struct vcmd_ctx_flags_v0 vc_data;
18780 +
18781 +       vc_data.flagword = vxi->vx_flags;
18782 +
18783 +       /* special STATE flag handling */
18784 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
18785 +
18786 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18787 +               return -EFAULT;
18788 +       return 0;
18789 +}
18790 +
18791 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
18792 +{
18793 +       struct vcmd_ctx_flags_v0 vc_data;
18794 +       uint64_t mask, trigger;
18795 +
18796 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18797 +               return -EFAULT;
18798 +
18799 +       /* special STATE flag handling */
18800 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
18801 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
18802 +
18803 +       if (vxi == current->vx_info) {
18804 +               if (trigger & VXF_STATE_SETUP)
18805 +                       vx_mask_cap_bset(vxi, current);
18806 +               if (trigger & VXF_STATE_INIT) {
18807 +                       int ret;
18808 +
18809 +                       ret = vx_set_init(vxi, current);
18810 +                       if (ret)
18811 +                               return ret;
18812 +                       ret = vx_set_reaper(vxi, current);
18813 +                       if (ret)
18814 +                               return ret;
18815 +               }
18816 +       }
18817 +
18818 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
18819 +               vc_data.flagword, mask);
18820 +       if (trigger & VXF_PERSISTENT)
18821 +               vx_update_persistent(vxi);
18822 +
18823 +       return 0;
18824 +}
18825 +
18826 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
18827 +{
18828 +       if (bcaps)
18829 +               *bcaps = vxi->vx_bcaps;
18830 +       if (ccaps)
18831 +               *ccaps = vxi->vx_ccaps;
18832 +
18833 +       return 0;
18834 +}
18835 +
18836 +int vc_get_ccaps_v0(struct vx_info *vxi, void __user *data)
18837 +{
18838 +       struct vcmd_ctx_caps_v0 vc_data;
18839 +       int ret;
18840 +
18841 +       ret = do_get_caps(vxi, &vc_data.bcaps, &vc_data.ccaps);
18842 +       if (ret)
18843 +               return ret;
18844 +       vc_data.cmask = ~0ULL;
18845 +
18846 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18847 +               return -EFAULT;
18848 +       return 0;
18849 +}
18850 +
18851 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
18852 +{
18853 +       struct vcmd_ctx_caps_v1 vc_data;
18854 +       int ret;
18855 +
18856 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
18857 +       if (ret)
18858 +               return ret;
18859 +       vc_data.cmask = ~0ULL;
18860 +
18861 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18862 +               return -EFAULT;
18863 +       return 0;
18864 +}
18865 +
18866 +static int do_set_caps(struct vx_info *vxi,
18867 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
18868 +{
18869 +       vxi->vx_bcaps = vs_mask_flags(vxi->vx_bcaps, bcaps, bmask);
18870 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
18871 +
18872 +       return 0;
18873 +}
18874 +
18875 +int vc_set_ccaps_v0(struct vx_info *vxi, void __user *data)
18876 +{
18877 +       struct vcmd_ctx_caps_v0 vc_data;
18878 +
18879 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18880 +               return -EFAULT;
18881 +
18882 +       /* simulate old &= behaviour for bcaps */
18883 +       return do_set_caps(vxi, 0, ~vc_data.bcaps,
18884 +               vc_data.ccaps, vc_data.cmask);
18885 +}
18886 +
18887 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
18888 +{
18889 +       struct vcmd_ctx_caps_v1 vc_data;
18890 +
18891 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18892 +               return -EFAULT;
18893 +
18894 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
18895 +}
18896 +
18897 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
18898 +{
18899 +       struct vcmd_bcaps vc_data;
18900 +       int ret;
18901 +
18902 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
18903 +       if (ret)
18904 +               return ret;
18905 +       vc_data.bmask = ~0ULL;
18906 +
18907 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18908 +               return -EFAULT;
18909 +       return 0;
18910 +}
18911 +
18912 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
18913 +{
18914 +       struct vcmd_bcaps vc_data;
18915 +
18916 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18917 +               return -EFAULT;
18918 +
18919 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
18920 +}
18921 +
18922 +#include <linux/module.h>
18923 +
18924 +EXPORT_SYMBOL_GPL(free_vx_info);
18925 +
18926 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/cvirt.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/cvirt.c
18927 --- linux-2.6.24-rc7/kernel/vserver/cvirt.c     1970-01-01 01:00:00 +0100
18928 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/cvirt.c       2007-12-18 01:13:00 +0100
18929 @@ -0,0 +1,305 @@
18930 +/*
18931 + *  linux/kernel/vserver/cvirt.c
18932 + *
18933 + *  Virtual Server: Context Virtualization
18934 + *
18935 + *  Copyright (C) 2004-2007  Herbert Pötzl
18936 + *
18937 + *  V0.01  broken out from limit.c
18938 + *  V0.02  added utsname stuff
18939 + *  V0.03  changed vcmds to vxi arg
18940 + *
18941 + */
18942 +
18943 +#include <linux/sched.h>
18944 +#include <linux/sysctl.h>
18945 +#include <linux/types.h>
18946 +#include <linux/utsname.h>
18947 +#include <linux/vs_context.h>
18948 +#include <linux/vs_cvirt.h>
18949 +#include <linux/vserver/switch.h>
18950 +#include <linux/vserver/cvirt_cmd.h>
18951 +
18952 +#include <asm/errno.h>
18953 +#include <asm/uaccess.h>
18954 +
18955 +
18956 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
18957 +{
18958 +       struct vx_info *vxi = current->vx_info;
18959 +
18960 +       set_normalized_timespec(uptime,
18961 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
18962 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
18963 +       if (!idle)
18964 +               return;
18965 +       set_normalized_timespec(idle,
18966 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
18967 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
18968 +       return;
18969 +}
18970 +
18971 +uint64_t vx_idle_jiffies(void)
18972 +{
18973 +       return init_task.utime + init_task.stime;
18974 +}
18975 +
18976 +
18977 +
18978 +static inline uint32_t __update_loadavg(uint32_t load,
18979 +       int wsize, int delta, int n)
18980 +{
18981 +       unsigned long long calc, prev;
18982 +
18983 +       /* just set it to n */
18984 +       if (unlikely(delta >= wsize))
18985 +               return (n << FSHIFT);
18986 +
18987 +       calc = delta * n;
18988 +       calc <<= FSHIFT;
18989 +       prev = (wsize - delta);
18990 +       prev *= load;
18991 +       calc += prev;
18992 +       do_div(calc, wsize);
18993 +       return calc;
18994 +}
18995 +
18996 +
18997 +void vx_update_load(struct vx_info *vxi)
18998 +{
18999 +       uint32_t now, last, delta;
19000 +       unsigned int nr_running, nr_uninterruptible;
19001 +       unsigned int total;
19002 +       unsigned long flags;
19003 +
19004 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
19005 +
19006 +       now = jiffies;
19007 +       last = vxi->cvirt.load_last;
19008 +       delta = now - last;
19009 +
19010 +       if (delta < 5*HZ)
19011 +               goto out;
19012 +
19013 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
19014 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
19015 +       total = nr_running + nr_uninterruptible;
19016 +
19017 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
19018 +               60*HZ, delta, total);
19019 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
19020 +               5*60*HZ, delta, total);
19021 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
19022 +               15*60*HZ, delta, total);
19023 +
19024 +       vxi->cvirt.load_last = now;
19025 +out:
19026 +       atomic_inc(&vxi->cvirt.load_updates);
19027 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
19028 +}
19029 +
19030 +
19031 +/*
19032 + * Commands to do_syslog:
19033 + *
19034 + *      0 -- Close the log.  Currently a NOP.
19035 + *      1 -- Open the log. Currently a NOP.
19036 + *      2 -- Read from the log.
19037 + *      3 -- Read all messages remaining in the ring buffer.
19038 + *      4 -- Read and clear all messages remaining in the ring buffer
19039 + *      5 -- Clear ring buffer.
19040 + *      6 -- Disable printk's to console
19041 + *      7 -- Enable printk's to console
19042 + *      8 -- Set level of messages printed to console
19043 + *      9 -- Return number of unread characters in the log buffer
19044 + *     10 -- Return size of the log buffer
19045 + */
19046 +int vx_do_syslog(int type, char __user *buf, int len)
19047 +{
19048 +       int error = 0;
19049 +       int do_clear = 0;
19050 +       struct vx_info *vxi = current->vx_info;
19051 +       struct _vx_syslog *log;
19052 +
19053 +       if (!vxi)
19054 +               return -EINVAL;
19055 +       log = &vxi->cvirt.syslog;
19056 +
19057 +       switch (type) {
19058 +       case 0:         /* Close log */
19059 +       case 1:         /* Open log */
19060 +               break;
19061 +       case 2:         /* Read from log */
19062 +               error = wait_event_interruptible(log->log_wait,
19063 +                       (log->log_start - log->log_end));
19064 +               if (error)
19065 +                       break;
19066 +               spin_lock_irq(&log->logbuf_lock);
19067 +               spin_unlock_irq(&log->logbuf_lock);
19068 +               break;
19069 +       case 4:         /* Read/clear last kernel messages */
19070 +               do_clear = 1;
19071 +               /* fall through */
19072 +       case 3:         /* Read last kernel messages */
19073 +               return 0;
19074 +
19075 +       case 5:         /* Clear ring buffer */
19076 +               return 0;
19077 +
19078 +       case 6:         /* Disable logging to console */
19079 +       case 7:         /* Enable logging to console */
19080 +       case 8:         /* Set level of messages printed to console */
19081 +               break;
19082 +
19083 +       case 9:         /* Number of chars in the log buffer */
19084 +               return 0;
19085 +       case 10:        /* Size of the log buffer */
19086 +               return 0;
19087 +       default:
19088 +               error = -EINVAL;
19089 +               break;
19090 +       }
19091 +       return error;
19092 +}
19093 +
19094 +
19095 +/* virtual host info names */
19096 +
19097 +static char *vx_vhi_name(struct vx_info *vxi, int id)
19098 +{
19099 +       struct nsproxy *nsproxy;
19100 +       struct uts_namespace *uts;
19101 +
19102 +
19103 +       if (id == VHIN_CONTEXT)
19104 +               return vxi->vx_name;
19105 +
19106 +       nsproxy = vxi->vx_nsproxy;
19107 +       if (!nsproxy)
19108 +               return NULL;
19109 +
19110 +       uts = nsproxy->uts_ns;
19111 +       if (!uts)
19112 +               return NULL;
19113 +
19114 +       switch (id) {
19115 +       case VHIN_SYSNAME:
19116 +               return uts->name.sysname;
19117 +       case VHIN_NODENAME:
19118 +               return uts->name.nodename;
19119 +       case VHIN_RELEASE:
19120 +               return uts->name.release;
19121 +       case VHIN_VERSION:
19122 +               return uts->name.version;
19123 +       case VHIN_MACHINE:
19124 +               return uts->name.machine;
19125 +       case VHIN_DOMAINNAME:
19126 +               return uts->name.domainname;
19127 +       default:
19128 +               return NULL;
19129 +       }
19130 +       return NULL;
19131 +}
19132 +
19133 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
19134 +{
19135 +       struct vcmd_vhi_name_v0 vc_data;
19136 +       char *name;
19137 +
19138 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19139 +               return -EFAULT;
19140 +
19141 +       name = vx_vhi_name(vxi, vc_data.field);
19142 +       if (!name)
19143 +               return -EINVAL;
19144 +
19145 +       memcpy(name, vc_data.name, 65);
19146 +       return 0;
19147 +}
19148 +
19149 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
19150 +{
19151 +       struct vcmd_vhi_name_v0 vc_data;
19152 +       char *name;
19153 +
19154 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19155 +               return -EFAULT;
19156 +
19157 +       name = vx_vhi_name(vxi, vc_data.field);
19158 +       if (!name)
19159 +               return -EINVAL;
19160 +
19161 +       memcpy(vc_data.name, name, 65);
19162 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19163 +               return -EFAULT;
19164 +       return 0;
19165 +}
19166 +
19167 +
19168 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
19169 +{
19170 +       struct vcmd_virt_stat_v0 vc_data;
19171 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
19172 +       struct timespec uptime;
19173 +
19174 +       do_posix_clock_monotonic_gettime(&uptime);
19175 +       set_normalized_timespec(&uptime,
19176 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
19177 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
19178 +
19179 +       vc_data.offset = timeval_to_ns(&cvirt->bias_tv);
19180 +       vc_data.uptime = timespec_to_ns(&uptime);
19181 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
19182 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
19183 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
19184 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
19185 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
19186 +       vc_data.load[0] = cvirt->load[0];
19187 +       vc_data.load[1] = cvirt->load[1];
19188 +       vc_data.load[2] = cvirt->load[2];
19189 +
19190 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19191 +               return -EFAULT;
19192 +       return 0;
19193 +}
19194 +
19195 +
19196 +#ifdef CONFIG_VSERVER_VTIME
19197 +
19198 +/* virtualized time base */
19199 +
19200 +void vx_gettimeofday(struct timeval *tv)
19201 +{
19202 +       do_gettimeofday(tv);
19203 +       if (!vx_flags(VXF_VIRT_TIME, 0))
19204 +               return;
19205 +
19206 +       tv->tv_sec += current->vx_info->cvirt.bias_tv.tv_sec;
19207 +       tv->tv_usec += current->vx_info->cvirt.bias_tv.tv_usec;
19208 +
19209 +       if (tv->tv_usec >= USEC_PER_SEC) {
19210 +               tv->tv_sec++;
19211 +               tv->tv_usec -= USEC_PER_SEC;
19212 +       } else if (tv->tv_usec < 0) {
19213 +               tv->tv_sec--;
19214 +               tv->tv_usec += USEC_PER_SEC;
19215 +       }
19216 +}
19217 +
19218 +int vx_settimeofday(struct timespec *ts)
19219 +{
19220 +       struct timeval tv;
19221 +
19222 +       if (!vx_flags(VXF_VIRT_TIME, 0))
19223 +               return do_settimeofday(ts);
19224 +
19225 +       do_gettimeofday(&tv);
19226 +       current->vx_info->cvirt.bias_tv.tv_sec =
19227 +               ts->tv_sec - tv.tv_sec;
19228 +       current->vx_info->cvirt.bias_tv.tv_usec =
19229 +               (ts->tv_nsec/NSEC_PER_USEC) - tv.tv_usec;
19230 +       return 0;
19231 +}
19232 +
19233 +#endif
19234 +
19235 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/cvirt_init.h linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/cvirt_init.h
19236 --- linux-2.6.24-rc7/kernel/vserver/cvirt_init.h        1970-01-01 01:00:00 +0100
19237 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/cvirt_init.h  2007-12-13 13:25:43 +0100
19238 @@ -0,0 +1,69 @@
19239 +
19240 +
19241 +extern uint64_t vx_idle_jiffies(void);
19242 +
19243 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
19244 +{
19245 +       uint64_t idle_jiffies = vx_idle_jiffies();
19246 +       uint64_t nsuptime;
19247 +
19248 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
19249 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
19250 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
19251 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
19252 +       cvirt->bias_tv.tv_sec = 0;
19253 +       cvirt->bias_tv.tv_usec = 0;
19254 +
19255 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
19256 +       atomic_set(&cvirt->nr_threads, 0);
19257 +       atomic_set(&cvirt->nr_running, 0);
19258 +       atomic_set(&cvirt->nr_uninterruptible, 0);
19259 +       atomic_set(&cvirt->nr_onhold, 0);
19260 +
19261 +       spin_lock_init(&cvirt->load_lock);
19262 +       cvirt->load_last = jiffies;
19263 +       atomic_set(&cvirt->load_updates, 0);
19264 +       cvirt->load[0] = 0;
19265 +       cvirt->load[1] = 0;
19266 +       cvirt->load[2] = 0;
19267 +       atomic_set(&cvirt->total_forks, 0);
19268 +
19269 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
19270 +       init_waitqueue_head(&cvirt->syslog.log_wait);
19271 +       cvirt->syslog.log_start = 0;
19272 +       cvirt->syslog.log_end = 0;
19273 +       cvirt->syslog.con_start = 0;
19274 +       cvirt->syslog.logged_chars = 0;
19275 +}
19276 +
19277 +static inline
19278 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
19279 +{
19280 +       // cvirt_pc->cpustat = { 0 };
19281 +}
19282 +
19283 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
19284 +{
19285 +       int value;
19286 +
19287 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
19288 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
19289 +               cvirt, value);
19290 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
19291 +               "!!! cvirt: %p[nr_running] = %d on exit.",
19292 +               cvirt, value);
19293 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
19294 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
19295 +               cvirt, value);
19296 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
19297 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
19298 +               cvirt, value);
19299 +       return;
19300 +}
19301 +
19302 +static inline
19303 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
19304 +{
19305 +       return;
19306 +}
19307 +
19308 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/cvirt_proc.h linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/cvirt_proc.h
19309 --- linux-2.6.24-rc7/kernel/vserver/cvirt_proc.h        1970-01-01 01:00:00 +0100
19310 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/cvirt_proc.h  2007-12-13 13:25:43 +0100
19311 @@ -0,0 +1,133 @@
19312 +#ifndef _VX_CVIRT_PROC_H
19313 +#define _VX_CVIRT_PROC_H
19314 +
19315 +#include <linux/nsproxy.h>
19316 +#include <linux/mnt_namespace.h>
19317 +#include <linux/utsname.h>
19318 +#include <linux/ipc.h>
19319 +
19320 +
19321 +static inline
19322 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
19323 +{
19324 +       struct mnt_namespace *ns;
19325 +       struct uts_namespace *uts;
19326 +       struct ipc_namespace *ipc;
19327 +       struct vfsmount *mnt;
19328 +       char *path, *root;
19329 +       int length = 0;
19330 +
19331 +       if (!nsproxy)
19332 +               goto out;
19333 +
19334 +       length += sprintf(buffer + length,
19335 +               "NSProxy:\t%p [%p,%p,%p]\n",
19336 +               nsproxy, nsproxy->mnt_ns,
19337 +               nsproxy->uts_ns, nsproxy->ipc_ns);
19338 +
19339 +       ns = nsproxy->mnt_ns;
19340 +       if (!ns)
19341 +               goto skip_ns;
19342 +
19343 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
19344 +       if (!path)
19345 +               goto skip_ns;
19346 +
19347 +       mnt = ns->root;
19348 +       root = d_path(mnt->mnt_root, mnt->mnt_parent, path, PATH_MAX - 2);
19349 +       length += sprintf(buffer + length,
19350 +               "Namespace:\t%p [#%u]\n"
19351 +               "RootPath:\t%s\n",
19352 +               ns, atomic_read(&ns->count),
19353 +               root);
19354 +       kfree(path);
19355 +skip_ns:
19356 +
19357 +       uts = nsproxy->uts_ns;
19358 +       if (!uts)
19359 +               goto skip_uts;
19360 +
19361 +       length += sprintf(buffer + length,
19362 +               "SysName:\t%.*s\n"
19363 +               "NodeName:\t%.*s\n"
19364 +               "Release:\t%.*s\n"
19365 +               "Version:\t%.*s\n"
19366 +               "Machine:\t%.*s\n"
19367 +               "DomainName:\t%.*s\n",
19368 +               __NEW_UTS_LEN, uts->name.sysname,
19369 +               __NEW_UTS_LEN, uts->name.nodename,
19370 +               __NEW_UTS_LEN, uts->name.release,
19371 +               __NEW_UTS_LEN, uts->name.version,
19372 +               __NEW_UTS_LEN, uts->name.machine,
19373 +               __NEW_UTS_LEN, uts->name.domainname);
19374 +skip_uts:
19375 +
19376 +       ipc = nsproxy->ipc_ns;
19377 +       if (!ipc)
19378 +               goto skip_ipc;
19379 +
19380 +       length += sprintf(buffer + length,
19381 +               "SEMS:\t\t%d %d %d %d  %d\n"
19382 +               "MSG:\t\t%d %d %d\n"
19383 +               "SHM:\t\t%lu %lu  %d %d\n",
19384 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
19385 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
19386 +               ipc->used_sems,
19387 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
19388 +               (unsigned long)ipc->shm_ctlmax,
19389 +               (unsigned long)ipc->shm_ctlall,
19390 +               ipc->shm_ctlmni, ipc->shm_tot);
19391 +skip_ipc:
19392 +out:
19393 +       return length;
19394 +}
19395 +
19396 +
19397 +#include <linux/sched.h>
19398 +
19399 +#define LOAD_INT(x) ((x) >> FSHIFT)
19400 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
19401 +
19402 +static inline
19403 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
19404 +{
19405 +       int length = 0;
19406 +       int a, b, c;
19407 +
19408 +       length += sprintf(buffer + length,
19409 +               "BiasUptime:\t%lu.%02lu\n",
19410 +               (unsigned long)cvirt->bias_uptime.tv_sec,
19411 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
19412 +
19413 +       a = cvirt->load[0] + (FIXED_1 / 200);
19414 +       b = cvirt->load[1] + (FIXED_1 / 200);
19415 +       c = cvirt->load[2] + (FIXED_1 / 200);
19416 +       length += sprintf(buffer + length,
19417 +               "nr_threads:\t%d\n"
19418 +               "nr_running:\t%d\n"
19419 +               "nr_unintr:\t%d\n"
19420 +               "nr_onhold:\t%d\n"
19421 +               "load_updates:\t%d\n"
19422 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
19423 +               "total_forks:\t%d\n",
19424 +               atomic_read(&cvirt->nr_threads),
19425 +               atomic_read(&cvirt->nr_running),
19426 +               atomic_read(&cvirt->nr_uninterruptible),
19427 +               atomic_read(&cvirt->nr_onhold),
19428 +               atomic_read(&cvirt->load_updates),
19429 +               LOAD_INT(a), LOAD_FRAC(a),
19430 +               LOAD_INT(b), LOAD_FRAC(b),
19431 +               LOAD_INT(c), LOAD_FRAC(c),
19432 +               atomic_read(&cvirt->total_forks));
19433 +       return length;
19434 +}
19435 +
19436 +static inline
19437 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
19438 +       char *buffer, int cpu)
19439 +{
19440 +       int length = 0;
19441 +       return length;
19442 +}
19443 +
19444 +#endif /* _VX_CVIRT_PROC_H */
19445 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/debug.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/debug.c
19446 --- linux-2.6.24-rc7/kernel/vserver/debug.c     1970-01-01 01:00:00 +0100
19447 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/debug.c       2007-12-13 13:25:42 +0100
19448 @@ -0,0 +1,35 @@
19449 +/*
19450 + *  kernel/vserver/debug.c
19451 + *
19452 + *  Copyright (C) 2005-2007 Herbert Pötzl
19453 + *
19454 + *  V0.01  vx_info dump support
19455 + *
19456 + */
19457 +
19458 +#include <linux/errno.h>
19459 +#include <linux/kernel.h>
19460 +#include <linux/module.h>
19461 +#include <linux/vs_base.h>
19462 +
19463 +#include <linux/vserver/context.h>
19464 +
19465 +
19466 +void   dump_vx_info(struct vx_info *vxi, int level)
19467 +{
19468 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
19469 +               atomic_read(&vxi->vx_usecnt),
19470 +               atomic_read(&vxi->vx_tasks),
19471 +               vxi->vx_state);
19472 +       if (level > 0) {
19473 +               __dump_vx_limit(&vxi->limit);
19474 +               __dump_vx_sched(&vxi->sched);
19475 +               __dump_vx_cvirt(&vxi->cvirt);
19476 +               __dump_vx_cacct(&vxi->cacct);
19477 +       }
19478 +       printk("---\n");
19479 +}
19480 +
19481 +
19482 +EXPORT_SYMBOL_GPL(dump_vx_info);
19483 +
19484 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/dlimit.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/dlimit.c
19485 --- linux-2.6.24-rc7/kernel/vserver/dlimit.c    1970-01-01 01:00:00 +0100
19486 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/dlimit.c      2007-12-13 13:25:46 +0100
19487 @@ -0,0 +1,526 @@
19488 +/*
19489 + *  linux/kernel/vserver/dlimit.c
19490 + *
19491 + *  Virtual Server: Context Disk Limits
19492 + *
19493 + *  Copyright (C) 2004-2007  Herbert Pötzl
19494 + *
19495 + *  V0.01  initial version
19496 + *  V0.02  compat32 splitup
19497 + *
19498 + */
19499 +
19500 +#include <linux/fs.h>
19501 +#include <linux/namei.h>
19502 +#include <linux/statfs.h>
19503 +#include <linux/compat.h>
19504 +#include <linux/vserver/switch.h>
19505 +#include <linux/vs_context.h>
19506 +#include <linux/vs_tag.h>
19507 +#include <linux/vs_dlimit.h>
19508 +#include <linux/vserver/dlimit_cmd.h>
19509 +
19510 +#include <asm/errno.h>
19511 +#include <asm/uaccess.h>
19512 +
19513 +/*     __alloc_dl_info()
19514 +
19515 +       * allocate an initialized dl_info struct
19516 +       * doesn't make it visible (hash)                        */
19517 +
19518 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
19519 +{
19520 +       struct dl_info *new = NULL;
19521 +
19522 +       vxdprintk(VXD_CBIT(dlim, 5),
19523 +               "alloc_dl_info(%p,%d)*", sb, tag);
19524 +
19525 +       /* would this benefit from a slab cache? */
19526 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
19527 +       if (!new)
19528 +               return 0;
19529 +
19530 +       memset(new, 0, sizeof(struct dl_info));
19531 +       new->dl_tag = tag;
19532 +       new->dl_sb = sb;
19533 +       INIT_RCU_HEAD(&new->dl_rcu);
19534 +       INIT_HLIST_NODE(&new->dl_hlist);
19535 +       spin_lock_init(&new->dl_lock);
19536 +       atomic_set(&new->dl_refcnt, 0);
19537 +       atomic_set(&new->dl_usecnt, 0);
19538 +
19539 +       /* rest of init goes here */
19540 +
19541 +       vxdprintk(VXD_CBIT(dlim, 4),
19542 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
19543 +       return new;
19544 +}
19545 +
19546 +/*     __dealloc_dl_info()
19547 +
19548 +       * final disposal of dl_info                             */
19549 +
19550 +static void __dealloc_dl_info(struct dl_info *dli)
19551 +{
19552 +       vxdprintk(VXD_CBIT(dlim, 4),
19553 +               "dealloc_dl_info(%p)", dli);
19554 +
19555 +       dli->dl_hlist.next = LIST_POISON1;
19556 +       dli->dl_tag = -1;
19557 +       dli->dl_sb = 0;
19558 +
19559 +       BUG_ON(atomic_read(&dli->dl_usecnt));
19560 +       BUG_ON(atomic_read(&dli->dl_refcnt));
19561 +
19562 +       kfree(dli);
19563 +}
19564 +
19565 +
19566 +/*     hash table for dl_info hash */
19567 +
19568 +#define DL_HASH_SIZE   13
19569 +
19570 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
19571 +
19572 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
19573 +
19574 +
19575 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
19576 +{
19577 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
19578 +}
19579 +
19580 +
19581 +
19582 +/*     __hash_dl_info()
19583 +
19584 +       * add the dli to the global hash table
19585 +       * requires the hash_lock to be held                     */
19586 +
19587 +static inline void __hash_dl_info(struct dl_info *dli)
19588 +{
19589 +       struct hlist_head *head;
19590 +
19591 +       vxdprintk(VXD_CBIT(dlim, 6),
19592 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
19593 +       get_dl_info(dli);
19594 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
19595 +       hlist_add_head_rcu(&dli->dl_hlist, head);
19596 +}
19597 +
19598 +/*     __unhash_dl_info()
19599 +
19600 +       * remove the dli from the global hash table
19601 +       * requires the hash_lock to be held                     */
19602 +
19603 +static inline void __unhash_dl_info(struct dl_info *dli)
19604 +{
19605 +       vxdprintk(VXD_CBIT(dlim, 6),
19606 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
19607 +       hlist_del_rcu(&dli->dl_hlist);
19608 +       put_dl_info(dli);
19609 +}
19610 +
19611 +
19612 +/*     __lookup_dl_info()
19613 +
19614 +       * requires the rcu_read_lock()
19615 +       * doesn't increment the dl_refcnt                       */
19616 +
19617 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
19618 +{
19619 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
19620 +       struct hlist_node *pos;
19621 +       struct dl_info *dli;
19622 +
19623 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
19624 +
19625 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
19626 +                       return dli;
19627 +               }
19628 +       }
19629 +       return NULL;
19630 +}
19631 +
19632 +
19633 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
19634 +{
19635 +       struct dl_info *dli;
19636 +
19637 +       rcu_read_lock();
19638 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
19639 +       vxdprintk(VXD_CBIT(dlim, 7),
19640 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
19641 +       rcu_read_unlock();
19642 +       return dli;
19643 +}
19644 +
19645 +void rcu_free_dl_info(struct rcu_head *head)
19646 +{
19647 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
19648 +       int usecnt, refcnt;
19649 +
19650 +       BUG_ON(!dli || !head);
19651 +
19652 +       usecnt = atomic_read(&dli->dl_usecnt);
19653 +       BUG_ON(usecnt < 0);
19654 +
19655 +       refcnt = atomic_read(&dli->dl_refcnt);
19656 +       BUG_ON(refcnt < 0);
19657 +
19658 +       vxdprintk(VXD_CBIT(dlim, 3),
19659 +               "rcu_free_dl_info(%p)", dli);
19660 +       if (!usecnt)
19661 +               __dealloc_dl_info(dli);
19662 +       else
19663 +               printk("!!! rcu didn't free\n");
19664 +}
19665 +
19666 +
19667 +
19668 +
19669 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
19670 +       uint32_t flags, int add)
19671 +{
19672 +       struct nameidata nd;
19673 +       int ret;
19674 +
19675 +       ret = user_path_walk_link(name, &nd);
19676 +       if (!ret) {
19677 +               struct super_block *sb;
19678 +               struct dl_info *dli;
19679 +
19680 +               ret = -EINVAL;
19681 +               if (!nd.dentry->d_inode)
19682 +                       goto out_release;
19683 +               if (!(sb = nd.dentry->d_inode->i_sb))
19684 +                       goto out_release;
19685 +
19686 +               if (add) {
19687 +                       dli = __alloc_dl_info(sb, id);
19688 +                       spin_lock(&dl_info_hash_lock);
19689 +
19690 +                       ret = -EEXIST;
19691 +                       if (__lookup_dl_info(sb, id))
19692 +                               goto out_unlock;
19693 +                       __hash_dl_info(dli);
19694 +                       dli = NULL;
19695 +               } else {
19696 +                       spin_lock(&dl_info_hash_lock);
19697 +                       dli = __lookup_dl_info(sb, id);
19698 +
19699 +                       ret = -ESRCH;
19700 +                       if (!dli)
19701 +                               goto out_unlock;
19702 +                       __unhash_dl_info(dli);
19703 +               }
19704 +               ret = 0;
19705 +       out_unlock:
19706 +               spin_unlock(&dl_info_hash_lock);
19707 +               if (add && dli)
19708 +                       __dealloc_dl_info(dli);
19709 +       out_release:
19710 +               path_release(&nd);
19711 +       }
19712 +       return ret;
19713 +}
19714 +
19715 +int vc_add_dlimit(uint32_t id, void __user *data)
19716 +{
19717 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
19718 +
19719 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19720 +               return -EFAULT;
19721 +
19722 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
19723 +}
19724 +
19725 +int vc_rem_dlimit(uint32_t id, void __user *data)
19726 +{
19727 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
19728 +
19729 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19730 +               return -EFAULT;
19731 +
19732 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
19733 +}
19734 +
19735 +#ifdef CONFIG_COMPAT
19736 +
19737 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
19738 +{
19739 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19740 +
19741 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19742 +               return -EFAULT;
19743 +
19744 +       return do_addrem_dlimit(id,
19745 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
19746 +}
19747 +
19748 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
19749 +{
19750 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19751 +
19752 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19753 +               return -EFAULT;
19754 +
19755 +       return do_addrem_dlimit(id,
19756 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
19757 +}
19758 +
19759 +#endif /* CONFIG_COMPAT */
19760 +
19761 +
19762 +static inline
19763 +int do_set_dlimit(uint32_t id, const char __user *name,
19764 +       uint32_t space_used, uint32_t space_total,
19765 +       uint32_t inodes_used, uint32_t inodes_total,
19766 +       uint32_t reserved, uint32_t flags)
19767 +{
19768 +       struct nameidata nd;
19769 +       int ret;
19770 +
19771 +       ret = user_path_walk_link(name, &nd);
19772 +       if (!ret) {
19773 +               struct super_block *sb;
19774 +               struct dl_info *dli;
19775 +
19776 +               ret = -EINVAL;
19777 +               if (!nd.dentry->d_inode)
19778 +                       goto out_release;
19779 +               if (!(sb = nd.dentry->d_inode->i_sb))
19780 +                       goto out_release;
19781 +               if ((reserved != CDLIM_KEEP &&
19782 +                       reserved > 100) ||
19783 +                       (inodes_used != CDLIM_KEEP &&
19784 +                       inodes_used > inodes_total) ||
19785 +                       (space_used != CDLIM_KEEP &&
19786 +                       space_used > space_total))
19787 +                       goto out_release;
19788 +
19789 +               ret = -ESRCH;
19790 +               dli = locate_dl_info(sb, id);
19791 +               if (!dli)
19792 +                       goto out_release;
19793 +
19794 +               spin_lock(&dli->dl_lock);
19795 +
19796 +               if (inodes_used != CDLIM_KEEP)
19797 +                       dli->dl_inodes_used = inodes_used;
19798 +               if (inodes_total != CDLIM_KEEP)
19799 +                       dli->dl_inodes_total = inodes_total;
19800 +               if (space_used != CDLIM_KEEP) {
19801 +                       dli->dl_space_used = space_used;
19802 +                       dli->dl_space_used <<= 10;
19803 +               }
19804 +               if (space_total == CDLIM_INFINITY)
19805 +                       dli->dl_space_total = DLIM_INFINITY;
19806 +               else if (space_total != CDLIM_KEEP) {
19807 +                       dli->dl_space_total = space_total;
19808 +                       dli->dl_space_total <<= 10;
19809 +               }
19810 +               if (reserved != CDLIM_KEEP)
19811 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
19812 +
19813 +               spin_unlock(&dli->dl_lock);
19814 +
19815 +               put_dl_info(dli);
19816 +               ret = 0;
19817 +
19818 +       out_release:
19819 +               path_release(&nd);
19820 +       }
19821 +       return ret;
19822 +}
19823 +
19824 +int vc_set_dlimit(uint32_t id, void __user *data)
19825 +{
19826 +       struct vcmd_ctx_dlimit_v0 vc_data;
19827 +
19828 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19829 +               return -EFAULT;
19830 +
19831 +       return do_set_dlimit(id, vc_data.name,
19832 +               vc_data.space_used, vc_data.space_total,
19833 +               vc_data.inodes_used, vc_data.inodes_total,
19834 +               vc_data.reserved, vc_data.flags);
19835 +}
19836 +
19837 +#ifdef CONFIG_COMPAT
19838 +
19839 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
19840 +{
19841 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
19842 +
19843 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19844 +               return -EFAULT;
19845 +
19846 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
19847 +               vc_data.space_used, vc_data.space_total,
19848 +               vc_data.inodes_used, vc_data.inodes_total,
19849 +               vc_data.reserved, vc_data.flags);
19850 +}
19851 +
19852 +#endif /* CONFIG_COMPAT */
19853 +
19854 +
19855 +static inline
19856 +int do_get_dlimit(uint32_t id, const char __user *name,
19857 +       uint32_t *space_used, uint32_t *space_total,
19858 +       uint32_t *inodes_used, uint32_t *inodes_total,
19859 +       uint32_t *reserved, uint32_t *flags)
19860 +{
19861 +       struct nameidata nd;
19862 +       int ret;
19863 +
19864 +       ret = user_path_walk_link(name, &nd);
19865 +       if (!ret) {
19866 +               struct super_block *sb;
19867 +               struct dl_info *dli;
19868 +
19869 +               ret = -EINVAL;
19870 +               if (!nd.dentry->d_inode)
19871 +                       goto out_release;
19872 +               if (!(sb = nd.dentry->d_inode->i_sb))
19873 +                       goto out_release;
19874 +
19875 +               ret = -ESRCH;
19876 +               dli = locate_dl_info(sb, id);
19877 +               if (!dli)
19878 +                       goto out_release;
19879 +
19880 +               spin_lock(&dli->dl_lock);
19881 +               *inodes_used = dli->dl_inodes_used;
19882 +               *inodes_total = dli->dl_inodes_total;
19883 +               *space_used = dli->dl_space_used >> 10;
19884 +               if (dli->dl_space_total == DLIM_INFINITY)
19885 +                       *space_total = CDLIM_INFINITY;
19886 +               else
19887 +                       *space_total = dli->dl_space_total >> 10;
19888 +
19889 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
19890 +               spin_unlock(&dli->dl_lock);
19891 +
19892 +               put_dl_info(dli);
19893 +               ret = -EFAULT;
19894 +
19895 +               ret = 0;
19896 +       out_release:
19897 +               path_release(&nd);
19898 +       }
19899 +       return ret;
19900 +}
19901 +
19902 +
19903 +int vc_get_dlimit(uint32_t id, void __user *data)
19904 +{
19905 +       struct vcmd_ctx_dlimit_v0 vc_data;
19906 +       int ret;
19907 +
19908 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19909 +               return -EFAULT;
19910 +
19911 +       ret = do_get_dlimit(id, vc_data.name,
19912 +               &vc_data.space_used, &vc_data.space_total,
19913 +               &vc_data.inodes_used, &vc_data.inodes_total,
19914 +               &vc_data.reserved, &vc_data.flags);
19915 +       if (ret)
19916 +               return ret;
19917 +
19918 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19919 +               return -EFAULT;
19920 +       return 0;
19921 +}
19922 +
19923 +#ifdef CONFIG_COMPAT
19924 +
19925 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
19926 +{
19927 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
19928 +       int ret;
19929 +
19930 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19931 +               return -EFAULT;
19932 +
19933 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
19934 +               &vc_data.space_used, &vc_data.space_total,
19935 +               &vc_data.inodes_used, &vc_data.inodes_total,
19936 +               &vc_data.reserved, &vc_data.flags);
19937 +       if (ret)
19938 +               return ret;
19939 +
19940 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19941 +               return -EFAULT;
19942 +       return 0;
19943 +}
19944 +
19945 +#endif /* CONFIG_COMPAT */
19946 +
19947 +
19948 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
19949 +{
19950 +       struct dl_info *dli;
19951 +       __u64 blimit, bfree, bavail;
19952 +       __u32 ifree;
19953 +
19954 +       dli = locate_dl_info(sb, dx_current_tag());
19955 +       if (!dli)
19956 +               return;
19957 +
19958 +       spin_lock(&dli->dl_lock);
19959 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
19960 +               goto no_ilim;
19961 +
19962 +       /* reduce max inodes available to limit */
19963 +       if (buf->f_files > dli->dl_inodes_total)
19964 +               buf->f_files = dli->dl_inodes_total;
19965 +
19966 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
19967 +       /* reduce free inodes to min */
19968 +       if (ifree < buf->f_ffree)
19969 +               buf->f_ffree = ifree;
19970 +
19971 +no_ilim:
19972 +       if (dli->dl_space_total == DLIM_INFINITY)
19973 +               goto no_blim;
19974 +
19975 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
19976 +
19977 +       if (dli->dl_space_total < dli->dl_space_used)
19978 +               bfree = 0;
19979 +       else
19980 +               bfree = (dli->dl_space_total - dli->dl_space_used)
19981 +                       >> sb->s_blocksize_bits;
19982 +
19983 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
19984 +       if (bavail < dli->dl_space_used)
19985 +               bavail = 0;
19986 +       else
19987 +               bavail = (bavail - dli->dl_space_used)
19988 +                       >> sb->s_blocksize_bits;
19989 +
19990 +       /* reduce max space available to limit */
19991 +       if (buf->f_blocks > blimit)
19992 +               buf->f_blocks = blimit;
19993 +
19994 +       /* reduce free space to min */
19995 +       if (bfree < buf->f_bfree)
19996 +               buf->f_bfree = bfree;
19997 +
19998 +       /* reduce avail space to min */
19999 +       if (bavail < buf->f_bavail)
20000 +               buf->f_bavail = bavail;
20001 +
20002 +no_blim:
20003 +       spin_unlock(&dli->dl_lock);
20004 +       put_dl_info(dli);
20005 +
20006 +       return;
20007 +}
20008 +
20009 +#include <linux/module.h>
20010 +
20011 +EXPORT_SYMBOL_GPL(locate_dl_info);
20012 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
20013 +
20014 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/helper.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/helper.c
20015 --- linux-2.6.24-rc7/kernel/vserver/helper.c    1970-01-01 01:00:00 +0100
20016 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/helper.c      2007-12-13 13:25:41 +0100
20017 @@ -0,0 +1,208 @@
20018 +/*
20019 + *  linux/kernel/vserver/helper.c
20020 + *
20021 + *  Virtual Context Support
20022 + *
20023 + *  Copyright (C) 2004-2007  Herbert Pötzl
20024 + *
20025 + *  V0.01  basic helper
20026 + *
20027 + */
20028 +
20029 +#include <linux/errno.h>
20030 +#include <linux/kmod.h>
20031 +#include <linux/sched.h>
20032 +#include <linux/reboot.h>
20033 +#include <linux/vs_context.h>
20034 +#include <linux/vs_network.h>
20035 +#include <linux/vserver/signal.h>
20036 +
20037 +#include <asm/uaccess.h>
20038 +#include <asm/unistd.h>
20039 +
20040 +
20041 +char vshelper_path[255] = "/sbin/vshelper";
20042 +
20043 +
20044 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
20045 +{
20046 +       int ret;
20047 +
20048 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
20049 +               printk( KERN_WARNING
20050 +                       "%s: (%s %s) returned %s with %d\n",
20051 +                       name, argv[1], argv[2],
20052 +                       sync ? "sync" : "async", ret);
20053 +       }
20054 +       vxdprintk(VXD_CBIT(switch, 4),
20055 +               "%s: (%s %s) returned %s with %d",
20056 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
20057 +       return ret;
20058 +}
20059 +
20060 +/*
20061 + *      vshelper path is set via /proc/sys
20062 + *      invoked by vserver sys_reboot(), with
20063 + *      the following arguments
20064 + *
20065 + *      argv [0] = vshelper_path;
20066 + *      argv [1] = action: "restart", "halt", "poweroff", ...
20067 + *      argv [2] = context identifier
20068 + *
20069 + *      envp [*] = type-specific parameters
20070 + */
20071 +
20072 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
20073 +{
20074 +       char id_buf[8], cmd_buf[16];
20075 +       char uid_buf[16], pid_buf[16];
20076 +       int ret;
20077 +
20078 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20079 +       char *envp[] = {"HOME=/", "TERM=linux",
20080 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
20081 +                       uid_buf, pid_buf, cmd_buf, 0};
20082 +
20083 +       if (vx_info_state(vxi, VXS_HELPER))
20084 +               return -EAGAIN;
20085 +       vxi->vx_state |= VXS_HELPER;
20086 +
20087 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20088 +
20089 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20090 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current->uid);
20091 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
20092 +
20093 +       switch (cmd) {
20094 +       case LINUX_REBOOT_CMD_RESTART:
20095 +               argv[1] = "restart";
20096 +               break;
20097 +
20098 +       case LINUX_REBOOT_CMD_HALT:
20099 +               argv[1] = "halt";
20100 +               break;
20101 +
20102 +       case LINUX_REBOOT_CMD_POWER_OFF:
20103 +               argv[1] = "poweroff";
20104 +               break;
20105 +
20106 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
20107 +               argv[1] = "swsusp";
20108 +               break;
20109 +
20110 +       default:
20111 +               vxi->vx_state &= ~VXS_HELPER;
20112 +               return 0;
20113 +       }
20114 +
20115 +#ifndef CONFIG_VSERVER_LEGACY
20116 +       ret = do_vshelper(vshelper_path, argv, envp, 1);
20117 +#else
20118 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
20119 +#endif
20120 +       vxi->vx_state &= ~VXS_HELPER;
20121 +       __wakeup_vx_info(vxi);
20122 +       return (ret) ? -EPERM : 0;
20123 +}
20124 +
20125 +
20126 +long vs_reboot(unsigned int cmd, void __user *arg)
20127 +{
20128 +       struct vx_info *vxi = current->vx_info;
20129 +       long ret = 0;
20130 +
20131 +       vxdprintk(VXD_CBIT(misc, 5),
20132 +               "vs_reboot(%p[#%d],%d)",
20133 +               vxi, vxi ? vxi->vx_id : 0, cmd);
20134 +
20135 +       ret = vs_reboot_helper(vxi, cmd, arg);
20136 +       if (ret)
20137 +               return ret;
20138 +
20139 +       vxi->reboot_cmd = cmd;
20140 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
20141 +               switch (cmd) {
20142 +               case LINUX_REBOOT_CMD_RESTART:
20143 +               case LINUX_REBOOT_CMD_HALT:
20144 +               case LINUX_REBOOT_CMD_POWER_OFF:
20145 +                       vx_info_kill(vxi, 0, SIGKILL);
20146 +                       vx_info_kill(vxi, 1, SIGKILL);
20147 +               default:
20148 +                       break;
20149 +               }
20150 +       }
20151 +       return 0;
20152 +}
20153 +
20154 +
20155 +/*
20156 + *      argv [0] = vshelper_path;
20157 + *      argv [1] = action: "startup", "shutdown"
20158 + *      argv [2] = context identifier
20159 + *
20160 + *      envp [*] = type-specific parameters
20161 + */
20162 +
20163 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
20164 +{
20165 +       char id_buf[8], cmd_buf[16];
20166 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20167 +       char *envp[] = {"HOME=/", "TERM=linux",
20168 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20169 +
20170 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
20171 +               return 0;
20172 +
20173 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20174 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20175 +
20176 +       switch (cmd) {
20177 +       case VSC_STARTUP:
20178 +               argv[1] = "startup";
20179 +               break;
20180 +       case VSC_SHUTDOWN:
20181 +               argv[1] = "shutdown";
20182 +               break;
20183 +       default:
20184 +               return 0;
20185 +       }
20186 +
20187 +       return do_vshelper(vshelper_path, argv, envp, 1);
20188 +}
20189 +
20190 +
20191 +/*
20192 + *      argv [0] = vshelper_path;
20193 + *      argv [1] = action: "netup", "netdown"
20194 + *      argv [2] = context identifier
20195 + *
20196 + *      envp [*] = type-specific parameters
20197 + */
20198 +
20199 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
20200 +{
20201 +       char id_buf[8], cmd_buf[16];
20202 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20203 +       char *envp[] = {"HOME=/", "TERM=linux",
20204 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20205 +
20206 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
20207 +               return 0;
20208 +
20209 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
20210 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20211 +
20212 +       switch (cmd) {
20213 +       case VSC_NETUP:
20214 +               argv[1] = "netup";
20215 +               break;
20216 +       case VSC_NETDOWN:
20217 +               argv[1] = "netdown";
20218 +               break;
20219 +       default:
20220 +               return 0;
20221 +       }
20222 +
20223 +       return do_vshelper(vshelper_path, argv, envp, 1);
20224 +}
20225 +
20226 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/history.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/history.c
20227 --- linux-2.6.24-rc7/kernel/vserver/history.c   1970-01-01 01:00:00 +0100
20228 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/history.c     2007-12-13 13:25:42 +0100
20229 @@ -0,0 +1,264 @@
20230 +/*
20231 + *  kernel/vserver/history.c
20232 + *
20233 + *  Virtual Context History Backtrace
20234 + *
20235 + *  Copyright (C) 2004-2007  Herbert Pötzl
20236 + *
20237 + *  V0.01  basic structure
20238 + *  V0.02  hash/unhash and trace
20239 + *  V0.03  preemption fixes
20240 + *
20241 + */
20242 +
20243 +#include <linux/errno.h>
20244 +#include <linux/module.h>
20245 +#include <linux/types.h>
20246 +#include <linux/ctype.h>
20247 +
20248 +#include <asm/uaccess.h>
20249 +#include <asm/atomic.h>
20250 +#include <asm/unistd.h>
20251 +
20252 +#include <linux/vserver/context.h>
20253 +#include <linux/vserver/debug.h>
20254 +#include <linux/vserver/debug_cmd.h>
20255 +#include <linux/vserver/history.h>
20256 +
20257 +
20258 +#ifdef CONFIG_VSERVER_HISTORY
20259 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
20260 +#else
20261 +#define VXH_SIZE       64
20262 +#endif
20263 +
20264 +struct _vx_history {
20265 +       unsigned int counter;
20266 +
20267 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
20268 +};
20269 +
20270 +
20271 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
20272 +
20273 +unsigned volatile int vxh_active = 1;
20274 +
20275 +static atomic_t sequence = ATOMIC_INIT(0);
20276 +
20277 +
20278 +/*     vxh_advance()
20279 +
20280 +       * requires disabled preemption                          */
20281 +
20282 +struct _vx_hist_entry *vxh_advance(void *loc)
20283 +{
20284 +       unsigned int cpu = smp_processor_id();
20285 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20286 +       struct _vx_hist_entry *entry;
20287 +       unsigned int index;
20288 +
20289 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
20290 +       entry = &hist->entry[index];
20291 +
20292 +       entry->seq = atomic_inc_return(&sequence);
20293 +       entry->loc = loc;
20294 +       return entry;
20295 +}
20296 +
20297 +EXPORT_SYMBOL_GPL(vxh_advance);
20298 +
20299 +
20300 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
20301 +
20302 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
20303 +
20304 +
20305 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
20306 +
20307 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
20308 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
20309 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
20310 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
20311 +
20312 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
20313 +{
20314 +       switch (e->type) {
20315 +       case VXH_THROW_OOPS:
20316 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
20317 +               break;
20318 +
20319 +       case VXH_GET_VX_INFO:
20320 +       case VXH_PUT_VX_INFO:
20321 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20322 +                       VXH_LOC_ARGS(e),
20323 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
20324 +                       VXH_VXI_ARGS(e));
20325 +               break;
20326 +
20327 +       case VXH_INIT_VX_INFO:
20328 +       case VXH_SET_VX_INFO:
20329 +       case VXH_CLR_VX_INFO:
20330 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20331 +                       VXH_LOC_ARGS(e),
20332 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
20333 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
20334 +                       VXH_VXI_ARGS(e), e->sc.data);
20335 +               break;
20336 +
20337 +       case VXH_CLAIM_VX_INFO:
20338 +       case VXH_RELEASE_VX_INFO:
20339 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20340 +                       VXH_LOC_ARGS(e),
20341 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
20342 +                       VXH_VXI_ARGS(e), e->sc.data);
20343 +               break;
20344 +
20345 +       case VXH_ALLOC_VX_INFO:
20346 +       case VXH_DEALLOC_VX_INFO:
20347 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20348 +                       VXH_LOC_ARGS(e),
20349 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
20350 +                       VXH_VXI_ARGS(e));
20351 +               break;
20352 +
20353 +       case VXH_HASH_VX_INFO:
20354 +       case VXH_UNHASH_VX_INFO:
20355 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
20356 +                       VXH_LOC_ARGS(e),
20357 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
20358 +                       VXH_VXI_ARGS(e));
20359 +               break;
20360 +
20361 +       case VXH_LOC_VX_INFO:
20362 +       case VXH_LOOKUP_VX_INFO:
20363 +       case VXH_CREATE_VX_INFO:
20364 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
20365 +                       VXH_LOC_ARGS(e),
20366 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
20367 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
20368 +                       e->ll.arg, VXH_VXI_ARGS(e));
20369 +               break;
20370 +       }
20371 +}
20372 +
20373 +static void __vxh_dump_history(void)
20374 +{
20375 +       unsigned int i, cpu;
20376 +
20377 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
20378 +               atomic_read(&sequence), NR_CPUS);
20379 +
20380 +       for (i = 0; i < VXH_SIZE; i++) {
20381 +               for_each_online_cpu(cpu) {
20382 +                       struct _vx_history *hist =
20383 +                               &per_cpu(vx_history_buffer, cpu);
20384 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
20385 +                       struct _vx_hist_entry *entry = &hist->entry[index];
20386 +
20387 +                       vxh_dump_entry(entry, cpu);
20388 +               }
20389 +       }
20390 +}
20391 +
20392 +void   vxh_dump_history(void)
20393 +{
20394 +       vxh_active = 0;
20395 +#ifdef CONFIG_SMP
20396 +       local_irq_enable();
20397 +       smp_send_stop();
20398 +       local_irq_disable();
20399 +#endif
20400 +       __vxh_dump_history();
20401 +}
20402 +
20403 +
20404 +/* vserver syscall commands below here */
20405 +
20406 +
20407 +int vc_dump_history(uint32_t id)
20408 +{
20409 +       vxh_active = 0;
20410 +       __vxh_dump_history();
20411 +       vxh_active = 1;
20412 +
20413 +       return 0;
20414 +}
20415 +
20416 +
20417 +int do_read_history(struct __user _vx_hist_entry *data,
20418 +       int cpu, uint32_t *index, uint32_t *count)
20419 +{
20420 +       int pos, ret = 0;
20421 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20422 +       int end = hist->counter;
20423 +       int start = end - VXH_SIZE + 2;
20424 +       int idx = *index;
20425 +
20426 +       /* special case: get current pos */
20427 +       if (!*count) {
20428 +               *index = end;
20429 +               return 0;
20430 +       }
20431 +
20432 +       /* have we lost some data? */
20433 +       if (idx < start)
20434 +               idx = start;
20435 +
20436 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
20437 +               struct _vx_hist_entry *entry =
20438 +                       &hist->entry[idx % VXH_SIZE];
20439 +
20440 +               /* send entry to userspace */
20441 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
20442 +               if (ret)
20443 +                       break;
20444 +       }
20445 +       /* save new index and count */
20446 +       *index = idx;
20447 +       *count = pos;
20448 +       return ret ? ret : (*index < end);
20449 +}
20450 +
20451 +int vc_read_history(uint32_t id, void __user *data)
20452 +{
20453 +       struct vcmd_read_history_v0 vc_data;
20454 +       int ret;
20455 +
20456 +       if (id >= NR_CPUS)
20457 +               return -EINVAL;
20458 +
20459 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20460 +               return -EFAULT;
20461 +
20462 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
20463 +               id, &vc_data.index, &vc_data.count);
20464 +
20465 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20466 +               return -EFAULT;
20467 +       return ret;
20468 +}
20469 +
20470 +#ifdef CONFIG_COMPAT
20471 +
20472 +int vc_read_history_x32(uint32_t id, void __user *data)
20473 +{
20474 +       struct vcmd_read_history_v0_x32 vc_data;
20475 +       int ret;
20476 +
20477 +       if (id >= NR_CPUS)
20478 +               return -EINVAL;
20479 +
20480 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20481 +               return -EFAULT;
20482 +
20483 +       ret = do_read_history((struct __user _vx_hist_entry *)
20484 +               compat_ptr(vc_data.data_ptr),
20485 +               id, &vc_data.index, &vc_data.count);
20486 +
20487 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20488 +               return -EFAULT;
20489 +       return ret;
20490 +}
20491 +
20492 +#endif /* CONFIG_COMPAT */
20493 +
20494 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/init.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/init.c
20495 --- linux-2.6.24-rc7/kernel/vserver/init.c      1970-01-01 01:00:00 +0100
20496 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/init.c        2007-12-13 13:25:26 +0100
20497 @@ -0,0 +1,47 @@
20498 +/*
20499 + *  linux/kernel/init.c
20500 + *
20501 + *  Virtual Server Init
20502 + *
20503 + *  Copyright (C) 2004-2007  Herbert Pötzl
20504 + *
20505 + *  V0.01  basic structure
20506 + *
20507 + */
20508 +
20509 +#include <linux/errno.h>
20510 +#include <linux/init.h>
20511 +#include <linux/module.h>
20512 +
20513 +int    vserver_register_sysctl(void);
20514 +void   vserver_unregister_sysctl(void);
20515 +
20516 +
20517 +static int __init init_vserver(void)
20518 +{
20519 +       int ret = 0;
20520 +
20521 +#ifdef CONFIG_VSERVER_DEBUG
20522 +       vserver_register_sysctl();
20523 +#endif
20524 +       return ret;
20525 +}
20526 +
20527 +
20528 +static void __exit exit_vserver(void)
20529 +{
20530 +
20531 +#ifdef CONFIG_VSERVER_DEBUG
20532 +       vserver_unregister_sysctl();
20533 +#endif
20534 +       return;
20535 +}
20536 +
20537 +/* FIXME: GFP_ZONETYPES gone
20538 +long vx_slab[GFP_ZONETYPES]; */
20539 +long vx_area;
20540 +
20541 +
20542 +module_init(init_vserver);
20543 +module_exit(exit_vserver);
20544 +
20545 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/inode.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/inode.c
20546 --- linux-2.6.24-rc7/kernel/vserver/inode.c     1970-01-01 01:00:00 +0100
20547 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/inode.c       2007-12-13 13:25:38 +0100
20548 @@ -0,0 +1,417 @@
20549 +/*
20550 + *  linux/kernel/vserver/inode.c
20551 + *
20552 + *  Virtual Server: File System Support
20553 + *
20554 + *  Copyright (C) 2004-2007  Herbert Pötzl
20555 + *
20556 + *  V0.01  separated from vcontext V0.05
20557 + *
20558 + */
20559 +
20560 +#include <linux/sched.h>
20561 +#include <linux/proc_fs.h>
20562 +#include <linux/devpts_fs.h>
20563 +#include <linux/namei.h>
20564 +#include <linux/mount.h>
20565 +#include <linux/parser.h>
20566 +#include <linux/file.h>
20567 +#include <linux/compat.h>
20568 +#include <linux/vserver/inode.h>
20569 +#include <linux/vserver/inode_cmd.h>
20570 +#include <linux/vs_base.h>
20571 +#include <linux/vs_tag.h>
20572 +
20573 +#include <asm/errno.h>
20574 +#include <asm/uaccess.h>
20575 +
20576 +
20577 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
20578 +{
20579 +       struct proc_dir_entry *entry;
20580 +
20581 +       if (!in || !in->i_sb)
20582 +               return -ESRCH;
20583 +
20584 +       *flags = IATTR_TAG
20585 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
20586 +               | (IS_IUNLINK(in) ? IATTR_IUNLINK : 0)
20587 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0);
20588 +       *mask = IATTR_IUNLINK | IATTR_IMMUTABLE;
20589 +
20590 +       if (S_ISDIR(in->i_mode))
20591 +               *mask |= IATTR_BARRIER;
20592 +
20593 +       if (IS_TAGGED(in)) {
20594 +               *tag = in->i_tag;
20595 +               *mask |= IATTR_TAG;
20596 +       }
20597 +
20598 +       switch (in->i_sb->s_magic) {
20599 +       case PROC_SUPER_MAGIC:
20600 +               entry = PROC_I(in)->pde;
20601 +
20602 +               /* check for specific inodes? */
20603 +               if (entry)
20604 +                       *mask |= IATTR_FLAGS;
20605 +               if (entry)
20606 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
20607 +               else
20608 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
20609 +               break;
20610 +
20611 +       case DEVPTS_SUPER_MAGIC:
20612 +               *tag = in->i_tag;
20613 +               *mask |= IATTR_TAG;
20614 +               break;
20615 +
20616 +       default:
20617 +               break;
20618 +       }
20619 +       return 0;
20620 +}
20621 +
20622 +int vc_get_iattr(void __user *data)
20623 +{
20624 +       struct nameidata nd;
20625 +       struct vcmd_ctx_iattr_v1 vc_data = { .xid = -1 };
20626 +       int ret;
20627 +
20628 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20629 +               return -EFAULT;
20630 +
20631 +       ret = user_path_walk_link(vc_data.name, &nd);
20632 +       if (!ret) {
20633 +               ret = __vc_get_iattr(nd.dentry->d_inode,
20634 +                       &vc_data.xid, &vc_data.flags, &vc_data.mask);
20635 +               path_release(&nd);
20636 +       }
20637 +       if (ret)
20638 +               return ret;
20639 +
20640 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20641 +               ret = -EFAULT;
20642 +       return ret;
20643 +}
20644 +
20645 +#ifdef CONFIG_COMPAT
20646 +
20647 +int vc_get_iattr_x32(void __user *data)
20648 +{
20649 +       struct nameidata nd;
20650 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .xid = -1 };
20651 +       int ret;
20652 +
20653 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20654 +               return -EFAULT;
20655 +
20656 +       ret = user_path_walk_link(compat_ptr(vc_data.name_ptr), &nd);
20657 +       if (!ret) {
20658 +               ret = __vc_get_iattr(nd.dentry->d_inode,
20659 +                       &vc_data.xid, &vc_data.flags, &vc_data.mask);
20660 +               path_release(&nd);
20661 +       }
20662 +       if (ret)
20663 +               return ret;
20664 +
20665 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20666 +               ret = -EFAULT;
20667 +       return ret;
20668 +}
20669 +
20670 +#endif /* CONFIG_COMPAT */
20671 +
20672 +
20673 +int vc_fget_iattr(uint32_t fd, void __user *data)
20674 +{
20675 +       struct file *filp;
20676 +       struct vcmd_ctx_fiattr_v0 vc_data = { .xid = -1 };
20677 +       int ret;
20678 +
20679 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20680 +               return -EFAULT;
20681 +
20682 +       filp = fget(fd);
20683 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
20684 +               return -EBADF;
20685 +
20686 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
20687 +               &vc_data.xid, &vc_data.flags, &vc_data.mask);
20688 +
20689 +       fput(filp);
20690 +
20691 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20692 +               ret = -EFAULT;
20693 +       return ret;
20694 +}
20695 +
20696 +
20697 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
20698 +{
20699 +       struct inode *in = de->d_inode;
20700 +       int error = 0, is_proc = 0, has_tag = 0;
20701 +       struct iattr attr = { 0 };
20702 +
20703 +       if (!in || !in->i_sb)
20704 +               return -ESRCH;
20705 +
20706 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
20707 +       if ((*mask & IATTR_FLAGS) && !is_proc)
20708 +               return -EINVAL;
20709 +
20710 +       has_tag = IS_TAGGED(in) ||
20711 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
20712 +       if ((*mask & IATTR_TAG) && !has_tag)
20713 +               return -EINVAL;
20714 +
20715 +       mutex_lock(&in->i_mutex);
20716 +       if (*mask & IATTR_TAG) {
20717 +               attr.ia_tag = *tag;
20718 +               attr.ia_valid |= ATTR_TAG;
20719 +       }
20720 +
20721 +       if (*mask & IATTR_FLAGS) {
20722 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
20723 +               unsigned int iflags = PROC_I(in)->vx_flags;
20724 +
20725 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
20726 +                       | (*flags & IATTR_FLAGS);
20727 +               PROC_I(in)->vx_flags = iflags;
20728 +               if (entry)
20729 +                       entry->vx_flags = iflags;
20730 +       }
20731 +
20732 +       if (*mask & (IATTR_BARRIER | IATTR_IUNLINK | IATTR_IMMUTABLE)) {
20733 +               if (*mask & IATTR_IMMUTABLE) {
20734 +                       if (*flags & IATTR_IMMUTABLE)
20735 +                               in->i_flags |= S_IMMUTABLE;
20736 +                       else
20737 +                               in->i_flags &= ~S_IMMUTABLE;
20738 +               }
20739 +               if (*mask & IATTR_IUNLINK) {
20740 +                       if (*flags & IATTR_IUNLINK)
20741 +                               in->i_flags |= S_IUNLINK;
20742 +                       else
20743 +                               in->i_flags &= ~S_IUNLINK;
20744 +               }
20745 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
20746 +                       if (*flags & IATTR_BARRIER)
20747 +                               in->i_flags |= S_BARRIER;
20748 +                       else
20749 +                               in->i_flags &= ~S_BARRIER;
20750 +               }
20751 +               if (in->i_op && in->i_op->sync_flags) {
20752 +                       error = in->i_op->sync_flags(in);
20753 +                       if (error)
20754 +                               goto out;
20755 +               }
20756 +       }
20757 +
20758 +       if (attr.ia_valid) {
20759 +               if (in->i_op && in->i_op->setattr)
20760 +                       error = in->i_op->setattr(de, &attr);
20761 +               else {
20762 +                       error = inode_change_ok(in, &attr);
20763 +                       if (!error)
20764 +                               error = inode_setattr(in, &attr);
20765 +               }
20766 +       }
20767 +
20768 +out:
20769 +       mutex_unlock(&in->i_mutex);
20770 +       return error;
20771 +}
20772 +
20773 +int vc_set_iattr(void __user *data)
20774 +{
20775 +       struct nameidata nd;
20776 +       struct vcmd_ctx_iattr_v1 vc_data;
20777 +       int ret;
20778 +
20779 +       if (!capable(CAP_LINUX_IMMUTABLE))
20780 +               return -EPERM;
20781 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20782 +               return -EFAULT;
20783 +
20784 +       ret = user_path_walk_link(vc_data.name, &nd);
20785 +       if (!ret) {
20786 +               ret = __vc_set_iattr(nd.dentry,
20787 +                       &vc_data.xid, &vc_data.flags, &vc_data.mask);
20788 +               path_release(&nd);
20789 +       }
20790 +
20791 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20792 +               ret = -EFAULT;
20793 +       return ret;
20794 +}
20795 +
20796 +#ifdef CONFIG_COMPAT
20797 +
20798 +int vc_set_iattr_x32(void __user *data)
20799 +{
20800 +       struct nameidata nd;
20801 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
20802 +       int ret;
20803 +
20804 +       if (!capable(CAP_LINUX_IMMUTABLE))
20805 +               return -EPERM;
20806 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20807 +               return -EFAULT;
20808 +
20809 +       ret = user_path_walk_link(compat_ptr(vc_data.name_ptr), &nd);
20810 +       if (!ret) {
20811 +               ret = __vc_set_iattr(nd.dentry,
20812 +                       &vc_data.xid, &vc_data.flags, &vc_data.mask);
20813 +               path_release(&nd);
20814 +       }
20815 +
20816 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20817 +               ret = -EFAULT;
20818 +       return ret;
20819 +}
20820 +
20821 +#endif /* CONFIG_COMPAT */
20822 +
20823 +int vc_fset_iattr(uint32_t fd, void __user *data)
20824 +{
20825 +       struct file *filp;
20826 +       struct vcmd_ctx_fiattr_v0 vc_data;
20827 +       int ret;
20828 +
20829 +       if (!capable(CAP_LINUX_IMMUTABLE))
20830 +               return -EPERM;
20831 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20832 +               return -EFAULT;
20833 +
20834 +       filp = fget(fd);
20835 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
20836 +               return -EBADF;
20837 +
20838 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.xid,
20839 +               &vc_data.flags, &vc_data.mask);
20840 +
20841 +       fput(filp);
20842 +
20843 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20844 +               return -EFAULT;
20845 +       return ret;
20846 +}
20847 +
20848 +#ifdef CONFIG_VSERVER_LEGACY
20849 +
20850 +#define PROC_DYNAMIC_FIRST 0xF0000000UL
20851 +
20852 +int vx_proc_ioctl(struct inode *inode, struct file *filp,
20853 +       unsigned int cmd, unsigned long arg)
20854 +{
20855 +       struct proc_dir_entry *entry;
20856 +       int error = 0;
20857 +       int flags;
20858 +
20859 +       if (inode->i_ino < PROC_DYNAMIC_FIRST)
20860 +               return -ENOTTY;
20861 +
20862 +       entry = PROC_I(inode)->pde;
20863 +       if (!entry)
20864 +               return -ENOTTY;
20865 +
20866 +       switch(cmd) {
20867 +       case FIOC_GETXFLG: {
20868 +               /* fixme: if stealth, return -ENOTTY */
20869 +               error = -EPERM;
20870 +               flags = entry->vx_flags;
20871 +               if (capable(CAP_CONTEXT))
20872 +                       error = put_user(flags, (int __user *) arg);
20873 +               break;
20874 +       }
20875 +       case FIOC_SETXFLG: {
20876 +               /* fixme: if stealth, return -ENOTTY */
20877 +               error = -EPERM;
20878 +               if (!capable(CAP_CONTEXT))
20879 +                       break;
20880 +               error = -EROFS;
20881 +               if (IS_RDONLY(inode))
20882 +                       break;
20883 +               error = -EFAULT;
20884 +               if (get_user(flags, (int __user *) arg))
20885 +                       break;
20886 +               error = 0;
20887 +               entry->vx_flags = flags;
20888 +               break;
20889 +       }
20890 +       default:
20891 +               return -ENOTTY;
20892 +       }
20893 +       return error;
20894 +}
20895 +#endif /* CONFIG_VSERVER_LEGACY */
20896 +
20897 +#ifdef CONFIG_PROPAGATE
20898 +
20899 +int dx_parse_tag(char *string, tag_t *tag, int remove)
20900 +{
20901 +       static match_table_t tokens = {
20902 +               {1, "tagid=%u"},
20903 +               {0, NULL}
20904 +       };
20905 +       substring_t args[MAX_OPT_ARGS];
20906 +       int token, option = 0;
20907 +
20908 +       if (!string)
20909 +               return 0;
20910 +
20911 +       token = match_token(string, tokens, args);
20912 +       if (token && tag && !match_int(args, &option))
20913 +               *tag = option;
20914 +
20915 +       vxdprintk(VXD_CBIT(tag, 7),
20916 +               "dx_parse_tag(»%s«): %d:#%d",
20917 +               string, token, option);
20918 +
20919 +       if ((token == 1) && remove) {
20920 +               char *p = strstr(string, "tagid=");
20921 +               char *q = p;
20922 +
20923 +               if (p) {
20924 +                       while (*q != '\0' && *q != ',')
20925 +                               q++;
20926 +                       while (*q)
20927 +                               *p++ = *q++;
20928 +                       while (*p)
20929 +                               *p++ = '\0';
20930 +               }
20931 +       }
20932 +       return token;
20933 +}
20934 +
20935 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
20936 +{
20937 +       tag_t new_tag = 0;
20938 +       struct vfsmount *mnt;
20939 +       int propagate;
20940 +
20941 +       if (!nd)
20942 +               return;
20943 +       mnt = nd->mnt;
20944 +       if (!mnt)
20945 +               return;
20946 +
20947 +       propagate = (mnt->mnt_flags & MNT_TAGID);
20948 +       if (propagate)
20949 +               new_tag = mnt->mnt_tag;
20950 +
20951 +       vxdprintk(VXD_CBIT(tag, 7),
20952 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
20953 +               inode, inode->i_ino, inode->i_tag,
20954 +               new_tag, (propagate) ? 1 : 0);
20955 +
20956 +       if (propagate)
20957 +               inode->i_tag = new_tag;
20958 +}
20959 +
20960 +#include <linux/module.h>
20961 +
20962 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
20963 +
20964 +#endif /* CONFIG_PROPAGATE */
20965 +
20966 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/legacy.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/legacy.c
20967 --- linux-2.6.24-rc7/kernel/vserver/legacy.c    1970-01-01 01:00:00 +0100
20968 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/legacy.c      2007-12-13 13:25:52 +0100
20969 @@ -0,0 +1,114 @@
20970 +/*
20971 + *  linux/kernel/vserver/legacy.c
20972 + *
20973 + *  Virtual Server: Legacy Funtions
20974 + *
20975 + *  Copyright (C) 2001-2003  Jacques Gelinas
20976 + *  Copyright (C) 2003-2007  Herbert Pötzl
20977 + *
20978 + *  V0.01  broken out from vcontext.c V0.05
20979 + *  V0.02  updated to spaces *sigh*
20980 + *
20981 + */
20982 +
20983 +#include <linux/sched.h>
20984 +#include <linux/vs_context.h>
20985 +#include <linux/vs_network.h>
20986 +#include <linux/vserver/legacy.h>
20987 +#include <linux/vserver/space.h>
20988 +// #include <linux/mnt_namespace.h>
20989 +
20990 +#include <asm/errno.h>
20991 +#include <asm/uaccess.h>
20992 +
20993 +
20994 +extern int vx_set_init(struct vx_info *, struct task_struct *);
20995 +
20996 +static int vx_set_initpid(struct vx_info *vxi, int pid)
20997 +{
20998 +       struct task_struct *init;
20999 +
21000 +       init = find_task_by_real_pid(pid);
21001 +       if (!init)
21002 +               return -ESRCH;
21003 +       return vx_set_init(vxi, init);
21004 +}
21005 +
21006 +int vc_new_s_context(uint32_t ctx, void __user *data)
21007 +{
21008 +       int ret = -ENOMEM;
21009 +       struct vcmd_new_s_context_v1 vc_data;
21010 +       struct vx_info *new_vxi;
21011 +
21012 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21013 +               return -EFAULT;
21014 +
21015 +       /* legacy hack, will be removed soon */
21016 +       if (ctx == -2) {
21017 +               /* assign flags and initpid */
21018 +               if (!current->vx_info)
21019 +                       return -EINVAL;
21020 +               ret = 0;
21021 +               if (vc_data.flags & VX_INFO_INIT)
21022 +                       ret = vx_set_initpid(current->vx_info, current->tgid);
21023 +               if (ret == 0) {
21024 +                       /* We keep the same vx_id, but lower the capabilities */
21025 +                       current->vx_info->vx_bcaps &= (~vc_data.remove_cap);
21026 +                       ret = vx_current_xid();
21027 +                       current->vx_info->vx_flags |= vc_data.flags;
21028 +               }
21029 +               return ret;
21030 +       }
21031 +
21032 +       if (!vx_check(0, VS_ADMIN) || !capable(CAP_SYS_ADMIN)
21033 +               /* might make sense in the future, or not ... */
21034 +               || vx_flags(VX_INFO_PRIVATE, 0))
21035 +               return -EPERM;
21036 +
21037 +       /* ugly hack for Spectator */
21038 +       if (ctx == 1) {
21039 +               current->xid = 1;
21040 +               return 0;
21041 +       }
21042 +
21043 +       if (((ctx > MAX_S_CONTEXT) && (ctx != VX_DYNAMIC_ID)) ||
21044 +               (ctx == 0))
21045 +               return -EINVAL;
21046 +
21047 +       if ((ctx == VX_DYNAMIC_ID) || (ctx < MIN_D_CONTEXT))
21048 +               new_vxi = lookup_or_create_vx_info(ctx);
21049 +       else
21050 +               new_vxi = lookup_vx_info(ctx);
21051 +
21052 +       if (!new_vxi)
21053 +               return -EINVAL;
21054 +
21055 +       ret = -EPERM;
21056 +       if (!vx_info_flags(new_vxi, VXF_STATE_SETUP, 0) &&
21057 +               vx_info_flags(new_vxi, VX_INFO_PRIVATE, 0))
21058 +               goto out_put;
21059 +
21060 +       ret = vx_migrate_task(current, new_vxi,
21061 +               vx_info_flags(new_vxi, VXF_STATE_SETUP, 0));
21062 +       new_vxi->vx_flags &= ~VXF_STATE_SETUP;
21063 +
21064 +       if (ret == 0) {
21065 +               current->vx_info->vx_bcaps &= (~vc_data.remove_cap);
21066 +               new_vxi->vx_flags |= vc_data.flags;
21067 +               if (vc_data.flags & VX_INFO_INIT)
21068 +                       vx_set_initpid(new_vxi, current->tgid);
21069 +               if (vc_data.flags & VX_INFO_NAMESPACE)
21070 +                       vx_set_space(new_vxi, CLONE_NEWNS | CLONE_FS);
21071 +               if (vc_data.flags & VX_INFO_NPROC)
21072 +                       __rlim_set(&new_vxi->limit, RLIMIT_NPROC,
21073 +                               current->signal->rlim[RLIMIT_NPROC].rlim_max);
21074 +
21075 +               /* tweak some defaults for legacy */
21076 +               new_vxi->vx_flags |= (VXF_HIDE_NETIF | VXF_INFO_INIT);
21077 +               ret = new_vxi->vx_id;
21078 +       }
21079 +out_put:
21080 +       put_vx_info(new_vxi);
21081 +       return ret;
21082 +}
21083 +
21084 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/legacynet.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/legacynet.c
21085 --- linux-2.6.24-rc7/kernel/vserver/legacynet.c 1970-01-01 01:00:00 +0100
21086 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/legacynet.c   2007-12-13 13:25:52 +0100
21087 @@ -0,0 +1,85 @@
21088 +
21089 +/*
21090 + *  linux/kernel/vserver/legacynet.c
21091 + *
21092 + *  Virtual Server: Legacy Network Funtions
21093 + *
21094 + *  Copyright (C) 2001-2003  Jacques Gelinas
21095 + *  Copyright (C) 2003-2007  Herbert Pötzl
21096 + *
21097 + *  V0.01  broken out from legacy.c
21098 + *
21099 + */
21100 +
21101 +#include <linux/sched.h>
21102 +#include <linux/vs_context.h>
21103 +#include <linux/vs_network.h>
21104 +#include <linux/vserver/legacy.h>
21105 +// #include <linux/mnt_namespace.h>
21106 +#include <linux/err.h>
21107 +
21108 +#include <asm/errno.h>
21109 +#include <asm/uaccess.h>
21110 +
21111 +
21112 +extern struct nx_info *create_nx_info(void);
21113 +
21114 +/*  set ipv4 root (syscall) */
21115 +
21116 +int vc_set_ipv4root(uint32_t nbip, void __user *data)
21117 +{
21118 +       int i, err = -EPERM;
21119 +       struct vcmd_set_ipv4root_v3 vc_data;
21120 +       struct nx_info *new_nxi, *nxi = current->nx_info;
21121 +
21122 +       if (nbip < 0 || nbip > NB_IPV4ROOT)
21123 +               return -EINVAL;
21124 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21125 +               return -EFAULT;
21126 +
21127 +       if (!nxi || nxi->ipv4[0] == 0 || capable(CAP_NET_ADMIN))
21128 +               /* We are allowed to change everything */
21129 +               err = 0;
21130 +       else if (nxi) {
21131 +               int found = 0;
21132 +
21133 +               /* We are allowed to select a subset of the currently
21134 +                  installed IP numbers. No new one are allowed
21135 +                  We can't change the broadcast address though */
21136 +               for (i = 0; i < nbip; i++) {
21137 +                       int j;
21138 +                       __u32 nxip = vc_data.nx_mask_pair[i].ip;
21139 +                       for (j = 0; j < nxi->nbipv4; j++) {
21140 +                               if (nxip == nxi->ipv4[j]) {
21141 +                                       found++;
21142 +                                       break;
21143 +                               }
21144 +                       }
21145 +               }
21146 +               if ((found == nbip) &&
21147 +                       (vc_data.broadcast == nxi->v4_bcast))
21148 +                       err = 0;
21149 +       }
21150 +       if (err)
21151 +               return err;
21152 +
21153 +       new_nxi = create_nx_info();
21154 +       if (IS_ERR(new_nxi))
21155 +               return -EINVAL;
21156 +
21157 +       new_nxi->nbipv4 = nbip;
21158 +       for (i = 0; i < nbip; i++) {
21159 +               new_nxi->ipv4[i] = vc_data.nx_mask_pair[i].ip;
21160 +               new_nxi->mask[i] = vc_data.nx_mask_pair[i].mask;
21161 +       }
21162 +       new_nxi->v4_bcast = vc_data.broadcast;
21163 +       if (nxi)
21164 +               printk("!!! switching nx_info %p->%p\n", nxi, new_nxi);
21165 +
21166 +       nx_migrate_task(current, new_nxi);
21167 +       release_nx_info(new_nxi, NULL);
21168 +       put_nx_info(new_nxi);
21169 +       return 0;
21170 +}
21171 +
21172 +
21173 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/limit.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/limit.c
21174 --- linux-2.6.24-rc7/kernel/vserver/limit.c     1970-01-01 01:00:00 +0100
21175 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/limit.c       2007-12-13 13:25:42 +0100
21176 @@ -0,0 +1,319 @@
21177 +/*
21178 + *  linux/kernel/vserver/limit.c
21179 + *
21180 + *  Virtual Server: Context Limits
21181 + *
21182 + *  Copyright (C) 2004-2007  Herbert Pötzl
21183 + *
21184 + *  V0.01  broken out from vcontext V0.05
21185 + *  V0.02  changed vcmds to vxi arg
21186 + *
21187 + */
21188 +
21189 +#include <linux/module.h>
21190 +#include <linux/vs_context.h>
21191 +#include <linux/vs_limit.h>
21192 +#include <linux/vserver/limit.h>
21193 +#include <linux/vserver/switch.h>
21194 +#include <linux/vserver/limit_cmd.h>
21195 +
21196 +#include <asm/errno.h>
21197 +#include <asm/uaccess.h>
21198 +
21199 +
21200 +const char *vlimit_name[NUM_LIMITS] = {
21201 +       [RLIMIT_CPU]            = "CPU",
21202 +       [RLIMIT_RSS]            = "RSS",
21203 +       [RLIMIT_NPROC]          = "NPROC",
21204 +       [RLIMIT_NOFILE]         = "NOFILE",
21205 +       [RLIMIT_MEMLOCK]        = "VML",
21206 +       [RLIMIT_AS]             = "VM",
21207 +       [RLIMIT_LOCKS]          = "LOCKS",
21208 +       [RLIMIT_SIGPENDING]     = "SIGP",
21209 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
21210 +
21211 +       [VLIMIT_NSOCK]          = "NSOCK",
21212 +       [VLIMIT_OPENFD]         = "OPENFD",
21213 +       [VLIMIT_ANON]           = "ANON",
21214 +       [VLIMIT_SHMEM]          = "SHMEM",
21215 +       [VLIMIT_DENTRY]         = "DENTRY",
21216 +};
21217 +
21218 +EXPORT_SYMBOL_GPL(vlimit_name);
21219 +
21220 +#define MASK_ENTRY(x)  (1 << (x))
21221 +
21222 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
21223 +               /* minimum */
21224 +       0
21225 +       ,       /* softlimit */
21226 +       MASK_ENTRY( RLIMIT_RSS          ) |
21227 +       MASK_ENTRY( VLIMIT_ANON         ) |
21228 +       0
21229 +       ,       /* maximum */
21230 +       MASK_ENTRY( RLIMIT_RSS          ) |
21231 +       MASK_ENTRY( RLIMIT_NPROC        ) |
21232 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
21233 +       MASK_ENTRY( RLIMIT_MEMLOCK      ) |
21234 +       MASK_ENTRY( RLIMIT_AS           ) |
21235 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
21236 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
21237 +
21238 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
21239 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
21240 +       MASK_ENTRY( VLIMIT_ANON         ) |
21241 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
21242 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
21243 +       0
21244 +};
21245 +               /* accounting only */
21246 +uint32_t account_mask =
21247 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
21248 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
21249 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
21250 +       0;
21251 +
21252 +
21253 +static int is_valid_vlimit(int id)
21254 +{
21255 +       uint32_t mask = vlimit_mask.minimum |
21256 +               vlimit_mask.softlimit | vlimit_mask.maximum;
21257 +       return mask & (1 << id);
21258 +}
21259 +
21260 +static int is_accounted_vlimit(int id)
21261 +{
21262 +       if (is_valid_vlimit(id))
21263 +               return 1;
21264 +       return account_mask & (1 << id);
21265 +}
21266 +
21267 +
21268 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
21269 +{
21270 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
21271 +       return VX_VLIM(limit);
21272 +}
21273 +
21274 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
21275 +{
21276 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
21277 +       return VX_VLIM(limit);
21278 +}
21279 +
21280 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
21281 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
21282 +{
21283 +       if (!is_valid_vlimit(id))
21284 +               return -EINVAL;
21285 +
21286 +       if (minimum)
21287 +               *minimum = CRLIM_UNSET;
21288 +       if (softlimit)
21289 +               *softlimit = vc_get_soft(vxi, id);
21290 +       if (maximum)
21291 +               *maximum = vc_get_hard(vxi, id);
21292 +       return 0;
21293 +}
21294 +
21295 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
21296 +{
21297 +       struct vcmd_ctx_rlimit_v0 vc_data;
21298 +       int ret;
21299 +
21300 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21301 +               return -EFAULT;
21302 +
21303 +       ret = do_get_rlimit(vxi, vc_data.id,
21304 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21305 +       if (ret)
21306 +               return ret;
21307 +
21308 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21309 +               return -EFAULT;
21310 +       return 0;
21311 +}
21312 +
21313 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
21314 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
21315 +{
21316 +       if (!is_valid_vlimit(id))
21317 +               return -EINVAL;
21318 +
21319 +       if (maximum != CRLIM_KEEP)
21320 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
21321 +       if (softlimit != CRLIM_KEEP)
21322 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
21323 +
21324 +       /* clamp soft limit */
21325 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
21326 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
21327 +
21328 +       return 0;
21329 +}
21330 +
21331 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
21332 +{
21333 +       struct vcmd_ctx_rlimit_v0 vc_data;
21334 +
21335 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21336 +               return -EFAULT;
21337 +
21338 +       return do_set_rlimit(vxi, vc_data.id,
21339 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21340 +}
21341 +
21342 +#ifdef CONFIG_IA32_EMULATION
21343 +
21344 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
21345 +{
21346 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21347 +
21348 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21349 +               return -EFAULT;
21350 +
21351 +       return do_set_rlimit(vxi, vc_data.id,
21352 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21353 +}
21354 +
21355 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
21356 +{
21357 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21358 +       int ret;
21359 +
21360 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21361 +               return -EFAULT;
21362 +
21363 +       ret = do_get_rlimit(vxi, vc_data.id,
21364 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21365 +       if (ret)
21366 +               return ret;
21367 +
21368 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21369 +               return -EFAULT;
21370 +       return 0;
21371 +}
21372 +
21373 +#endif /* CONFIG_IA32_EMULATION */
21374 +
21375 +
21376 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
21377 +{
21378 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
21379 +               return -EFAULT;
21380 +       return 0;
21381 +}
21382 +
21383 +
21384 +static inline void vx_reset_minmax(struct _vx_limit *limit)
21385 +{
21386 +       rlim_t value;
21387 +       int lim;
21388 +
21389 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21390 +               value = __rlim_get(limit, lim);
21391 +               __rlim_rmax(limit, lim) = value;
21392 +               __rlim_rmin(limit, lim) = value;
21393 +       }
21394 +}
21395 +
21396 +
21397 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
21398 +{
21399 +       vx_reset_minmax(&vxi->limit);
21400 +       return 0;
21401 +}
21402 +
21403 +
21404 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
21405 +{
21406 +       struct vcmd_rlimit_stat_v0 vc_data;
21407 +       struct _vx_limit *limit = &vxi->limit;
21408 +       int id;
21409 +
21410 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21411 +               return -EFAULT;
21412 +
21413 +       id = vc_data.id;
21414 +       if (!is_accounted_vlimit(id))
21415 +               return -EINVAL;
21416 +
21417 +       vx_limit_fixup(limit, id);
21418 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
21419 +       vc_data.value = __rlim_get(limit, id);
21420 +       vc_data.minimum = __rlim_rmin(limit, id);
21421 +       vc_data.maximum = __rlim_rmax(limit, id);
21422 +
21423 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21424 +               return -EFAULT;
21425 +       return 0;
21426 +}
21427 +
21428 +
21429 +void vx_vsi_meminfo(struct sysinfo *val)
21430 +{
21431 +       struct vx_info *vxi = current->vx_info;
21432 +       unsigned long totalram, freeram;
21433 +       rlim_t v;
21434 +
21435 +       /* we blindly accept the max */
21436 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21437 +       totalram = (v != RLIM_INFINITY) ? v : val->totalram;
21438 +
21439 +       /* total minus used equals free */
21440 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21441 +       freeram = (v < totalram) ? totalram - v : 0;
21442 +
21443 +       val->totalram = totalram;
21444 +       val->freeram = freeram;
21445 +       val->bufferram = 0;
21446 +       val->totalhigh = 0;
21447 +       val->freehigh = 0;
21448 +       return;
21449 +}
21450 +
21451 +void vx_vsi_swapinfo(struct sysinfo *val)
21452 +{
21453 +       struct vx_info *vxi = current->vx_info;
21454 +       unsigned long totalswap, freeswap;
21455 +       rlim_t v, w;
21456 +
21457 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21458 +       if (v == RLIM_INFINITY) {
21459 +               val->freeswap = val->totalswap;
21460 +               return;
21461 +       }
21462 +
21463 +       /* we blindly accept the max */
21464 +       w = __rlim_hard(&vxi->limit, RLIMIT_RSS);
21465 +       totalswap = (w != RLIM_INFINITY) ? (w - v) : val->totalswap;
21466 +
21467 +       /* currently 'used' swap */
21468 +       w = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21469 +       w -= (w > v) ? v : w;
21470 +
21471 +       /* total minus used equals free */
21472 +       freeswap = (w < totalswap) ? totalswap - w : 0;
21473 +
21474 +       val->totalswap = totalswap;
21475 +       val->freeswap = freeswap;
21476 +       return;
21477 +}
21478 +
21479 +
21480 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
21481 +{
21482 +       struct vx_info *vxi = mm->mm_vx_info;
21483 +       unsigned long points;
21484 +       rlim_t v, w;
21485 +
21486 +       if (!vxi)
21487 +               return 0;
21488 +
21489 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21490 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21491 +       points = (v > w) ? (v - w) : 0;
21492 +
21493 +       return points;
21494 +}
21495 +
21496 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/limit_init.h linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/limit_init.h
21497 --- linux-2.6.24-rc7/kernel/vserver/limit_init.h        1970-01-01 01:00:00 +0100
21498 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/limit_init.h  2007-12-13 13:25:43 +0100
21499 @@ -0,0 +1,33 @@
21500 +
21501 +
21502 +static inline void vx_info_init_limit(struct _vx_limit *limit)
21503 +{
21504 +       int lim;
21505 +
21506 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21507 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
21508 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
21509 +               __rlim_set(limit, lim, 0);
21510 +               atomic_set(&__rlim_lhit(limit, lim), 0);
21511 +               __rlim_rmin(limit, lim) = 0;
21512 +               __rlim_rmax(limit, lim) = 0;
21513 +       }
21514 +}
21515 +
21516 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
21517 +{
21518 +#ifdef CONFIG_VSERVER_WARN
21519 +       rlim_t value;
21520 +       int lim;
21521 +
21522 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21523 +               if ((1 << lim) & VLIM_NOCHECK)
21524 +                       continue;
21525 +               value = __rlim_get(limit, lim);
21526 +               vxwprintk_xid(value,
21527 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
21528 +                       limit, vlimit_name[lim], lim, (long)value);
21529 +       }
21530 +#endif
21531 +}
21532 +
21533 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/limit_proc.h linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/limit_proc.h
21534 --- linux-2.6.24-rc7/kernel/vserver/limit_proc.h        1970-01-01 01:00:00 +0100
21535 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/limit_proc.h  2007-12-13 13:25:43 +0100
21536 @@ -0,0 +1,57 @@
21537 +#ifndef _VX_LIMIT_PROC_H
21538 +#define _VX_LIMIT_PROC_H
21539 +
21540 +#include <linux/vserver/limit_int.h>
21541 +
21542 +
21543 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
21544 +#define VX_LIMIT_TOP   \
21545 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
21546 +
21547 +#define VX_LIMIT_ARG(r)                                \
21548 +       (unsigned long)__rlim_get(limit, r),    \
21549 +       (unsigned long)__rlim_rmin(limit, r),   \
21550 +       (unsigned long)__rlim_rmax(limit, r),   \
21551 +       VX_VLIM(__rlim_soft(limit, r)),         \
21552 +       VX_VLIM(__rlim_hard(limit, r)),         \
21553 +       atomic_read(&__rlim_lhit(limit, r))
21554 +
21555 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
21556 +{
21557 +       vx_limit_fixup(limit, -1);
21558 +       return sprintf(buffer, VX_LIMIT_TOP
21559 +               "PROC"  VX_LIMIT_FMT
21560 +               "VM"    VX_LIMIT_FMT
21561 +               "VML"   VX_LIMIT_FMT
21562 +               "RSS"   VX_LIMIT_FMT
21563 +               "ANON"  VX_LIMIT_FMT
21564 +               "RMAP"  VX_LIMIT_FMT
21565 +               "FILES" VX_LIMIT_FMT
21566 +               "OFD"   VX_LIMIT_FMT
21567 +               "LOCKS" VX_LIMIT_FMT
21568 +               "SOCK"  VX_LIMIT_FMT
21569 +               "MSGQ"  VX_LIMIT_FMT
21570 +               "SHM"   VX_LIMIT_FMT
21571 +               "SEMA"  VX_LIMIT_FMT
21572 +               "SEMS"  VX_LIMIT_FMT
21573 +               "DENT"  VX_LIMIT_FMT,
21574 +               VX_LIMIT_ARG(RLIMIT_NPROC),
21575 +               VX_LIMIT_ARG(RLIMIT_AS),
21576 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
21577 +               VX_LIMIT_ARG(RLIMIT_RSS),
21578 +               VX_LIMIT_ARG(VLIMIT_ANON),
21579 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
21580 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
21581 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
21582 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
21583 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
21584 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
21585 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
21586 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
21587 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
21588 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
21589 +}
21590 +
21591 +#endif /* _VX_LIMIT_PROC_H */
21592 +
21593 +
21594 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/monitor.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/monitor.c
21595 --- linux-2.6.24-rc7/kernel/vserver/monitor.c   1970-01-01 01:00:00 +0100
21596 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/monitor.c     2007-12-13 13:25:42 +0100
21597 @@ -0,0 +1,143 @@
21598 +/*
21599 + *  kernel/vserver/monitor.c
21600 + *
21601 + *  Virtual Context Scheduler Monitor
21602 + *
21603 + *  Copyright (C) 2006-2007 Herbert Pötzl
21604 + *
21605 + *  V0.01  basic design
21606 + *
21607 + */
21608 +
21609 +#include <linux/errno.h>
21610 +#include <linux/module.h>
21611 +#include <linux/types.h>
21612 +#include <linux/ctype.h>
21613 +#include <linux/jiffies.h>
21614 +
21615 +#include <asm/uaccess.h>
21616 +#include <asm/atomic.h>
21617 +#include <asm/unistd.h>
21618 +
21619 +#include <linux/vserver/monitor.h>
21620 +#include <linux/vserver/debug_cmd.h>
21621 +
21622 +
21623 +#ifdef CONFIG_VSERVER_MONITOR
21624 +#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
21625 +#else
21626 +#define VXM_SIZE       64
21627 +#endif
21628 +
21629 +struct _vx_monitor {
21630 +       unsigned int counter;
21631 +
21632 +       struct _vx_mon_entry entry[VXM_SIZE+1];
21633 +};
21634 +
21635 +
21636 +DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
21637 +
21638 +unsigned volatile int vxm_active = 1;
21639 +
21640 +static atomic_t sequence = ATOMIC_INIT(0);
21641 +
21642 +
21643 +/*     vxm_advance()
21644 +
21645 +       * requires disabled preemption                          */
21646 +
21647 +struct _vx_mon_entry *vxm_advance(int cpu)
21648 +{
21649 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
21650 +       struct _vx_mon_entry *entry;
21651 +       unsigned int index;
21652 +
21653 +       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
21654 +       entry = &mon->entry[index];
21655 +
21656 +       entry->ev.seq = atomic_inc_return(&sequence);
21657 +       entry->ev.jif = jiffies;
21658 +       return entry;
21659 +}
21660 +
21661 +EXPORT_SYMBOL_GPL(vxm_advance);
21662 +
21663 +
21664 +int do_read_monitor(struct __user _vx_mon_entry *data,
21665 +       int cpu, uint32_t *index, uint32_t *count)
21666 +{
21667 +       int pos, ret = 0;
21668 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
21669 +       int end = mon->counter;
21670 +       int start = end - VXM_SIZE + 2;
21671 +       int idx = *index;
21672 +
21673 +       /* special case: get current pos */
21674 +       if (!*count) {
21675 +               *index = end;
21676 +               return 0;
21677 +       }
21678 +
21679 +       /* have we lost some data? */
21680 +       if (idx < start)
21681 +               idx = start;
21682 +
21683 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
21684 +               struct _vx_mon_entry *entry =
21685 +                       &mon->entry[idx % VXM_SIZE];
21686 +
21687 +               /* send entry to userspace */
21688 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
21689 +               if (ret)
21690 +                       break;
21691 +       }
21692 +       /* save new index and count */
21693 +       *index = idx;
21694 +       *count = pos;
21695 +       return ret ? ret : (*index < end);
21696 +}
21697 +
21698 +int vc_read_monitor(uint32_t id, void __user *data)
21699 +{
21700 +       struct vcmd_read_monitor_v0 vc_data;
21701 +       int ret;
21702 +
21703 +       if (id >= NR_CPUS)
21704 +               return -EINVAL;
21705 +
21706 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21707 +               return -EFAULT;
21708 +
21709 +       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
21710 +               id, &vc_data.index, &vc_data.count);
21711 +
21712 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21713 +               return -EFAULT;
21714 +       return ret;
21715 +}
21716 +
21717 +#ifdef CONFIG_COMPAT
21718 +
21719 +int vc_read_monitor_x32(uint32_t id, void __user *data)
21720 +{
21721 +       struct vcmd_read_monitor_v0_x32 vc_data;
21722 +       int ret;
21723 +
21724 +       if (id >= NR_CPUS)
21725 +               return -EINVAL;
21726 +
21727 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21728 +               return -EFAULT;
21729 +
21730 +       ret = do_read_monitor((struct __user _vx_mon_entry *)
21731 +               compat_ptr(vc_data.data_ptr),
21732 +               id, &vc_data.index, &vc_data.count);
21733 +
21734 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21735 +               return -EFAULT;
21736 +       return ret;
21737 +}
21738 +
21739 +#endif /* CONFIG_COMPAT */
21740 +
21741 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/network.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/network.c
21742 --- linux-2.6.24-rc7/kernel/vserver/network.c   1970-01-01 01:00:00 +0100
21743 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/network.c     2007-12-13 15:56:57 +0100
21744 @@ -0,0 +1,772 @@
21745 +/*
21746 + *  linux/kernel/vserver/network.c
21747 + *
21748 + *  Virtual Server: Network Support
21749 + *
21750 + *  Copyright (C) 2003-2007  Herbert Pötzl
21751 + *
21752 + *  V0.01  broken out from vcontext V0.05
21753 + *  V0.02  cleaned up implementation
21754 + *  V0.03  added equiv nx commands
21755 + *  V0.04  switch to RCU based hash
21756 + *  V0.05  and back to locking again
21757 + *  V0.06  changed vcmds to nxi arg
21758 + *  V0.07  have __create claim() the nxi
21759 + *
21760 + */
21761 +
21762 +#include <linux/slab.h>
21763 +#include <linux/rcupdate.h>
21764 +#include <net/tcp.h>
21765 +
21766 +#include <asm/errno.h>
21767 +#include <linux/vserver/base.h>
21768 +#include <linux/vserver/network_cmd.h>
21769 +#include <linux/vs_pid.h>
21770 +
21771 +
21772 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
21773 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
21774 +
21775 +
21776 +/*     __alloc_nx_info()
21777 +
21778 +       * allocate an initialized nx_info struct
21779 +       * doesn't make it visible (hash)                        */
21780 +
21781 +static struct nx_info *__alloc_nx_info(nid_t nid)
21782 +{
21783 +       struct nx_info *new = NULL;
21784 +
21785 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
21786 +
21787 +       /* would this benefit from a slab cache? */
21788 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
21789 +       if (!new)
21790 +               return 0;
21791 +
21792 +       memset(new, 0, sizeof(struct nx_info));
21793 +       new->nx_id = nid;
21794 +       INIT_HLIST_NODE(&new->nx_hlist);
21795 +       atomic_set(&new->nx_usecnt, 0);
21796 +       atomic_set(&new->nx_tasks, 0);
21797 +       new->nx_state = 0;
21798 +
21799 +       new->nx_flags = NXF_INIT_SET;
21800 +
21801 +       /* rest of init goes here */
21802 +
21803 +       vxdprintk(VXD_CBIT(nid, 0),
21804 +               "alloc_nx_info(%d) = %p", nid, new);
21805 +       atomic_inc(&nx_global_ctotal);
21806 +       return new;
21807 +}
21808 +
21809 +/*     __dealloc_nx_info()
21810 +
21811 +       * final disposal of nx_info                             */
21812 +
21813 +static void __dealloc_nx_info(struct nx_info *nxi)
21814 +{
21815 +       vxdprintk(VXD_CBIT(nid, 0),
21816 +               "dealloc_nx_info(%p)", nxi);
21817 +
21818 +       nxi->nx_hlist.next = LIST_POISON1;
21819 +       nxi->nx_id = -1;
21820 +
21821 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
21822 +       BUG_ON(atomic_read(&nxi->nx_tasks));
21823 +
21824 +       nxi->nx_state |= NXS_RELEASED;
21825 +       kfree(nxi);
21826 +       atomic_dec(&nx_global_ctotal);
21827 +}
21828 +
21829 +static void __shutdown_nx_info(struct nx_info *nxi)
21830 +{
21831 +       nxi->nx_state |= NXS_SHUTDOWN;
21832 +       vs_net_change(nxi, VSC_NETDOWN);
21833 +}
21834 +
21835 +/*     exported stuff                                          */
21836 +
21837 +void free_nx_info(struct nx_info *nxi)
21838 +{
21839 +       /* context shutdown is mandatory */
21840 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
21841 +
21842 +       /* context must not be hashed */
21843 +       BUG_ON(nxi->nx_state & NXS_HASHED);
21844 +
21845 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
21846 +       BUG_ON(atomic_read(&nxi->nx_tasks));
21847 +
21848 +       __dealloc_nx_info(nxi);
21849 +}
21850 +
21851 +
21852 +/*     hash table for nx_info hash */
21853 +
21854 +#define NX_HASH_SIZE   13
21855 +
21856 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
21857 +
21858 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
21859 +
21860 +
21861 +static inline unsigned int __hashval(nid_t nid)
21862 +{
21863 +       return (nid % NX_HASH_SIZE);
21864 +}
21865 +
21866 +
21867 +
21868 +/*     __hash_nx_info()
21869 +
21870 +       * add the nxi to the global hash table
21871 +       * requires the hash_lock to be held                     */
21872 +
21873 +static inline void __hash_nx_info(struct nx_info *nxi)
21874 +{
21875 +       struct hlist_head *head;
21876 +
21877 +       vxd_assert_lock(&nx_info_hash_lock);
21878 +       vxdprintk(VXD_CBIT(nid, 4),
21879 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
21880 +
21881 +       /* context must not be hashed */
21882 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
21883 +
21884 +       nxi->nx_state |= NXS_HASHED;
21885 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
21886 +       hlist_add_head(&nxi->nx_hlist, head);
21887 +       atomic_inc(&nx_global_cactive);
21888 +}
21889 +
21890 +/*     __unhash_nx_info()
21891 +
21892 +       * remove the nxi from the global hash table
21893 +       * requires the hash_lock to be held                     */
21894 +
21895 +static inline void __unhash_nx_info(struct nx_info *nxi)
21896 +{
21897 +       vxd_assert_lock(&nx_info_hash_lock);
21898 +       vxdprintk(VXD_CBIT(nid, 4),
21899 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
21900 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
21901 +
21902 +       /* context must be hashed */
21903 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
21904 +       /* but without tasks */
21905 +       BUG_ON(atomic_read(&nxi->nx_tasks));
21906 +
21907 +       nxi->nx_state &= ~NXS_HASHED;
21908 +       hlist_del(&nxi->nx_hlist);
21909 +       atomic_dec(&nx_global_cactive);
21910 +}
21911 +
21912 +
21913 +/*     __lookup_nx_info()
21914 +
21915 +       * requires the hash_lock to be held
21916 +       * doesn't increment the nx_refcnt                       */
21917 +
21918 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
21919 +{
21920 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
21921 +       struct hlist_node *pos;
21922 +       struct nx_info *nxi;
21923 +
21924 +       vxd_assert_lock(&nx_info_hash_lock);
21925 +       hlist_for_each(pos, head) {
21926 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
21927 +
21928 +               if (nxi->nx_id == nid)
21929 +                       goto found;
21930 +       }
21931 +       nxi = NULL;
21932 +found:
21933 +       vxdprintk(VXD_CBIT(nid, 0),
21934 +               "__lookup_nx_info(#%u): %p[#%u]",
21935 +               nid, nxi, nxi ? nxi->nx_id : 0);
21936 +       return nxi;
21937 +}
21938 +
21939 +
21940 +/*     __nx_dynamic_id()
21941 +
21942 +       * find unused dynamic nid
21943 +       * requires the hash_lock to be held                     */
21944 +
21945 +static inline nid_t __nx_dynamic_id(void)
21946 +{
21947 +       static nid_t seq = MAX_N_CONTEXT;
21948 +       nid_t barrier = seq;
21949 +
21950 +       vxd_assert_lock(&nx_info_hash_lock);
21951 +       do {
21952 +               if (++seq > MAX_N_CONTEXT)
21953 +                       seq = MIN_D_CONTEXT;
21954 +               if (!__lookup_nx_info(seq)) {
21955 +                       vxdprintk(VXD_CBIT(nid, 4),
21956 +                               "__nx_dynamic_id: [#%d]", seq);
21957 +                       return seq;
21958 +               }
21959 +       } while (barrier != seq);
21960 +       return 0;
21961 +}
21962 +
21963 +/*     __create_nx_info()
21964 +
21965 +       * create the requested context
21966 +       * get(), claim() and hash it                            */
21967 +
21968 +static struct nx_info *__create_nx_info(int id)
21969 +{
21970 +       struct nx_info *new, *nxi = NULL;
21971 +
21972 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
21973 +
21974 +       if (!(new = __alloc_nx_info(id)))
21975 +               return ERR_PTR(-ENOMEM);
21976 +
21977 +       /* required to make dynamic xids unique */
21978 +       spin_lock(&nx_info_hash_lock);
21979 +
21980 +       /* dynamic context requested */
21981 +       if (id == NX_DYNAMIC_ID) {
21982 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
21983 +               id = __nx_dynamic_id();
21984 +               if (!id) {
21985 +                       printk(KERN_ERR "no dynamic context available.\n");
21986 +                       nxi = ERR_PTR(-EAGAIN);
21987 +                       goto out_unlock;
21988 +               }
21989 +               new->nx_id = id;
21990 +#else
21991 +               printk(KERN_ERR "dynamic contexts disabled.\n");
21992 +               nxi = ERR_PTR(-EINVAL);
21993 +               goto out_unlock;
21994 +#endif
21995 +       }
21996 +       /* static context requested */
21997 +       else if ((nxi = __lookup_nx_info(id))) {
21998 +               vxdprintk(VXD_CBIT(nid, 0),
21999 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
22000 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22001 +                       nxi = ERR_PTR(-EBUSY);
22002 +               else
22003 +                       nxi = ERR_PTR(-EEXIST);
22004 +               goto out_unlock;
22005 +       }
22006 +       /* dynamic nid creation blocker */
22007 +       else if (id >= MIN_D_CONTEXT) {
22008 +               vxdprintk(VXD_CBIT(nid, 0),
22009 +                       "create_nx_info(%d) (dynamic rejected)", id);
22010 +               nxi = ERR_PTR(-EINVAL);
22011 +               goto out_unlock;
22012 +       }
22013 +
22014 +       /* new context */
22015 +       vxdprintk(VXD_CBIT(nid, 0),
22016 +               "create_nx_info(%d) = %p (new)", id, new);
22017 +       claim_nx_info(new, NULL);
22018 +       __hash_nx_info(get_nx_info(new));
22019 +       nxi = new, new = NULL;
22020 +
22021 +out_unlock:
22022 +       spin_unlock(&nx_info_hash_lock);
22023 +       if (new)
22024 +               __dealloc_nx_info(new);
22025 +       return nxi;
22026 +}
22027 +
22028 +
22029 +
22030 +/*     exported stuff                                          */
22031 +
22032 +
22033 +void unhash_nx_info(struct nx_info *nxi)
22034 +{
22035 +       __shutdown_nx_info(nxi);
22036 +       spin_lock(&nx_info_hash_lock);
22037 +       __unhash_nx_info(nxi);
22038 +       spin_unlock(&nx_info_hash_lock);
22039 +}
22040 +
22041 +#ifdef  CONFIG_VSERVER_LEGACYNET
22042 +
22043 +struct nx_info *create_nx_info(void)
22044 +{
22045 +       return __create_nx_info(NX_DYNAMIC_ID);
22046 +}
22047 +
22048 +#endif
22049 +
22050 +/*     lookup_nx_info()
22051 +
22052 +       * search for a nx_info and get() it
22053 +       * negative id means current                             */
22054 +
22055 +struct nx_info *lookup_nx_info(int id)
22056 +{
22057 +       struct nx_info *nxi = NULL;
22058 +
22059 +       if (id < 0) {
22060 +               nxi = get_nx_info(current->nx_info);
22061 +       } else if (id > 1) {
22062 +               spin_lock(&nx_info_hash_lock);
22063 +               nxi = get_nx_info(__lookup_nx_info(id));
22064 +               spin_unlock(&nx_info_hash_lock);
22065 +       }
22066 +       return nxi;
22067 +}
22068 +
22069 +/*     nid_is_hashed()
22070 +
22071 +       * verify that nid is still hashed                       */
22072 +
22073 +int nid_is_hashed(nid_t nid)
22074 +{
22075 +       int hashed;
22076 +
22077 +       spin_lock(&nx_info_hash_lock);
22078 +       hashed = (__lookup_nx_info(nid) != NULL);
22079 +       spin_unlock(&nx_info_hash_lock);
22080 +       return hashed;
22081 +}
22082 +
22083 +
22084 +#ifdef CONFIG_PROC_FS
22085 +
22086 +/*     get_nid_list()
22087 +
22088 +       * get a subset of hashed nids for proc
22089 +       * assumes size is at least one                          */
22090 +
22091 +int get_nid_list(int index, unsigned int *nids, int size)
22092 +{
22093 +       int hindex, nr_nids = 0;
22094 +
22095 +       /* only show current and children */
22096 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
22097 +               if (index > 0)
22098 +                       return 0;
22099 +               nids[nr_nids] = nx_current_nid();
22100 +               return 1;
22101 +       }
22102 +
22103 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
22104 +               struct hlist_head *head = &nx_info_hash[hindex];
22105 +               struct hlist_node *pos;
22106 +
22107 +               spin_lock(&nx_info_hash_lock);
22108 +               hlist_for_each(pos, head) {
22109 +                       struct nx_info *nxi;
22110 +
22111 +                       if (--index > 0)
22112 +                               continue;
22113 +
22114 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22115 +                       nids[nr_nids] = nxi->nx_id;
22116 +                       if (++nr_nids >= size) {
22117 +                               spin_unlock(&nx_info_hash_lock);
22118 +                               goto out;
22119 +                       }
22120 +               }
22121 +               /* keep the lock time short */
22122 +               spin_unlock(&nx_info_hash_lock);
22123 +       }
22124 +out:
22125 +       return nr_nids;
22126 +}
22127 +#endif
22128 +
22129 +
22130 +/*
22131 + *     migrate task to new network
22132 + *     gets nxi, puts old_nxi on change
22133 + */
22134 +
22135 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
22136 +{
22137 +       struct nx_info *old_nxi;
22138 +       int ret = 0;
22139 +
22140 +       if (!p || !nxi)
22141 +               BUG();
22142 +
22143 +       vxdprintk(VXD_CBIT(nid, 5),
22144 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
22145 +               p, nxi, nxi->nx_id,
22146 +               atomic_read(&nxi->nx_usecnt),
22147 +               atomic_read(&nxi->nx_tasks));
22148 +
22149 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
22150 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22151 +               return -EACCES;
22152 +
22153 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
22154 +               return -EFAULT;
22155 +
22156 +       /* maybe disallow this completely? */
22157 +       old_nxi = task_get_nx_info(p);
22158 +       if (old_nxi == nxi)
22159 +               goto out;
22160 +
22161 +       task_lock(p);
22162 +       if (old_nxi)
22163 +               clr_nx_info(&p->nx_info);
22164 +       claim_nx_info(nxi, p);
22165 +       set_nx_info(&p->nx_info, nxi);
22166 +       p->nid = nxi->nx_id;
22167 +       task_unlock(p);
22168 +
22169 +       vxdprintk(VXD_CBIT(nid, 5),
22170 +               "moved task %p into nxi:%p[#%d]",
22171 +               p, nxi, nxi->nx_id);
22172 +
22173 +       if (old_nxi)
22174 +               release_nx_info(old_nxi, p);
22175 +       ret = 0;
22176 +out:
22177 +       put_nx_info(old_nxi);
22178 +       return ret;
22179 +}
22180 +
22181 +
22182 +#ifdef CONFIG_INET
22183 +
22184 +#include <linux/netdevice.h>
22185 +#include <linux/inetdevice.h>
22186 +
22187 +int ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
22188 +{
22189 +       if (!nxi)
22190 +               return 1;
22191 +       if (!ifa)
22192 +               return 0;
22193 +       return addr_in_nx_info(nxi, ifa->ifa_local);
22194 +}
22195 +
22196 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
22197 +{
22198 +       struct in_device *in_dev;
22199 +       struct in_ifaddr **ifap;
22200 +       struct in_ifaddr *ifa;
22201 +       int ret = 0;
22202 +
22203 +       if (!nxi)
22204 +               return 1;
22205 +
22206 +       if (!dev)
22207 +               goto out;
22208 +       in_dev = in_dev_get(dev);
22209 +       if (!in_dev)
22210 +               goto out;
22211 +
22212 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
22213 +               ifap = &ifa->ifa_next) {
22214 +               if (addr_in_nx_info(nxi, ifa->ifa_local)) {
22215 +                       ret = 1;
22216 +                       break;
22217 +               }
22218 +       }
22219 +       in_dev_put(in_dev);
22220 +out:
22221 +       return ret;
22222 +}
22223 +
22224 +/*
22225 + *     check if address is covered by socket
22226 + *
22227 + *     sk:     the socket to check against
22228 + *     addr:   the address in question (must be != 0)
22229 + */
22230 +static inline int __addr_in_socket(const struct sock *sk, uint32_t addr)
22231 +{
22232 +       struct nx_info *nxi = sk->sk_nx_info;
22233 +       uint32_t saddr = inet_rcv_saddr(sk);
22234 +
22235 +       vxdprintk(VXD_CBIT(net, 5),
22236 +               "__addr_in_socket(%p," NIPQUAD_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
22237 +               sk, NIPQUAD(addr), nxi, NIPQUAD(saddr), sk->sk_socket,
22238 +               (sk->sk_socket ? sk->sk_socket->flags : 0));
22239 +
22240 +       if (saddr) {
22241 +               /* direct address match */
22242 +               return (saddr == addr);
22243 +       } else if (nxi) {
22244 +               /* match against nx_info */
22245 +               return addr_in_nx_info(nxi, addr);
22246 +       } else {
22247 +               /* unrestricted any socket */
22248 +               return 1;
22249 +       }
22250 +}
22251 +
22252 +
22253 +int nx_addr_conflict(struct nx_info *nxi, uint32_t addr, const struct sock *sk)
22254 +{
22255 +       vxdprintk(VXD_CBIT(net, 2),
22256 +               "nx_addr_conflict(%p,%p) " NIPQUAD_FMT,
22257 +               nxi, sk, NIPQUAD(addr));
22258 +
22259 +       if (addr) {
22260 +               /* check real address */
22261 +               return __addr_in_socket(sk, addr);
22262 +       } else if (nxi) {
22263 +               /* check against nx_info */
22264 +               int i, n = nxi->nbipv4;
22265 +
22266 +               for (i = 0; i < n; i++)
22267 +                       if (__addr_in_socket(sk, nxi->ipv4[i]))
22268 +                               return 1;
22269 +               return 0;
22270 +       } else {
22271 +               /* check against any */
22272 +               return 1;
22273 +       }
22274 +}
22275 +
22276 +#endif /* CONFIG_INET */
22277 +
22278 +void nx_set_persistent(struct nx_info *nxi)
22279 +{
22280 +       vxdprintk(VXD_CBIT(nid, 6),
22281 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
22282 +
22283 +       get_nx_info(nxi);
22284 +       claim_nx_info(nxi, NULL);
22285 +}
22286 +
22287 +void nx_clear_persistent(struct nx_info *nxi)
22288 +{
22289 +       vxdprintk(VXD_CBIT(nid, 6),
22290 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
22291 +
22292 +       release_nx_info(nxi, NULL);
22293 +       put_nx_info(nxi);
22294 +}
22295 +
22296 +void nx_update_persistent(struct nx_info *nxi)
22297 +{
22298 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
22299 +               nx_set_persistent(nxi);
22300 +       else
22301 +               nx_clear_persistent(nxi);
22302 +}
22303 +
22304 +/* vserver syscall commands below here */
22305 +
22306 +/* taks nid and nx_info functions */
22307 +
22308 +#include <asm/uaccess.h>
22309 +
22310 +
22311 +int vc_task_nid(uint32_t id, void __user *data)
22312 +{
22313 +       nid_t nid;
22314 +
22315 +       if (id) {
22316 +               struct task_struct *tsk;
22317 +
22318 +               if (!nx_check(0, VS_ADMIN | VS_WATCH))
22319 +                       return -EPERM;
22320 +
22321 +               read_lock(&tasklist_lock);
22322 +               tsk = find_task_by_real_pid(id);
22323 +               nid = (tsk) ? tsk->nid : -ESRCH;
22324 +               read_unlock(&tasklist_lock);
22325 +       } else
22326 +               nid = nx_current_nid();
22327 +       return nid;
22328 +}
22329 +
22330 +
22331 +int vc_nx_info(struct nx_info *nxi, void __user *data)
22332 +{
22333 +       struct vcmd_nx_info_v0 vc_data;
22334 +
22335 +       vc_data.nid = nxi->nx_id;
22336 +
22337 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22338 +               return -EFAULT;
22339 +       return 0;
22340 +}
22341 +
22342 +
22343 +/* network functions */
22344 +
22345 +int vc_net_create(uint32_t nid, void __user *data)
22346 +{
22347 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
22348 +       struct nx_info *new_nxi;
22349 +       int ret;
22350 +
22351 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22352 +               return -EFAULT;
22353 +
22354 +       if ((nid > MAX_S_CONTEXT) && (nid != NX_DYNAMIC_ID))
22355 +               return -EINVAL;
22356 +       if (nid < 2)
22357 +               return -EINVAL;
22358 +
22359 +       new_nxi = __create_nx_info(nid);
22360 +       if (IS_ERR(new_nxi))
22361 +               return PTR_ERR(new_nxi);
22362 +
22363 +       /* initial flags */
22364 +       new_nxi->nx_flags = vc_data.flagword;
22365 +
22366 +       ret = -ENOEXEC;
22367 +       if (vs_net_change(new_nxi, VSC_NETUP))
22368 +               goto out;
22369 +
22370 +       ret = nx_migrate_task(current, new_nxi);
22371 +       if (ret)
22372 +               goto out;
22373 +
22374 +       /* return context id on success */
22375 +       ret = new_nxi->nx_id;
22376 +
22377 +       /* get a reference for persistent contexts */
22378 +       if ((vc_data.flagword & NXF_PERSISTENT))
22379 +               nx_set_persistent(new_nxi);
22380 +out:
22381 +       release_nx_info(new_nxi, NULL);
22382 +       put_nx_info(new_nxi);
22383 +       return ret;
22384 +}
22385 +
22386 +
22387 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
22388 +{
22389 +       return nx_migrate_task(current, nxi);
22390 +}
22391 +
22392 +int vc_net_add(struct nx_info *nxi, void __user *data)
22393 +{
22394 +       struct vcmd_net_addr_v0 vc_data;
22395 +       int index, pos, ret = 0;
22396 +
22397 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22398 +               return -EFAULT;
22399 +
22400 +       switch (vc_data.type) {
22401 +       case NXA_TYPE_IPV4:
22402 +               if ((vc_data.count < 1) || (vc_data.count > 4))
22403 +                       return -EINVAL;
22404 +               break;
22405 +
22406 +       default:
22407 +               break;
22408 +       }
22409 +
22410 +       switch (vc_data.type) {
22411 +       case NXA_TYPE_IPV4:
22412 +               index = 0;
22413 +               while ((index < vc_data.count) &&
22414 +                       ((pos = nxi->nbipv4) < NB_IPV4ROOT)) {
22415 +                       nxi->ipv4[pos] = vc_data.ip[index];
22416 +                       nxi->mask[pos] = vc_data.mask[index];
22417 +                       index++;
22418 +                       nxi->nbipv4++;
22419 +               }
22420 +               ret = index;
22421 +               break;
22422 +
22423 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
22424 +               nxi->v4_bcast = vc_data.ip[0];
22425 +               ret = 1;
22426 +               break;
22427 +
22428 +       default:
22429 +               ret = -EINVAL;
22430 +               break;
22431 +       }
22432 +       return ret;
22433 +}
22434 +
22435 +int vc_net_remove(struct nx_info *nxi, void __user *data)
22436 +{
22437 +       struct vcmd_net_addr_v0 vc_data;
22438 +
22439 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22440 +               return -EFAULT;
22441 +
22442 +       switch (vc_data.type) {
22443 +       case NXA_TYPE_ANY:
22444 +               nxi->nbipv4 = 0;
22445 +               break;
22446 +
22447 +       default:
22448 +               return -EINVAL;
22449 +       }
22450 +       return 0;
22451 +}
22452 +
22453 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
22454 +{
22455 +       struct vcmd_net_flags_v0 vc_data;
22456 +
22457 +       vc_data.flagword = nxi->nx_flags;
22458 +
22459 +       /* special STATE flag handling */
22460 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
22461 +
22462 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22463 +               return -EFAULT;
22464 +       return 0;
22465 +}
22466 +
22467 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
22468 +{
22469 +       struct vcmd_net_flags_v0 vc_data;
22470 +       uint64_t mask, trigger;
22471 +
22472 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22473 +               return -EFAULT;
22474 +
22475 +       /* special STATE flag handling */
22476 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
22477 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
22478 +
22479 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
22480 +               vc_data.flagword, mask);
22481 +       if (trigger & NXF_PERSISTENT)
22482 +               nx_update_persistent(nxi);
22483 +
22484 +       return 0;
22485 +}
22486 +
22487 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
22488 +{
22489 +       struct vcmd_net_caps_v0 vc_data;
22490 +
22491 +       vc_data.ncaps = nxi->nx_ncaps;
22492 +       vc_data.cmask = ~0ULL;
22493 +
22494 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22495 +               return -EFAULT;
22496 +       return 0;
22497 +}
22498 +
22499 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
22500 +{
22501 +       struct vcmd_net_caps_v0 vc_data;
22502 +
22503 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22504 +               return -EFAULT;
22505 +
22506 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
22507 +               vc_data.ncaps, vc_data.cmask);
22508 +       return 0;
22509 +}
22510 +
22511 +
22512 +#include <linux/module.h>
22513 +
22514 +EXPORT_SYMBOL_GPL(free_nx_info);
22515 +EXPORT_SYMBOL_GPL(unhash_nx_info);
22516 +
22517 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/proc.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/proc.c
22518 --- linux-2.6.24-rc7/kernel/vserver/proc.c      1970-01-01 01:00:00 +0100
22519 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/proc.c        2007-12-15 00:35:35 +0100
22520 @@ -0,0 +1,1035 @@
22521 +/*
22522 + *  linux/kernel/vserver/proc.c
22523 + *
22524 + *  Virtual Context Support
22525 + *
22526 + *  Copyright (C) 2003-2007  Herbert Pötzl
22527 + *
22528 + *  V0.01  basic structure
22529 + *  V0.02  adaptation vs1.3.0
22530 + *  V0.03  proc permissions
22531 + *  V0.04  locking/generic
22532 + *  V0.05  next generation procfs
22533 + *  V0.06  inode validation
22534 + *  V0.07  generic rewrite vid
22535 + *  V0.08  remove inode type
22536 + *
22537 + */
22538 +
22539 +#include <linux/errno.h>
22540 +#include <linux/proc_fs.h>
22541 +#include <linux/sched.h>
22542 +#include <linux/vs_context.h>
22543 +#include <linux/vs_network.h>
22544 +#include <linux/vs_cvirt.h>
22545 +
22546 +#include <linux/vserver/switch.h>
22547 +#include <linux/vserver/global.h>
22548 +
22549 +#include <asm/uaccess.h>
22550 +#include <asm/unistd.h>
22551 +
22552 +#include "cvirt_proc.h"
22553 +#include "cacct_proc.h"
22554 +#include "limit_proc.h"
22555 +#include "sched_proc.h"
22556 +#include "vci_config.h"
22557 +
22558 +static struct proc_dir_entry *proc_virtual;
22559 +
22560 +static struct proc_dir_entry *proc_virtnet;
22561 +
22562 +
22563 +/* first the actual feeds */
22564 +
22565 +
22566 +static int proc_vci(char *buffer)
22567 +{
22568 +       return sprintf(buffer,
22569 +               "VCIVersion:\t%04x:%04x\n"
22570 +               "VCISyscall:\t%d\n"
22571 +               "VCIKernel:\t%08x\n",
22572 +               VCI_VERSION >> 16,
22573 +               VCI_VERSION & 0xFFFF,
22574 +               __NR_vserver,
22575 +               vci_kernel_config());
22576 +}
22577 +
22578 +static int proc_virtual_info(char *buffer)
22579 +{
22580 +       return proc_vci(buffer);
22581 +}
22582 +
22583 +static int proc_virtual_status(char *buffer)
22584 +{
22585 +       return sprintf(buffer,
22586 +               "#CTotal:\t%d\n"
22587 +               "#CActive:\t%d\n"
22588 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n",
22589 +               atomic_read(&vx_global_ctotal),
22590 +               atomic_read(&vx_global_cactive),
22591 +               atomic_read(&vs_global_nsproxy),
22592 +               atomic_read(&vs_global_fs),
22593 +               atomic_read(&vs_global_mnt_ns),
22594 +               atomic_read(&vs_global_uts_ns),
22595 +               atomic_read(&vs_global_ipc_ns),
22596 +               atomic_read(&vs_global_user_ns),
22597 +               atomic_read(&vs_global_pid_ns));
22598 +}
22599 +
22600 +
22601 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
22602 +{
22603 +       int length;
22604 +
22605 +       length = sprintf(buffer,
22606 +               "ID:\t%d\n"
22607 +               "Info:\t%p\n"
22608 +               "Init:\t%d\n",
22609 +               vxi->vx_id,
22610 +               vxi,
22611 +               vxi->vx_initpid);
22612 +       return length;
22613 +}
22614 +
22615 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
22616 +{
22617 +       int length;
22618 +
22619 +       length = sprintf(buffer,
22620 +               "UseCnt:\t%d\n"
22621 +               "Tasks:\t%d\n"
22622 +               "Flags:\t%016llx\n"
22623 +               "BCaps:\t%016llx\n"
22624 +               "CCaps:\t%016llx\n"
22625 +               "Spaces:\t%08lx\n",
22626 +               atomic_read(&vxi->vx_usecnt),
22627 +               atomic_read(&vxi->vx_tasks),
22628 +               (unsigned long long)vxi->vx_flags,
22629 +               (unsigned long long)vxi->vx_bcaps,
22630 +               (unsigned long long)vxi->vx_ccaps,
22631 +               vxi->vx_nsmask);
22632 +       return length;
22633 +}
22634 +
22635 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
22636 +{
22637 +       return vx_info_proc_limit(&vxi->limit, buffer);
22638 +}
22639 +
22640 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
22641 +{
22642 +       int cpu, length;
22643 +
22644 +       length = vx_info_proc_sched(&vxi->sched, buffer);
22645 +       for_each_online_cpu(cpu) {
22646 +               length += vx_info_proc_sched_pc(
22647 +                       &vx_per_cpu(vxi, sched_pc, cpu),
22648 +                       buffer + length, cpu);
22649 +       }
22650 +       return length;
22651 +}
22652 +
22653 +int proc_vxi_nsproxy(struct vx_info *vxi, char *buffer)
22654 +{
22655 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy, buffer);
22656 +}
22657 +
22658 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
22659 +{
22660 +       int cpu, length;
22661 +
22662 +       vx_update_load(vxi);
22663 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
22664 +       for_each_online_cpu(cpu) {
22665 +               length += vx_info_proc_cvirt_pc(
22666 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
22667 +                       buffer + length, cpu);
22668 +       }
22669 +       return length;
22670 +}
22671 +
22672 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
22673 +{
22674 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
22675 +}
22676 +
22677 +
22678 +static int proc_virtnet_info(char *buffer)
22679 +{
22680 +       return proc_vci(buffer);
22681 +}
22682 +
22683 +static int proc_virtnet_status(char *buffer)
22684 +{
22685 +       return sprintf(buffer,
22686 +               "#CTotal:\t%d\n"
22687 +               "#CActive:\t%d\n",
22688 +               atomic_read(&nx_global_ctotal),
22689 +               atomic_read(&nx_global_cactive));
22690 +}
22691 +
22692 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
22693 +{
22694 +       int length, i;
22695 +
22696 +       length = sprintf(buffer,
22697 +               "ID:\t%d\n"
22698 +               "Info:\t%p\n",
22699 +               nxi->nx_id,
22700 +               nxi);
22701 +       for (i = 0; i < nxi->nbipv4; i++) {
22702 +               length += sprintf(buffer + length,
22703 +                       "%d:\t" NIPQUAD_FMT "/" NIPQUAD_FMT "\n", i,
22704 +                       NIPQUAD(nxi->ipv4[i]), NIPQUAD(nxi->mask[i]));
22705 +       }
22706 +       return length;
22707 +}
22708 +
22709 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
22710 +{
22711 +       int length;
22712 +
22713 +       length = sprintf(buffer,
22714 +               "UseCnt:\t%d\n"
22715 +               "Tasks:\t%d\n"
22716 +               "Flags:\t%016llx\n"
22717 +               "NCaps:\t%016llx\n",
22718 +               atomic_read(&nxi->nx_usecnt),
22719 +               atomic_read(&nxi->nx_tasks),
22720 +               (unsigned long long)nxi->nx_flags,
22721 +               (unsigned long long)nxi->nx_ncaps);
22722 +       return length;
22723 +}
22724 +
22725 +
22726 +
22727 +/* here the inode helpers */
22728 +
22729 +struct vs_entry {
22730 +       int len;
22731 +       char *name;
22732 +       mode_t mode;
22733 +       struct inode_operations *iop;
22734 +       struct file_operations *fop;
22735 +       union proc_op op;
22736 +};
22737 +
22738 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
22739 +{
22740 +       struct inode *inode = new_inode(sb);
22741 +
22742 +       if (!inode)
22743 +               goto out;
22744 +
22745 +       inode->i_mode = p->mode;
22746 +       if (p->iop)
22747 +               inode->i_op = p->iop;
22748 +       if (p->fop)
22749 +               inode->i_fop = p->fop;
22750 +
22751 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
22752 +       inode->i_flags |= S_IMMUTABLE;
22753 +
22754 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
22755 +
22756 +       inode->i_uid = 0;
22757 +       inode->i_gid = 0;
22758 +       inode->i_tag = 0;
22759 +out:
22760 +       return inode;
22761 +}
22762 +
22763 +static struct dentry *vs_proc_instantiate(struct inode *dir,
22764 +       struct dentry *dentry, int id, void *ptr)
22765 +{
22766 +       struct vs_entry *p = ptr;
22767 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
22768 +       struct dentry *error = ERR_PTR(-EINVAL);
22769 +
22770 +       if (!inode)
22771 +               goto out;
22772 +
22773 +       PROC_I(inode)->op = p->op;
22774 +       PROC_I(inode)->fd = id;
22775 +       d_add(dentry, inode);
22776 +       error = NULL;
22777 +out:
22778 +       return error;
22779 +}
22780 +
22781 +/* Lookups */
22782 +
22783 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
22784 +
22785 +/*
22786 + * Fill a directory entry.
22787 + *
22788 + * If possible create the dcache entry and derive our inode number and
22789 + * file type from dcache entry.
22790 + *
22791 + * Since all of the proc inode numbers are dynamically generated, the inode
22792 + * numbers do not exist until the inode is cache.  This means creating the
22793 + * the dcache entry in readdir is necessary to keep the inode numbers
22794 + * reported by readdir in sync with the inode numbers reported
22795 + * by stat.
22796 + */
22797 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
22798 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
22799 +{
22800 +       struct dentry *child, *dir = filp->f_dentry;
22801 +       struct inode *inode;
22802 +       struct qstr qname;
22803 +       ino_t ino = 0;
22804 +       unsigned type = DT_UNKNOWN;
22805 +
22806 +       qname.name = name;
22807 +       qname.len  = len;
22808 +       qname.hash = full_name_hash(name, len);
22809 +
22810 +       child = d_lookup(dir, &qname);
22811 +       if (!child) {
22812 +               struct dentry *new;
22813 +               new = d_alloc(dir, &qname);
22814 +               if (new) {
22815 +                       child = instantiate(dir->d_inode, new, id, ptr);
22816 +                       if (child)
22817 +                               dput(new);
22818 +                       else
22819 +                               child = new;
22820 +               }
22821 +       }
22822 +       if (!child || IS_ERR(child) || !child->d_inode)
22823 +               goto end_instantiate;
22824 +       inode = child->d_inode;
22825 +       if (inode) {
22826 +               ino = inode->i_ino;
22827 +               type = inode->i_mode >> 12;
22828 +       }
22829 +       dput(child);
22830 +end_instantiate:
22831 +       if (!ino)
22832 +               ino = find_inode_number(dir, &qname);
22833 +       if (!ino)
22834 +               ino = 1;
22835 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
22836 +}
22837 +
22838 +
22839 +
22840 +/* get and revalidate vx_info/xid */
22841 +
22842 +static inline
22843 +struct vx_info *get_proc_vx_info(struct inode *inode)
22844 +{
22845 +       return lookup_vx_info(PROC_I(inode)->fd);
22846 +}
22847 +
22848 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
22849 +{
22850 +       struct inode *inode = dentry->d_inode;
22851 +       xid_t xid = PROC_I(inode)->fd;
22852 +
22853 +       if (!xid || xid_is_hashed(xid))
22854 +               return 1;
22855 +       d_drop(dentry);
22856 +       return 0;
22857 +}
22858 +
22859 +
22860 +/* get and revalidate nx_info/nid */
22861 +
22862 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
22863 +{
22864 +       struct inode *inode = dentry->d_inode;
22865 +       nid_t nid = PROC_I(inode)->fd;
22866 +
22867 +       if (!nid || nid_is_hashed(nid))
22868 +               return 1;
22869 +       d_drop(dentry);
22870 +       return 0;
22871 +}
22872 +
22873 +
22874 +
22875 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
22876 +
22877 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
22878 +                         size_t count, loff_t *ppos)
22879 +{
22880 +       struct inode *inode = file->f_dentry->d_inode;
22881 +       unsigned long page;
22882 +       ssize_t length = 0;
22883 +
22884 +       if (count > PROC_BLOCK_SIZE)
22885 +               count = PROC_BLOCK_SIZE;
22886 +
22887 +       /* fade that out as soon as stable */
22888 +       WARN_ON(PROC_I(inode)->fd);
22889 +
22890 +       if (!(page = __get_free_page(GFP_KERNEL)))
22891 +               return -ENOMEM;
22892 +
22893 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
22894 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
22895 +
22896 +       if (length >= 0)
22897 +               length = simple_read_from_buffer(buf, count, ppos,
22898 +                       (char *)page, length);
22899 +
22900 +       free_page(page);
22901 +       return length;
22902 +}
22903 +
22904 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
22905 +                         size_t count, loff_t *ppos)
22906 +{
22907 +       struct inode *inode = file->f_dentry->d_inode;
22908 +       struct vx_info *vxi = NULL;
22909 +       xid_t xid = PROC_I(inode)->fd;
22910 +       unsigned long page;
22911 +       ssize_t length = 0;
22912 +
22913 +       if (count > PROC_BLOCK_SIZE)
22914 +               count = PROC_BLOCK_SIZE;
22915 +
22916 +       /* fade that out as soon as stable */
22917 +       WARN_ON(!xid);
22918 +       vxi = lookup_vx_info(xid);
22919 +       if (!vxi)
22920 +               goto out;
22921 +
22922 +       length = -ENOMEM;
22923 +       if (!(page = __get_free_page(GFP_KERNEL)))
22924 +               goto out_put;
22925 +
22926 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
22927 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
22928 +
22929 +       if (length >= 0)
22930 +               length = simple_read_from_buffer(buf, count, ppos,
22931 +                       (char *)page, length);
22932 +
22933 +       free_page(page);
22934 +out_put:
22935 +       put_vx_info(vxi);
22936 +out:
22937 +       return length;
22938 +}
22939 +
22940 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
22941 +                         size_t count, loff_t *ppos)
22942 +{
22943 +       struct inode *inode = file->f_dentry->d_inode;
22944 +       struct nx_info *nxi = NULL;
22945 +       nid_t nid = PROC_I(inode)->fd;
22946 +       unsigned long page;
22947 +       ssize_t length = 0;
22948 +
22949 +       if (count > PROC_BLOCK_SIZE)
22950 +               count = PROC_BLOCK_SIZE;
22951 +
22952 +       /* fade that out as soon as stable */
22953 +       WARN_ON(!nid);
22954 +       nxi = lookup_nx_info(nid);
22955 +       if (!nxi)
22956 +               goto out;
22957 +
22958 +       length = -ENOMEM;
22959 +       if (!(page = __get_free_page(GFP_KERNEL)))
22960 +               goto out_put;
22961 +
22962 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
22963 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
22964 +
22965 +       if (length >= 0)
22966 +               length = simple_read_from_buffer(buf, count, ppos,
22967 +                       (char *)page, length);
22968 +
22969 +       free_page(page);
22970 +out_put:
22971 +       put_nx_info(nxi);
22972 +out:
22973 +       return length;
22974 +}
22975 +
22976 +
22977 +
22978 +/* here comes the lower level */
22979 +
22980 +
22981 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
22982 +       .len  = sizeof(NAME) - 1,       \
22983 +       .name = (NAME),                 \
22984 +       .mode = MODE,                   \
22985 +       .iop  = IOP,                    \
22986 +       .fop  = FOP,                    \
22987 +       .op   = OP,                     \
22988 +}
22989 +
22990 +
22991 +#define DIR(NAME, MODE, OTYPE)                         \
22992 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
22993 +               &proc_ ## OTYPE ## _inode_operations,   \
22994 +               &proc_ ## OTYPE ## _file_operations, { } )
22995 +
22996 +#define INF(NAME, MODE, OTYPE)                         \
22997 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22998 +               &proc_vs_info_file_operations,          \
22999 +               { .proc_vs_read = &proc_##OTYPE } )
23000 +
23001 +#define VINF(NAME, MODE, OTYPE)                                \
23002 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23003 +               &proc_vx_info_file_operations,          \
23004 +               { .proc_vxi_read = &proc_##OTYPE } )
23005 +
23006 +#define NINF(NAME, MODE, OTYPE)                                \
23007 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23008 +               &proc_nx_info_file_operations,          \
23009 +               { .proc_nxi_read = &proc_##OTYPE } )
23010 +
23011 +
23012 +static struct file_operations proc_vs_info_file_operations = {
23013 +       .read =         proc_vs_info_read,
23014 +};
23015 +
23016 +static struct file_operations proc_vx_info_file_operations = {
23017 +       .read =         proc_vx_info_read,
23018 +};
23019 +
23020 +static struct dentry_operations proc_xid_dentry_operations = {
23021 +       .d_revalidate = proc_xid_revalidate,
23022 +};
23023 +
23024 +static struct vs_entry vx_base_stuff[] = {
23025 +       VINF("info",    S_IRUGO, vxi_info),
23026 +       VINF("status",  S_IRUGO, vxi_status),
23027 +       VINF("limit",   S_IRUGO, vxi_limit),
23028 +       VINF("sched",   S_IRUGO, vxi_sched),
23029 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy),
23030 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
23031 +       VINF("cacct",   S_IRUGO, vxi_cacct),
23032 +       {}
23033 +};
23034 +
23035 +
23036 +
23037 +
23038 +static struct dentry *proc_xid_instantiate(struct inode *dir,
23039 +       struct dentry *dentry, int id, void *ptr)
23040 +{
23041 +       dentry->d_op = &proc_xid_dentry_operations;
23042 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23043 +}
23044 +
23045 +static struct dentry *proc_xid_lookup(struct inode *dir,
23046 +       struct dentry *dentry, struct nameidata *nd)
23047 +{
23048 +       struct vs_entry *p = vx_base_stuff;
23049 +       struct dentry *error = ERR_PTR(-ENOENT);
23050 +
23051 +       for (; p->name; p++) {
23052 +               if (p->len != dentry->d_name.len)
23053 +                       continue;
23054 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23055 +                       break;
23056 +       }
23057 +       if (!p->name)
23058 +               goto out;
23059 +
23060 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23061 +out:
23062 +       return error;
23063 +}
23064 +
23065 +static int proc_xid_readdir(struct file *filp,
23066 +       void *dirent, filldir_t filldir)
23067 +{
23068 +       struct dentry *dentry = filp->f_dentry;
23069 +       struct inode *inode = dentry->d_inode;
23070 +       struct vs_entry *p = vx_base_stuff;
23071 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
23072 +       int pos, index;
23073 +       u64 ino;
23074 +
23075 +       pos = filp->f_pos;
23076 +       switch (pos) {
23077 +       case 0:
23078 +               ino = inode->i_ino;
23079 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23080 +                       goto out;
23081 +               pos++;
23082 +               /* fall through */
23083 +       case 1:
23084 +               ino = parent_ino(dentry);
23085 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23086 +                       goto out;
23087 +               pos++;
23088 +               /* fall through */
23089 +       default:
23090 +               index = pos - 2;
23091 +               if (index >= size)
23092 +                       goto out;
23093 +               for (p += index; p->name; p++) {
23094 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23095 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23096 +                               goto out;
23097 +                       pos++;
23098 +               }
23099 +       }
23100 +out:
23101 +       filp->f_pos = pos;
23102 +       return 1;
23103 +}
23104 +
23105 +
23106 +
23107 +static struct file_operations proc_nx_info_file_operations = {
23108 +       .read =         proc_nx_info_read,
23109 +};
23110 +
23111 +static struct dentry_operations proc_nid_dentry_operations = {
23112 +       .d_revalidate = proc_nid_revalidate,
23113 +};
23114 +
23115 +static struct vs_entry nx_base_stuff[] = {
23116 +       NINF("info",    S_IRUGO, nxi_info),
23117 +       NINF("status",  S_IRUGO, nxi_status),
23118 +       {}
23119 +};
23120 +
23121 +
23122 +static struct dentry *proc_nid_instantiate(struct inode *dir,
23123 +       struct dentry *dentry, int id, void *ptr)
23124 +{
23125 +       dentry->d_op = &proc_nid_dentry_operations;
23126 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23127 +}
23128 +
23129 +static struct dentry *proc_nid_lookup(struct inode *dir,
23130 +       struct dentry *dentry, struct nameidata *nd)
23131 +{
23132 +       struct vs_entry *p = nx_base_stuff;
23133 +       struct dentry *error = ERR_PTR(-ENOENT);
23134 +
23135 +       for (; p->name; p++) {
23136 +               if (p->len != dentry->d_name.len)
23137 +                       continue;
23138 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23139 +                       break;
23140 +       }
23141 +       if (!p->name)
23142 +               goto out;
23143 +
23144 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23145 +out:
23146 +       return error;
23147 +}
23148 +
23149 +static int proc_nid_readdir(struct file *filp,
23150 +       void *dirent, filldir_t filldir)
23151 +{
23152 +       struct dentry *dentry = filp->f_dentry;
23153 +       struct inode *inode = dentry->d_inode;
23154 +       struct vs_entry *p = nx_base_stuff;
23155 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
23156 +       int pos, index;
23157 +       u64 ino;
23158 +
23159 +       pos = filp->f_pos;
23160 +       switch (pos) {
23161 +       case 0:
23162 +               ino = inode->i_ino;
23163 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23164 +                       goto out;
23165 +               pos++;
23166 +               /* fall through */
23167 +       case 1:
23168 +               ino = parent_ino(dentry);
23169 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23170 +                       goto out;
23171 +               pos++;
23172 +               /* fall through */
23173 +       default:
23174 +               index = pos - 2;
23175 +               if (index >= size)
23176 +                       goto out;
23177 +               for (p += index; p->name; p++) {
23178 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23179 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23180 +                               goto out;
23181 +                       pos++;
23182 +               }
23183 +       }
23184 +out:
23185 +       filp->f_pos = pos;
23186 +       return 1;
23187 +}
23188 +
23189 +
23190 +#define MAX_MULBY10    ((~0U - 9) / 10)
23191 +
23192 +static inline int atovid(const char *str, int len)
23193 +{
23194 +       int vid, c;
23195 +
23196 +       vid = 0;
23197 +       while (len-- > 0) {
23198 +               c = *str - '0';
23199 +               str++;
23200 +               if (c > 9)
23201 +                       return -1;
23202 +               if (vid >= MAX_MULBY10)
23203 +                       return -1;
23204 +               vid *= 10;
23205 +               vid += c;
23206 +               if (!vid)
23207 +                       return -1;
23208 +       }
23209 +       return vid;
23210 +}
23211 +
23212 +/* now the upper level (virtual) */
23213 +
23214 +
23215 +static struct file_operations proc_xid_file_operations = {
23216 +       .read =         generic_read_dir,
23217 +       .readdir =      proc_xid_readdir,
23218 +};
23219 +
23220 +static struct inode_operations proc_xid_inode_operations = {
23221 +       .lookup =       proc_xid_lookup,
23222 +};
23223 +
23224 +static struct vs_entry vx_virtual_stuff[] = {
23225 +       INF("info",     S_IRUGO, virtual_info),
23226 +       INF("status",   S_IRUGO, virtual_status),
23227 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
23228 +};
23229 +
23230 +
23231 +static struct dentry *proc_virtual_lookup(struct inode *dir,
23232 +       struct dentry *dentry, struct nameidata *nd)
23233 +{
23234 +       struct vs_entry *p = vx_virtual_stuff;
23235 +       struct dentry *error = ERR_PTR(-ENOENT);
23236 +       int id = 0;
23237 +
23238 +       for (; p->name; p++) {
23239 +               if (p->len != dentry->d_name.len)
23240 +                       continue;
23241 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23242 +                       break;
23243 +       }
23244 +       if (p->name)
23245 +               goto instantiate;
23246 +
23247 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23248 +       if ((id < 0) || !xid_is_hashed(id))
23249 +               goto out;
23250 +
23251 +instantiate:
23252 +       error = proc_xid_instantiate(dir, dentry, id, p);
23253 +out:
23254 +       return error;
23255 +}
23256 +
23257 +static struct file_operations proc_nid_file_operations = {
23258 +       .read =         generic_read_dir,
23259 +       .readdir =      proc_nid_readdir,
23260 +};
23261 +
23262 +static struct inode_operations proc_nid_inode_operations = {
23263 +       .lookup =       proc_nid_lookup,
23264 +};
23265 +
23266 +static struct vs_entry nx_virtnet_stuff[] = {
23267 +       INF("info",     S_IRUGO, virtnet_info),
23268 +       INF("status",   S_IRUGO, virtnet_status),
23269 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
23270 +};
23271 +
23272 +
23273 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
23274 +       struct dentry *dentry, struct nameidata *nd)
23275 +{
23276 +       struct vs_entry *p = nx_virtnet_stuff;
23277 +       struct dentry *error = ERR_PTR(-ENOENT);
23278 +       int id = 0;
23279 +
23280 +       for (; p->name; p++) {
23281 +               if (p->len != dentry->d_name.len)
23282 +                       continue;
23283 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23284 +                       break;
23285 +       }
23286 +       if (p->name)
23287 +               goto instantiate;
23288 +
23289 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23290 +       if ((id < 0) || !nid_is_hashed(id))
23291 +               goto out;
23292 +
23293 +instantiate:
23294 +       error = proc_nid_instantiate(dir, dentry, id, p);
23295 +out:
23296 +       return error;
23297 +}
23298 +
23299 +
23300 +
23301 +#define PROC_NUMBUF 10
23302 +#define PROC_MAXVIDS 32
23303 +
23304 +int proc_virtual_readdir(struct file *filp,
23305 +       void *dirent, filldir_t filldir)
23306 +{
23307 +       struct dentry *dentry = filp->f_dentry;
23308 +       struct inode *inode = dentry->d_inode;
23309 +       struct vs_entry *p = vx_virtual_stuff;
23310 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
23311 +       int pos, index;
23312 +       unsigned int xid_array[PROC_MAXVIDS];
23313 +       char buf[PROC_NUMBUF];
23314 +       unsigned int nr_xids, i;
23315 +       u64 ino;
23316 +
23317 +       pos = filp->f_pos;
23318 +       switch (pos) {
23319 +       case 0:
23320 +               ino = inode->i_ino;
23321 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23322 +                       goto out;
23323 +               pos++;
23324 +               /* fall through */
23325 +       case 1:
23326 +               ino = parent_ino(dentry);
23327 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23328 +                       goto out;
23329 +               pos++;
23330 +               /* fall through */
23331 +       default:
23332 +               index = pos - 2;
23333 +               if (index >= size)
23334 +                       goto entries;
23335 +               for (p += index; p->name; p++) {
23336 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23337 +                               vs_proc_instantiate, 0, p))
23338 +                               goto out;
23339 +                       pos++;
23340 +               }
23341 +       entries:
23342 +               index = pos - size;
23343 +               p = &vx_virtual_stuff[size - 1];
23344 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
23345 +               for (i = 0; i < nr_xids; i++) {
23346 +                       int n, xid = xid_array[i];
23347 +                       unsigned int j = PROC_NUMBUF;
23348 +
23349 +                       n = xid;
23350 +                       do
23351 +                               buf[--j] = '0' + (n % 10);
23352 +                       while (n /= 10);
23353 +
23354 +                       if (proc_fill_cache(filp, dirent, filldir,
23355 +                               buf + j, PROC_NUMBUF - j,
23356 +                               vs_proc_instantiate, xid, p))
23357 +                               goto out;
23358 +                       pos++;
23359 +               }
23360 +       }
23361 +out:
23362 +       filp->f_pos = pos;
23363 +       return 0;
23364 +}
23365 +
23366 +static int proc_virtual_getattr(struct vfsmount *mnt,
23367 +       struct dentry *dentry, struct kstat *stat)
23368 +{
23369 +       struct inode *inode = dentry->d_inode;
23370 +
23371 +       generic_fillattr(inode, stat);
23372 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
23373 +       return 0;
23374 +}
23375 +
23376 +static struct file_operations proc_virtual_dir_operations = {
23377 +       .read =         generic_read_dir,
23378 +       .readdir =      proc_virtual_readdir,
23379 +};
23380 +
23381 +static struct inode_operations proc_virtual_dir_inode_operations = {
23382 +       .getattr =      proc_virtual_getattr,
23383 +       .lookup =       proc_virtual_lookup,
23384 +};
23385 +
23386 +
23387 +
23388 +
23389 +
23390 +int proc_virtnet_readdir(struct file *filp,
23391 +       void *dirent, filldir_t filldir)
23392 +{
23393 +       struct dentry *dentry = filp->f_dentry;
23394 +       struct inode *inode = dentry->d_inode;
23395 +       struct vs_entry *p = nx_virtnet_stuff;
23396 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
23397 +       int pos, index;
23398 +       unsigned int nid_array[PROC_MAXVIDS];
23399 +       char buf[PROC_NUMBUF];
23400 +       unsigned int nr_nids, i;
23401 +       u64 ino;
23402 +
23403 +       pos = filp->f_pos;
23404 +       switch (pos) {
23405 +       case 0:
23406 +               ino = inode->i_ino;
23407 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23408 +                       goto out;
23409 +               pos++;
23410 +               /* fall through */
23411 +       case 1:
23412 +               ino = parent_ino(dentry);
23413 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23414 +                       goto out;
23415 +               pos++;
23416 +               /* fall through */
23417 +       default:
23418 +               index = pos - 2;
23419 +               if (index >= size)
23420 +                       goto entries;
23421 +               for (p += index; p->name; p++) {
23422 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23423 +                               vs_proc_instantiate, 0, p))
23424 +                               goto out;
23425 +                       pos++;
23426 +               }
23427 +       entries:
23428 +               index = pos - size;
23429 +               p = &nx_virtnet_stuff[size - 1];
23430 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
23431 +               for (i = 0; i < nr_nids; i++) {
23432 +                       int n, nid = nid_array[i];
23433 +                       unsigned int j = PROC_NUMBUF;
23434 +
23435 +                       n = nid;
23436 +                       do
23437 +                               buf[--j] = '0' + (n % 10);
23438 +                       while (n /= 10);
23439 +
23440 +                       if (proc_fill_cache(filp, dirent, filldir,
23441 +                               buf + j, PROC_NUMBUF - j,
23442 +                               vs_proc_instantiate, nid, p))
23443 +                               goto out;
23444 +                       pos++;
23445 +               }
23446 +       }
23447 +out:
23448 +       filp->f_pos = pos;
23449 +       return 0;
23450 +}
23451 +
23452 +static int proc_virtnet_getattr(struct vfsmount *mnt,
23453 +       struct dentry *dentry, struct kstat *stat)
23454 +{
23455 +       struct inode *inode = dentry->d_inode;
23456 +
23457 +       generic_fillattr(inode, stat);
23458 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
23459 +       return 0;
23460 +}
23461 +
23462 +static struct file_operations proc_virtnet_dir_operations = {
23463 +       .read =         generic_read_dir,
23464 +       .readdir =      proc_virtnet_readdir,
23465 +};
23466 +
23467 +static struct inode_operations proc_virtnet_dir_inode_operations = {
23468 +       .getattr =      proc_virtnet_getattr,
23469 +       .lookup =       proc_virtnet_lookup,
23470 +};
23471 +
23472 +
23473 +
23474 +void proc_vx_init(void)
23475 +{
23476 +       struct proc_dir_entry *ent;
23477 +
23478 +       ent = proc_mkdir("virtual", 0);
23479 +       if (ent) {
23480 +               ent->proc_fops = &proc_virtual_dir_operations;
23481 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
23482 +       }
23483 +       proc_virtual = ent;
23484 +
23485 +       ent = proc_mkdir("virtnet", 0);
23486 +       if (ent) {
23487 +               ent->proc_fops = &proc_virtnet_dir_operations;
23488 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
23489 +       }
23490 +       proc_virtnet = ent;
23491 +}
23492 +
23493 +
23494 +
23495 +
23496 +/* per pid info */
23497 +
23498 +
23499 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
23500 +{
23501 +       struct vx_info *vxi;
23502 +       char *orig = buffer;
23503 +
23504 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
23505 +
23506 +       vxi = task_get_vx_info(p);
23507 +       if (!vxi)
23508 +               goto out;
23509 +
23510 +       buffer += sprintf(buffer, "BCaps:\t%016llx\n",
23511 +               (unsigned long long)vxi->vx_bcaps);
23512 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
23513 +               (unsigned long long)vxi->vx_ccaps);
23514 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
23515 +               (unsigned long long)vxi->vx_flags);
23516 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
23517 +
23518 +       put_vx_info(vxi);
23519 +out:
23520 +       return buffer - orig;
23521 +}
23522 +
23523 +
23524 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
23525 +{
23526 +       struct nx_info *nxi;
23527 +       char *orig = buffer;
23528 +       int i;
23529 +
23530 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
23531 +
23532 +       nxi = task_get_nx_info(p);
23533 +       if (!nxi)
23534 +               goto out;
23535 +
23536 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
23537 +               (unsigned long long)nxi->nx_ncaps);
23538 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
23539 +               (unsigned long long)nxi->nx_flags);
23540 +
23541 +       for (i = 0; i < nxi->nbipv4; i++){
23542 +               buffer += sprintf(buffer,
23543 +                       "V4Root[%d]:\t" NIPQUAD_FMT "/" NIPQUAD_FMT "\n", i,
23544 +                       NIPQUAD(nxi->ipv4[i]),
23545 +                       NIPQUAD(nxi->mask[i]));
23546 +       }
23547 +       buffer += sprintf(buffer,
23548 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
23549 +               NIPQUAD(nxi->v4_bcast));
23550 +
23551 +       put_nx_info(nxi);
23552 +out:
23553 +       return buffer - orig;
23554 +}
23555 +
23556 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/sched.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/sched.c
23557 --- linux-2.6.24-rc7/kernel/vserver/sched.c     1970-01-01 01:00:00 +0100
23558 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/sched.c       2007-12-13 13:25:37 +0100
23559 @@ -0,0 +1,447 @@
23560 +/*
23561 + *  linux/kernel/vserver/sched.c
23562 + *
23563 + *  Virtual Server: Scheduler Support
23564 + *
23565 + *  Copyright (C) 2004-2007  Herbert Pötzl
23566 + *
23567 + *  V0.01  adapted Sam Vilains version to 2.6.3
23568 + *  V0.02  removed legacy interface
23569 + *  V0.03  changed vcmds to vxi arg
23570 + *
23571 + */
23572 +
23573 +#include <linux/sched.h>
23574 +#include <linux/vs_context.h>
23575 +#include <linux/vs_sched.h>
23576 +#include <linux/vserver/sched_cmd.h>
23577 +
23578 +#include <asm/errno.h>
23579 +#include <asm/uaccess.h>
23580 +
23581 +#define vxd_check_range(val, min, max) do {            \
23582 +       vxlprintk((val < min) || (val > max),           \
23583 +               "check_range(%ld,%ld,%ld)",             \
23584 +               (long)val, (long)min, (long)max,        \
23585 +               __FILE__, __LINE__);                    \
23586 +       } while (0)
23587 +
23588 +
23589 +void vx_update_sched_param(struct _vx_sched *sched,
23590 +       struct _vx_sched_pc *sched_pc)
23591 +{
23592 +       unsigned int set_mask = sched->update_mask;
23593 +
23594 +       if (set_mask & VXSM_FILL_RATE)
23595 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
23596 +       if (set_mask & VXSM_INTERVAL)
23597 +               sched_pc->interval[0] = sched->interval[0];
23598 +       if (set_mask & VXSM_FILL_RATE2)
23599 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
23600 +       if (set_mask & VXSM_INTERVAL2)
23601 +               sched_pc->interval[1] = sched->interval[1];
23602 +       if (set_mask & VXSM_TOKENS)
23603 +               sched_pc->tokens = sched->tokens;
23604 +       if (set_mask & VXSM_TOKENS_MIN)
23605 +               sched_pc->tokens_min = sched->tokens_min;
23606 +       if (set_mask & VXSM_TOKENS_MAX)
23607 +               sched_pc->tokens_max = sched->tokens_max;
23608 +       if (set_mask & VXSM_PRIO_BIAS)
23609 +               sched_pc->prio_bias = sched->prio_bias;
23610 +
23611 +       if (set_mask & VXSM_IDLE_TIME)
23612 +               sched_pc->flags |= VXSF_IDLE_TIME;
23613 +       else
23614 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
23615 +
23616 +       /* reset time */
23617 +       sched_pc->norm_time = jiffies;
23618 +}
23619 +
23620 +
23621 +/*
23622 + * recalculate the context's scheduling tokens
23623 + *
23624 + * ret > 0 : number of tokens available
23625 + * ret < 0 : on hold, check delta_min[]
23626 + *          -1 only jiffies
23627 + *          -2 also idle time
23628 + *
23629 + */
23630 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
23631 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
23632 +{
23633 +       long delta;
23634 +       long tokens = 0;
23635 +       int flags = sched_pc->flags;
23636 +
23637 +       /* how much time did pass? */
23638 +       delta = *norm_time - sched_pc->norm_time;
23639 +       vxd_check_range(delta, 0, INT_MAX);
23640 +
23641 +       if (delta >= sched_pc->interval[0]) {
23642 +               long tokens, integral;
23643 +
23644 +               /* calc integral token part */
23645 +               tokens = delta / sched_pc->interval[0];
23646 +               integral = tokens * sched_pc->interval[0];
23647 +               tokens *= sched_pc->fill_rate[0];
23648 +#ifdef CONFIG_VSERVER_HARDCPU
23649 +               delta_min[0] = delta - integral;
23650 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
23651 +#endif
23652 +               /* advance time */
23653 +               sched_pc->norm_time += delta;
23654 +
23655 +               /* add tokens */
23656 +               sched_pc->tokens += tokens;
23657 +               sched_pc->token_time += tokens;
23658 +       } else
23659 +               delta_min[0] = delta;
23660 +
23661 +#ifdef CONFIG_VSERVER_IDLETIME
23662 +       if (!(flags & VXSF_IDLE_TIME))
23663 +               goto skip_idle;
23664 +
23665 +       /* how much was the idle skip? */
23666 +       delta = *idle_time - sched_pc->idle_time;
23667 +       vxd_check_range(delta, 0, INT_MAX);
23668 +
23669 +       if (delta >= sched_pc->interval[1]) {
23670 +               long tokens, integral;
23671 +
23672 +               /* calc fair share token part */
23673 +               tokens = delta / sched_pc->interval[1];
23674 +               integral = tokens * sched_pc->interval[1];
23675 +               tokens *= sched_pc->fill_rate[1];
23676 +               delta_min[1] = delta - integral;
23677 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
23678 +
23679 +               /* advance idle time */
23680 +               sched_pc->idle_time += integral;
23681 +
23682 +               /* add tokens */
23683 +               sched_pc->tokens += tokens;
23684 +               sched_pc->token_time += tokens;
23685 +       } else
23686 +               delta_min[1] = delta;
23687 +skip_idle:
23688 +#endif
23689 +
23690 +       /* clip at maximum */
23691 +       if (sched_pc->tokens > sched_pc->tokens_max)
23692 +               sched_pc->tokens = sched_pc->tokens_max;
23693 +       tokens = sched_pc->tokens;
23694 +
23695 +       if ((flags & VXSF_ONHOLD)) {
23696 +               /* can we unhold? */
23697 +               if (tokens >= sched_pc->tokens_min) {
23698 +                       flags &= ~VXSF_ONHOLD;
23699 +                       sched_pc->hold_ticks +=
23700 +                               *norm_time - sched_pc->onhold;
23701 +               } else
23702 +                       goto on_hold;
23703 +       } else {
23704 +               /* put on hold? */
23705 +               if (tokens <= 0) {
23706 +                       flags |= VXSF_ONHOLD;
23707 +                       sched_pc->onhold = *norm_time;
23708 +                       goto on_hold;
23709 +               }
23710 +       }
23711 +       sched_pc->flags = flags;
23712 +       return tokens;
23713 +
23714 +on_hold:
23715 +       tokens = sched_pc->tokens_min - tokens;
23716 +       sched_pc->flags = flags;
23717 +       BUG_ON(tokens < 0);
23718 +
23719 +#ifdef CONFIG_VSERVER_HARDCPU
23720 +       /* next interval? */
23721 +       if (!sched_pc->fill_rate[0])
23722 +               delta_min[0] = HZ;
23723 +       else if (tokens > sched_pc->fill_rate[0])
23724 +               delta_min[0] += sched_pc->interval[0] *
23725 +                       tokens / sched_pc->fill_rate[0];
23726 +       else
23727 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
23728 +       vxd_check_range(delta_min[0], 0, INT_MAX);
23729 +
23730 +#ifdef CONFIG_VSERVER_IDLETIME
23731 +       if (!(flags & VXSF_IDLE_TIME))
23732 +               return -1;
23733 +
23734 +       /* next interval? */
23735 +       if (!sched_pc->fill_rate[1])
23736 +               delta_min[1] = HZ;
23737 +       else if (tokens > sched_pc->fill_rate[1])
23738 +               delta_min[1] += sched_pc->interval[1] *
23739 +                       tokens / sched_pc->fill_rate[1];
23740 +       else
23741 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
23742 +       vxd_check_range(delta_min[1], 0, INT_MAX);
23743 +
23744 +       return -2;
23745 +#else
23746 +       return -1;
23747 +#endif /* CONFIG_VSERVER_IDLETIME */
23748 +#else
23749 +       return 0;
23750 +#endif /* CONFIG_VSERVER_HARDCPU */
23751 +}
23752 +
23753 +static inline unsigned long msec_to_ticks(unsigned long msec)
23754 +{
23755 +       return msecs_to_jiffies(msec);
23756 +}
23757 +
23758 +static inline unsigned long ticks_to_msec(unsigned long ticks)
23759 +{
23760 +       return jiffies_to_msecs(ticks);
23761 +}
23762 +
23763 +static inline unsigned long ticks_to_usec(unsigned long ticks)
23764 +{
23765 +       return jiffies_to_usecs(ticks);
23766 +}
23767 +
23768 +
23769 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
23770 +{
23771 +       unsigned int set_mask = data->mask;
23772 +       unsigned int update_mask;
23773 +       int i, cpu;
23774 +
23775 +       /* Sanity check data values */
23776 +       if (data->tokens_max <= 0)
23777 +               data->tokens_max = HZ;
23778 +       if (data->tokens_min < 0)
23779 +               data->tokens_min = HZ / 3;
23780 +       if (data->tokens_min >= data->tokens_max)
23781 +               data->tokens_min = data->tokens_max;
23782 +
23783 +       if (data->prio_bias > MAX_PRIO_BIAS)
23784 +               data->prio_bias = MAX_PRIO_BIAS;
23785 +       if (data->prio_bias < MIN_PRIO_BIAS)
23786 +               data->prio_bias = MIN_PRIO_BIAS;
23787 +
23788 +       spin_lock(&vxi->sched.tokens_lock);
23789 +
23790 +       /* sync up on delayed updates */
23791 +       for_each_cpu_mask(cpu, vxi->sched.update)
23792 +               vx_update_sched_param(&vxi->sched,
23793 +                       &vx_per_cpu(vxi, sched_pc, cpu));
23794 +
23795 +       if (set_mask & VXSM_FILL_RATE)
23796 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
23797 +       if (set_mask & VXSM_FILL_RATE2)
23798 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
23799 +       if (set_mask & VXSM_INTERVAL)
23800 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
23801 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
23802 +       if (set_mask & VXSM_INTERVAL2)
23803 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
23804 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
23805 +       if (set_mask & VXSM_TOKENS)
23806 +               vxi->sched.tokens = data->tokens;
23807 +       if (set_mask & VXSM_TOKENS_MIN)
23808 +               vxi->sched.tokens_min = data->tokens_min;
23809 +       if (set_mask & VXSM_TOKENS_MAX)
23810 +               vxi->sched.tokens_max = data->tokens_max;
23811 +       if (set_mask & VXSM_PRIO_BIAS)
23812 +               vxi->sched.prio_bias = data->prio_bias;
23813 +
23814 +       /* Sanity check rate/interval */
23815 +       for (i = 0; i < 2; i++) {
23816 +               if (data->fill_rate[i] < 0)
23817 +                       data->fill_rate[i] = 0;
23818 +               if (data->interval[i] <= 0)
23819 +                       data->interval[i] = HZ;
23820 +       }
23821 +
23822 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
23823 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
23824 +       vxi->sched.update_mask = update_mask;
23825 +#ifdef CONFIG_SMP
23826 +       rmb();
23827 +       if (set_mask & VXSM_CPU_ID) {
23828 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
23829 +               cpus_and(vxi->sched.update, cpu_online_map,
23830 +                       vxi->sched.update);
23831 +       } else
23832 +               vxi->sched.update = cpu_online_map;
23833 +
23834 +       /* forced reload? */
23835 +       if (set_mask & VXSM_FORCE) {
23836 +               for_each_cpu_mask(cpu, vxi->sched.update)
23837 +                       vx_update_sched_param(&vxi->sched,
23838 +                               &vx_per_cpu(vxi, sched_pc, cpu));
23839 +               vxi->sched.update = CPU_MASK_NONE;
23840 +       }
23841 +#else
23842 +       /* on UP we update immediately */
23843 +       vx_update_sched_param(&vxi->sched,
23844 +               &vx_per_cpu(vxi, sched_pc, 0));
23845 +#endif
23846 +
23847 +       spin_unlock(&vxi->sched.tokens_lock);
23848 +       return 0;
23849 +}
23850 +
23851 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
23852 +#define COPY_PRI(C) C(prio_bias)
23853 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
23854 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
23855 +                   C(fill_rate[1]); C(interval[1]);
23856 +
23857 +#define COPY_VALUE(name) vc_data.name = data->name
23858 +
23859 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
23860 +{
23861 +       struct vcmd_sched_v5 vc_data;
23862 +
23863 +       vc_data.mask = data->set_mask;
23864 +       COPY_IDS(COPY_VALUE);
23865 +       COPY_PRI(COPY_VALUE);
23866 +       COPY_TOK(COPY_VALUE);
23867 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
23868 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
23869 +       return do_set_sched(vxi, &vc_data);
23870 +}
23871 +
23872 +#ifdef CONFIG_VSERVER_LEGACY
23873 +
23874 +#define COPY_MASK_V2(name, mask)                       \
23875 +       if (vc_data.name != SCHED_KEEP) {               \
23876 +               vc_data_v4.name = vc_data.name;         \
23877 +               vc_data_v4.set_mask |= mask;            \
23878 +       }
23879 +
23880 +int vc_set_sched_v2(struct vx_info *vxi, void __user *data)
23881 +{
23882 +       struct vcmd_set_sched_v2 vc_data;
23883 +       struct vcmd_set_sched_v4 vc_data_v4 = { .set_mask = 0 };
23884 +
23885 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23886 +               return -EFAULT;
23887 +
23888 +       COPY_MASK_V2(fill_rate,  VXSM_FILL_RATE);
23889 +       COPY_MASK_V2(interval,   VXSM_INTERVAL);
23890 +       COPY_MASK_V2(tokens,     VXSM_TOKENS);
23891 +       COPY_MASK_V2(tokens_min, VXSM_TOKENS_MIN);
23892 +       COPY_MASK_V2(tokens_max, VXSM_TOKENS_MAX);
23893 +       vc_data_v4.bucket_id = 0;
23894 +
23895 +       do_set_sched_v4(vxi, &vc_data_v4);
23896 +       return 0;
23897 +}
23898 +#endif
23899 +
23900 +int vc_set_sched_v3(struct vx_info *vxi, void __user *data)
23901 +{
23902 +       struct vcmd_set_sched_v3 vc_data;
23903 +       struct vcmd_set_sched_v4 vc_data_v4;
23904 +
23905 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23906 +               return -EFAULT;
23907 +
23908 +       /* structures are binary compatible */
23909 +       memcpy(&vc_data_v4, &vc_data, sizeof(vc_data));
23910 +       vc_data_v4.set_mask &= VXSM_V3_MASK;
23911 +       vc_data_v4.bucket_id = 0;
23912 +
23913 +       return do_set_sched_v4(vxi, &vc_data_v4);
23914 +}
23915 +
23916 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
23917 +{
23918 +       struct vcmd_set_sched_v4 vc_data;
23919 +
23920 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23921 +               return -EFAULT;
23922 +
23923 +       return do_set_sched_v4(vxi, &vc_data);
23924 +}
23925 +
23926 +       /* latest interface is v5 */
23927 +
23928 +int vc_set_sched(struct vx_info *vxi, void __user *data)
23929 +{
23930 +       struct vcmd_sched_v5 vc_data;
23931 +
23932 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23933 +               return -EFAULT;
23934 +
23935 +       return do_set_sched(vxi, &vc_data);
23936 +}
23937 +
23938 +
23939 +int vc_get_sched(struct vx_info *vxi, void __user *data)
23940 +{
23941 +       struct vcmd_sched_v5 vc_data;
23942 +
23943 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23944 +               return -EFAULT;
23945 +
23946 +       if (vc_data.mask & VXSM_CPU_ID) {
23947 +               int cpu = vc_data.cpu_id;
23948 +               struct _vx_sched_pc *data;
23949 +
23950 +               if (!cpu_possible(cpu))
23951 +                       return -EINVAL;
23952 +
23953 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
23954 +               COPY_TOK(COPY_VALUE);
23955 +               COPY_PRI(COPY_VALUE);
23956 +               COPY_FRI(COPY_VALUE);
23957 +
23958 +               if (data->flags & VXSF_IDLE_TIME)
23959 +                       vc_data.mask |= VXSM_IDLE_TIME;
23960 +       } else {
23961 +               struct _vx_sched *data = &vxi->sched;
23962 +
23963 +               COPY_TOK(COPY_VALUE);
23964 +               COPY_PRI(COPY_VALUE);
23965 +               COPY_FRI(COPY_VALUE);
23966 +       }
23967 +
23968 +       if (vc_data.mask & VXSM_MSEC) {
23969 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
23970 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
23971 +       }
23972 +
23973 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23974 +               return -EFAULT;
23975 +       return 0;
23976 +}
23977 +
23978 +
23979 +int vc_sched_info(struct vx_info *vxi, void __user *data)
23980 +{
23981 +       struct vcmd_sched_info vc_data;
23982 +       int cpu;
23983 +
23984 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23985 +               return -EFAULT;
23986 +
23987 +       cpu = vc_data.cpu_id;
23988 +       if (!cpu_possible(cpu))
23989 +               return -EINVAL;
23990 +
23991 +       if (vxi) {
23992 +               struct _vx_sched_pc *sched_pc =
23993 +                       &vx_per_cpu(vxi, sched_pc, cpu);
23994 +
23995 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
23996 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
23997 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
23998 +               vc_data.vavavoom = sched_pc->vavavoom;
23999 +       }
24000 +       vc_data.token_usec = ticks_to_usec(1);
24001 +
24002 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24003 +               return -EFAULT;
24004 +       return 0;
24005 +}
24006 +
24007 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/sched_init.h linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/sched_init.h
24008 --- linux-2.6.24-rc7/kernel/vserver/sched_init.h        1970-01-01 01:00:00 +0100
24009 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/sched_init.h  2007-12-13 13:25:43 +0100
24010 @@ -0,0 +1,50 @@
24011 +
24012 +static inline void vx_info_init_sched(struct _vx_sched *sched)
24013 +{
24014 +       static struct lock_class_key tokens_lock_key;
24015 +
24016 +       /* scheduling; hard code starting values as constants */
24017 +       sched->fill_rate[0]     = 1;
24018 +       sched->interval[0]      = 4;
24019 +       sched->fill_rate[1]     = 1;
24020 +       sched->interval[1]      = 8;
24021 +       sched->tokens           = HZ >> 2;
24022 +       sched->tokens_min       = HZ >> 4;
24023 +       sched->tokens_max       = HZ >> 1;
24024 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
24025 +       sched->prio_bias        = 0;
24026 +
24027 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
24028 +}
24029 +
24030 +static inline
24031 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24032 +{
24033 +       sched_pc->fill_rate[0]  = 1;
24034 +       sched_pc->interval[0]   = 4;
24035 +       sched_pc->fill_rate[1]  = 1;
24036 +       sched_pc->interval[1]   = 8;
24037 +       sched_pc->tokens        = HZ >> 2;
24038 +       sched_pc->tokens_min    = HZ >> 4;
24039 +       sched_pc->tokens_max    = HZ >> 1;
24040 +       sched_pc->prio_bias     = 0;
24041 +       sched_pc->vavavoom      = 0;
24042 +       sched_pc->token_time    = 0;
24043 +       sched_pc->idle_time     = 0;
24044 +       sched_pc->norm_time     = jiffies;
24045 +
24046 +       sched_pc->user_ticks = 0;
24047 +       sched_pc->sys_ticks = 0;
24048 +       sched_pc->hold_ticks = 0;
24049 +}
24050 +
24051 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
24052 +{
24053 +       return;
24054 +}
24055 +
24056 +static inline
24057 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24058 +{
24059 +       return;
24060 +}
24061 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/sched_proc.h linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/sched_proc.h
24062 --- linux-2.6.24-rc7/kernel/vserver/sched_proc.h        1970-01-01 01:00:00 +0100
24063 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/sched_proc.h  2007-12-13 13:25:43 +0100
24064 @@ -0,0 +1,57 @@
24065 +#ifndef _VX_SCHED_PROC_H
24066 +#define _VX_SCHED_PROC_H
24067 +
24068 +
24069 +static inline
24070 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
24071 +{
24072 +       int length = 0;
24073 +
24074 +       length += sprintf(buffer,
24075 +               "FillRate:\t%8d,%d\n"
24076 +               "Interval:\t%8d,%d\n"
24077 +               "TokensMin:\t%8d\n"
24078 +               "TokensMax:\t%8d\n"
24079 +               "PrioBias:\t%8d\n",
24080 +               sched->fill_rate[0],
24081 +               sched->fill_rate[1],
24082 +               sched->interval[0],
24083 +               sched->interval[1],
24084 +               sched->tokens_min,
24085 +               sched->tokens_max,
24086 +               sched->prio_bias);
24087 +       return length;
24088 +}
24089 +
24090 +static inline
24091 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
24092 +       char *buffer, int cpu)
24093 +{
24094 +       int length = 0;
24095 +
24096 +       length += sprintf(buffer + length,
24097 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
24098 +               (unsigned long long)sched_pc->user_ticks,
24099 +               (unsigned long long)sched_pc->sys_ticks,
24100 +               (unsigned long long)sched_pc->hold_ticks,
24101 +               sched_pc->token_time,
24102 +               sched_pc->idle_time);
24103 +       length += sprintf(buffer + length,
24104 +               " %c%c %d %d %d %d/%d %d/%d",
24105 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
24106 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
24107 +               sched_pc->tokens,
24108 +               sched_pc->tokens_min,
24109 +               sched_pc->tokens_max,
24110 +               sched_pc->fill_rate[0],
24111 +               sched_pc->interval[0],
24112 +               sched_pc->fill_rate[1],
24113 +               sched_pc->interval[1]);
24114 +       length += sprintf(buffer + length,
24115 +               " %d %d\n",
24116 +               sched_pc->prio_bias,
24117 +               sched_pc->vavavoom);
24118 +       return length;
24119 +}
24120 +
24121 +#endif /* _VX_SCHED_PROC_H */
24122 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/signal.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/signal.c
24123 --- linux-2.6.24-rc7/kernel/vserver/signal.c    1970-01-01 01:00:00 +0100
24124 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/signal.c      2007-12-13 15:58:28 +0100
24125 @@ -0,0 +1,135 @@
24126 +/*
24127 + *  linux/kernel/vserver/signal.c
24128 + *
24129 + *  Virtual Server: Signal Support
24130 + *
24131 + *  Copyright (C) 2003-2007  Herbert Pötzl
24132 + *
24133 + *  V0.01  broken out from vcontext V0.05
24134 + *  V0.02  changed vcmds to vxi arg
24135 + *  V0.03  adjusted siginfo for kill
24136 + *
24137 + */
24138 +
24139 +#include <linux/sched.h>
24140 +
24141 +#include <asm/errno.h>
24142 +#include <asm/uaccess.h>
24143 +
24144 +#include <linux/vs_context.h>
24145 +#include <linux/vs_pid.h>
24146 +#include <linux/vserver/signal_cmd.h>
24147 +
24148 +
24149 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
24150 +{
24151 +       int retval, count = 0;
24152 +       struct task_struct *p;
24153 +       struct siginfo *sip = SEND_SIG_PRIV;
24154 +
24155 +       retval = -ESRCH;
24156 +       vxdprintk(VXD_CBIT(misc, 4),
24157 +               "vx_info_kill(%p[#%d],%d,%d)*",
24158 +               vxi, vxi->vx_id, pid, sig);
24159 +       read_lock(&tasklist_lock);
24160 +       switch (pid) {
24161 +       case  0:
24162 +       case -1:
24163 +               for_each_process(p) {
24164 +                       int err = 0;
24165 +
24166 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
24167 +                               (pid && vxi->vx_initpid == p->pid))
24168 +                               continue;
24169 +
24170 +                       err = group_send_sig_info(sig, sip, p);
24171 +                       ++count;
24172 +                       if (err != -EPERM)
24173 +                               retval = err;
24174 +               }
24175 +               break;
24176 +
24177 +       case 1:
24178 +               if (vxi->vx_initpid) {
24179 +                       pid = vxi->vx_initpid;
24180 +                       /* for now, only SIGINT to private init ... */
24181 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24182 +                               /* ... as long as there are tasks left */
24183 +                               (atomic_read(&vxi->vx_tasks) > 1))
24184 +                               sig = SIGINT;
24185 +               }
24186 +               /* fallthrough */
24187 +       default:
24188 +               p = find_task_by_real_pid(pid);
24189 +               if (p) {
24190 +                       if (vx_task_xid(p) == vxi->vx_id)
24191 +                               retval = group_send_sig_info(sig, sip, p);
24192 +               }
24193 +               break;
24194 +       }
24195 +       read_unlock(&tasklist_lock);
24196 +       vxdprintk(VXD_CBIT(misc, 4),
24197 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
24198 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
24199 +       return retval;
24200 +}
24201 +
24202 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
24203 +{
24204 +       struct vcmd_ctx_kill_v0 vc_data;
24205 +
24206 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24207 +               return -EFAULT;
24208 +
24209 +       /* special check to allow guest shutdown */
24210 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24211 +               /* forbid killall pid=0 when init is present */
24212 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
24213 +               (vc_data.pid > 1)))
24214 +               return -EACCES;
24215 +
24216 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
24217 +}
24218 +
24219 +
24220 +static int __wait_exit(struct vx_info *vxi)
24221 +{
24222 +       DECLARE_WAITQUEUE(wait, current);
24223 +       int ret = 0;
24224 +
24225 +       add_wait_queue(&vxi->vx_wait, &wait);
24226 +       set_current_state(TASK_INTERRUPTIBLE);
24227 +
24228 +wait:
24229 +       if (vx_info_state(vxi,
24230 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
24231 +               goto out;
24232 +       if (signal_pending(current)) {
24233 +               ret = -ERESTARTSYS;
24234 +               goto out;
24235 +       }
24236 +       schedule();
24237 +       goto wait;
24238 +
24239 +out:
24240 +       set_current_state(TASK_RUNNING);
24241 +       remove_wait_queue(&vxi->vx_wait, &wait);
24242 +       return ret;
24243 +}
24244 +
24245 +
24246 +
24247 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
24248 +{
24249 +       struct vcmd_wait_exit_v0 vc_data;
24250 +       int ret;
24251 +
24252 +       ret = __wait_exit(vxi);
24253 +       vc_data.reboot_cmd = vxi->reboot_cmd;
24254 +       vc_data.exit_code = vxi->exit_code;
24255 +
24256 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24257 +               ret = -EFAULT;
24258 +       return ret;
24259 +}
24260 +
24261 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/space.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/space.c
24262 --- linux-2.6.24-rc7/kernel/vserver/space.c     1970-01-01 01:00:00 +0100
24263 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/space.c       2007-12-15 00:35:03 +0100
24264 @@ -0,0 +1,308 @@
24265 +/*
24266 + *  linux/kernel/vserver/space.c
24267 + *
24268 + *  Virtual Server: Context Space Support
24269 + *
24270 + *  Copyright (C) 2003-2007  Herbert Pötzl
24271 + *
24272 + *  V0.01  broken out from context.c 0.07
24273 + *  V0.02  added task locking for namespace
24274 + *  V0.03  broken out vx_enter_namespace
24275 + *  V0.04  added *space support and commands
24276 + *
24277 + */
24278 +
24279 +#include <linux/utsname.h>
24280 +#include <linux/sched.h>
24281 +#include <linux/vs_context.h>
24282 +#include <linux/vserver/space.h>
24283 +#include <linux/vserver/space_cmd.h>
24284 +#include <linux/dcache.h>
24285 +#include <linux/mount.h>
24286 +#include <linux/nsproxy.h>
24287 +#include <linux/user_namespace.h>
24288 +#include <linux/pid_namespace.h>
24289 +#include <linux/fs.h>
24290 +
24291 +#include <asm/errno.h>
24292 +#include <asm/uaccess.h>
24293 +
24294 +
24295 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
24296 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
24297 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
24298 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
24299 +atomic_t vs_global_ipc_ns      = ATOMIC_INIT(0);
24300 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
24301 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
24302 +
24303 +
24304 +/* namespace functions */
24305 +
24306 +#include <linux/mnt_namespace.h>
24307 +
24308 +const struct vcmd_space_mask space_mask = {
24309 +       .mask = CLONE_NEWNS |
24310 +               CLONE_NEWUTS |
24311 +               CLONE_NEWIPC |
24312 +               CLONE_NEWUSER |
24313 +               CLONE_FS
24314 +};
24315 +
24316 +
24317 +/*
24318 + *     build a new nsproxy mix
24319 + *      assumes that both proxies are 'const'
24320 + *     does not touch nsproxy refcounts
24321 + *     will hold a reference on the result.
24322 + */
24323 +
24324 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
24325 +       struct nsproxy *new_nsproxy, unsigned long mask)
24326 +{
24327 +       struct mnt_namespace *old_ns;
24328 +       struct uts_namespace *old_uts;
24329 +       struct ipc_namespace *old_ipc;
24330 +       struct pid_namespace *old_pid;
24331 +       struct user_namespace *old_user;
24332 +       struct nsproxy *nsproxy;
24333 +
24334 +       nsproxy = copy_nsproxy(old_nsproxy);
24335 +       if (!nsproxy)
24336 +               goto out;
24337 +
24338 +       if (mask & CLONE_NEWNS) {
24339 +               old_ns = nsproxy->mnt_ns;
24340 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
24341 +               if (nsproxy->mnt_ns)
24342 +                       get_mnt_ns(nsproxy->mnt_ns);
24343 +       } else
24344 +               old_ns = NULL;
24345 +
24346 +       if (mask & CLONE_NEWUTS) {
24347 +               old_uts = nsproxy->uts_ns;
24348 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
24349 +               if (nsproxy->uts_ns)
24350 +                       get_uts_ns(nsproxy->uts_ns);
24351 +       } else
24352 +               old_uts = NULL;
24353 +
24354 +       if (mask & CLONE_NEWIPC) {
24355 +               old_ipc = nsproxy->ipc_ns;
24356 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
24357 +               if (nsproxy->ipc_ns)
24358 +                       get_ipc_ns(nsproxy->ipc_ns);
24359 +       } else
24360 +               old_ipc = NULL;
24361 +
24362 +       if (mask & CLONE_NEWUSER) {
24363 +               old_user = nsproxy->user_ns;
24364 +               nsproxy->user_ns = new_nsproxy->user_ns;
24365 +               if (nsproxy->user_ns)
24366 +                       get_user_ns(nsproxy->user_ns);
24367 +       } else
24368 +               old_user = NULL;
24369 +
24370 +       if (mask & CLONE_NEWPID) {
24371 +               old_pid = nsproxy->pid_ns;
24372 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
24373 +               if (nsproxy->pid_ns)
24374 +                       get_pid_ns(nsproxy->pid_ns);
24375 +       } else
24376 +               old_pid = NULL;
24377 +
24378 +       if (old_ns)
24379 +               put_mnt_ns(old_ns);
24380 +       if (old_uts)
24381 +               put_uts_ns(old_uts);
24382 +       if (old_ipc)
24383 +               put_ipc_ns(old_ipc);
24384 +       if (old_pid)
24385 +               put_pid_ns(old_pid);
24386 +       if (old_user)
24387 +               put_user_ns(old_user);
24388 +out:
24389 +       return nsproxy;
24390 +}
24391 +
24392 +
24393 +/*
24394 + *     merge two nsproxy structs into a new one.
24395 + *     will hold a reference on the result.
24396 + */
24397 +
24398 +static inline
24399 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
24400 +       struct nsproxy *proxy, unsigned long mask)
24401 +{
24402 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
24403 +
24404 +       if (!proxy)
24405 +               return NULL;
24406 +
24407 +       if (mask) {
24408 +               /* vs_mix_nsproxy returns with reference */
24409 +               return vs_mix_nsproxy(old ? old : &null_proxy,
24410 +                       proxy, mask);
24411 +       }
24412 +       get_nsproxy(proxy);
24413 +       return proxy;
24414 +}
24415 +
24416 +/*
24417 + *     merge two fs structs into a new one.
24418 + *     will take a reference on the result.
24419 + */
24420 +
24421 +static inline
24422 +struct fs_struct *__vs_merge_fs(struct fs_struct *old,
24423 +       struct fs_struct *fs, unsigned long mask)
24424 +{
24425 +       if (!(mask & CLONE_FS)) {
24426 +               if (old)
24427 +                       atomic_inc(&old->count);
24428 +               return old;
24429 +       }
24430 +
24431 +       if (!fs)
24432 +               return NULL;
24433 +
24434 +       return copy_fs_struct(fs);
24435 +}
24436 +
24437 +
24438 +int vx_enter_space(struct vx_info *vxi, unsigned long mask)
24439 +{
24440 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
24441 +       struct fs_struct *fs, *fs_cur, *fs_new;
24442 +       int ret;
24443 +
24444 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
24445 +               return -EACCES;
24446 +
24447 +       if (!mask)
24448 +               mask = vxi->vx_nsmask;
24449 +
24450 +       if ((mask & vxi->vx_nsmask) != mask)
24451 +               return -EINVAL;
24452 +
24453 +       proxy = vxi->vx_nsproxy;
24454 +       fs = vxi->vx_fs;
24455 +
24456 +       task_lock(current);
24457 +       fs_cur = current->fs;
24458 +       atomic_inc(&fs_cur->count);
24459 +       proxy_cur = current->nsproxy;
24460 +       get_nsproxy(proxy_cur);
24461 +       task_unlock(current);
24462 +
24463 +       fs_new = __vs_merge_fs(fs_cur, fs, mask);
24464 +       if (IS_ERR(fs_new)) {
24465 +               ret = PTR_ERR(fs_new);
24466 +               goto out_put;
24467 +       }
24468 +
24469 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
24470 +       if (IS_ERR(proxy_new)) {
24471 +               ret = PTR_ERR(proxy_new);
24472 +               goto out_put_fs;
24473 +       }
24474 +
24475 +       fs_new = xchg(&current->fs, fs_new);
24476 +       proxy_new = xchg(&current->nsproxy, proxy_new);
24477 +       ret = 0;
24478 +
24479 +       if (proxy_new)
24480 +               put_nsproxy(proxy_new);
24481 +out_put_fs:
24482 +       if (fs_new)
24483 +               put_fs_struct(fs_new);
24484 +out_put:
24485 +       if (proxy_cur)
24486 +               put_nsproxy(proxy_cur);
24487 +       if (fs_cur)
24488 +               put_fs_struct(fs_cur);
24489 +       return ret;
24490 +}
24491 +
24492 +
24493 +int vx_set_space(struct vx_info *vxi, unsigned long mask)
24494 +{
24495 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
24496 +       struct fs_struct *fs_vxi, *fs_cur, *fs_new;
24497 +       int ret;
24498 +
24499 +       if (!mask)
24500 +               mask = space_mask.mask;
24501 +
24502 +       if ((mask & space_mask.mask) != mask)
24503 +               return -EINVAL;
24504 +
24505 +       proxy_vxi = vxi->vx_nsproxy;
24506 +       fs_vxi = vxi->vx_fs;
24507 +
24508 +       task_lock(current);
24509 +       fs_cur = current->fs;
24510 +       atomic_inc(&fs_cur->count);
24511 +       proxy_cur = current->nsproxy;
24512 +       get_nsproxy(proxy_cur);
24513 +       task_unlock(current);
24514 +
24515 +       fs_new = __vs_merge_fs(fs_vxi, fs_cur, mask);
24516 +       if (IS_ERR(fs_new)) {
24517 +               ret = PTR_ERR(fs_new);
24518 +               goto out_put;
24519 +       }
24520 +
24521 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
24522 +       if (IS_ERR(proxy_new)) {
24523 +               ret = PTR_ERR(proxy_new);
24524 +               goto out_put_fs;
24525 +       }
24526 +
24527 +       fs_new = xchg(&vxi->vx_fs, fs_new);
24528 +       proxy_new = xchg(&vxi->vx_nsproxy, proxy_new);
24529 +       vxi->vx_nsmask |= mask;
24530 +       ret = 0;
24531 +
24532 +       if (proxy_new)
24533 +               put_nsproxy(proxy_new);
24534 +out_put_fs:
24535 +       if (fs_new)
24536 +               put_fs_struct(fs_new);
24537 +out_put:
24538 +       if (proxy_cur)
24539 +               put_nsproxy(proxy_cur);
24540 +       if (fs_cur)
24541 +               put_fs_struct(fs_cur);
24542 +       return ret;
24543 +}
24544 +
24545 +
24546 +int vc_enter_space(struct vx_info *vxi, void __user *data)
24547 +{
24548 +       struct vcmd_space_mask vc_data = { .mask = 0 };
24549 +
24550 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24551 +               return -EFAULT;
24552 +
24553 +       return vx_enter_space(vxi, vc_data.mask);
24554 +}
24555 +
24556 +int vc_set_space(struct vx_info *vxi, void __user *data)
24557 +{
24558 +       struct vcmd_space_mask vc_data = { .mask = 0 };
24559 +
24560 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24561 +               return -EFAULT;
24562 +
24563 +       return vx_set_space(vxi, vc_data.mask);
24564 +}
24565 +
24566 +int vc_get_space_mask(struct vx_info *vxi, void __user *data)
24567 +{
24568 +       if (copy_to_user(data, &space_mask, sizeof(space_mask)))
24569 +               return -EFAULT;
24570 +       return 0;
24571 +}
24572 +
24573 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/switch.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/switch.c
24574 --- linux-2.6.24-rc7/kernel/vserver/switch.c    1970-01-01 01:00:00 +0100
24575 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/switch.c      2007-12-13 13:25:30 +0100
24576 @@ -0,0 +1,538 @@
24577 +/*
24578 + *  linux/kernel/vserver/switch.c
24579 + *
24580 + *  Virtual Server: Syscall Switch
24581 + *
24582 + *  Copyright (C) 2003-2007  Herbert Pötzl
24583 + *
24584 + *  V0.01  syscall switch
24585 + *  V0.02  added signal to context
24586 + *  V0.03  added rlimit functions
24587 + *  V0.04  added iattr, task/xid functions
24588 + *  V0.05  added debug/history stuff
24589 + *  V0.06  added compat32 layer
24590 + *  V0.07  vcmd args and perms
24591 + *  V0.08  added status commands
24592 + *
24593 + */
24594 +
24595 +#include <linux/linkage.h>
24596 +#include <linux/sched.h>
24597 +#include <linux/compat.h>
24598 +#include <asm/errno.h>
24599 +
24600 +#include <linux/vs_context.h>
24601 +#include <linux/vs_network.h>
24602 +#include <linux/vserver/switch.h>
24603 +
24604 +#include "vci_config.h"
24605 +
24606 +static inline
24607 +int vc_get_version(uint32_t id)
24608 +{
24609 +#ifdef CONFIG_VSERVER_LEGACY_VERSION
24610 +       if (id == 63)
24611 +               return VCI_LEGACY_VERSION;
24612 +#endif
24613 +       return VCI_VERSION;
24614 +}
24615 +
24616 +static inline
24617 +int vc_get_vci(uint32_t id)
24618 +{
24619 +       return vci_kernel_config();
24620 +}
24621 +
24622 +#include <linux/vserver/context_cmd.h>
24623 +#include <linux/vserver/cvirt_cmd.h>
24624 +#include <linux/vserver/cacct_cmd.h>
24625 +#include <linux/vserver/limit_cmd.h>
24626 +#include <linux/vserver/network_cmd.h>
24627 +#include <linux/vserver/sched_cmd.h>
24628 +#include <linux/vserver/debug_cmd.h>
24629 +#include <linux/vserver/inode_cmd.h>
24630 +#include <linux/vserver/dlimit_cmd.h>
24631 +#include <linux/vserver/signal_cmd.h>
24632 +#include <linux/vserver/space_cmd.h>
24633 +
24634 +#include <linux/vserver/legacy.h>
24635 +#include <linux/vserver/inode.h>
24636 +#include <linux/vserver/dlimit.h>
24637 +
24638 +
24639 +#ifdef CONFIG_COMPAT
24640 +#define __COMPAT(name, id, data, compat)       \
24641 +       (compat) ? name ## _x32(id, data) : name(id, data)
24642 +#define __COMPAT_NO_ID(name, data, compat)     \
24643 +       (compat) ? name ## _x32(data) : name(data)
24644 +#else
24645 +#define __COMPAT(name, id, data, compat)       \
24646 +       name(id, data)
24647 +#define __COMPAT_NO_ID(name, data, compat)     \
24648 +       name(data)
24649 +#endif
24650 +
24651 +
24652 +static inline
24653 +long do_vcmd(uint32_t cmd, uint32_t id,
24654 +       struct vx_info *vxi, struct nx_info *nxi,
24655 +       void __user *data, int compat)
24656 +{
24657 +       switch (cmd) {
24658 +
24659 +       case VCMD_get_version:
24660 +               return vc_get_version(id);
24661 +       case VCMD_get_vci:
24662 +               return vc_get_vci(id);
24663 +
24664 +       case VCMD_task_xid:
24665 +               return vc_task_xid(id, data);
24666 +       case VCMD_vx_info:
24667 +               return vc_vx_info(vxi, data);
24668 +
24669 +       case VCMD_task_nid:
24670 +               return vc_task_nid(id, data);
24671 +       case VCMD_nx_info:
24672 +               return vc_nx_info(nxi, data);
24673 +
24674 +       case VCMD_set_space_v0:
24675 +       /* this is version 1 */
24676 +       case VCMD_set_space:
24677 +               return vc_set_space(vxi, data);
24678 +
24679 +       case VCMD_get_space_mask:
24680 +               return vc_get_space_mask(vxi, data);
24681 +
24682 +#ifdef CONFIG_IA32_EMULATION
24683 +       case VCMD_get_rlimit:
24684 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
24685 +       case VCMD_set_rlimit:
24686 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
24687 +#else
24688 +       case VCMD_get_rlimit:
24689 +               return vc_get_rlimit(vxi, data);
24690 +       case VCMD_set_rlimit:
24691 +               return vc_set_rlimit(vxi, data);
24692 +#endif
24693 +       case VCMD_get_rlimit_mask:
24694 +               return vc_get_rlimit_mask(id, data);
24695 +       case VCMD_reset_minmax:
24696 +               return vc_reset_minmax(vxi, data);
24697 +
24698 +       case VCMD_get_vhi_name:
24699 +               return vc_get_vhi_name(vxi, data);
24700 +       case VCMD_set_vhi_name:
24701 +               return vc_set_vhi_name(vxi, data);
24702 +
24703 +       case VCMD_ctx_stat:
24704 +               return vc_ctx_stat(vxi, data);
24705 +       case VCMD_virt_stat:
24706 +               return vc_virt_stat(vxi, data);
24707 +       case VCMD_sock_stat:
24708 +               return vc_sock_stat(vxi, data);
24709 +       case VCMD_rlimit_stat:
24710 +               return vc_rlimit_stat(vxi, data);
24711 +
24712 +       case VCMD_set_cflags:
24713 +               return vc_set_cflags(vxi, data);
24714 +       case VCMD_get_cflags:
24715 +               return vc_get_cflags(vxi, data);
24716 +
24717 +       case VCMD_set_ccaps_v0:
24718 +               return vc_set_ccaps_v0(vxi, data);
24719 +       /* this is version 1 */
24720 +       case VCMD_set_ccaps:
24721 +               return vc_set_ccaps(vxi, data);
24722 +       case VCMD_get_ccaps_v0:
24723 +               return vc_get_ccaps_v0(vxi, data);
24724 +       /* this is version 1 */
24725 +       case VCMD_get_ccaps:
24726 +               return vc_get_ccaps(vxi, data);
24727 +       case VCMD_set_bcaps:
24728 +               return vc_set_bcaps(vxi, data);
24729 +       case VCMD_get_bcaps:
24730 +               return vc_get_bcaps(vxi, data);
24731 +
24732 +       case VCMD_set_nflags:
24733 +               return vc_set_nflags(nxi, data);
24734 +       case VCMD_get_nflags:
24735 +               return vc_get_nflags(nxi, data);
24736 +
24737 +       case VCMD_set_ncaps:
24738 +               return vc_set_ncaps(nxi, data);
24739 +       case VCMD_get_ncaps:
24740 +               return vc_get_ncaps(nxi, data);
24741 +
24742 +#ifdef CONFIG_VSERVER_LEGACY
24743 +       case VCMD_set_sched_v2:
24744 +               return vc_set_sched_v2(vxi, data);
24745 +#endif
24746 +       case VCMD_set_sched_v3:
24747 +               return vc_set_sched_v3(vxi, data);
24748 +       case VCMD_set_sched_v4:
24749 +               return vc_set_sched_v4(vxi, data);
24750 +       /* this is version 5 */
24751 +       case VCMD_set_sched:
24752 +               return vc_set_sched(vxi, data);
24753 +       case VCMD_get_sched:
24754 +               return vc_get_sched(vxi, data);
24755 +       case VCMD_sched_info:
24756 +               return vc_sched_info(vxi, data);
24757 +
24758 +       case VCMD_add_dlimit:
24759 +               return __COMPAT(vc_add_dlimit, id, data, compat);
24760 +       case VCMD_rem_dlimit:
24761 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
24762 +       case VCMD_set_dlimit:
24763 +               return __COMPAT(vc_set_dlimit, id, data, compat);
24764 +       case VCMD_get_dlimit:
24765 +               return __COMPAT(vc_get_dlimit, id, data, compat);
24766 +
24767 +       case VCMD_ctx_kill:
24768 +               return vc_ctx_kill(vxi, data);
24769 +
24770 +       case VCMD_wait_exit:
24771 +               return vc_wait_exit(vxi, data);
24772 +
24773 +#ifdef CONFIG_VSERVER_LEGACY
24774 +       case VCMD_create_context:
24775 +               return vc_ctx_create(id, NULL);
24776 +#endif
24777 +
24778 +       case VCMD_get_iattr:
24779 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
24780 +       case VCMD_set_iattr:
24781 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
24782 +
24783 +       case VCMD_fget_iattr:
24784 +               return vc_fget_iattr(id, data);
24785 +       case VCMD_fset_iattr:
24786 +               return vc_fset_iattr(id, data);
24787 +
24788 +       case VCMD_enter_space_v0:
24789 +               return vc_enter_space(vxi, NULL);
24790 +       /* this is version 1 */
24791 +       case VCMD_enter_space:
24792 +               return vc_enter_space(vxi, data);
24793 +
24794 +       case VCMD_ctx_create_v0:
24795 +               return vc_ctx_create(id, NULL);
24796 +       case VCMD_ctx_create:
24797 +               return vc_ctx_create(id, data);
24798 +       case VCMD_ctx_migrate_v0:
24799 +               return vc_ctx_migrate(vxi, NULL);
24800 +       case VCMD_ctx_migrate:
24801 +               return vc_ctx_migrate(vxi, data);
24802 +
24803 +       case VCMD_net_create_v0:
24804 +               return vc_net_create(id, NULL);
24805 +       case VCMD_net_create:
24806 +               return vc_net_create(id, data);
24807 +       case VCMD_net_migrate:
24808 +               return vc_net_migrate(nxi, data);
24809 +       case VCMD_net_add:
24810 +               return vc_net_add(nxi, data);
24811 +       case VCMD_net_remove:
24812 +               return vc_net_remove(nxi, data);
24813 +
24814 +#ifdef CONFIG_VSERVER_HISTORY
24815 +       case VCMD_dump_history:
24816 +               return vc_dump_history(id);
24817 +       case VCMD_read_history:
24818 +               return __COMPAT(vc_read_history, id, data, compat);
24819 +#endif
24820 +#ifdef CONFIG_VSERVER_MONITOR
24821 +       case VCMD_read_monitor:
24822 +               return __COMPAT(vc_read_monitor, id, data, compat);
24823 +#endif
24824 +#ifdef CONFIG_VSERVER_LEGACY
24825 +       case VCMD_new_s_context:
24826 +               return vc_new_s_context(id, data);
24827 +#endif
24828 +#ifdef CONFIG_VSERVER_LEGACYNET
24829 +       case VCMD_set_ipv4root:
24830 +               return vc_set_ipv4root(id, data);
24831 +#endif
24832 +       default:
24833 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
24834 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
24835 +       }
24836 +       return -ENOSYS;
24837 +}
24838 +
24839 +
24840 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
24841 +       case VCMD_ ## vcmd: perm = _perm;               \
24842 +               args = _args; flags = _flags; break
24843 +
24844 +
24845 +#define VCA_NONE       0x00
24846 +#define VCA_VXI                0x01
24847 +#define VCA_NXI                0x02
24848 +
24849 +#define VCF_NONE       0x00
24850 +#define VCF_INFO       0x01
24851 +#define VCF_ADMIN      0x02
24852 +#define VCF_ARES       0x06    /* includes admin */
24853 +#define VCF_SETUP      0x08
24854 +
24855 +#define VCF_ZIDOK      0x10    /* zero id okay */
24856 +
24857 +
24858 +static inline
24859 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
24860 +{
24861 +       long ret;
24862 +       int permit = -1, state = 0;
24863 +       int perm = -1, args = 0, flags = 0;
24864 +       struct vx_info *vxi = NULL;
24865 +       struct nx_info *nxi = NULL;
24866 +
24867 +       switch (cmd) {
24868 +       /* unpriviledged commands */
24869 +       __VCMD(get_version,      0, VCA_NONE,   0);
24870 +       __VCMD(get_vci,          0, VCA_NONE,   0);
24871 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
24872 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
24873 +
24874 +       /* info commands */
24875 +       __VCMD(task_xid,         2, VCA_NONE,   0);
24876 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
24877 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
24878 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
24879 +       __VCMD(get_ccaps_v0,     3, VCA_VXI,    VCF_INFO);
24880 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
24881 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
24882 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
24883 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
24884 +
24885 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
24886 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
24887 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
24888 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
24889 +
24890 +       __VCMD(task_nid,         2, VCA_NONE,   0);
24891 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
24892 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
24893 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
24894 +
24895 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
24896 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
24897 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
24898 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
24899 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
24900 +
24901 +       /* lower admin commands */
24902 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
24903 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
24904 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
24905 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
24906 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
24907 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
24908 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
24909 +
24910 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
24911 +       __VCMD(net_create,       5, VCA_NONE,   0);
24912 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
24913 +
24914 +       /* higher admin commands */
24915 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
24916 +       __VCMD(set_space_v0,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24917 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24918 +
24919 +       __VCMD(set_ccaps_v0,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24920 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24921 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24922 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24923 +
24924 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24925 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24926 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24927 +       __VCMD(set_sched_v2,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24928 +       __VCMD(set_sched_v3,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24929 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24930 +
24931 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
24932 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
24933 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24934 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24935 +
24936 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
24937 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
24938 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
24939 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
24940 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
24941 +
24942 +       /* debug level admin commands */
24943 +#ifdef CONFIG_VSERVER_HISTORY
24944 +       __VCMD(dump_history,     9, VCA_NONE,   0);
24945 +       __VCMD(read_history,     9, VCA_NONE,   0);
24946 +#endif
24947 +#ifdef CONFIG_VSERVER_MONITOR
24948 +       __VCMD(read_monitor,     9, VCA_NONE,   0);
24949 +#endif
24950 +
24951 +       /* legacy commands */
24952 +#ifdef CONFIG_VSERVER_LEGACY
24953 +       __VCMD(new_s_context,    1, VCA_NONE,   0);
24954 +       __VCMD(create_context,   5, VCA_NONE,   0);
24955 +#endif
24956 +#ifdef CONFIG_VSERVER_LEGACYNET
24957 +       __VCMD(set_ipv4root,     5, VCA_NONE,   0);
24958 +#endif
24959 +       default:
24960 +               perm = -1;
24961 +       }
24962 +
24963 +       vxdprintk(VXD_CBIT(switch, 0),
24964 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
24965 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
24966 +               VC_VERSION(cmd), id, data, compat,
24967 +               perm, args, flags);
24968 +
24969 +       ret = -ENOSYS;
24970 +       if (perm < 0)
24971 +               goto out;
24972 +
24973 +       state = 1;
24974 +#ifdef CONFIG_VSERVER_LEGACY
24975 +       if (!capable(CAP_CONTEXT) &&
24976 +               /* dirty hack for capremove */
24977 +               !(cmd == VCMD_new_s_context && id == -2))
24978 +               goto out;
24979 +#else
24980 +       if (!capable(CAP_CONTEXT))
24981 +               goto out;
24982 +#endif
24983 +
24984 +       state = 2;
24985 +       /* moved here from the individual commands */
24986 +       ret = -EPERM;
24987 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
24988 +               goto out;
24989 +
24990 +       state = 3;
24991 +       /* vcmd involves resource management  */
24992 +       ret = -EPERM;
24993 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
24994 +               goto out;
24995 +
24996 +       state = 4;
24997 +       /* various legacy exceptions */
24998 +       switch (cmd) {
24999 +#ifdef CONFIG_VSERVER_LEGACY
25000 +       case VCMD_set_cflags:
25001 +       case VCMD_set_ccaps_v0:
25002 +               ret = 0;
25003 +               if (vx_check(0, VS_WATCH))
25004 +                       goto out;
25005 +               break;
25006 +
25007 +       case VCMD_ctx_create_v0:
25008 +#endif
25009 +       /* will go away when spectator is a cap */
25010 +       case VCMD_ctx_migrate_v0:
25011 +       case VCMD_ctx_migrate:
25012 +               if (id == 1) {
25013 +                       current->xid = 1;
25014 +                       ret = 1;
25015 +                       goto out;
25016 +               }
25017 +               break;
25018 +
25019 +       /* will go away when spectator is a cap */
25020 +       case VCMD_net_migrate:
25021 +               if (id == 1) {
25022 +                       current->nid = 1;
25023 +                       ret = 1;
25024 +                       goto out;
25025 +               }
25026 +               break;
25027 +
25028 +       /* legacy special casing */
25029 +       case VCMD_set_space_v0:
25030 +               id = -1;
25031 +               break;
25032 +       }
25033 +
25034 +       /* vcmds are fine by default */
25035 +       permit = 1;
25036 +
25037 +       /* admin type vcmds require admin ... */
25038 +       if (flags & VCF_ADMIN)
25039 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
25040 +
25041 +       /* ... but setup type vcmds override that */
25042 +       if (!permit && (flags & VCF_SETUP))
25043 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
25044 +
25045 +       state = 5;
25046 +       ret = -EPERM;
25047 +       if (!permit)
25048 +               goto out;
25049 +
25050 +       state = 6;
25051 +       if (!id && (flags & VCF_ZIDOK))
25052 +               goto skip_id;
25053 +
25054 +       ret = -ESRCH;
25055 +       if (args & VCA_VXI) {
25056 +               vxi = lookup_vx_info(id);
25057 +               if (!vxi)
25058 +                       goto out;
25059 +
25060 +               if ((flags & VCF_ADMIN) &&
25061 +                       /* special case kill for shutdown */
25062 +                       (cmd != VCMD_ctx_kill) &&
25063 +                       /* can context be administrated? */
25064 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
25065 +                       ret = -EACCES;
25066 +                       goto out_vxi;
25067 +               }
25068 +       }
25069 +       state = 7;
25070 +       if (args & VCA_NXI) {
25071 +               nxi = lookup_nx_info(id);
25072 +               if (!nxi)
25073 +                       goto out_vxi;
25074 +
25075 +               if ((flags & VCF_ADMIN) &&
25076 +                       /* can context be administrated? */
25077 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
25078 +                       ret = -EACCES;
25079 +                       goto out_nxi;
25080 +               }
25081 +       }
25082 +skip_id:
25083 +       state = 8;
25084 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
25085 +
25086 +out_nxi:
25087 +       if ((args & VCA_NXI) && nxi)
25088 +               put_nx_info(nxi);
25089 +out_vxi:
25090 +       if ((args & VCA_VXI) && vxi)
25091 +               put_vx_info(vxi);
25092 +out:
25093 +       vxdprintk(VXD_CBIT(switch, 1),
25094 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
25095 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25096 +               VC_VERSION(cmd), ret, ret, state, permit);
25097 +       return ret;
25098 +}
25099 +
25100 +asmlinkage long
25101 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
25102 +{
25103 +       return do_vserver(cmd, id, data, 0);
25104 +}
25105 +
25106 +#ifdef CONFIG_COMPAT
25107 +
25108 +asmlinkage long
25109 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
25110 +{
25111 +       return do_vserver(cmd, id, data, 1);
25112 +}
25113 +
25114 +#endif /* CONFIG_COMPAT */
25115 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/sysctl.c linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/sysctl.c
25116 --- linux-2.6.24-rc7/kernel/vserver/sysctl.c    1970-01-01 01:00:00 +0100
25117 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/sysctl.c      2007-12-15 02:33:48 +0100
25118 @@ -0,0 +1,249 @@
25119 +/*
25120 + *  kernel/vserver/sysctl.c
25121 + *
25122 + *  Virtual Context Support
25123 + *
25124 + *  Copyright (C) 2004-2007  Herbert Pötzl
25125 + *
25126 + *  V0.01  basic structure
25127 + *
25128 + */
25129 +
25130 +#include <linux/errno.h>
25131 +#include <linux/module.h>
25132 +#include <linux/types.h>
25133 +#include <linux/ctype.h>
25134 +#include <linux/sysctl.h>
25135 +#include <linux/parser.h>
25136 +#include <linux/fs.h>
25137 +
25138 +#include <asm/uaccess.h>
25139 +#include <asm/unistd.h>
25140 +
25141 +
25142 +enum {
25143 +       CTL_DEBUG_ERROR         = 0,
25144 +       CTL_DEBUG_SWITCH        = 1,
25145 +       CTL_DEBUG_XID,
25146 +       CTL_DEBUG_NID,
25147 +       CTL_DEBUG_TAG,
25148 +       CTL_DEBUG_NET,
25149 +       CTL_DEBUG_LIMIT,
25150 +       CTL_DEBUG_CRES,
25151 +       CTL_DEBUG_DLIM,
25152 +       CTL_DEBUG_QUOTA,
25153 +       CTL_DEBUG_CVIRT,
25154 +       CTL_DEBUG_SPACE,
25155 +       CTL_DEBUG_MISC,
25156 +};
25157 +
25158 +
25159 +unsigned int vx_debug_switch   = 0;
25160 +unsigned int vx_debug_xid      = 0;
25161 +unsigned int vx_debug_nid      = 0;
25162 +unsigned int vx_debug_tag      = 0;
25163 +unsigned int vx_debug_net      = 0;
25164 +unsigned int vx_debug_limit    = 0;
25165 +unsigned int vx_debug_cres     = 0;
25166 +unsigned int vx_debug_dlim     = 0;
25167 +unsigned int vx_debug_quota    = 0;
25168 +unsigned int vx_debug_cvirt    = 0;
25169 +unsigned int vx_debug_space    = 0;
25170 +unsigned int vx_debug_misc     = 0;
25171 +
25172 +
25173 +static struct ctl_table_header *vserver_table_header;
25174 +static ctl_table vserver_root_table[];
25175 +
25176 +
25177 +void vserver_register_sysctl(void)
25178 +{
25179 +       if (!vserver_table_header) {
25180 +               vserver_table_header = register_sysctl_table(vserver_root_table);
25181 +       }
25182 +
25183 +}
25184 +
25185 +void vserver_unregister_sysctl(void)
25186 +{
25187 +       if (vserver_table_header) {
25188 +               unregister_sysctl_table(vserver_table_header);
25189 +               vserver_table_header = NULL;
25190 +       }
25191 +}
25192 +
25193 +
25194 +static int proc_dodebug(ctl_table *table, int write,
25195 +       struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
25196 +{
25197 +       char            tmpbuf[20], *p, c;
25198 +       unsigned int    value;
25199 +       size_t          left, len;
25200 +
25201 +       if ((*ppos && !write) || !*lenp) {
25202 +               *lenp = 0;
25203 +               return 0;
25204 +       }
25205 +
25206 +       left = *lenp;
25207 +
25208 +       if (write) {
25209 +               if (!access_ok(VERIFY_READ, buffer, left))
25210 +                       return -EFAULT;
25211 +               p = (char *)buffer;
25212 +               while (left && __get_user(c, p) >= 0 && isspace(c))
25213 +                       left--, p++;
25214 +               if (!left)
25215 +                       goto done;
25216 +
25217 +               if (left > sizeof(tmpbuf) - 1)
25218 +                       return -EINVAL;
25219 +               if (copy_from_user(tmpbuf, p, left))
25220 +                       return -EFAULT;
25221 +               tmpbuf[left] = '\0';
25222 +
25223 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
25224 +                       value = 10 * value + (*p - '0');
25225 +               if (*p && !isspace(*p))
25226 +                       return -EINVAL;
25227 +               while (left && isspace(*p))
25228 +                       left--, p++;
25229 +               *(unsigned int *)table->data = value;
25230 +       } else {
25231 +               if (!access_ok(VERIFY_WRITE, buffer, left))
25232 +                       return -EFAULT;
25233 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
25234 +               if (len > left)
25235 +                       len = left;
25236 +               if (__copy_to_user(buffer, tmpbuf, len))
25237 +                       return -EFAULT;
25238 +               if ((left -= len) > 0) {
25239 +                       if (put_user('\n', (char *)buffer + len))
25240 +                               return -EFAULT;
25241 +                       left--;
25242 +               }
25243 +       }
25244 +
25245 +done:
25246 +       *lenp -= left;
25247 +       *ppos += *lenp;
25248 +       return 0;
25249 +}
25250 +
25251 +static int zero;
25252 +
25253 +#define        CTL_ENTRY(ctl, name)                            \
25254 +       {                                               \
25255 +               .ctl_name       = ctl,                  \
25256 +               .procname       = #name,                \
25257 +               .data           = &vx_ ## name,         \
25258 +               .maxlen         = sizeof(int),          \
25259 +               .mode           = 0644,                 \
25260 +               .proc_handler   = &proc_dodebug,        \
25261 +               .strategy       = &sysctl_intvec,       \
25262 +               .extra1         = &zero,                \
25263 +       }
25264 +
25265 +static ctl_table vserver_debug_table[] = {
25266 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
25267 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
25268 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
25269 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
25270 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
25271 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
25272 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
25273 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
25274 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
25275 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
25276 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
25277 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
25278 +       { .ctl_name = 0 }
25279 +};
25280 +
25281 +static ctl_table vserver_root_table[] = {
25282 +       {
25283 +               .ctl_name       = CTL_VSERVER,
25284 +               .procname       = "vserver",
25285 +               .mode           = 0555,
25286 +               .child          = vserver_debug_table
25287 +       },
25288 +       { .ctl_name = 0 }
25289 +};
25290 +
25291 +
25292 +static match_table_t tokens = {
25293 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
25294 +       { CTL_DEBUG_XID,        "xid=%x"        },
25295 +       { CTL_DEBUG_NID,        "nid=%x"        },
25296 +       { CTL_DEBUG_TAG,        "tag=%x"        },
25297 +       { CTL_DEBUG_NET,        "net=%x"        },
25298 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
25299 +       { CTL_DEBUG_CRES,       "cres=%x"       },
25300 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
25301 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
25302 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
25303 +       { CTL_DEBUG_SPACE,      "space=%x"      },
25304 +       { CTL_DEBUG_MISC,       "misc=%x"       },
25305 +       { CTL_DEBUG_ERROR,      NULL            }
25306 +};
25307 +
25308 +#define        HANDLE_CASE(id, name, val)                              \
25309 +       case CTL_DEBUG_ ## id:                                  \
25310 +               vx_debug_ ## name = val;                        \
25311 +               printk("vs_debug_" #name "=0x%x\n", val);       \
25312 +               break
25313 +
25314 +
25315 +static int __init vs_debug_setup(char *str)
25316 +{
25317 +       char *p;
25318 +       int token;
25319 +
25320 +       printk("vs_debug_setup(%s)\n", str);
25321 +       while ((p = strsep(&str, ",")) != NULL) {
25322 +               substring_t args[MAX_OPT_ARGS];
25323 +               unsigned int value;
25324 +
25325 +               if (!*p)
25326 +                       continue;
25327 +
25328 +               token = match_token(p, tokens, args);
25329 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
25330 +
25331 +               switch (token) {
25332 +               HANDLE_CASE(SWITCH, switch, value);
25333 +               HANDLE_CASE(XID,    xid,    value);
25334 +               HANDLE_CASE(NID,    nid,    value);
25335 +               HANDLE_CASE(TAG,    tag,    value);
25336 +               HANDLE_CASE(NET,    net,    value);
25337 +               HANDLE_CASE(LIMIT,  limit,  value);
25338 +               HANDLE_CASE(CRES,   cres,   value);
25339 +               HANDLE_CASE(DLIM,   dlim,   value);
25340 +               HANDLE_CASE(QUOTA,  quota,  value);
25341 +               HANDLE_CASE(CVIRT,  cvirt,  value);
25342 +               HANDLE_CASE(SPACE,  space,  value);
25343 +               HANDLE_CASE(MISC,   misc,   value);
25344 +               default:
25345 +                       return -EINVAL;
25346 +                       break;
25347 +               }
25348 +       }
25349 +       return 1;
25350 +}
25351 +
25352 +__setup("vsdebug=", vs_debug_setup);
25353 +
25354 +
25355 +
25356 +EXPORT_SYMBOL_GPL(vx_debug_switch);
25357 +EXPORT_SYMBOL_GPL(vx_debug_xid);
25358 +EXPORT_SYMBOL_GPL(vx_debug_nid);
25359 +EXPORT_SYMBOL_GPL(vx_debug_net);
25360 +EXPORT_SYMBOL_GPL(vx_debug_limit);
25361 +EXPORT_SYMBOL_GPL(vx_debug_cres);
25362 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
25363 +EXPORT_SYMBOL_GPL(vx_debug_quota);
25364 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
25365 +EXPORT_SYMBOL_GPL(vx_debug_space);
25366 +EXPORT_SYMBOL_GPL(vx_debug_misc);
25367 +
25368 diff -NurpP --minimal linux-2.6.24-rc7/kernel/vserver/vci_config.h linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/vci_config.h
25369 --- linux-2.6.24-rc7/kernel/vserver/vci_config.h        1970-01-01 01:00:00 +0100
25370 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/kernel/vserver/vci_config.h  2007-12-13 13:25:26 +0100
25371 @@ -0,0 +1,92 @@
25372 +
25373 +/*  interface version */
25374 +
25375 +#define VCI_VERSION            0x00020200
25376 +#define VCI_LEGACY_VERSION     0x000100FF
25377 +
25378 +
25379 +enum {
25380 +       VCI_KCBIT_NO_DYNAMIC = 0,
25381 +       VCI_KCBIT_LEGACY = 1,
25382 +       VCI_KCBIT_LEGACYNET = 2,
25383 +       VCI_KCBIT_NGNET = 3,
25384 +
25385 +       VCI_KCBIT_PROC_SECURE = 4,
25386 +       VCI_KCBIT_HARDCPU = 5,
25387 +       VCI_KCBIT_IDLELIMIT = 6,
25388 +       VCI_KCBIT_IDLETIME = 7,
25389 +
25390 +       VCI_KCBIT_COWBL = 8,
25391 +       VCI_KCBIT_FULLCOWBL = 9,
25392 +       VCI_KCBIT_SPACES = 10,
25393 +
25394 +       VCI_KCBIT_LEGACY_VERSION = 15,
25395 +       VCI_KCBIT_DEBUG = 16,
25396 +       VCI_KCBIT_HISTORY = 20,
25397 +       VCI_KCBIT_TAGGED = 24,
25398 +};
25399 +
25400 +
25401 +static inline uint32_t vci_kernel_config(void)
25402 +{
25403 +       return
25404 +       /* various legacy options */
25405 +#ifndef CONFIG_VSERVER_DYNAMIC_IDS
25406 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
25407 +#endif
25408 +#ifdef CONFIG_VSERVER_LEGACY
25409 +       (1 << VCI_KCBIT_LEGACY) |
25410 +#endif
25411 +#ifdef CONFIG_VSERVER_LEGACYNET
25412 +       (1 << VCI_KCBIT_LEGACYNET) |
25413 +#endif
25414 +#ifdef CONFIG_VSERVER_LEGACY_VERSION
25415 +       (1 << VCI_KCBIT_LEGACY_VERSION) |
25416 +#endif
25417 +
25418 +       /* configured features */
25419 +#ifdef CONFIG_VSERVER_PROC_SECURE
25420 +       (1 << VCI_KCBIT_PROC_SECURE) |
25421 +#endif
25422 +#ifdef CONFIG_VSERVER_HARDCPU
25423 +       (1 << VCI_KCBIT_HARDCPU) |
25424 +#endif
25425 +#ifdef CONFIG_VSERVER_IDLELIMIT
25426 +       (1 << VCI_KCBIT_IDLELIMIT) |
25427 +#endif
25428 +#ifdef CONFIG_VSERVER_IDLETIME
25429 +       (1 << VCI_KCBIT_IDLETIME) |
25430 +#endif
25431 +#ifdef CONFIG_VSERVER_COWBL
25432 +       (1 << VCI_KCBIT_COWBL) |
25433 +       (1 << VCI_KCBIT_FULLCOWBL) |
25434 +#endif
25435 +       (1 << VCI_KCBIT_SPACES) |
25436 +
25437 +       /* debug options */
25438 +#ifdef CONFIG_VSERVER_DEBUG
25439 +       (1 << VCI_KCBIT_DEBUG) |
25440 +#endif
25441 +#ifdef CONFIG_VSERVER_HISTORY
25442 +       (1 << VCI_KCBIT_HISTORY) |
25443 +#endif
25444 +
25445 +       /* inode context tagging */
25446 +#if    defined(CONFIG_TAGGING_NONE)
25447 +       (0 << VCI_KCBIT_TAGGED) |
25448 +#elif  defined(CONFIG_TAGGING_UID16)
25449 +       (1 << VCI_KCBIT_TAGGED) |
25450 +#elif  defined(CONFIG_TAGGING_GID16)
25451 +       (2 << VCI_KCBIT_TAGGED) |
25452 +#elif  defined(CONFIG_TAGGING_ID24)
25453 +       (3 << VCI_KCBIT_TAGGED) |
25454 +#elif  defined(CONFIG_TAGGING_INTERN)
25455 +       (4 << VCI_KCBIT_TAGGED) |
25456 +#elif  defined(CONFIG_TAGGING_RUNTIME)
25457 +       (5 << VCI_KCBIT_TAGGED) |
25458 +#else
25459 +       (7 << VCI_KCBIT_TAGGED) |
25460 +#endif
25461 +       0;
25462 +}
25463 +
25464 diff -NurpP --minimal linux-2.6.24-rc7/mm/filemap_xip.c linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/filemap_xip.c
25465 --- linux-2.6.24-rc7/mm/filemap_xip.c   2007-12-31 17:58:29 +0100
25466 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/filemap_xip.c     2007-12-31 12:34:44 +0100
25467 @@ -14,6 +14,7 @@
25468  #include <linux/uio.h>
25469  #include <linux/rmap.h>
25470  #include <linux/sched.h>
25471 +#include <linux/vs_memory.h>
25472  #include <asm/tlbflush.h>
25473  
25474  /*
25475 diff -NurpP --minimal linux-2.6.24-rc7/mm/fremap.c linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/fremap.c
25476 --- linux-2.6.24-rc7/mm/fremap.c        2007-11-29 01:12:32 +0100
25477 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/fremap.c  2007-12-13 13:25:12 +0100
25478 @@ -15,6 +15,7 @@
25479  #include <linux/rmap.h>
25480  #include <linux/module.h>
25481  #include <linux/syscalls.h>
25482 +#include <linux/vs_memory.h>
25483  
25484  #include <asm/mmu_context.h>
25485  #include <asm/cacheflush.h>
25486 diff -NurpP --minimal linux-2.6.24-rc7/mm/hugetlb.c linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/hugetlb.c
25487 --- linux-2.6.24-rc7/mm/hugetlb.c       2007-12-31 17:58:29 +0100
25488 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/hugetlb.c 2007-12-31 12:34:44 +0100
25489 @@ -19,6 +19,7 @@
25490  #include <asm/pgtable.h>
25491  
25492  #include <linux/hugetlb.h>
25493 +#include <linux/vs_memory.h>
25494  #include "internal.h"
25495  
25496  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
25497 diff -NurpP --minimal linux-2.6.24-rc7/mm/memory.c linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/memory.c
25498 --- linux-2.6.24-rc7/mm/memory.c        2007-11-29 01:12:32 +0100
25499 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/memory.c  2008-01-07 03:04:39 +0100
25500 @@ -493,6 +493,9 @@ static int copy_pte_range(struct mm_stru
25501         int progress = 0;
25502         int rss[2];
25503  
25504 +       if (!vx_rss_avail(dst_mm, ((end - addr)/PAGE_SIZE + 1)))
25505 +               return -ENOMEM;
25506 +
25507  again:
25508         rss[1] = rss[0] = 0;
25509         dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
25510 @@ -2084,6 +2087,11 @@ static int do_swap_page(struct mm_struct
25511                 count_vm_event(PGMAJFAULT);
25512         }
25513  
25514 +       if (!vx_rss_avail(mm, 1)) {
25515 +               ret = VM_FAULT_OOM;
25516 +               goto out;
25517 +       }
25518 +
25519         mark_page_accessed(page);
25520         lock_page(page);
25521         delayacct_clear_flag(DELAYACCT_PF_SWAPIN);
25522 @@ -2155,6 +2163,8 @@ static int do_anonymous_page(struct mm_s
25523         /* Allocate our own private page. */
25524         pte_unmap(page_table);
25525  
25526 +       if (!vx_rss_avail(mm, 1))
25527 +               goto oom;
25528         if (unlikely(anon_vma_prepare(vma)))
25529                 goto oom;
25530         page = alloc_zeroed_user_highpage_movable(vma, address);
25531 @@ -2462,6 +2472,7 @@ static inline int handle_pte_fault(struc
25532  {
25533         pte_t entry;
25534         spinlock_t *ptl;
25535 +       int ret = 0, type = VXPT_UNKNOWN;
25536  
25537         entry = *pte;
25538         if (!pte_present(entry)) {
25539 @@ -2489,9 +2500,12 @@ static inline int handle_pte_fault(struc
25540         if (unlikely(!pte_same(*pte, entry)))
25541                 goto unlock;
25542         if (write_access) {
25543 -               if (!pte_write(entry))
25544 -                       return do_wp_page(mm, vma, address,
25545 +               if (!pte_write(entry)) {
25546 +                       ret = do_wp_page(mm, vma, address,
25547                                         pte, pmd, ptl, entry);
25548 +                       type = VXPT_WRITE;
25549 +                       goto out;
25550 +               }
25551                 entry = pte_mkdirty(entry);
25552         }
25553         entry = pte_mkyoung(entry);
25554 @@ -2509,7 +2523,10 @@ static inline int handle_pte_fault(struc
25555         }
25556  unlock:
25557         pte_unmap_unlock(pte, ptl);
25558 -       return 0;
25559 +       ret = 0;
25560 +out:
25561 +       vx_page_fault(mm, vma, type, ret);
25562 +       return ret;
25563  }
25564  
25565  /*
25566 diff -NurpP --minimal linux-2.6.24-rc7/mm/mlock.c linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/mlock.c
25567 --- linux-2.6.24-rc7/mm/mlock.c 2007-11-29 01:02:27 +0100
25568 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/mlock.c   2007-12-13 13:25:41 +0100
25569 @@ -12,6 +12,7 @@
25570  #include <linux/syscalls.h>
25571  #include <linux/sched.h>
25572  #include <linux/module.h>
25573 +#include <linux/vs_memory.h>
25574  
25575  int can_do_mlock(void)
25576  {
25577 @@ -76,7 +77,7 @@ success:
25578                         ret = make_pages_present(start, end);
25579         }
25580  
25581 -       mm->locked_vm -= pages;
25582 +       vx_vmlocked_sub(mm, pages);
25583  out:
25584         if (ret == -ENOMEM)
25585                 ret = -EAGAIN;
25586 @@ -134,7 +135,7 @@ static int do_mlock(unsigned long start,
25587  
25588  asmlinkage long sys_mlock(unsigned long start, size_t len)
25589  {
25590 -       unsigned long locked;
25591 +       unsigned long locked, grow;
25592         unsigned long lock_limit;
25593         int error = -ENOMEM;
25594  
25595 @@ -145,8 +146,10 @@ asmlinkage long sys_mlock(unsigned long 
25596         len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
25597         start &= PAGE_MASK;
25598  
25599 -       locked = len >> PAGE_SHIFT;
25600 -       locked += current->mm->locked_vm;
25601 +       grow = len >> PAGE_SHIFT;
25602 +       if (!vx_vmlocked_avail(current->mm, grow))
25603 +               goto out;
25604 +       locked = current->mm->locked_vm + grow;
25605  
25606         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
25607         lock_limit >>= PAGE_SHIFT;
25608 @@ -154,6 +157,7 @@ asmlinkage long sys_mlock(unsigned long 
25609         /* check against resource limits */
25610         if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
25611                 error = do_mlock(start, len, 1);
25612 +out:
25613         up_write(&current->mm->mmap_sem);
25614         return error;
25615  }
25616 @@ -213,6 +217,8 @@ asmlinkage long sys_mlockall(int flags)
25617         lock_limit >>= PAGE_SHIFT;
25618  
25619         ret = -ENOMEM;
25620 +       if (!vx_vmlocked_avail(current->mm, current->mm->total_vm))
25621 +               goto out;
25622         if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
25623             capable(CAP_IPC_LOCK))
25624                 ret = do_mlockall(flags);
25625 diff -NurpP --minimal linux-2.6.24-rc7/mm/mmap.c linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/mmap.c
25626 --- linux-2.6.24-rc7/mm/mmap.c  2007-12-31 17:58:29 +0100
25627 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/mmap.c    2007-12-31 12:34:44 +0100
25628 @@ -1192,10 +1192,10 @@ munmap_back:
25629                 kmem_cache_free(vm_area_cachep, vma);
25630         }
25631  out:   
25632 -       mm->total_vm += len >> PAGE_SHIFT;
25633 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
25634         vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
25635         if (vm_flags & VM_LOCKED) {
25636 -               mm->locked_vm += len >> PAGE_SHIFT;
25637 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
25638                 make_pages_present(addr, addr + len);
25639         }
25640         if ((flags & MAP_POPULATE) && !(flags & MAP_NONBLOCK))
25641 @@ -1544,9 +1544,9 @@ static int acct_stack_growth(struct vm_a
25642                 return -ENOMEM;
25643  
25644         /* Ok, everything looks good - let it rip */
25645 -       mm->total_vm += grow;
25646 +       vx_vmpages_add(mm, grow);
25647         if (vma->vm_flags & VM_LOCKED)
25648 -               mm->locked_vm += grow;
25649 +               vx_vmlocked_add(mm, grow);
25650         vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
25651         return 0;
25652  }
25653 @@ -1717,9 +1717,9 @@ static void remove_vma_list(struct mm_st
25654         do {
25655                 long nrpages = vma_pages(vma);
25656  
25657 -               mm->total_vm -= nrpages;
25658 +               vx_vmpages_sub(mm, nrpages);
25659                 if (vma->vm_flags & VM_LOCKED)
25660 -                       mm->locked_vm -= nrpages;
25661 +                       vx_vmlocked_sub(mm, nrpages);
25662                 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
25663                 vma = remove_vma(vma);
25664         } while (vma);
25665 @@ -1962,6 +1962,8 @@ unsigned long do_brk(unsigned long addr,
25666                 lock_limit >>= PAGE_SHIFT;
25667                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
25668                         return -EAGAIN;
25669 +               if (!vx_vmlocked_avail(mm, len >> PAGE_SHIFT))
25670 +                       return -ENOMEM;
25671         }
25672  
25673         /*
25674 @@ -1988,7 +1990,8 @@ unsigned long do_brk(unsigned long addr,
25675         if (mm->map_count > sysctl_max_map_count)
25676                 return -ENOMEM;
25677  
25678 -       if (security_vm_enough_memory(len >> PAGE_SHIFT))
25679 +       if (security_vm_enough_memory(len >> PAGE_SHIFT) ||
25680 +               !vx_vmpages_avail(mm, len >> PAGE_SHIFT))
25681                 return -ENOMEM;
25682  
25683         /* Can we just expand an old private anonymous mapping? */
25684 @@ -2013,9 +2016,9 @@ unsigned long do_brk(unsigned long addr,
25685         vma->vm_page_prot = vm_get_page_prot(flags);
25686         vma_link(mm, vma, prev, rb_link, rb_parent);
25687  out:
25688 -       mm->total_vm += len >> PAGE_SHIFT;
25689 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
25690         if (flags & VM_LOCKED) {
25691 -               mm->locked_vm += len >> PAGE_SHIFT;
25692 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
25693                 make_pages_present(addr, addr + len);
25694         }
25695         return addr;
25696 @@ -2044,6 +2047,11 @@ void exit_mmap(struct mm_struct *mm)
25697         free_pgtables(&tlb, vma, FIRST_USER_ADDRESS, 0);
25698         tlb_finish_mmu(tlb, 0, end);
25699  
25700 +       set_mm_counter(mm, file_rss, 0);
25701 +       set_mm_counter(mm, anon_rss, 0);
25702 +       vx_vmpages_sub(mm, mm->total_vm);
25703 +       vx_vmlocked_sub(mm, mm->locked_vm);
25704 +
25705         /*
25706          * Walk the list again, actually closing and freeing it,
25707          * with preemption enabled, without holding any MM locks.
25708 @@ -2083,7 +2091,8 @@ int insert_vm_struct(struct mm_struct * 
25709         if (__vma && __vma->vm_start < vma->vm_end)
25710                 return -ENOMEM;
25711         if ((vma->vm_flags & VM_ACCOUNT) &&
25712 -            security_vm_enough_memory_mm(mm, vma_pages(vma)))
25713 +               (security_vm_enough_memory_mm(mm, vma_pages(vma)) ||
25714 +               !vx_vmpages_avail(mm, vma_pages(vma))))
25715                 return -ENOMEM;
25716         vma_link(mm, vma, prev, rb_link, rb_parent);
25717         return 0;
25718 @@ -2156,6 +2165,8 @@ int may_expand_vm(struct mm_struct *mm, 
25719  
25720         if (cur + npages > lim)
25721                 return 0;
25722 +       if (!vx_vmpages_avail(mm, npages))
25723 +               return 0;
25724         return 1;
25725  }
25726  
25727 @@ -2226,7 +2237,6 @@ int install_special_mapping(struct mm_st
25728                 return -ENOMEM;
25729         }
25730  
25731 -       mm->total_vm += len >> PAGE_SHIFT;
25732 -
25733 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
25734         return 0;
25735  }
25736 diff -NurpP --minimal linux-2.6.24-rc7/mm/mremap.c linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/mremap.c
25737 --- linux-2.6.24-rc7/mm/mremap.c        2007-11-29 01:12:32 +0100
25738 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/mremap.c  2007-12-13 13:25:41 +0100
25739 @@ -18,6 +18,7 @@
25740  #include <linux/highmem.h>
25741  #include <linux/security.h>
25742  #include <linux/syscalls.h>
25743 +#include <linux/vs_memory.h>
25744  
25745  #include <asm/uaccess.h>
25746  #include <asm/cacheflush.h>
25747 @@ -212,7 +213,7 @@ static unsigned long move_vma(struct vm_
25748          * If this were a serious issue, we'd add a flag to do_munmap().
25749          */
25750         hiwater_vm = mm->hiwater_vm;
25751 -       mm->total_vm += new_len >> PAGE_SHIFT;
25752 +       vx_vmpages_add(mm, new_len >> PAGE_SHIFT);
25753         vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
25754  
25755         if (do_munmap(mm, old_addr, old_len) < 0) {
25756 @@ -230,7 +231,7 @@ static unsigned long move_vma(struct vm_
25757         }
25758  
25759         if (vm_flags & VM_LOCKED) {
25760 -               mm->locked_vm += new_len >> PAGE_SHIFT;
25761 +               vx_vmlocked_add(mm, new_len >> PAGE_SHIFT);
25762                 if (new_len > old_len)
25763                         make_pages_present(new_addr + old_len,
25764                                            new_addr + new_len);
25765 @@ -341,6 +342,9 @@ unsigned long do_mremap(unsigned long ad
25766                 ret = -EAGAIN;
25767                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
25768                         goto out;
25769 +               if (!vx_vmlocked_avail(current->mm,
25770 +                       (new_len - old_len) >> PAGE_SHIFT))
25771 +                       goto out;
25772         }
25773         if (!may_expand_vm(mm, (new_len - old_len) >> PAGE_SHIFT)) {
25774                 ret = -ENOMEM;
25775 @@ -369,10 +373,10 @@ unsigned long do_mremap(unsigned long ad
25776                         vma_adjust(vma, vma->vm_start,
25777                                 addr + new_len, vma->vm_pgoff, NULL);
25778  
25779 -                       mm->total_vm += pages;
25780 +                       vx_vmpages_add(mm, pages);
25781                         vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages);
25782                         if (vma->vm_flags & VM_LOCKED) {
25783 -                               mm->locked_vm += pages;
25784 +                               vx_vmlocked_add(mm, pages);
25785                                 make_pages_present(addr + old_len,
25786                                                    addr + new_len);
25787                         }
25788 diff -NurpP --minimal linux-2.6.24-rc7/mm/nommu.c linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/nommu.c
25789 --- linux-2.6.24-rc7/mm/nommu.c 2007-12-31 17:58:29 +0100
25790 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/nommu.c   2007-12-31 12:34:44 +0100
25791 @@ -963,7 +963,7 @@ unsigned long do_mmap_pgoff(struct file 
25792         realalloc += kobjsize(vma);
25793         askedalloc += sizeof(*vma);
25794  
25795 -       current->mm->total_vm += len >> PAGE_SHIFT;
25796 +       vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
25797  
25798         add_nommu_vma(vma);
25799  
25800 @@ -1089,7 +1089,7 @@ int do_munmap(struct mm_struct *mm, unsi
25801         kfree(vml);
25802  
25803         update_hiwater_vm(mm);
25804 -       mm->total_vm -= len >> PAGE_SHIFT;
25805 +       vx_vmpages_sub(mm, len >> PAGE_SHIFT);
25806  
25807  #ifdef DEBUG
25808         show_process_blocks();
25809 @@ -1122,7 +1122,7 @@ void exit_mmap(struct mm_struct * mm)
25810                 printk("Exit_mmap:\n");
25811  #endif
25812  
25813 -               mm->total_vm = 0;
25814 +               vx_vmpages_sub(mm, mm->total_vm);
25815  
25816                 while ((tmp = mm->context.vmlist)) {
25817                         mm->context.vmlist = tmp->next;
25818 diff -NurpP --minimal linux-2.6.24-rc7/mm/oom_kill.c linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/oom_kill.c
25819 --- linux-2.6.24-rc7/mm/oom_kill.c      2007-11-29 01:12:32 +0100
25820 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/oom_kill.c        2007-12-13 13:25:41 +0100
25821 @@ -25,6 +25,7 @@
25822  #include <linux/cpuset.h>
25823  #include <linux/module.h>
25824  #include <linux/notifier.h>
25825 +#include <linux/vs_memory.h>
25826  
25827  int sysctl_panic_on_oom;
25828  int sysctl_oom_kill_allocating_task;
25829 @@ -69,6 +70,12 @@ unsigned long badness(struct task_struct
25830         points = mm->total_vm;
25831  
25832         /*
25833 +        * add points for context badness
25834 +        */
25835 +
25836 +       points += vx_badness(p, mm);
25837 +
25838 +       /*
25839          * After this unlock we can no longer dereference local variable `mm'
25840          */
25841         task_unlock(p);
25842 @@ -159,8 +166,8 @@ unsigned long badness(struct task_struct
25843         }
25844  
25845  #ifdef DEBUG
25846 -       printk(KERN_DEBUG "OOMkill: task %d (%s) got %lu points\n",
25847 -       p->pid, p->comm, points);
25848 +       printk(KERN_DEBUG "OOMkill: task %d:#%u (%s) got %d points\n",
25849 +               task_pid_nr(p), p->xid, p->comm, points);
25850  #endif
25851         return points;
25852  }
25853 @@ -278,8 +285,8 @@ static void __oom_kill_task(struct task_
25854         }
25855  
25856         if (verbose)
25857 -               printk(KERN_ERR "Killed process %d (%s)\n",
25858 -                               task_pid_nr(p), p->comm);
25859 +               printk(KERN_ERR "Killed process %d:#%u (%s)\n",
25860 +                               task_pid_nr(p), p->xid, p->comm);
25861  
25862         /*
25863          * We give our sacrificial lamb high priority and access to
25864 @@ -356,8 +363,8 @@ static int oom_kill_process(struct task_
25865                 return 0;
25866         }
25867  
25868 -       printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n",
25869 -                                       message, task_pid_nr(p), p->comm, points);
25870 +       printk(KERN_ERR "%s: kill process %d:#%u (%s) score %li or a child\n",
25871 +                               message, task_pid_nr(p), p->xid, p->comm, points);
25872  
25873         /* Try to kill a child first */
25874         list_for_each_entry(c, &p->children, sibling) {
25875 diff -NurpP --minimal linux-2.6.24-rc7/mm/page_alloc.c linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/page_alloc.c
25876 --- linux-2.6.24-rc7/mm/page_alloc.c    2007-12-31 17:58:29 +0100
25877 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/page_alloc.c      2007-12-31 12:34:44 +0100
25878 @@ -43,6 +43,8 @@
25879  #include <linux/backing-dev.h>
25880  #include <linux/fault-inject.h>
25881  #include <linux/page-isolation.h>
25882 +#include <linux/vs_base.h>
25883 +#include <linux/vs_limit.h>
25884  
25885  #include <asm/tlbflush.h>
25886  #include <asm/div64.h>
25887 @@ -1754,6 +1756,9 @@ void si_meminfo(struct sysinfo *val)
25888         val->totalhigh = totalhigh_pages;
25889         val->freehigh = nr_free_highpages();
25890         val->mem_unit = PAGE_SIZE;
25891 +
25892 +       if (vx_flags(VXF_VIRT_MEM, 0))
25893 +               vx_vsi_meminfo(val);
25894  }
25895  
25896  EXPORT_SYMBOL(si_meminfo);
25897 @@ -1774,6 +1779,9 @@ void si_meminfo_node(struct sysinfo *val
25898         val->freehigh = 0;
25899  #endif
25900         val->mem_unit = PAGE_SIZE;
25901 +
25902 +       if (vx_flags(VXF_VIRT_MEM, 0))
25903 +               vx_vsi_meminfo(val);
25904  }
25905  #endif
25906  
25907 diff -NurpP --minimal linux-2.6.24-rc7/mm/rmap.c linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/rmap.c
25908 --- linux-2.6.24-rc7/mm/rmap.c  2007-12-31 17:58:29 +0100
25909 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/rmap.c    2007-12-31 12:34:44 +0100
25910 @@ -49,6 +49,7 @@
25911  #include <linux/rcupdate.h>
25912  #include <linux/module.h>
25913  #include <linux/kallsyms.h>
25914 +#include <linux/vs_memory.h>
25915  
25916  #include <asm/tlbflush.h>
25917  
25918 diff -NurpP --minimal linux-2.6.24-rc7/mm/shmem.c linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/shmem.c
25919 --- linux-2.6.24-rc7/mm/shmem.c 2007-12-31 17:58:29 +0100
25920 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/shmem.c   2007-12-31 12:34:44 +0100
25921 @@ -55,7 +55,6 @@
25922  #include <asm/pgtable.h>
25923  
25924  /* This magic number is used in glibc for posix shared memory */
25925 -#define TMPFS_MAGIC    0x01021994
25926  
25927  #define ENTRIES_PER_PAGE (PAGE_CACHE_SIZE/sizeof(unsigned long))
25928  #define ENTRIES_PER_PAGEPAGE (ENTRIES_PER_PAGE*ENTRIES_PER_PAGE)
25929 @@ -1723,7 +1722,7 @@ static int shmem_statfs(struct dentry *d
25930  {
25931         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
25932  
25933 -       buf->f_type = TMPFS_MAGIC;
25934 +       buf->f_type = TMPFS_SUPER_MAGIC;
25935         buf->f_bsize = PAGE_CACHE_SIZE;
25936         buf->f_namelen = NAME_MAX;
25937         spin_lock(&sbinfo->stat_lock);
25938 @@ -2288,7 +2287,7 @@ static int shmem_fill_super(struct super
25939         sb->s_maxbytes = SHMEM_MAX_BYTES;
25940         sb->s_blocksize = PAGE_CACHE_SIZE;
25941         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
25942 -       sb->s_magic = TMPFS_MAGIC;
25943 +       sb->s_magic = TMPFS_SUPER_MAGIC;
25944         sb->s_op = &shmem_ops;
25945         sb->s_time_gran = 1;
25946  #ifdef CONFIG_TMPFS_POSIX_ACL
25947 diff -NurpP --minimal linux-2.6.24-rc7/mm/slab.c linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/slab.c
25948 --- linux-2.6.24-rc7/mm/slab.c  2008-01-11 12:00:51 +0100
25949 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/slab.c    2008-01-11 04:30:10 +0100
25950 @@ -509,6 +509,8 @@ struct kmem_cache {
25951  #define STATS_INC_FREEMISS(x)  do { } while (0)
25952  #endif
25953  
25954 +#include "slab_vs.h"
25955 +
25956  #if DEBUG
25957  
25958  /*
25959 @@ -3342,6 +3344,7 @@ retry:
25960  
25961         obj = slab_get_obj(cachep, slabp, nodeid);
25962         check_slabp(cachep, slabp);
25963 +       vx_slab_alloc(cachep, flags);
25964         l3->free_objects--;
25965         /* move slabp to correct slabp list: */
25966         list_del(&slabp->list);
25967 @@ -3414,6 +3417,7 @@ __cache_alloc_node(struct kmem_cache *ca
25968         /* ___cache_alloc_node can fall back to other nodes */
25969         ptr = ____cache_alloc_node(cachep, flags, nodeid);
25970    out:
25971 +       vx_slab_alloc(cachep, flags);
25972         local_irq_restore(save_flags);
25973         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
25974  
25975 @@ -3585,6 +3589,7 @@ static inline void __cache_free(struct k
25976  
25977         check_irq_off();
25978         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
25979 +       vx_slab_free(cachep);
25980  
25981         /*
25982          * Skip calling cache_free_alien() when the platform is not numa.
25983 diff -NurpP --minimal linux-2.6.24-rc7/mm/slab_vs.h linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/slab_vs.h
25984 --- linux-2.6.24-rc7/mm/slab_vs.h       1970-01-01 01:00:00 +0100
25985 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/slab_vs.h 2007-12-13 13:25:42 +0100
25986 @@ -0,0 +1,27 @@
25987 +
25988 +#include <linux/vserver/context.h>
25989 +
25990 +#include <linux/vs_context.h>
25991 +
25992 +static inline
25993 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
25994 +{
25995 +       int what = gfp_zone(cachep->gfpflags);
25996 +
25997 +       if (!current->vx_info)
25998 +               return;
25999 +
26000 +       atomic_add(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
26001 +}
26002 +
26003 +static inline
26004 +void vx_slab_free(struct kmem_cache *cachep)
26005 +{
26006 +       int what = gfp_zone(cachep->gfpflags);
26007 +
26008 +       if (!current->vx_info)
26009 +               return;
26010 +
26011 +       atomic_sub(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
26012 +}
26013 +
26014 diff -NurpP --minimal linux-2.6.24-rc7/mm/swapfile.c linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/swapfile.c
26015 --- linux-2.6.24-rc7/mm/swapfile.c      2007-11-29 01:02:27 +0100
26016 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/mm/swapfile.c        2007-12-13 13:25:37 +0100
26017 @@ -31,6 +31,8 @@
26018  #include <asm/pgtable.h>
26019  #include <asm/tlbflush.h>
26020  #include <linux/swapops.h>
26021 +#include <linux/vs_base.h>
26022 +#include <linux/vs_memory.h>
26023  
26024  DEFINE_SPINLOCK(swap_lock);
26025  unsigned int nr_swapfiles;
26026 @@ -1712,6 +1714,8 @@ void si_swapinfo(struct sysinfo *val)
26027         val->freeswap = nr_swap_pages + nr_to_be_unused;
26028         val->totalswap = total_swap_pages + nr_to_be_unused;
26029         spin_unlock(&swap_lock);
26030 +       if (vx_flags(VXF_VIRT_MEM, 0))
26031 +               vx_vsi_swapinfo(val);
26032  }
26033  
26034  /*
26035 diff -NurpP --minimal linux-2.6.24-rc7/net/core/dev.c linux-2.6.24-rc7-vs2.2.0.5.0.7/net/core/dev.c
26036 --- linux-2.6.24-rc7/net/core/dev.c     2008-01-11 12:00:51 +0100
26037 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/net/core/dev.c       2008-01-11 04:30:11 +0100
26038 @@ -119,6 +119,8 @@
26039  #include <linux/err.h>
26040  #include <linux/ctype.h>
26041  #include <linux/if_arp.h>
26042 +#include <linux/vs_context.h> /* remove with NXF_HIDE_NETIF */
26043 +#include <linux/vs_network.h>
26044  
26045  #include "net-sysfs.h"
26046  
26047 @@ -2327,6 +2329,9 @@ static int dev_ifconf(struct net *net, c
26048  
26049         total = 0;
26050         for_each_netdev(net, dev) {
26051 +               if (vx_flags(VXF_HIDE_NETIF, 0) &&
26052 +                       !dev_in_nx_info(dev, current->nx_info))
26053 +                       continue;
26054                 for (i = 0; i < NPROTO; i++) {
26055                         if (gifconf_list[i]) {
26056                                 int done;
26057 @@ -2392,6 +2397,10 @@ void dev_seq_stop(struct seq_file *seq, 
26058  static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
26059  {
26060         struct net_device_stats *stats = dev->get_stats(dev);
26061 +       struct nx_info *nxi = current->nx_info;
26062 +
26063 +       if (vx_flags(VXF_HIDE_NETIF, 0) && !dev_in_nx_info(dev, nxi))
26064 +               return;
26065  
26066         seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
26067                    "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
26068 diff -NurpP --minimal linux-2.6.24-rc7/net/core/rtnetlink.c linux-2.6.24-rc7-vs2.2.0.5.0.7/net/core/rtnetlink.c
26069 --- linux-2.6.24-rc7/net/core/rtnetlink.c       2007-11-29 01:12:35 +0100
26070 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/net/core/rtnetlink.c 2007-12-13 13:25:31 +0100
26071 @@ -36,6 +36,7 @@
26072  #include <linux/mutex.h>
26073  #include <linux/if_addr.h>
26074  #include <linux/nsproxy.h>
26075 +#include <linux/vs_context.h> /* remove with NXF_HIDE_NETIF */
26076  
26077  #include <asm/uaccess.h>
26078  #include <asm/system.h>
26079 @@ -702,6 +703,9 @@ static int rtnl_dump_ifinfo(struct sk_bu
26080  
26081         idx = 0;
26082         for_each_netdev(net, dev) {
26083 +               if (vx_info_flags(skb->sk->sk_vx_info, VXF_HIDE_NETIF, 0) &&
26084 +                       !dev_in_nx_info(dev, skb->sk->sk_nx_info))
26085 +                       continue;
26086                 if (idx < s_idx)
26087                         goto cont;
26088                 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
26089 diff -NurpP --minimal linux-2.6.24-rc7/net/core/sock.c linux-2.6.24-rc7-vs2.2.0.5.0.7/net/core/sock.c
26090 --- linux-2.6.24-rc7/net/core/sock.c    2007-11-29 01:12:35 +0100
26091 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/net/core/sock.c      2007-12-13 13:25:30 +0100
26092 @@ -126,6 +126,9 @@
26093  #include <linux/ipsec.h>
26094  
26095  #include <linux/filter.h>
26096 +#include <linux/vs_socket.h>
26097 +#include <linux/vs_limit.h>
26098 +#include <linux/vs_context.h>
26099  
26100  #ifdef CONFIG_INET
26101  #include <net/tcp.h>
26102 @@ -889,6 +892,8 @@ static struct sock *sk_prot_alloc(struct
26103                 if (!try_module_get(prot->owner))
26104                         goto out_free_sec;
26105         }
26106 +               sock_vx_init(sk);
26107 +               sock_nx_init(sk);
26108  
26109         return sk;
26110  
26111 @@ -966,6 +971,11 @@ void sk_free(struct sock *sk)
26112                        __FUNCTION__, atomic_read(&sk->sk_omem_alloc));
26113  
26114         put_net(sk->sk_net);
26115 +       vx_sock_dec(sk);
26116 +       clr_vx_info(&sk->sk_vx_info);
26117 +       sk->sk_xid = -1;
26118 +       clr_nx_info(&sk->sk_nx_info);
26119 +       sk->sk_nid = -1;
26120         sk_prot_free(sk->sk_prot_creator, sk);
26121  }
26122  
26123 @@ -981,6 +991,8 @@ struct sock *sk_clone(const struct sock 
26124  
26125                 /* SANITY */
26126                 get_net(newsk->sk_net);
26127 +               sock_vx_init(newsk);
26128 +               sock_nx_init(newsk);
26129                 sk_node_init(&newsk->sk_node);
26130                 sock_lock_init(newsk);
26131                 bh_lock_sock(newsk);
26132 @@ -1027,6 +1039,12 @@ struct sock *sk_clone(const struct sock 
26133                 newsk->sk_priority = 0;
26134                 atomic_set(&newsk->sk_refcnt, 2);
26135  
26136 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
26137 +               newsk->sk_xid = sk->sk_xid;
26138 +               vx_sock_inc(newsk);
26139 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
26140 +               newsk->sk_nid = sk->sk_nid;
26141 +
26142                 /*
26143                  * Increment the counter in the same struct proto as the master
26144                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
26145 @@ -1610,6 +1628,11 @@ void sock_init_data(struct socket *sock,
26146  
26147         sk->sk_stamp = ktime_set(-1L, -1L);
26148  
26149 +       set_vx_info(&sk->sk_vx_info, current->vx_info);
26150 +       sk->sk_xid = vx_current_xid();
26151 +       vx_sock_inc(sk);
26152 +       set_nx_info(&sk->sk_nx_info, current->nx_info);
26153 +       sk->sk_nid = nx_current_nid();
26154         atomic_set(&sk->sk_refcnt, 1);
26155  }
26156  
26157 diff -NurpP --minimal linux-2.6.24-rc7/net/ipv4/af_inet.c linux-2.6.24-rc7-vs2.2.0.5.0.7/net/ipv4/af_inet.c
26158 --- linux-2.6.24-rc7/net/ipv4/af_inet.c 2007-11-29 01:12:36 +0100
26159 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/net/ipv4/af_inet.c   2007-12-13 13:25:43 +0100
26160 @@ -115,6 +115,7 @@
26161  #ifdef CONFIG_IP_MROUTE
26162  #include <linux/mroute.h>
26163  #endif
26164 +#include <linux/vs_limit.h>
26165  
26166  DEFINE_SNMP_STAT(struct linux_mib, net_statistics) __read_mostly;
26167  
26168 @@ -311,9 +312,11 @@ lookup_protocol:
26169         }
26170  
26171         err = -EPERM;
26172 +       if ((protocol == IPPROTO_ICMP) && vx_ccaps(VXC_RAW_ICMP))
26173 +               goto override;
26174         if (answer->capability > 0 && !capable(answer->capability))
26175                 goto out_rcu_unlock;
26176 -
26177 +override:
26178         sock->ops = answer->ops;
26179         answer_prot = answer->prot;
26180         answer_no_check = answer->no_check;
26181 @@ -430,6 +433,10 @@ int inet_bind(struct socket *sock, struc
26182         unsigned short snum;
26183         int chk_addr_ret;
26184         int err;
26185 +       __u32 s_addr;   /* Address used for validation */
26186 +       __u32 s_addr1;  /* Address used for socket */
26187 +       __u32 s_addr2;  /* Broadcast address for the socket */
26188 +       struct nx_info *nxi = sk->sk_nx_info;
26189  
26190         /* If the socket has its own bind function then use it. (RAW) */
26191         if (sk->sk_prot->bind) {
26192 @@ -440,7 +447,40 @@ int inet_bind(struct socket *sock, struc
26193         if (addr_len < sizeof(struct sockaddr_in))
26194                 goto out;
26195  
26196 -       chk_addr_ret = inet_addr_type(addr->sin_addr.s_addr);
26197 +       s_addr = addr->sin_addr.s_addr;
26198 +       s_addr1 = s_addr;
26199 +       s_addr2 = 0xffffffffl;
26200 +
26201 +       vxdprintk(VXD_CBIT(net, 3),
26202 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
26203 +               sk, sk->sk_nx_info, sk->sk_socket,
26204 +               (sk->sk_socket?sk->sk_socket->flags:0),
26205 +               NIPQUAD(s_addr));
26206 +       if (nxi) {
26207 +               __u32 v4_bcast = nxi->v4_bcast;
26208 +               __u32 ipv4root = nxi->ipv4[0];
26209 +               int nbipv4 = nxi->nbipv4;
26210 +
26211 +               if (s_addr == 0) {
26212 +                       /* bind to any for 1-n */
26213 +                       s_addr = ipv4root;
26214 +                       s_addr1 = (nbipv4 > 1) ? 0 : s_addr;
26215 +                       s_addr2 = v4_bcast;
26216 +               } else if (s_addr == IPI_LOOPBACK) {
26217 +                       /* rewrite localhost to ipv4root */
26218 +                       s_addr = ipv4root;
26219 +                       s_addr1 = ipv4root;
26220 +               } else if (s_addr != v4_bcast) {
26221 +                       /* normal address bind */
26222 +                       if (!addr_in_nx_info(nxi, s_addr))
26223 +                               return -EADDRNOTAVAIL;
26224 +               }
26225 +       }
26226 +       chk_addr_ret = inet_addr_type(s_addr);
26227 +
26228 +       vxdprintk(VXD_CBIT(net, 3),
26229 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT ", " NIPQUAD_FMT,
26230 +               sk, NIPQUAD(s_addr), NIPQUAD(s_addr1), NIPQUAD(s_addr2));
26231  
26232         /* Not specified by any standard per-se, however it breaks too
26233          * many applications when removed.  It is unfortunate since
26234 @@ -452,7 +492,7 @@ int inet_bind(struct socket *sock, struc
26235         err = -EADDRNOTAVAIL;
26236         if (!sysctl_ip_nonlocal_bind &&
26237             !inet->freebind &&
26238 -           addr->sin_addr.s_addr != INADDR_ANY &&
26239 +           s_addr != INADDR_ANY &&
26240             chk_addr_ret != RTN_LOCAL &&
26241             chk_addr_ret != RTN_MULTICAST &&
26242             chk_addr_ret != RTN_BROADCAST)
26243 @@ -477,7 +517,8 @@ int inet_bind(struct socket *sock, struc
26244         if (sk->sk_state != TCP_CLOSE || inet->num)
26245                 goto out_release_sock;
26246  
26247 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
26248 +       inet->rcv_saddr = inet->saddr = s_addr1;
26249 +       inet->rcv_saddr2 = s_addr2;
26250         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
26251                 inet->saddr = 0;  /* Use device */
26252  
26253 diff -NurpP --minimal linux-2.6.24-rc7/net/ipv4/devinet.c linux-2.6.24-rc7-vs2.2.0.5.0.7/net/ipv4/devinet.c
26254 --- linux-2.6.24-rc7/net/ipv4/devinet.c 2008-01-11 12:00:52 +0100
26255 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/net/ipv4/devinet.c   2008-01-11 04:30:11 +0100
26256 @@ -56,6 +56,7 @@
26257  #include <linux/sysctl.h>
26258  #endif
26259  #include <linux/kmod.h>
26260 +#include <linux/vs_context.h>
26261  
26262  #include <net/arp.h>
26263  #include <net/ip.h>
26264 @@ -673,6 +674,9 @@ int devinet_ioctl(unsigned int cmd, void
26265                 *colon = ':';
26266  
26267         if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) {
26268 +               struct nx_info *nxi = current->nx_info;
26269 +               int hide_netif = vx_flags(VXF_HIDE_NETIF, 0);
26270 +
26271                 if (tryaddrmatch) {
26272                         /* Matthias Andree */
26273                         /* compare label and address (4.4BSD style) */
26274 @@ -681,6 +685,8 @@ int devinet_ioctl(unsigned int cmd, void
26275                            This is checked above. */
26276                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26277                              ifap = &ifa->ifa_next) {
26278 +                               if (hide_netif && !ifa_in_nx_info(ifa, nxi))
26279 +                                       continue;
26280                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
26281                                     sin_orig.sin_addr.s_addr ==
26282                                                         ifa->ifa_address) {
26283 @@ -693,9 +699,12 @@ int devinet_ioctl(unsigned int cmd, void
26284                    comparing just the label */
26285                 if (!ifa) {
26286                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26287 -                            ifap = &ifa->ifa_next)
26288 +                            ifap = &ifa->ifa_next) {
26289 +                               if (hide_netif && !ifa_in_nx_info(ifa, nxi))
26290 +                                       continue;
26291                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
26292                                         break;
26293 +                       }
26294                 }
26295         }
26296  
26297 @@ -846,6 +855,9 @@ static int inet_gifconf(struct net_devic
26298                 goto out;
26299  
26300         for (; ifa; ifa = ifa->ifa_next) {
26301 +               if (vx_flags(VXF_HIDE_NETIF, 0) &&
26302 +                       !ifa_in_nx_info(ifa, current->nx_info))
26303 +                       continue;
26304                 if (!buf) {
26305                         done += sizeof(ifr);
26306                         continue;
26307 @@ -1178,6 +1190,7 @@ static int inet_dump_ifaddr(struct sk_bu
26308         struct net_device *dev;
26309         struct in_device *in_dev;
26310         struct in_ifaddr *ifa;
26311 +       struct sock *sk = skb->sk;
26312         int s_ip_idx, s_idx = cb->args[0];
26313  
26314         s_ip_idx = ip_idx = cb->args[1];
26315 @@ -1192,6 +1205,9 @@ static int inet_dump_ifaddr(struct sk_bu
26316  
26317                 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
26318                      ifa = ifa->ifa_next, ip_idx++) {
26319 +                       if (sk && vx_info_flags(sk->sk_vx_info, VXF_HIDE_NETIF, 0) &&
26320 +                               !ifa_in_nx_info(ifa, sk->sk_nx_info))
26321 +                               continue;
26322                         if (ip_idx < s_ip_idx)
26323                                 continue;
26324                         if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
26325 diff -NurpP --minimal linux-2.6.24-rc7/net/ipv4/fib_hash.c linux-2.6.24-rc7-vs2.2.0.5.0.7/net/ipv4/fib_hash.c
26326 --- linux-2.6.24-rc7/net/ipv4/fib_hash.c        2007-11-29 01:12:36 +0100
26327 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/net/ipv4/fib_hash.c  2007-12-13 13:25:31 +0100
26328 @@ -34,6 +34,7 @@
26329  #include <linux/skbuff.h>
26330  #include <linux/netlink.h>
26331  #include <linux/init.h>
26332 +#include <linux/vs_context.h>
26333  
26334  #include <net/net_namespace.h>
26335  #include <net/ip.h>
26336 @@ -983,6 +984,8 @@ static unsigned fib_flag_trans(int type,
26337         return flags;
26338  }
26339  
26340 +extern int dev_in_nx_info(struct net_device *, struct nx_info *);
26341 +
26342  /*
26343   *     This outputs /proc/net/route.
26344   *
26345 @@ -1013,7 +1016,8 @@ static int fib_seq_show(struct seq_file 
26346         prefix  = f->fn_key;
26347         mask    = FZ_MASK(iter->zone);
26348         flags   = fib_flag_trans(fa->fa_type, mask, fi);
26349 -       if (fi)
26350 +       if (fi && (!vx_flags(VXF_HIDE_NETIF, 0) ||
26351 +               dev_in_nx_info(fi->fib_dev, current->nx_info)))
26352                 snprintf(bf, sizeof(bf),
26353                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u",
26354                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
26355 diff -NurpP --minimal linux-2.6.24-rc7/net/ipv4/inet_connection_sock.c linux-2.6.24-rc7-vs2.2.0.5.0.7/net/ipv4/inet_connection_sock.c
26356 --- linux-2.6.24-rc7/net/ipv4/inet_connection_sock.c    2007-11-29 01:12:36 +0100
26357 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/net/ipv4/inet_connection_sock.c      2007-12-13 13:25:30 +0100
26358 @@ -50,7 +50,6 @@ EXPORT_SYMBOL(inet_get_local_port_range)
26359  int inet_csk_bind_conflict(const struct sock *sk,
26360                            const struct inet_bind_bucket *tb)
26361  {
26362 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
26363         struct sock *sk2;
26364         struct hlist_node *node;
26365         int reuse = sk->sk_reuse;
26366 @@ -63,9 +62,8 @@ int inet_csk_bind_conflict(const struct 
26367                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
26368                         if (!reuse || !sk2->sk_reuse ||
26369                             sk2->sk_state == TCP_LISTEN) {
26370 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
26371 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
26372 -                                   sk2_rcv_saddr == sk_rcv_saddr)
26373 +                               if (nx_addr_conflict(sk->sk_nx_info,
26374 +                                       inet_rcv_saddr(sk), sk2))
26375                                         break;
26376                         }
26377                 }
26378 diff -NurpP --minimal linux-2.6.24-rc7/net/ipv4/inet_diag.c linux-2.6.24-rc7-vs2.2.0.5.0.7/net/ipv4/inet_diag.c
26379 --- linux-2.6.24-rc7/net/ipv4/inet_diag.c       2007-12-31 17:58:29 +0100
26380 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/net/ipv4/inet_diag.c 2007-12-31 12:34:46 +0100
26381 @@ -729,6 +729,8 @@ static int inet_diag_dump(struct sk_buff
26382                         sk_for_each(sk, node, &hashinfo->listening_hash[i]) {
26383                                 struct inet_sock *inet = inet_sk(sk);
26384  
26385 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26386 +                                       continue;
26387                                 if (num < s_num) {
26388                                         num++;
26389                                         continue;
26390 @@ -790,6 +792,8 @@ skip_listen_ht:
26391                 sk_for_each(sk, node, &head->chain) {
26392                         struct inet_sock *inet = inet_sk(sk);
26393  
26394 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26395 +                               continue;
26396                         if (num < s_num)
26397                                 goto next_normal;
26398                         if (!(r->idiag_states & (1 << sk->sk_state)))
26399 @@ -814,6 +818,8 @@ next_normal:
26400                         inet_twsk_for_each(tw, node,
26401                                     &head->twchain) {
26402  
26403 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
26404 +                                       continue;
26405                                 if (num < s_num)
26406                                         goto next_dying;
26407                                 if (r->id.idiag_sport != tw->tw_sport &&
26408 diff -NurpP --minimal linux-2.6.24-rc7/net/ipv4/inet_hashtables.c linux-2.6.24-rc7-vs2.2.0.5.0.7/net/ipv4/inet_hashtables.c
26409 --- linux-2.6.24-rc7/net/ipv4/inet_hashtables.c 2007-11-29 01:12:36 +0100
26410 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/net/ipv4/inet_hashtables.c   2007-12-13 13:25:30 +0100
26411 @@ -140,11 +140,10 @@ static struct sock *inet_lookup_listener
26412                         const __be32 rcv_saddr = inet->rcv_saddr;
26413                         int score = sk->sk_family == PF_INET ? 1 : 0;
26414  
26415 -                       if (rcv_saddr) {
26416 -                               if (rcv_saddr != daddr)
26417 -                                       continue;
26418 +                       if (inet_addr_match(sk->sk_nx_info, daddr, rcv_saddr))
26419                                 score += 2;
26420 -                       }
26421 +                       else
26422 +                               continue;
26423                         if (sk->sk_bound_dev_if) {
26424                                 if (sk->sk_bound_dev_if != dif)
26425                                         continue;
26426 @@ -175,7 +174,7 @@ struct sock *__inet_lookup_listener(stru
26427                 const struct inet_sock *inet = inet_sk((sk = __sk_head(head)));
26428  
26429                 if (inet->num == hnum && !sk->sk_node.next &&
26430 -                   (!inet->rcv_saddr || inet->rcv_saddr == daddr) &&
26431 +                   inet_addr_match(sk->sk_nx_info, daddr, inet->rcv_saddr) &&
26432                     (sk->sk_family == PF_INET || !ipv6_only_sock(sk)) &&
26433                     !sk->sk_bound_dev_if)
26434                         goto sherry_cache;
26435 diff -NurpP --minimal linux-2.6.24-rc7/net/ipv4/netfilter.c linux-2.6.24-rc7-vs2.2.0.5.0.7/net/ipv4/netfilter.c
26436 --- linux-2.6.24-rc7/net/ipv4/netfilter.c       2007-11-29 01:12:36 +0100
26437 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/net/ipv4/netfilter.c 2007-12-13 17:05:46 +0100
26438 @@ -4,7 +4,7 @@
26439  #include <linux/netfilter_ipv4.h>
26440  #include <linux/ip.h>
26441  #include <linux/skbuff.h>
26442 -#include <net/route.h>
26443 +// #include <net/route.h>
26444  #include <net/xfrm.h>
26445  #include <net/ip.h>
26446  
26447 diff -NurpP --minimal linux-2.6.24-rc7/net/ipv4/raw.c linux-2.6.24-rc7-vs2.2.0.5.0.7/net/ipv4/raw.c
26448 --- linux-2.6.24-rc7/net/ipv4/raw.c     2007-11-29 01:12:36 +0100
26449 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/net/ipv4/raw.c       2007-12-13 13:25:31 +0100
26450 @@ -102,6 +102,27 @@ static void raw_v4_unhash(struct sock *s
26451         write_unlock_bh(&raw_v4_lock);
26452  }
26453  
26454 +
26455 +/*
26456 + *     Check if a given address matches for a socket
26457 + *
26458 + *     nxi:            the socket's nx_info if any
26459 + *     addr:           to be verified address
26460 + *     saddr/baddr:    socket addresses
26461 + */
26462 +static inline int raw_addr_match (
26463 +       struct nx_info *nxi,
26464 +       uint32_t addr,
26465 +       uint32_t saddr,
26466 +       uint32_t baddr)
26467 +{
26468 +       if (addr && (saddr == addr || baddr == addr))
26469 +               return 1;
26470 +       if (!saddr)
26471 +               return addr_in_nx_info(nxi, addr);
26472 +       return 0;
26473 +}
26474 +
26475  struct sock *__raw_v4_lookup(struct sock *sk, unsigned short num,
26476                              __be32 raddr, __be32 laddr,
26477                              int dif)
26478 @@ -113,7 +134,8 @@ struct sock *__raw_v4_lookup(struct sock
26479  
26480                 if (inet->num == num                                    &&
26481                     !(inet->daddr && inet->daddr != raddr)              &&
26482 -                   !(inet->rcv_saddr && inet->rcv_saddr != laddr)      &&
26483 +                   raw_addr_match(sk->sk_nx_info, laddr,
26484 +                       inet->rcv_saddr, inet->rcv_saddr2)              &&
26485                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
26486                         goto found; /* gotcha */
26487         }
26488 @@ -318,6 +340,11 @@ static int raw_send_hdrinc(struct sock *
26489                 icmp_out_count(((struct icmphdr *)
26490                         skb_transport_header(skb))->type);
26491  
26492 +       err = -EPERM;
26493 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW)
26494 +               && (!addr_in_nx_info(sk->sk_nx_info, iph->saddr)))
26495 +               goto error_free;
26496 +
26497         err = NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
26498                       dst_output);
26499         if (err > 0)
26500 @@ -329,6 +356,7 @@ out:
26501  
26502  error_fault:
26503         err = -EFAULT;
26504 +error_free:
26505         kfree_skb(skb);
26506  error:
26507         IP_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
26508 @@ -495,6 +523,12 @@ static int raw_sendmsg(struct kiocb *ioc
26509                 }
26510  
26511                 security_sk_classify_flow(sk, &fl);
26512 +               if (sk->sk_nx_info) {
26513 +                       err = ip_find_src(sk->sk_nx_info, &rt, &fl);
26514 +
26515 +                       if (err)
26516 +                               goto done;
26517 +               }
26518                 err = ip_route_output_flow(&rt, &fl, sk, 1);
26519         }
26520         if (err)
26521 @@ -802,7 +836,8 @@ static struct sock *raw_get_first(struct
26522                 struct hlist_node *node;
26523  
26524                 sk_for_each(sk, node, &raw_v4_htable[state->bucket])
26525 -                       if (sk->sk_family == PF_INET)
26526 +                       if (sk->sk_family == PF_INET &&
26527 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26528                                 goto found;
26529         }
26530         sk = NULL;
26531 @@ -818,7 +853,8 @@ static struct sock *raw_get_next(struct 
26532                 sk = sk_next(sk);
26533  try_again:
26534                 ;
26535 -       } while (sk && sk->sk_family != PF_INET);
26536 +       } while (sk && (sk->sk_family != PF_INET ||
26537 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
26538  
26539         if (!sk && ++state->bucket < RAWV4_HTABLE_SIZE) {
26540                 sk = sk_head(&raw_v4_htable[state->bucket]);
26541 diff -NurpP --minimal linux-2.6.24-rc7/net/ipv4/tcp.c linux-2.6.24-rc7-vs2.2.0.5.0.7/net/ipv4/tcp.c
26542 --- linux-2.6.24-rc7/net/ipv4/tcp.c     2007-11-29 01:12:36 +0100
26543 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/net/ipv4/tcp.c       2007-12-13 13:25:25 +0100
26544 @@ -259,6 +259,7 @@
26545  #include <linux/cache.h>
26546  #include <linux/err.h>
26547  #include <linux/crypto.h>
26548 +#include <linux/in.h>
26549  
26550  #include <net/icmp.h>
26551  #include <net/tcp.h>
26552 diff -NurpP --minimal linux-2.6.24-rc7/net/ipv4/tcp_ipv4.c linux-2.6.24-rc7-vs2.2.0.5.0.7/net/ipv4/tcp_ipv4.c
26553 --- linux-2.6.24-rc7/net/ipv4/tcp_ipv4.c        2007-12-31 17:58:32 +0100
26554 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/net/ipv4/tcp_ipv4.c  2007-12-31 12:34:47 +0100
26555 @@ -1979,6 +1979,12 @@ static void *listening_get_next(struct s
26556                 req = req->dl_next;
26557                 while (1) {
26558                         while (req) {
26559 +                               vxdprintk(VXD_CBIT(net, 6),
26560 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
26561 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
26562 +                               if (req->sk &&
26563 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
26564 +                                       continue;
26565                                 if (req->rsk_ops->family == st->family) {
26566                                         cur = req;
26567                                         goto out;
26568 @@ -2003,6 +2009,10 @@ get_req:
26569         }
26570  get_sk:
26571         sk_for_each_from(sk, node) {
26572 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
26573 +                       sk, sk->sk_nid, nx_current_nid());
26574 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26575 +                       continue;
26576                 if (sk->sk_family == st->family) {
26577                         cur = sk;
26578                         goto out;
26579 @@ -2052,18 +2062,26 @@ static void *established_get_first(struc
26580  
26581                 read_lock_bh(lock);
26582                 sk_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
26583 -                       if (sk->sk_family != st->family) {
26584 +                       vxdprintk(VXD_CBIT(net, 6),
26585 +                               "sk,egf: %p [#%d] (from %d)",
26586 +                               sk, sk->sk_nid, nx_current_nid());
26587 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26588 +                               continue;
26589 +                       if (sk->sk_family != st->family)
26590                                 continue;
26591 -                       }
26592                         rc = sk;
26593                         goto out;
26594                 }
26595                 st->state = TCP_SEQ_STATE_TIME_WAIT;
26596                 inet_twsk_for_each(tw, node,
26597                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
26598 -                       if (tw->tw_family != st->family) {
26599 +                       vxdprintk(VXD_CBIT(net, 6),
26600 +                               "tw: %p [#%d] (from %d)",
26601 +                               tw, tw->tw_nid, nx_current_nid());
26602 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
26603 +                               continue;
26604 +                       if (tw->tw_family != st->family)
26605                                 continue;
26606 -                       }
26607                         rc = tw;
26608                         goto out;
26609                 }
26610 @@ -2087,7 +2105,8 @@ static void *established_get_next(struct
26611                 tw = cur;
26612                 tw = tw_next(tw);
26613  get_tw:
26614 -               while (tw && tw->tw_family != st->family) {
26615 +               while (tw && (tw->tw_family != st->family ||
26616 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
26617                         tw = tw_next(tw);
26618                 }
26619                 if (tw) {
26620 @@ -2108,6 +2127,11 @@ get_tw:
26621                 sk = sk_next(sk);
26622  
26623         sk_for_each_from(sk, node) {
26624 +               vxdprintk(VXD_CBIT(net, 6),
26625 +                       "sk,egn: %p [#%d] (from %d)",
26626 +                       sk, sk->sk_nid, nx_current_nid());
26627 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26628 +                       continue;
26629                 if (sk->sk_family == st->family)
26630                         goto found;
26631         }
26632 diff -NurpP --minimal linux-2.6.24-rc7/net/ipv4/tcp_minisocks.c linux-2.6.24-rc7-vs2.2.0.5.0.7/net/ipv4/tcp_minisocks.c
26633 --- linux-2.6.24-rc7/net/ipv4/tcp_minisocks.c   2007-11-29 01:12:36 +0100
26634 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/net/ipv4/tcp_minisocks.c     2007-12-13 13:25:30 +0100
26635 @@ -28,6 +28,10 @@
26636  #include <net/inet_common.h>
26637  #include <net/xfrm.h>
26638  
26639 +#include <linux/vs_limit.h>
26640 +#include <linux/vs_socket.h>
26641 +#include <linux/vs_context.h>
26642 +
26643  #ifdef CONFIG_SYSCTL
26644  #define SYNC_INIT 0 /* let the user enable it */
26645  #else
26646 @@ -293,6 +297,11 @@ void tcp_time_wait(struct sock *sk, int 
26647                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
26648                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
26649  
26650 +               tw->tw_xid              = sk->sk_xid;
26651 +               tw->tw_vx_info          = NULL;
26652 +               tw->tw_nid              = sk->sk_nid;
26653 +               tw->tw_nx_info          = NULL;
26654 +
26655  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
26656                 if (tw->tw_family == PF_INET6) {
26657                         struct ipv6_pinfo *np = inet6_sk(sk);
26658 diff -NurpP --minimal linux-2.6.24-rc7/net/ipv4/udp.c linux-2.6.24-rc7-vs2.2.0.5.0.7/net/ipv4/udp.c
26659 --- linux-2.6.24-rc7/net/ipv4/udp.c     2007-11-29 01:12:37 +0100
26660 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/net/ipv4/udp.c       2007-12-13 13:25:52 +0100
26661 @@ -230,11 +230,8 @@ int udp_get_port(struct sock *sk, unsign
26662  
26663  int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
26664  {
26665 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
26666 -
26667         return  ( !ipv6_only_sock(sk2)  &&
26668 -                 (!inet1->rcv_saddr || !inet2->rcv_saddr ||
26669 -                  inet1->rcv_saddr == inet2->rcv_saddr      ));
26670 +                  nx_addr_conflict(sk1->sk_nx_info, inet_rcv_saddr(sk1), sk2));
26671  }
26672  
26673  static inline int udp_v4_get_port(struct sock *sk, unsigned short snum)
26674 @@ -255,15 +252,22 @@ static struct sock *__udp4_lib_lookup(__
26675         int badness = -1;
26676  
26677         read_lock(&udp_hash_lock);
26678 +
26679         sk_for_each(sk, node, &udptable[hnum & (UDP_HTABLE_SIZE - 1)]) {
26680                 struct inet_sock *inet = inet_sk(sk);
26681  
26682                 if (sk->sk_hash == hnum && !ipv6_only_sock(sk)) {
26683                         int score = (sk->sk_family == PF_INET ? 1 : 0);
26684 +
26685                         if (inet->rcv_saddr) {
26686                                 if (inet->rcv_saddr != daddr)
26687                                         continue;
26688                                 score+=2;
26689 +                       } else if (sk->sk_nx_info) {
26690 +                               if (addr_in_nx_info(sk->sk_nx_info, daddr))
26691 +                                       score+=2;
26692 +                               else
26693 +                                       continue;
26694                         }
26695                         if (inet->daddr) {
26696                                 if (inet->daddr != saddr)
26697 @@ -289,6 +293,7 @@ static struct sock *__udp4_lib_lookup(__
26698                         }
26699                 }
26700         }
26701 +
26702         if (result)
26703                 sock_hold(result);
26704         read_unlock(&udp_hash_lock);
26705 @@ -310,7 +315,8 @@ static inline struct sock *udp_v4_mcast_
26706                 if (s->sk_hash != hnum                                  ||
26707                     (inet->daddr && inet->daddr != rmt_addr)            ||
26708                     (inet->dport != rmt_port && inet->dport)            ||
26709 -                   (inet->rcv_saddr && inet->rcv_saddr != loc_addr)    ||
26710 +                   (inet->rcv_saddr && inet->rcv_saddr != loc_addr &&
26711 +                    inet->rcv_saddr2 && inet->rcv_saddr2 != loc_addr)  ||
26712                     ipv6_only_sock(s)                                   ||
26713                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
26714                         continue;
26715 @@ -642,7 +648,20 @@ int udp_sendmsg(struct kiocb *iocb, stru
26716                                     .uli_u = { .ports =
26717                                                { .sport = inet->sport,
26718                                                  .dport = dport } } };
26719 +               struct nx_info *nxi = sk->sk_nx_info;
26720 +
26721                 security_sk_classify_flow(sk, &fl);
26722 +               if (nxi) {
26723 +                       err = ip_find_src(nxi, &rt, &fl);
26724 +                       if (err)
26725 +                               goto out;
26726 +                       if (daddr == IPI_LOOPBACK && !nx_check(0, VS_ADMIN))
26727 +                               daddr = fl.fl4_dst = nxi->ipv4[0];
26728 +#ifdef CONFIG_VSERVER_REMAP_SADDR
26729 +                       if (saddr == IPI_LOOPBACK && !nx_check(0, VS_ADMIN))
26730 +                               saddr = fl.fl4_src = nxi->ipv4[0];
26731 +#endif
26732 +               }
26733                 err = ip_route_output_flow(&rt, &fl, sk, 1);
26734                 if (err) {
26735                         if (err == -ENETUNREACH)
26736 @@ -1468,7 +1487,8 @@ static struct sock *udp_get_first(struct
26737         for (state->bucket = 0; state->bucket < UDP_HTABLE_SIZE; ++state->bucket) {
26738                 struct hlist_node *node;
26739                 sk_for_each(sk, node, state->hashtable + state->bucket) {
26740 -                       if (sk->sk_family == state->family)
26741 +                       if (sk->sk_family == state->family &&
26742 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26743                                 goto found;
26744                 }
26745         }
26746 @@ -1485,7 +1505,8 @@ static struct sock *udp_get_next(struct 
26747                 sk = sk_next(sk);
26748  try_again:
26749                 ;
26750 -       } while (sk && sk->sk_family != state->family);
26751 +       } while (sk && (sk->sk_family != state->family ||
26752 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
26753  
26754         if (!sk && ++state->bucket < UDP_HTABLE_SIZE) {
26755                 sk = sk_head(state->hashtable + state->bucket);
26756 diff -NurpP --minimal linux-2.6.24-rc7/net/ipv6/addrconf.c linux-2.6.24-rc7-vs2.2.0.5.0.7/net/ipv6/addrconf.c
26757 --- linux-2.6.24-rc7/net/ipv6/addrconf.c        2007-12-31 17:58:32 +0100
26758 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/net/ipv6/addrconf.c  2007-12-31 12:34:47 +0100
26759 @@ -2796,7 +2796,10 @@ static void if6_seq_stop(struct seq_file
26760  static int if6_seq_show(struct seq_file *seq, void *v)
26761  {
26762         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
26763 -       seq_printf(seq,
26764 +
26765 +       /* no ipv6 inside a vserver for now */
26766 +       if (nx_check(0, VS_ADMIN|VS_WATCH))
26767 +               seq_printf(seq,
26768                    NIP6_SEQFMT " %02x %02x %02x %02x %8s\n",
26769                    NIP6(ifp->addr),
26770                    ifp->idev->dev->ifindex,
26771 @@ -3263,6 +3266,10 @@ static int inet6_dump_addr(struct sk_buf
26772         struct ifmcaddr6 *ifmca;
26773         struct ifacaddr6 *ifaca;
26774  
26775 +       /* no ipv6 inside a vserver for now */
26776 +       if (skb->sk && skb->sk->sk_vx_info)
26777 +               return skb->len;
26778 +
26779         s_idx = cb->args[0];
26780         s_ip_idx = ip_idx = cb->args[1];
26781  
26782 @@ -3586,6 +3593,10 @@ static int inet6_dump_ifinfo(struct sk_b
26783         struct net_device *dev;
26784         struct inet6_dev *idev;
26785  
26786 +       /* no ipv6 inside a vserver for now */
26787 +       if (skb->sk && skb->sk->sk_vx_info)
26788 +               return skb->len;
26789 +
26790         read_lock(&dev_base_lock);
26791         idx = 0;
26792         for_each_netdev(&init_net, dev) {
26793 diff -NurpP --minimal linux-2.6.24-rc7/net/netlink/af_netlink.c linux-2.6.24-rc7-vs2.2.0.5.0.7/net/netlink/af_netlink.c
26794 --- linux-2.6.24-rc7/net/netlink/af_netlink.c   2007-11-29 01:12:40 +0100
26795 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/net/netlink/af_netlink.c     2007-12-13 13:25:25 +0100
26796 @@ -56,6 +56,9 @@
26797  #include <linux/audit.h>
26798  #include <linux/selinux.h>
26799  #include <linux/mutex.h>
26800 +#include <linux/vs_context.h>
26801 +#include <linux/vs_network.h>
26802 +#include <linux/vs_limit.h>
26803  
26804  #include <net/net_namespace.h>
26805  #include <net/sock.h>
26806 diff -NurpP --minimal linux-2.6.24-rc7/net/socket.c linux-2.6.24-rc7-vs2.2.0.5.0.7/net/socket.c
26807 --- linux-2.6.24-rc7/net/socket.c       2007-11-29 01:12:40 +0100
26808 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/net/socket.c 2007-12-13 13:25:49 +0100
26809 @@ -93,6 +93,8 @@
26810  
26811  #include <net/sock.h>
26812  #include <linux/netfilter.h>
26813 +#include <linux/vs_base.h>
26814 +#include <linux/vs_socket.h>
26815  
26816  static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
26817  static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
26818 @@ -543,7 +545,7 @@ static inline int __sock_sendmsg(struct 
26819                                  struct msghdr *msg, size_t size)
26820  {
26821         struct sock_iocb *si = kiocb_to_siocb(iocb);
26822 -       int err;
26823 +       int err, len;
26824  
26825         si->sock = sock;
26826         si->scm = NULL;
26827 @@ -554,7 +556,22 @@ static inline int __sock_sendmsg(struct 
26828         if (err)
26829                 return err;
26830  
26831 -       return sock->ops->sendmsg(iocb, sock, msg, size);
26832 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
26833 +       if (sock->sk) {
26834 +               if (len == size)
26835 +                       vx_sock_send(sock->sk, size);
26836 +               else
26837 +                       vx_sock_fail(sock->sk, size);
26838 +       }
26839 +       vxdprintk(VXD_CBIT(net, 7),
26840 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
26841 +               sock, sock->sk,
26842 +               (sock->sk)?sock->sk->sk_nx_info:0,
26843 +               (sock->sk)?sock->sk->sk_vx_info:0,
26844 +               (sock->sk)?sock->sk->sk_xid:0,
26845 +               (sock->sk)?sock->sk->sk_nid:0,
26846 +               (unsigned int)size, len);
26847 +       return len;
26848  }
26849  
26850  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
26851 @@ -623,7 +640,7 @@ EXPORT_SYMBOL_GPL(__sock_recv_timestamp)
26852  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
26853                                  struct msghdr *msg, size_t size, int flags)
26854  {
26855 -       int err;
26856 +       int err, len;
26857         struct sock_iocb *si = kiocb_to_siocb(iocb);
26858  
26859         si->sock = sock;
26860 @@ -636,7 +653,18 @@ static inline int __sock_recvmsg(struct 
26861         if (err)
26862                 return err;
26863  
26864 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
26865 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
26866 +       if ((len >= 0) && sock->sk)
26867 +               vx_sock_recv(sock->sk, len);
26868 +       vxdprintk(VXD_CBIT(net, 7),
26869 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
26870 +               sock, sock->sk,
26871 +               (sock->sk)?sock->sk->sk_nx_info:0,
26872 +               (sock->sk)?sock->sk->sk_vx_info:0,
26873 +               (sock->sk)?sock->sk->sk_xid:0,
26874 +               (sock->sk)?sock->sk->sk_nid:0,
26875 +               (unsigned int)size, len);
26876 +       return len;
26877  }
26878  
26879  int sock_recvmsg(struct socket *sock, struct msghdr *msg,
26880 @@ -1091,6 +1119,10 @@ static int __sock_create(struct net *net
26881         if (type < 0 || type >= SOCK_MAX)
26882                 return -EINVAL;
26883  
26884 +       /* disable IPv6 inside vservers for now */
26885 +       if (family == PF_INET6 && !nx_check(0, VS_ADMIN))
26886 +               return -EAFNOSUPPORT;
26887 +
26888         /* Compatibility.
26889  
26890            This uglymoron is moved from INET layer to here to avoid
26891 @@ -1208,6 +1240,7 @@ asmlinkage long sys_socket(int family, i
26892         if (retval < 0)
26893                 goto out;
26894  
26895 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
26896         retval = sock_map_fd(sock);
26897         if (retval < 0)
26898                 goto out_release;
26899 @@ -1240,10 +1273,12 @@ asmlinkage long sys_socketpair(int famil
26900         err = sock_create(family, type, protocol, &sock1);
26901         if (err < 0)
26902                 goto out;
26903 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
26904  
26905         err = sock_create(family, type, protocol, &sock2);
26906         if (err < 0)
26907                 goto out_release_1;
26908 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
26909  
26910         err = sock1->ops->socketpair(sock1, sock2);
26911         if (err < 0)
26912 diff -NurpP --minimal linux-2.6.24-rc7/net/sunrpc/auth.c linux-2.6.24-rc7-vs2.2.0.5.0.7/net/sunrpc/auth.c
26913 --- linux-2.6.24-rc7/net/sunrpc/auth.c  2007-11-29 01:02:38 +0100
26914 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/net/sunrpc/auth.c    2007-12-13 13:25:51 +0100
26915 @@ -13,6 +13,7 @@
26916  #include <linux/errno.h>
26917  #include <linux/sunrpc/clnt.h>
26918  #include <linux/spinlock.h>
26919 +#include <linux/vs_tag.h>
26920  
26921  #ifdef RPC_DEBUG
26922  # define RPCDBG_FACILITY       RPCDBG_AUTH
26923 @@ -339,6 +340,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
26924         struct auth_cred acred = {
26925                 .uid = current->fsuid,
26926                 .gid = current->fsgid,
26927 +               .tag = dx_current_tag(),
26928                 .group_info = current->group_info,
26929         };
26930         struct rpc_cred *ret;
26931 @@ -375,6 +377,7 @@ rpcauth_bindcred(struct rpc_task *task)
26932         struct auth_cred acred = {
26933                 .uid = current->fsuid,
26934                 .gid = current->fsgid,
26935 +               .tag = dx_current_tag(),
26936                 .group_info = current->group_info,
26937         };
26938         struct rpc_cred *ret;
26939 diff -NurpP --minimal linux-2.6.24-rc7/net/sunrpc/auth_unix.c linux-2.6.24-rc7-vs2.2.0.5.0.7/net/sunrpc/auth_unix.c
26940 --- linux-2.6.24-rc7/net/sunrpc/auth_unix.c     2007-11-29 01:02:38 +0100
26941 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/net/sunrpc/auth_unix.c       2007-12-13 13:25:51 +0100
26942 @@ -11,12 +11,14 @@
26943  #include <linux/module.h>
26944  #include <linux/sunrpc/clnt.h>
26945  #include <linux/sunrpc/auth.h>
26946 +#include <linux/vs_tag.h>
26947  
26948  #define NFS_NGROUPS    16
26949  
26950  struct unx_cred {
26951         struct rpc_cred         uc_base;
26952         gid_t                   uc_gid;
26953 +       tag_t                   uc_tag;
26954         gid_t                   uc_gids[NFS_NGROUPS];
26955  };
26956  #define uc_uid                 uc_base.cr_uid
26957 @@ -73,6 +75,7 @@ unx_create_cred(struct rpc_auth *auth, s
26958         if (flags & RPCAUTH_LOOKUP_ROOTCREDS) {
26959                 cred->uc_uid = 0;
26960                 cred->uc_gid = 0;
26961 +               cred->uc_tag = dx_current_tag();
26962                 cred->uc_gids[0] = NOGROUP;
26963         } else {
26964                 int groups = acred->group_info->ngroups;
26965 @@ -80,6 +83,7 @@ unx_create_cred(struct rpc_auth *auth, s
26966                         groups = NFS_NGROUPS;
26967  
26968                 cred->uc_gid = acred->gid;
26969 +               cred->uc_tag = acred->tag;
26970                 for (i = 0; i < groups; i++)
26971                         cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
26972                 if (i < NFS_NGROUPS)
26973 @@ -124,7 +128,8 @@ unx_match(struct auth_cred *acred, struc
26974                 int groups;
26975  
26976                 if (cred->uc_uid != acred->uid
26977 -                || cred->uc_gid != acred->gid)
26978 +                || cred->uc_gid != acred->gid
26979 +                || cred->uc_tag != acred->tag)
26980                         return 0;
26981  
26982                 groups = acred->group_info->ngroups;
26983 @@ -150,7 +155,7 @@ unx_marshal(struct rpc_task *task, __be3
26984         struct rpc_clnt *clnt = task->tk_client;
26985         struct unx_cred *cred = container_of(task->tk_msg.rpc_cred, struct unx_cred, uc_base);
26986         __be32          *base, *hold;
26987 -       int             i;
26988 +       int             i, tag;
26989  
26990         *p++ = htonl(RPC_AUTH_UNIX);
26991         base = p++;
26992 @@ -160,9 +165,12 @@ unx_marshal(struct rpc_task *task, __be3
26993          * Copy the UTS nodename captured when the client was created.
26994          */
26995         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
26996 +       tag = task->tk_client->cl_tag;
26997  
26998 -       *p++ = htonl((u32) cred->uc_uid);
26999 -       *p++ = htonl((u32) cred->uc_gid);
27000 +       *p++ = htonl((u32) TAGINO_UID(tag,
27001 +               cred->uc_uid, cred->uc_tag));
27002 +       *p++ = htonl((u32) TAGINO_GID(tag,
27003 +               cred->uc_gid, cred->uc_tag));
27004         hold = p++;
27005         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
27006                 *p++ = htonl((u32) cred->uc_gids[i]);
27007 diff -NurpP --minimal linux-2.6.24-rc7/net/sunrpc/clnt.c linux-2.6.24-rc7-vs2.2.0.5.0.7/net/sunrpc/clnt.c
27008 --- linux-2.6.24-rc7/net/sunrpc/clnt.c  2007-11-29 01:12:40 +0100
27009 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/net/sunrpc/clnt.c    2007-12-13 13:25:51 +0100
27010 @@ -30,6 +30,7 @@
27011  #include <linux/smp_lock.h>
27012  #include <linux/utsname.h>
27013  #include <linux/workqueue.h>
27014 +#include <linux/vs_cvirt.h>
27015  
27016  #include <linux/sunrpc/clnt.h>
27017  #include <linux/sunrpc/rpc_pipe_fs.h>
27018 @@ -298,7 +299,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
27019                 clnt->cl_autobind = 1;
27020         if (args->flags & RPC_CLNT_CREATE_DISCRTRY)
27021                 clnt->cl_discrtry = 1;
27022 -
27023 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
27024 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
27025 +               clnt->cl_tag = 1; */
27026         return clnt;
27027  }
27028  EXPORT_SYMBOL_GPL(rpc_create);
27029 diff -NurpP --minimal linux-2.6.24-rc7/net/unix/af_unix.c linux-2.6.24-rc7-vs2.2.0.5.0.7/net/unix/af_unix.c
27030 --- linux-2.6.24-rc7/net/unix/af_unix.c 2007-12-31 17:58:32 +0100
27031 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/net/unix/af_unix.c   2007-12-31 12:34:48 +0100
27032 @@ -116,6 +116,8 @@
27033  #include <linux/mount.h>
27034  #include <net/checksum.h>
27035  #include <linux/security.h>
27036 +#include <linux/vs_context.h>
27037 +#include <linux/vs_limit.h>
27038  
27039  int sysctl_unix_max_dgram_qlen __read_mostly = 10;
27040  
27041 @@ -279,6 +281,8 @@ static struct sock *__unix_find_socket_b
27042         sk_for_each(s, node, &unix_socket_table[hash ^ type]) {
27043                 struct unix_sock *u = unix_sk(s);
27044  
27045 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27046 +                       continue;
27047                 if (u->addr->len == len &&
27048                     !memcmp(u->addr->name, sunname, len))
27049                         goto found;
27050 @@ -839,7 +843,7 @@ static int unix_bind(struct socket *sock
27051                  */
27052                 mode = S_IFSOCK |
27053                        (SOCK_INODE(sock)->i_mode & ~current->fs->umask);
27054 -               err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);
27055 +               err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0, NULL);
27056                 if (err)
27057                         goto out_mknod_dput;
27058                 mutex_unlock(&nd.dentry->d_inode->i_mutex);
27059 diff -NurpP --minimal linux-2.6.24-rc7/net/x25/af_x25.c linux-2.6.24-rc7-vs2.2.0.5.0.7/net/x25/af_x25.c
27060 --- linux-2.6.24-rc7/net/x25/af_x25.c   2007-11-29 01:12:41 +0100
27061 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/net/x25/af_x25.c     2007-12-13 13:25:30 +0100
27062 @@ -506,7 +506,10 @@ static int x25_create(struct net *net, s
27063  
27064         x25 = x25_sk(sk);
27065  
27066 -       sock_init_data(sock, sk);
27067 +       sk->sk_socket = sock;
27068 +       sk->sk_type = sock->type;
27069 +       sk->sk_sleep = &sock->wait;
27070 +       sock->sk = sk;
27071  
27072         x25_init_timers(sk);
27073  
27074 diff -NurpP --minimal linux-2.6.24-rc7/scripts/checksyscalls.sh linux-2.6.24-rc7-vs2.2.0.5.0.7/scripts/checksyscalls.sh
27075 --- linux-2.6.24-rc7/scripts/checksyscalls.sh   2007-11-29 01:12:41 +0100
27076 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/scripts/checksyscalls.sh     2007-12-15 02:10:00 +0100
27077 @@ -108,7 +108,6 @@ cat << EOF
27078  #define __IGNORE_afs_syscall
27079  #define __IGNORE_getpmsg
27080  #define __IGNORE_putpmsg
27081 -#define __IGNORE_vserver
27082  EOF
27083  }
27084  
27085 diff -NurpP --minimal linux-2.6.24-rc7/security/commoncap.c linux-2.6.24-rc7-vs2.2.0.5.0.7/security/commoncap.c
27086 --- linux-2.6.24-rc7/security/commoncap.c       2007-12-31 17:58:32 +0100
27087 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/security/commoncap.c 2007-12-31 12:34:48 +0100
27088 @@ -24,6 +24,7 @@
27089  #include <linux/hugetlb.h>
27090  #include <linux/mount.h>
27091  #include <linux/sched.h>
27092 +#include <linux/vs_context.h>
27093  
27094  #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
27095  /*
27096 @@ -46,7 +47,7 @@ EXPORT_SYMBOL(securebits);
27097  
27098  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
27099  {
27100 -       NETLINK_CB(skb).eff_cap = current->cap_effective;
27101 +       cap_t(NETLINK_CB(skb).eff_cap) = vx_mbcap(cap_effective);
27102         return 0;
27103  }
27104  
27105 @@ -62,7 +63,7 @@ EXPORT_SYMBOL(cap_netlink_recv);
27106  int cap_capable (struct task_struct *tsk, int cap)
27107  {
27108         /* Derived from include/linux/sched.h:capable. */
27109 -       if (cap_raised(tsk->cap_effective, cap))
27110 +       if (vx_cap_raised(tsk->vx_info, tsk->cap_effective, cap))
27111                 return 0;
27112         return -EPERM;
27113  }
27114 @@ -314,7 +315,8 @@ void cap_bprm_apply_creds (struct linux_
27115         /* Derived from fs/exec.c:compute_creds. */
27116         kernel_cap_t new_permitted, working;
27117  
27118 -       new_permitted = cap_intersect (bprm->cap_permitted, cap_bset);
27119 +       new_permitted = cap_intersect (bprm->cap_permitted,
27120 +                                       vx_current_cap_bset());
27121         working = cap_intersect (bprm->cap_inheritable,
27122                                  current->cap_inheritable);
27123         new_permitted = cap_combine (new_permitted, working);
27124 @@ -586,7 +588,8 @@ void cap_task_reparent_to_init (struct t
27125  
27126  int cap_syslog (int type)
27127  {
27128 -       if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
27129 +       if ((type != 3 && type != 10) &&
27130 +               !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
27131                 return -EPERM;
27132         return 0;
27133  }
27134 diff -NurpP --minimal linux-2.6.24-rc7/security/dummy.c linux-2.6.24-rc7-vs2.2.0.5.0.7/security/dummy.c
27135 --- linux-2.6.24-rc7/security/dummy.c   2007-12-31 17:58:32 +0100
27136 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/security/dummy.c     2007-12-31 12:34:48 +0100
27137 @@ -27,6 +27,7 @@
27138  #include <linux/hugetlb.h>
27139  #include <linux/ptrace.h>
27140  #include <linux/file.h>
27141 +#include <linux/vs_context.h>
27142  
27143  static int dummy_ptrace (struct task_struct *parent, struct task_struct *child)
27144  {
27145 @@ -689,7 +690,7 @@ static int dummy_sem_semop (struct sem_a
27146  
27147  static int dummy_netlink_send (struct sock *sk, struct sk_buff *skb)
27148  {
27149 -       NETLINK_CB(skb).eff_cap = current->cap_effective;
27150 +       cap_t(NETLINK_CB(skb).eff_cap) = vx_mbcap(cap_effective);
27151         return 0;
27152  }
27153  
27154 diff -NurpP --minimal linux-2.6.24-rc7/security/selinux/hooks.c linux-2.6.24-rc7-vs2.2.0.5.0.7/security/selinux/hooks.c
27155 --- linux-2.6.24-rc7/security/selinux/hooks.c   2007-11-29 01:12:42 +0100
27156 +++ linux-2.6.24-rc7-vs2.2.0.5.0.7/security/selinux/hooks.c     2007-12-13 13:25:25 +0100
27157 @@ -61,7 +61,6 @@
27158  #include <linux/dccp.h>
27159  #include <linux/quota.h>
27160  #include <linux/un.h>          /* for Unix socket types */
27161 -#include <net/af_unix.h>       /* for Unix socket types */
27162  #include <linux/parser.h>
27163  #include <linux/nfs_mount.h>
27164  #include <net/ipv6.h>
This page took 2.196914 seconds and 3 git commands to generate.